1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52:
53: import ;
54: import ;
55:
56:
68: public class JFrame extends Frame
69: implements WindowConstants, RootPaneContainer, Accessible
70: {
71:
74: protected class AccessibleJFrame extends Frame.AccessibleAWTFrame
75: {
76:
79: protected AccessibleJFrame()
80: {
81: super();
82:
83: }
84: }
85:
86:
94: public static final int EXIT_ON_CLOSE = 3;
95:
96: private static final long serialVersionUID = -3362141868504252139L;
97: private static boolean defaultLookAndFeelDecorated;
98: private int closeAction = HIDE_ON_CLOSE;
99: protected AccessibleContext accessibleContext;
100: protected JRootPane rootPane;
101:
102:
105: protected boolean rootPaneCheckingEnabled = false;
106:
107:
110: public JFrame()
111: {
112: super("");
113: frameInit();
114: }
115:
116:
121: public JFrame(String title)
122: {
123: super(title);
124: frameInit();
125: }
126:
127:
136: public JFrame(GraphicsConfiguration gc)
137: {
138: super(gc);
139: frameInit();
140: }
141:
142:
152: public JFrame(String title, GraphicsConfiguration gc)
153: {
154: super(title, gc);
155: frameInit();
156: }
157:
158: protected void frameInit()
159: {
160: super.setLayout(new BorderLayout());
161: setBackground(UIManager.getDefaults().getColor("control"));
162: enableEvents(AWTEvent.WINDOW_EVENT_MASK);
163: getRootPane();
164:
165:
166: if (isDefaultLookAndFeelDecorated()
167: && UIManager.getLookAndFeel().getSupportsWindowDecorations())
168: {
169: setUndecorated(true);
170: getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
171: }
172:
173:
174: setRootPaneCheckingEnabled(true);
175: }
176:
177: public Dimension getPreferredSize()
178: {
179: return super.getPreferredSize();
180: }
181:
182: public JMenuBar getJMenuBar()
183: {
184: return getRootPane().getJMenuBar();
185: }
186:
187: public void setJMenuBar(JMenuBar menubar)
188: {
189: getRootPane().setJMenuBar(menubar);
190: }
191:
192: public void setLayout(LayoutManager manager)
193: {
194:
195:
196: if (isRootPaneCheckingEnabled())
197: getContentPane().setLayout(manager);
198: else
199: super.setLayout(manager);
200: }
201:
202: public void setLayeredPane(JLayeredPane layeredPane)
203: {
204: getRootPane().setLayeredPane(layeredPane);
205: }
206:
207: public JLayeredPane getLayeredPane()
208: {
209: return getRootPane().getLayeredPane();
210: }
211:
212: public JRootPane getRootPane()
213: {
214: if (rootPane == null)
215: setRootPane(createRootPane());
216: return rootPane;
217: }
218:
219: protected void setRootPane(JRootPane root)
220: {
221: if (rootPane != null)
222: remove(rootPane);
223:
224: rootPane = root;
225: add(rootPane, BorderLayout.CENTER);
226: }
227:
228: protected JRootPane createRootPane()
229: {
230: return new JRootPane();
231: }
232:
233: public Container getContentPane()
234: {
235: return getRootPane().getContentPane();
236: }
237:
238: public void setContentPane(Container contentPane)
239: {
240: getRootPane().setContentPane(contentPane);
241: }
242:
243: public Component getGlassPane()
244: {
245: return getRootPane().getGlassPane();
246: }
247:
248: public void setGlassPane(Component glassPane)
249: {
250: getRootPane().setGlassPane(glassPane);
251: }
252:
253: protected void addImpl(Component comp, Object constraints, int index)
254: {
255:
256:
257: if (isRootPaneCheckingEnabled())
258: getContentPane().add(comp,constraints,index);
259: else
260: super.addImpl(comp, constraints, index);
261: }
262:
263: public void remove(Component comp)
264: {
265:
266:
267: if (comp==rootPane)
268: super.remove(rootPane);
269: else
270: getContentPane().remove(comp);
271: }
272:
273: protected boolean isRootPaneCheckingEnabled()
274: {
275: return rootPaneCheckingEnabled;
276: }
277:
278: protected void setRootPaneCheckingEnabled(boolean enabled)
279: {
280: rootPaneCheckingEnabled = enabled;
281: }
282:
283: public void update(Graphics g)
284: {
285: paint(g);
286: }
287:
288: protected void processKeyEvent(KeyEvent e)
289: {
290: super.processKeyEvent(e);
291: }
292:
293: public static void setDefaultLookAndFeelDecorated(boolean decorated)
294: {
295: defaultLookAndFeelDecorated = decorated;
296: }
297:
298: public static boolean isDefaultLookAndFeelDecorated()
299: {
300: return defaultLookAndFeelDecorated;
301: }
302:
303:
309: public AccessibleContext getAccessibleContext()
310: {
311: if (accessibleContext == null)
312: accessibleContext = new AccessibleJFrame();
313: return accessibleContext;
314: }
315:
316:
326: public int getDefaultCloseOperation()
327: {
328: return closeAction;
329: }
330:
331:
338: protected String paramString()
339: {
340: StringBuffer sb = new StringBuffer(super.paramString());
341: sb.append(",defaultCloseOperation=");
342: sb.append(SwingUtilities.convertWindowConstantToString(
343: getDefaultCloseOperation()));
344: sb.append(",rootPane=");
345: if (rootPane != null)
346: sb.append(rootPane);
347: sb.append(",rootPaneCheckingEnabled=").append(rootPaneCheckingEnabled);
348: return sb.toString();
349: }
350:
351: protected void processWindowEvent(WindowEvent e)
352: {
353: super.processWindowEvent(e);
354: switch (e.getID())
355: {
356: case WindowEvent.WINDOW_CLOSING:
357: {
358: switch (closeAction)
359: {
360: case EXIT_ON_CLOSE:
361: {
362: System.exit(0);
363: break;
364: }
365: case DISPOSE_ON_CLOSE:
366: {
367: dispose();
368: break;
369: }
370: case HIDE_ON_CLOSE:
371: {
372: setVisible(false);
373: break;
374: }
375: case DO_NOTHING_ON_CLOSE:
376: break;
377: }
378: break;
379: }
380: case WindowEvent.WINDOW_CLOSED:
381: case WindowEvent.WINDOW_OPENED:
382: case WindowEvent.WINDOW_ICONIFIED:
383: case WindowEvent.WINDOW_DEICONIFIED:
384: case WindowEvent.WINDOW_ACTIVATED:
385: case WindowEvent.WINDOW_DEACTIVATED:
386: break;
387: }
388: }
389:
390:
408: public void setDefaultCloseOperation(int operation)
409: {
410: SecurityManager sm = System.getSecurityManager();
411: if (sm != null && operation == EXIT_ON_CLOSE)
412: sm.checkExit(0);
413:
414: if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
415: && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
416: throw new IllegalArgumentException("operation must be EXIT_ON_CLOSE, "
417: + "HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or DO_NOTHING_ON_CLOSE");
418:
419: closeAction = operation;
420: }
421: }