KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > common > DialogPanel


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  */

23 package org.enhydra.tool.common;
24
25 // Standard imports
26
import java.awt.BorderLayout JavaDoc;
27 import java.awt.Window JavaDoc;
28 import java.awt.Dialog JavaDoc;
29 import java.awt.Frame JavaDoc;
30 import java.awt.Point JavaDoc;
31 import java.awt.event.WindowEvent JavaDoc;
32 import javax.swing.JDialog JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.JOptionPane JavaDoc;
35
36 //
37
public class DialogPanel extends JPanel JavaDoc {
38     public final static int CANCEL_OPTION = JOptionPane.CANCEL_OPTION;
39     public final static int OK_OPTION = JOptionPane.OK_OPTION;
40
41     //
42
private int option = DialogPanel.CANCEL_OPTION;
43     private LocalDialog dialog = null;
44     private Window JavaDoc owner = null;
45     private boolean windowClose = false;
46     private boolean standalone = false;
47     private boolean modal = true;
48     private String JavaDoc title = new String JavaDoc();
49
50     public Window JavaDoc getOwner() {
51         return owner;
52     }
53
54     public void setOwner(Window JavaDoc w) {
55         owner = w;
56     }
57
58     public String JavaDoc getTitle() {
59         return title;
60     }
61
62     public void setTitle(String JavaDoc t) {
63         title = t;
64     }
65
66     public boolean isModal() {
67         return modal;
68     }
69
70     public void setModal(boolean b) {
71         modal = b;
72     }
73
74     public int getOption() {
75         return option;
76     }
77
78     public void setOption(int o) {
79         option = o;
80     }
81
82     public LocalDialog getDialog() {
83         return dialog;
84     }
85
86     public void startDialogThread() {
87         Thread JavaDoc dialogThread = new Thread JavaDoc() {
88             public void run() {
89                 showDialog();
90             }
91
92         };
93
94         dialogThread.start();
95     }
96
97     public int showDialog() {
98         BorderLayout JavaDoc layout = null;
99         Point JavaDoc cp = null;
100
101         if (dialog == null) {
102             if (getOwner() == null) {
103                 dialog = new LocalDialog();
104             } else if (getOwner() instanceof Frame JavaDoc) {
105                 dialog = new LocalDialog((Frame JavaDoc) getOwner());
106             } else if (getOwner() instanceof Dialog JavaDoc) {
107                 dialog = new LocalDialog((Dialog JavaDoc) getOwner());
108             } else {
109                 dialog = new LocalDialog();
110             }
111         }
112         dialog.setModal(isModal());
113         dialog.setTitle(getTitle());
114         layout = new BorderLayout JavaDoc();
115         dialog.getRootPane().setLayout(layout);
116         dialog.getRootPane().add(this, BorderLayout.CENTER);
117         dialog.pack();
118         cp = SwingUtil.getCenteringPoint(dialog.getSize());
119         dialog.setLocation(cp);
120         dialog.show();
121         return option;
122     }
123
124     //
125
// PROTECTED
126
//
127
protected void hideDialog() {
128         if (dialog != null) {
129             dialog.setVisible(false);
130         }
131     }
132
133     protected void clearDialog() {
134         if (dialog != null) {
135             dialog.setVisible(false);
136             dialog.getRootPane().removeAll();
137             dialog.removeAll();
138             dialog.dispose();
139         }
140         if (isStandalone()) {
141             System.exit(0);
142         }
143     }
144
145     protected boolean isWindowClose() {
146         return windowClose;
147     }
148
149     protected void setWindowClose(boolean b) {
150         windowClose = b;
151     }
152
153     protected boolean isStandalone() {
154         return standalone;
155     }
156
157     protected void setStandalone(boolean b) {
158         standalone = b;
159     }
160
161     private class LocalDialog extends JDialog JavaDoc {
162         public LocalDialog() {
163             super();
164         }
165
166         public LocalDialog(Dialog JavaDoc owner) {
167             super(owner);
168         }
169
170         public LocalDialog(Frame JavaDoc owner) {
171             super(owner);
172         }
173
174         protected void processWindowEvent(WindowEvent JavaDoc e) {
175             if (isWindowClose()) {
176                 if (e.getID() == WindowEvent.WINDOW_CLOSING) {
177                     clearDialog();
178                 }
179                 super.processWindowEvent(e);
180             }
181         }
182
183     }
184 }
185
Popular Tags