KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwt > awt > Dialog


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: Dialog.java,v $
11    Revision 1.10 2004/04/19 15:43:25 bobintetley
12    Missing (and incorrect) Dialog/JDialog constructors implemented
13
14    Revision 1.9 2004/04/18 20:07:09 bobintetley
15    GTK2 repainting bug fixed
16
17    Revision 1.8 2004/04/16 10:19:06 dannaab
18    Misc bug fixes, InputMap implementation, preliminary undo support
19
20    Revision 1.7 2004/03/31 08:47:49 bobintetley
21    Fixed JFileChooser no border bug (fault with JDialog empty constructor)
22
23    Revision 1.6 2004/03/22 15:10:21 bobintetley
24    JRootPane and JLayeredPane implementation
25
26    Revision 1.5 2004/03/18 14:42:10 bobintetley
27    Fix to Window hierarchy to match Swing, and fix to allow MDI apps
28       to work under SWT 2.x
29
30    Revision 1.4 2004/01/15 10:11:14 bobintetley
31    Fixed AWT constructors/hierarchy
32
33    Revision 1.3 2003/12/14 09:13:38 bobintetley
34    Added CVS log to source headers
35
36 */

37
38 package swingwt.awt;
39
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.widgets.Shell;
42
43 import swingwtx.swing.SwingUtilities;
44
45 public class Dialog extends Window {
46
47     protected boolean isModal = true;
48
49     public Dialog() { this((Frame) null, "", true); }
50     public Dialog(String JavaDoc title) { this((Frame) null, title, true); }
51     public Dialog(swingwt.awt.Dialog owner) { this(owner, "", true); }
52     public Dialog(swingwt.awt.Dialog owner, boolean modal) { this(owner, "", modal); }
53     public Dialog(swingwt.awt.Dialog owner, String JavaDoc title) { this(owner, title, true); }
54     public Dialog(swingwt.awt.Dialog owner, String JavaDoc title, boolean modal) { this(owner, title, true, null); }
55     public Dialog(swingwt.awt.Dialog owner, String JavaDoc title, boolean modal, GraphicsConfiguration gc) { super(owner, modal); setModal(modal); setTitle(title); }
56     public Dialog(Frame owner) { this(owner, "", true); }
57     public Dialog(Frame owner, boolean modal) { this(owner, "", modal); }
58     public Dialog(Frame owner, String JavaDoc title) { this(owner, title, true); }
59     public Dialog(Frame owner, String JavaDoc title, boolean modal) { this(owner, title, true, null); }
60     public Dialog(Frame owner, String JavaDoc title, boolean modal, GraphicsConfiguration gc) { super(owner, modal); setModal(modal); setTitle(title); }
61
62     public void setResizable(boolean b) { }
63     public boolean isResizable() { return true; }
64     public void setModal(boolean b) { isModal = b; }
65     public boolean isModal() { return isModal; }
66
67     /** Overridden from Window to force private events dispatching */
68     public void setVisible(final boolean b) {
69         final Dialog me = this;
70         SwingUtilities.invokeSync(new Runnable JavaDoc() {
71             public void run() {
72                 if (b) {
73
74                     // Dialogs create their own new event dispatcher. This means
75
// that whatever thread spawns the dialog gets tied up (it's ok
76
// it its an existing dispatch thread).
77
// Thus, the dialog blocks until it is closed and events are
78
// handled just fine.
79
if (isModal) {
80                         peer.open();
81             repaintFix();
82                         dispatchEvents();
83                     }
84                     else
85                     {
86                         // If the dialog doesn't want to be modal, then we need
87
// to recreate a new peer without the modal bit. Since we need
88
// to make a decision during construction, we guess modal since
89
// 99% of dialogs are modal.
90

91                         // Remember size, location, image and title of the old peer
92
Dimension size = getSize();
93                         Point location = getLocation();
94                         String JavaDoc title = getTitle();
95                         Image image = getIconImage();
96
97                         // Destroy our old peer
98
peer.dispose();
99
100                         // Create a new peer without modality and reattach the root pane
101
// containing the components + re-register the peer for window events
102
peer = new Shell(display, SWT.DIALOG_TRIM);
103                         composite = peer;
104                         peer.setLayout(new swingwt.awt.swtcustomlayout.SWTBorderLayout());
105                         try { rootPane.setSwingWTParent(me); } catch (Exception JavaDoc e) { e.printStackTrace(); }
106                         peer.setLayoutData(swingwt.awt.swtcustomlayout.SWTBorderLayout.CENTER);
107                         registerWindowEvents();
108
109                         // Set properties again
110
setSize(size);
111                         setLocation(location);
112                         setTitle(title);
113                         setIconImage(image);
114
115                         // Display the peer and fire events
116
peer.open();
117                         processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_OPENED);
118             repaintFix();
119                     }
120                 }
121                 else {
122                     // If the Window is already closing because the user hit the x
123
// button, don't do anything
124
if (isClosed) return;
125                     peer.close();
126                 }
127             }
128         });
129     }
130
131 }
132
Popular Tags