KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > JFrame


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: JFrame.java,v $
11    Revision 1.22 2004/03/22 15:10:22 bobintetley
12    JRootPane and JLayeredPane implementation
13
14    Revision 1.21 2004/03/18 15:13:22 bobintetley
15    Temporary fix to getRootPane()
16
17    Revision 1.20 2004/03/18 14:42:11 bobintetley
18    Fix to Window hierarchy to match Swing, and fix to allow MDI apps
19       to work under SWT 2.x
20
21    Revision 1.19 2004/01/26 08:11:00 bobintetley
22    Many bugfixes and addition of SwingSet
23
24    Revision 1.18 2004/01/16 09:35:47 bobintetley
25    Full event dispatch thread support!
26
27    Revision 1.17 2004/01/02 11:24:03 bobintetley
28    Frame extended states now work correctly
29
30    Revision 1.16 2003/12/15 18:29:57 bobintetley
31    Changed setParent() method to setSwingWTParent() to avoid conflicts with applications
32
33    Revision 1.15 2003/12/15 17:39:12 bobintetley
34    Missing implementations completed
35
36    Revision 1.14 2003/12/15 15:54:25 bobintetley
37    Additional core methods
38
39    Revision 1.13 2003/12/14 09:13:38 bobintetley
40    Added CVS log to source headers
41
42 */

43
44
45 package swingwtx.swing;
46
47 import swingwt.awt.Component;
48 import swingwt.awt.Container;
49 import swingwt.awt.GraphicsConfiguration;
50
51 public class JFrame extends swingwt.awt.Frame implements WindowConstants, RootPaneContainer {
52
53     public final static int NORMAL = 0;
54     public final static int ICONIFIED = 1;
55     public final static int MAXIMIZED_HORIZ = 2;
56     public final static int MAXIMIZED_VERT = 3;
57     public final static int MAXIMIZED_BOTH = 4;
58     
59     protected int closeOperation = WindowConstants.DISPOSE_ON_CLOSE;
60     
61     protected boolean isMax = false;
62     
63     public JFrame() { super();}
64     public JFrame(String JavaDoc title) {super(title); }
65     public JFrame(GraphicsConfiguration gc) { super(gc); }
66     
67     public int getExtendedState() {
68         if (isIcon) return ICONIFIED;
69         return NORMAL;
70     }
71     
72     public void setExtendedState(final int state) {
73         SwingUtilities.invokeSync(new Runnable JavaDoc() {
74            public void run() {
75                 if ( ((state & MAXIMIZED_BOTH) > 0) ||
76                     ((state & MAXIMIZED_HORIZ) > 0) ||
77                     ((state & MAXIMIZED_VERT) > 0) ) {
78                     peer.setMaximized(true);
79                     isMax = true;
80                 }
81                 else {
82                     peer.setMaximized(false);
83                     isMax = false;
84                 }
85
86                 if ((state & ICONIFIED) > 0) {
87                     peer.setMinimized(true);
88                     isIcon = true;
89                 }
90                 else {
91                     peer.setMinimized(false);
92                     isIcon = false;
93                 }
94            }
95         });
96     }
97     
98     /** Handy for layout problems. Toggles the window between
99      * max/norm according to what is set and guarantees
100      * relayout of components
101      */

102     public void toggleWindowState() {
103         SwingUtilities.invokeSync(new Runnable JavaDoc() {
104             public void run() {
105                if (isMax) {
106                    peer.setMaximized(false);
107                    peer.setMaximized(true);
108                }
109                else
110                {
111                    peer.setMaximized(true);
112                    peer.setMaximized(false);
113                }
114             }
115         });
116     }
117     
118     public int getDefaultCloseOperation() {
119         return closeOperation;
120     }
121     
122     public void setDefaultCloseOperation(int operation) {
123         closeOperation = operation;
124     }
125     
126     public Container getContentPane() {
127         return rootPane.getContentPane();
128     }
129     
130     public Component getGlassPane() {
131         return rootPane.getGlassPane();
132     }
133     
134     public JLayeredPane getLayeredPane() {
135         return rootPane.getLayeredPane();
136     }
137     
138     public JRootPane getRootPane() {
139         return rootPane;
140     }
141     
142     public void setContentPane(Container contentPane) {
143         rootPane.setContentPane(contentPane);
144     }
145     
146     public void setGlassPane(Component glassPane) {
147         rootPane.setGlassPane(glassPane);
148     }
149     
150     public void setLayeredPane(JLayeredPane layeredPane) {
151         rootPane.setLayeredPane(layeredPane);
152     }
153     
154     public void registerWindowEvents() {
155         
156         // Overriden here so we can manage default close operations.
157

158         peer.addShellListener(new org.eclipse.swt.events.ShellListener() {
159             public void shellActivated(org.eclipse.swt.events.ShellEvent e) {
160                 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_ACTIVATED);
161             }
162             public void shellClosed(org.eclipse.swt.events.ShellEvent e) {
163                 isClosed = true;
164                 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_CLOSING);
165                 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_CLOSED);
166                 // See what's set for the default close operation and handle it
167
switch (closeOperation) {
168                     case WindowConstants.DISPOSE_ON_CLOSE: e.doit = true; SwingWTUtils.decrementWindowReferences(); break;
169                     case WindowConstants.DO_NOTHING_ON_CLOSE: e.doit = false; break;
170                     case WindowConstants.EXIT_ON_CLOSE: e.doit = true; SwingWTUtils.decrementWindowReferences(); System.exit(0); break;
171                     case WindowConstants.HIDE_ON_CLOSE: e.doit = false; peer.setVisible(false); break;
172                 }
173             }
174             public void shellDeactivated(org.eclipse.swt.events.ShellEvent e) {
175                 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_DEACTIVATED);
176             }
177             public void shellDeiconified(org.eclipse.swt.events.ShellEvent e) {
178                 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_DEICONIFIED);
179             }
180             public void shellIconified(org.eclipse.swt.events.ShellEvent e) {
181                 processWindowEvent(swingwt.awt.event.WindowEvent.WINDOW_ICONIFIED);
182             }
183         });
184     }
185     
186 }
187
Popular Tags