comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Dialog.java
3 *
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
5 * All rights reserved.
6 *
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
8 * without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE.
10 */
11
12 package samer.core.util.swing;
13 import samer.core.*;
14 import java.awt.*;
15 import java.awt.event.*;
16 import javax.swing.*;
17
18 public class Dialog extends JDialog implements ActionListener, Shell.Dialog
19 {
20 String result;
21 Box buttons;
22
23 public Dialog( java.awt.Frame owner, String nm, boolean modal)
24 {
25 super(owner,nm,modal);
26 buttons=new Box(BoxLayout.X_AXIS);
27 buttons.add( Box.createHorizontalGlue());
28 container().setLayout( new BorderLayout());
29 container().add( buttons, "South");
30 setDefaultCloseOperation(HIDE_ON_CLOSE);
31 }
32
33 public Dialog(String nm, boolean modal)
34 {
35 setModal(modal);
36 setTitle(nm);
37
38 buttons=new Box(BoxLayout.X_AXIS);
39 buttons.add( Box.createHorizontalGlue());
40 container().setLayout( new BorderLayout());
41 container().add( buttons, "South");
42 setDefaultCloseOperation(HIDE_ON_CLOSE);
43 }
44
45 protected void finalize() { Shell.trace("SDialog finalizing"); }
46
47 public void actionPerformed(ActionEvent e)
48 {
49 result=e.getActionCommand();
50 Shell.trace("closing dialog: "+result);
51 setVisible(false);
52 }
53
54 public void centre() { setLocationRelativeTo(null); }
55
56 public Container container() { return getContentPane(); }
57 public String result() { return result; }
58 public void expose() { result="close"; pack(); centre(); setVisible(true); }
59
60 public void addAction(String label)
61 {
62 JButton btn=new JButton(label);
63 btn.addActionListener(this);
64 buttons.add(btn);
65 }
66 }
67