samer@0
|
1 /*
|
samer@0
|
2 * Dialog.java
|
samer@0
|
3 *
|
samer@0
|
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
5 * All rights reserved.
|
samer@0
|
6 *
|
samer@0
|
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
8 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
9 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
10 */
|
samer@0
|
11
|
samer@0
|
12 package samer.core.util.heavy;
|
samer@0
|
13 import samer.core.*;
|
samer@0
|
14 import java.awt.*;
|
samer@0
|
15 import java.awt.event.*;
|
samer@0
|
16
|
samer@0
|
17 public class Dialog extends java.awt.Dialog implements ActionListener, Shell.Dialog
|
samer@0
|
18 {
|
samer@0
|
19 String result;
|
samer@0
|
20 Container panel;
|
samer@0
|
21 Panel buttons;
|
samer@0
|
22
|
samer@0
|
23 public Dialog( java.awt.Frame owner, String nm, boolean modal)
|
samer@0
|
24 {
|
samer@0
|
25 super(owner,nm,modal);
|
samer@0
|
26
|
samer@0
|
27 panel = new JPanel(Border.create(Border.NONE));
|
samer@0
|
28 panel.setLayout(new GridLayout(0,1));
|
samer@0
|
29 buttons=new Panel(); // JPanel(Border.create(Border.NONE));
|
samer@0
|
30 buttons.setLayout( new FlowLayout(FlowLayout.RIGHT,6,2));
|
samer@0
|
31
|
samer@0
|
32 setFont(X.font(Shell.datum("dialog.font"),null));
|
samer@0
|
33 setLayout( new BorderLayout());
|
samer@0
|
34 add( panel, "Center");
|
samer@0
|
35 add( buttons, "South");
|
samer@0
|
36 addWindowListener( new WindowAdapter() {
|
samer@0
|
37 public void windowClosing(WindowEvent e) {
|
samer@0
|
38 result = "close";
|
samer@0
|
39 setVisible(false);
|
samer@0
|
40 }
|
samer@0
|
41 } );
|
samer@0
|
42 }
|
samer@0
|
43
|
samer@0
|
44 protected void finalize() { Shell.trace("Dialog finalizing"); }
|
samer@0
|
45
|
samer@0
|
46 public void actionPerformed(ActionEvent e)
|
samer@0
|
47 {
|
samer@0
|
48 result=e.getActionCommand();
|
samer@0
|
49 setVisible(false);
|
samer@0
|
50
|
samer@0
|
51 //String cmd=e.getActionCommand();
|
samer@0
|
52 //if (cmd=="ok") { result=cmd; setVisible(false); }
|
samer@0
|
53 //else if (cmd=="cancel") { result=cmd; setVisible(false); }
|
samer@0
|
54 }
|
samer@0
|
55
|
samer@0
|
56 public Container container() { return panel; }
|
samer@0
|
57 public String result() { return result; }
|
samer@0
|
58 public void expose() { pack(); centre(); setVisible(true); toFront(); }
|
samer@0
|
59
|
samer@0
|
60 public void centre()
|
samer@0
|
61 {
|
samer@0
|
62 Dimension d=getSize();
|
samer@0
|
63 setLocation( (SX-d.width)/2, (SY-d.height)/2);
|
samer@0
|
64 }
|
samer@0
|
65
|
samer@0
|
66 public void addAction(String label)
|
samer@0
|
67 {
|
samer@0
|
68 Button btn=new Button(label);
|
samer@0
|
69 btn.addActionListener(this);
|
samer@0
|
70 buttons.add(btn);
|
samer@0
|
71 }
|
samer@0
|
72
|
samer@0
|
73 private static int SX, SY; // screen width and height
|
samer@0
|
74 static {
|
samer@0
|
75 Dimension s=Toolkit.getDefaultToolkit().getScreenSize();
|
samer@0
|
76 SX=s.width;
|
samer@0
|
77 SY=s.height;
|
samer@0
|
78 }
|
samer@0
|
79 }
|
samer@0
|
80
|