diff src/samer/core_/util/swing/Dialog.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/samer/core_/util/swing/Dialog.java	Tue Jan 17 17:50:20 2012 +0000
@@ -0,0 +1,67 @@
+/*
+ *	Dialog.java
+ *
+ *	Copyright (c) 2000, Samer Abdallah, King's College London.
+ *	All rights reserved.
+ *
+ *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
+ *	without even the implied warranty of MERCHANTABILITY or 
+ *	FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+package samer.core.util.swing;
+import  samer.core.*;
+import  java.awt.*;
+import  java.awt.event.*;
+import  javax.swing.*;
+
+public class Dialog extends JDialog implements ActionListener, Shell.Dialog
+{
+	String	result;
+	Box	buttons;
+
+	public Dialog( java.awt.Frame owner, String nm, boolean modal)
+	{
+		super(owner,nm,modal);
+		buttons=new Box(BoxLayout.X_AXIS);
+		buttons.add( Box.createHorizontalGlue());
+		container().setLayout( new BorderLayout());
+		container().add( buttons, "South");
+		setDefaultCloseOperation(HIDE_ON_CLOSE);
+	}
+
+	public Dialog(String nm, boolean modal)
+	{
+		setModal(modal);
+		setTitle(nm);
+
+		buttons=new Box(BoxLayout.X_AXIS);
+		buttons.add( Box.createHorizontalGlue());
+		container().setLayout( new BorderLayout());
+		container().add( buttons, "South");
+		setDefaultCloseOperation(HIDE_ON_CLOSE);
+	}
+
+	protected void finalize() { Shell.trace("SDialog finalizing"); }
+
+	public void actionPerformed(ActionEvent e)
+	{
+		result=e.getActionCommand();
+		Shell.trace("closing dialog: "+result);
+		setVisible(false);
+	}
+
+	public void centre() { setLocationRelativeTo(null); }
+
+	public Container container() { return getContentPane(); }
+	public String	result() { return result; }
+	public void expose() { result="close"; pack(); centre(); setVisible(true); }
+
+	public void addAction(String label)
+	{
+		JButton btn=new JButton(label);
+		btn.addActionListener(this);
+		buttons.add(btn);
+	}
+}
+