comparison src/samer/core_/util/heavy/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.heavy;
13 import samer.core.*;
14 import java.awt.*;
15 import java.awt.event.*;
16
17 public class Dialog extends java.awt.Dialog implements ActionListener, Shell.Dialog
18 {
19 String result;
20 Container panel;
21 Panel buttons;
22
23 public Dialog( java.awt.Frame owner, String nm, boolean modal)
24 {
25 super(owner,nm,modal);
26
27 panel = new JPanel(Border.create(Border.NONE));
28 panel.setLayout(new GridLayout(0,1));
29 buttons=new Panel(); // JPanel(Border.create(Border.NONE));
30 buttons.setLayout( new FlowLayout(FlowLayout.RIGHT,6,2));
31
32 setFont(X.font(Shell.datum("dialog.font"),null));
33 setLayout( new BorderLayout());
34 add( panel, "Center");
35 add( buttons, "South");
36 addWindowListener( new WindowAdapter() {
37 public void windowClosing(WindowEvent e) {
38 result = "close";
39 setVisible(false);
40 }
41 } );
42 }
43
44 protected void finalize() { Shell.trace("Dialog finalizing"); }
45
46 public void actionPerformed(ActionEvent e)
47 {
48 result=e.getActionCommand();
49 setVisible(false);
50
51 //String cmd=e.getActionCommand();
52 //if (cmd=="ok") { result=cmd; setVisible(false); }
53 //else if (cmd=="cancel") { result=cmd; setVisible(false); }
54 }
55
56 public Container container() { return panel; }
57 public String result() { return result; }
58 public void expose() { pack(); centre(); setVisible(true); toFront(); }
59
60 public void centre()
61 {
62 Dimension d=getSize();
63 setLocation( (SX-d.width)/2, (SY-d.height)/2);
64 }
65
66 public void addAction(String label)
67 {
68 Button btn=new Button(label);
69 btn.addActionListener(this);
70 buttons.add(btn);
71 }
72
73 private static int SX, SY; // screen width and height
74 static {
75 Dimension s=Toolkit.getDefaultToolkit().getScreenSize();
76 SX=s.width;
77 SY=s.height;
78 }
79 }
80