1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48:
49: import ;
50: import ;
51:
52:
62: public class JRootPane extends JComponent
63: {
64:
65: protected static class AccessibleJRootPane
66: {
67:
70: private static final long serialVersionUID = 1082432482784468088L;
71:
72:
75: protected AccessibleJRootPane()
76: {
77: }
78:
79:
84: public AccessibleRole getAccessibleRole()
85: {
86: return AccessibleRole.ROOT_PANE;
87: }
88: }
89:
90:
91:
92: protected class RootLayout implements LayoutManager2, Serializable
93: {
94:
95: private static final long serialVersionUID = -4100116998559815027L;
96:
97:
100: protected RootLayout()
101: {
102: }
103:
104:
110: public void addLayoutComponent(Component comp, Object constraints)
111: {
112: }
113:
114:
120: public void addLayoutComponent(String name, Component comp)
121: {
122: }
123:
124:
131: public float getLayoutAlignmentX(Container target)
132: {
133: return target.getAlignmentX();
134: }
135:
136:
143: public float getLayoutAlignmentY(Container target)
144: {
145: return target.getAlignmentY();
146: }
147:
148:
153: public void invalidateLayout(Container target)
154: {
155: }
156:
157:
162: public void layoutContainer(Container c)
163: {
164: Dimension menuBarSize;
165: Dimension containerSize = c.getSize(null);
166: Dimension contentPaneSize = contentPane.getPreferredSize();
167:
168:
190: if (containerSize.width == 0 && containerSize.height == 0)
191: {
192: if (menuBar != null)
193: {
194: int maxWidth;
195: menuBarSize = menuBar.getPreferredSize();
196: maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
197: menuBar.setBounds(0, 0, maxWidth, menuBarSize.height);
198: glassPane.setBounds(0, menuBarSize.height, maxWidth,
199: contentPaneSize.height);
200: contentPane.setBounds(0, menuBarSize.height, maxWidth,
201: contentPaneSize.height);
202: layeredPane.setSize(maxWidth,
203: menuBarSize.height + contentPaneSize.height);
204: }
205: else
206: {
207: glassPane.setBounds(0, 0, contentPaneSize.width,
208: contentPaneSize.height);
209: contentPane.setBounds(0, 0, contentPaneSize.width,
210: contentPaneSize.height);
211: layeredPane.setSize(contentPaneSize.width, contentPaneSize.height);
212: }
213: }
214: else
215: {
216: if (menuBar != null)
217: {
218: menuBarSize = menuBar.getPreferredSize();
219: if (menuBarSize.height > containerSize.height)
220: menuBarSize.height = containerSize.height;
221: menuBar.setBounds(0, 0, containerSize.width, menuBarSize.height);
222: int remainingHeight = containerSize.height - menuBarSize.height;
223: glassPane.setBounds(0, menuBarSize.height, containerSize.width,
224: containerSize.height - menuBarSize.height);
225: contentPane.setBounds(0, menuBarSize.height,
226: containerSize.width,
227: (containerSize.height - menuBarSize.height));
228: }
229: else
230: {
231: glassPane.setBounds(0, 0, containerSize.width,
232: containerSize.height);
233: contentPane.setBounds(0, 0, containerSize.width,
234: containerSize.height);
235: }
236:
237: layeredPane.setSize(containerSize.width, containerSize.height);
238: }
239: }
240:
241:
248: public Dimension maximumLayoutSize(Container target)
249: {
250: return preferredLayoutSize(target);
251: }
252:
253:
260: public Dimension minimumLayoutSize(Container target)
261: {
262: return preferredLayoutSize(target);
263: }
264:
265:
272: public Dimension preferredLayoutSize(Container c)
273: {
274: Dimension menuBarSize;
275: Dimension prefSize;
276:
277: Dimension containerSize = c.getSize();
278: Dimension contentPaneSize = contentPane.getPreferredSize();
279:
280: if (containerSize.width == 0 && containerSize.height == 0)
281: {
282: if (menuBar != null)
283: {
284: int maxWidth;
285: menuBarSize = menuBar.getPreferredSize();
286: maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
287: prefSize = new Dimension(maxWidth,
288: contentPaneSize.height
289: + menuBarSize.height);
290: }
291: else
292: prefSize = contentPaneSize;
293: }
294: else
295: prefSize = c.getSize();
296:
297: return prefSize;
298: }
299:
300:
305: public void removeLayoutComponent(Component comp)
306: {
307: }
308: }
309:
310:
311: private static final long serialVersionUID = 8690748000348575668L;
312:
313: public static final int NONE = 0;
314: public static final int FRAME = 1;
315: public static final int PLAIN_DIALOG = 2;
316: public static final int INFORMATION_DIALOG = 3;
317: public static final int ERROR_DIALOG = 4;
318: public static final int COLOR_CHOOSER_DIALOG = 5;
319: public static final int FILE_CHOOSER_DIALOG = 6;
320: public static final int QUESTION_DIALOG = 7;
321: public static final int WARNING_DIALOG = 8;
322:
323:
324: protected Component glassPane;
325:
326:
327: protected JLayeredPane layeredPane;
328:
329:
330: protected JMenuBar menuBar;
331:
332:
333: protected Container contentPane;
334:
335: protected JButton defaultButton;
336:
337:
340: private int windowDecorationStyle = NONE;
341:
342:
347: public void setJMenuBar(JMenuBar m)
348: {
349: JLayeredPane jlPane = getLayeredPane();
350: if (menuBar != null)
351: jlPane.remove(menuBar);
352: menuBar = m;
353: if (menuBar != null)
354: jlPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
355: }
356:
357:
360: public void setMenuBar(JMenuBar m)
361: {
362: setJMenuBar(m);
363: }
364:
365:
370: public JMenuBar getJMenuBar()
371: {
372: return menuBar;
373: }
374:
375:
378: public JMenuBar getMenuBar()
379: {
380: return getJMenuBar();
381: }
382:
383:
388: public boolean isValidateRoot()
389: {
390: return true;
391: }
392:
393:
398: public Container getContentPane()
399: {
400: if (contentPane == null)
401: setContentPane(createContentPane());
402: return contentPane;
403: }
404:
405:
410: public void setContentPane(Container p)
411: {
412: contentPane = p;
413: getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
414: }
415:
416:
423: protected void addImpl(Component comp, Object constraints, int index)
424: {
425: super.addImpl(comp, constraints, index);
426: }
427:
428:
433: public Component getGlassPane()
434: {
435: if (glassPane == null)
436: setGlassPane(createGlassPane());
437: return glassPane;
438: }
439:
440:
445: public void setGlassPane(Component f)
446: {
447: if (glassPane != null)
448: remove(glassPane);
449:
450: glassPane = f;
451:
452: glassPane.setVisible(false);
453: add(glassPane, 0);
454: }
455:
456:
461: public JLayeredPane getLayeredPane()
462: {
463: if (layeredPane == null)
464: setLayeredPane(createLayeredPane());
465: return layeredPane;
466: }
467:
468:
473: public void setLayeredPane(JLayeredPane f)
474: {
475: if (layeredPane != null)
476: remove(layeredPane);
477:
478: layeredPane = f;
479: add(f, -1);
480: }
481:
482:
485: public JRootPane()
486: {
487: setLayout(createRootLayout());
488: getGlassPane();
489: getLayeredPane();
490: getContentPane();
491: setDoubleBuffered(true);
492: updateUI();
493: }
494:
495:
500: protected LayoutManager createRootLayout()
501: {
502: return new RootLayout();
503: }
504:
505:
510: protected Container createContentPane()
511: {
512: JPanel p = new JPanel();
513: p.setName(this.getName() + ".contentPane");
514: p.setLayout(new BorderLayout());
515: return p;
516: }
517:
518:
523: protected Component createGlassPane()
524: {
525: JPanel p = new JPanel();
526: p.setName(this.getName() + ".glassPane");
527: p.setLayout(new BorderLayout());
528: p.setVisible(false);
529: p.setOpaque(false);
530: return p;
531: }
532:
533:
538: protected JLayeredPane createLayeredPane()
539: {
540: JLayeredPane l = new JLayeredPane();
541: l.setLayout(null);
542: return l;
543: }
544:
545:
550: public RootPaneUI getUI()
551: {
552: return (RootPaneUI) ui;
553: }
554:
555:
560: public void setUI(RootPaneUI ui)
561: {
562: super.setUI(ui);
563: }
564:
565:
568: public void updateUI()
569: {
570: setUI((RootPaneUI) UIManager.getUI(this));
571: }
572:
573:
578: public String getUIClassID()
579: {
580: return "RootPaneUI";
581: }
582:
583: public JButton getDefaultButton()
584: {
585: return defaultButton;
586: }
587:
588: public void setDefaultButton(JButton newButton)
589: {
590: if (defaultButton == newButton)
591: return;
592:
593: JButton oldButton = defaultButton;
594: defaultButton = newButton;
595: firePropertyChange("defaultButton", oldButton, newButton);
596: }
597:
598:
601: public int getWindowDecorationStyle()
602: {
603: return windowDecorationStyle;
604: }
605:
606:
609: public void setWindowDecorationStyle(int style)
610: {
611: if (style != NONE
612: && style != FRAME
613: && style != INFORMATION_DIALOG
614: && style != ERROR_DIALOG
615: && style != COLOR_CHOOSER_DIALOG
616: && style != FILE_CHOOSER_DIALOG
617: && style != QUESTION_DIALOG
618: && style != WARNING_DIALOG)
619: throw new IllegalArgumentException("invalid style");
620:
621: int oldStyle = windowDecorationStyle;
622: windowDecorationStyle = style;
623: firePropertyChange("windowDecorationStyle", oldStyle, style);
624: }
625: }