KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > designer > view > ValueDialog


1 /*
2  * (c) Rob Gordon 2005.
3  */

4 package org.oddjob.designer.view;
5
6 import java.awt.Component JavaDoc;
7 import java.awt.Dialog JavaDoc;
8 import java.awt.Frame JavaDoc;
9 import java.awt.GridBagConstraints JavaDoc;
10 import java.awt.GridBagLayout JavaDoc;
11 import java.awt.Window JavaDoc;
12 import java.awt.event.ActionEvent JavaDoc;
13 import java.awt.event.ActionListener JavaDoc;
14
15 import javax.swing.JButton JavaDoc;
16 import javax.swing.JDialog JavaDoc;
17
18 /**
19  *
20  */

21 public class ValueDialog extends JDialog JavaDoc {
22     
23     public ValueDialog(Component JavaDoc form) {
24         super();
25         setForm(form);
26     }
27     
28     public ValueDialog(Dialog JavaDoc dialog, Component JavaDoc form) {
29         super(dialog);
30         setLocationRelativeTo(dialog);
31         setForm(form);
32     }
33     
34     public ValueDialog(Frame JavaDoc frame, Component JavaDoc form) {
35         super(frame);
36         setLocationRelativeTo(frame);
37         setForm(form);
38     }
39     
40     void setForm(Component JavaDoc form) {
41         getContentPane().setLayout(new GridBagLayout JavaDoc());
42         GridBagConstraints JavaDoc c = new GridBagConstraints JavaDoc();
43         c.gridx = 0;
44         c.gridy = 0;
45         c.weightx = 1;
46         c.weighty = 1;
47         c.fill = GridBagConstraints.BOTH;
48         getContentPane().add(form, c);
49         
50         JButton JavaDoc ok = new JButton JavaDoc("OK");
51         ok.addActionListener(new ActionListener JavaDoc() {
52             public void actionPerformed(ActionEvent JavaDoc e) {
53                 setVisible(false);
54             }
55         });
56         
57         c.gridx = 0;
58         c.gridy = 1;
59         c.weightx = 0;
60         c.weighty = 0;
61         c.fill = GridBagConstraints.NONE;
62         getContentPane().add(ok, c);
63         setModal(true);
64     }
65     
66     public static void showDialog(Component JavaDoc parent, Component JavaDoc form) {
67 // Window w = SwingUtilities.windowForComponent(parent);
68
Window JavaDoc w = ViewHelper.getWindowForComponent(parent);
69         ValueDialog valueDialog = null;
70         if (w instanceof Frame JavaDoc) {
71             valueDialog = new ValueDialog((Frame JavaDoc) w, form);
72         } else {
73             valueDialog = new ValueDialog((Dialog JavaDoc) w, form);
74         }
75         valueDialog.pack();
76         valueDialog.setVisible(true);
77     }
78
79
80 }
81
82
Popular Tags