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:
52: import ;
53: import ;
54: import ;
55: import ;
56:
57:
67: public class JRootPane extends JComponent implements Accessible
68: {
69:
70: protected class AccessibleJRootPane extends AccessibleJComponent
71: {
72:
75: private static final long serialVersionUID = 1082432482784468088L;
76:
77:
80: protected AccessibleJRootPane()
81: {
82:
83: }
84:
85:
90: public AccessibleRole getAccessibleRole()
91: {
92: return AccessibleRole.ROOT_PANE;
93: }
94: }
95:
96:
97:
98: protected class RootLayout implements LayoutManager2, Serializable
99: {
100:
101: private static final long serialVersionUID = -4100116998559815027L;
102:
103:
106: private Rectangle glassPaneBounds;
107:
108:
111: private Rectangle layeredPaneBounds;
112:
113:
116: private Rectangle contentPaneBounds;
117:
118:
121: private Rectangle menuBarBounds;
122:
123:
126: protected RootLayout()
127: {
128:
129: }
130:
131:
137: public void addLayoutComponent(Component comp, Object constraints)
138: {
139:
140: }
141:
142:
148: public void addLayoutComponent(String name, Component comp)
149: {
150:
151: }
152:
153:
160: public float getLayoutAlignmentX(Container target)
161: {
162: return 0.0F;
163: }
164:
165:
172: public float getLayoutAlignmentY(Container target)
173: {
174: return 0.0F;
175: }
176:
177:
182: public void invalidateLayout(Container target)
183: {
184: synchronized (this)
185: {
186: glassPaneBounds = null;
187: layeredPaneBounds = null;
188: contentPaneBounds = null;
189: menuBarBounds = null;
190: }
191: }
192:
193:
198: public void layoutContainer(Container c)
199: {
200: if (glassPaneBounds == null || layeredPaneBounds == null
201: || contentPaneBounds == null || menuBarBounds == null)
202: {
203: Insets i = getInsets();
204: int containerWidth = c.getBounds().width - i.left - i.right;
205: int containerHeight = c.getBounds().height - i.top - i.bottom;
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226: if (menuBar != null)
227: {
228: Dimension menuBarSize = menuBar.getPreferredSize();
229: if (menuBarSize.height > containerHeight)
230: menuBarSize.height = containerHeight;
231: menuBarBounds = new Rectangle(0, 0, containerWidth,
232: menuBarSize.height);
233: contentPaneBounds = new Rectangle(0, menuBarSize.height,
234: containerWidth,
235: containerHeight - menuBarSize.height);
236: }
237: else
238: contentPaneBounds = new Rectangle(0, 0, containerWidth,
239: containerHeight);
240:
241: glassPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
242: layeredPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
243: }
244:
245: glassPane.setBounds(glassPaneBounds);
246: layeredPane.setBounds(layeredPaneBounds);
247: if (menuBar != null)
248: menuBar.setBounds(menuBarBounds);
249: getContentPane().setBounds(contentPaneBounds);
250: }
251:
252:
259: public Dimension maximumLayoutSize(Container target)
260: {
261: return preferredLayoutSize(target);
262: }
263:
264:
271: public Dimension minimumLayoutSize(Container target)
272: {
273: return preferredLayoutSize(target);
274: }
275:
276:
283: public Dimension preferredLayoutSize(Container c)
284: {
285: Dimension prefSize = new Dimension();
286: Insets i = getInsets();
287: prefSize = new Dimension(i.left + i.right, i.top + i.bottom);
288: Dimension contentPrefSize = getContentPane().getPreferredSize();
289: prefSize.width += contentPrefSize.width;
290: prefSize.height += contentPrefSize.height;
291: if (menuBar != null)
292: {
293: Dimension menuBarSize = menuBar.getPreferredSize();
294: if (menuBarSize.width > contentPrefSize.width)
295: prefSize.width += menuBarSize.width - contentPrefSize.width;
296: prefSize.height += menuBarSize.height;
297: }
298: return prefSize;
299: }
300:
301:
306: public void removeLayoutComponent(Component comp)
307: {
308:
309: }
310: }
311:
312:
313: private static final long serialVersionUID = 8690748000348575668L;
314:
315: public static final int NONE = 0;
316: public static final int FRAME = 1;
317: public static final int PLAIN_DIALOG = 2;
318: public static final int INFORMATION_DIALOG = 3;
319: public static final int ERROR_DIALOG = 4;
320: public static final int COLOR_CHOOSER_DIALOG = 5;
321: public static final int FILE_CHOOSER_DIALOG = 6;
322: public static final int QUESTION_DIALOG = 7;
323: public static final int WARNING_DIALOG = 8;
324:
325:
326: protected Component glassPane;
327:
328:
329: protected JLayeredPane layeredPane;
330:
331:
332: protected JMenuBar menuBar;
333:
334:
335: protected Container contentPane;
336:
337: protected JButton defaultButton;
338:
339:
350: protected Action defaultPressAction;
351:
352:
363: protected Action defaultReleaseAction;
364:
365:
368: private int windowDecorationStyle = NONE;
369:
370:
375: public void setJMenuBar(JMenuBar m)
376: {
377: JLayeredPane jlPane = getLayeredPane();
378: if (menuBar != null)
379: jlPane.remove(menuBar);
380: menuBar = m;
381: if (menuBar != null)
382: jlPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
383: }
384:
385:
388: public void setMenuBar(JMenuBar m)
389: {
390: setJMenuBar(m);
391: }
392:
393:
398: public JMenuBar getJMenuBar()
399: {
400: return menuBar;
401: }
402:
403:
406: public JMenuBar getMenuBar()
407: {
408: return getJMenuBar();
409: }
410:
411:
416: public boolean isValidateRoot()
417: {
418: return true;
419: }
420:
421:
426: public Container getContentPane()
427: {
428: if (contentPane == null)
429: setContentPane(createContentPane());
430: return contentPane;
431: }
432:
433:
441: public void setContentPane(Container p)
442: {
443: if (p == null)
444: throw new IllegalComponentStateException ("cannot " +
445: "have a null content pane");
446: else
447: {
448: if (contentPane != null && contentPane.getParent() == layeredPane)
449: layeredPane.remove(contentPane);
450: contentPane = p;
451: getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
452: }
453: }
454:
455:
462: protected void addImpl(Component comp, Object constraints, int index)
463: {
464: super.addImpl(comp, constraints, index);
465: }
466:
467:
472: public Component getGlassPane()
473: {
474: if (glassPane == null)
475: setGlassPane(createGlassPane());
476: return glassPane;
477: }
478:
479:
484: public void setGlassPane(Component f)
485: {
486: if (glassPane != null)
487: remove(glassPane);
488:
489: glassPane = f;
490:
491: glassPane.setVisible(false);
492: add(glassPane, 0);
493: }
494:
495:
500: public JLayeredPane getLayeredPane()
501: {
502: if (layeredPane == null)
503: setLayeredPane(createLayeredPane());
504: return layeredPane;
505: }
506:
507:
515: public void setLayeredPane(JLayeredPane f)
516: {
517: if (f == null)
518: throw new IllegalComponentStateException();
519:
520: if (layeredPane != null)
521: remove(layeredPane);
522:
523: layeredPane = f;
524: add(f, -1);
525: }
526:
527:
530: public JRootPane()
531: {
532: setLayout(createRootLayout());
533: getGlassPane();
534: getLayeredPane();
535: getContentPane();
536: setOpaque(true);
537: updateUI();
538: }
539:
540:
545: protected LayoutManager createRootLayout()
546: {
547: return new RootLayout();
548: }
549:
550:
555: protected Container createContentPane()
556: {
557: JPanel p = new JPanel();
558: p.setName(this.getName() + ".contentPane");
559: p.setLayout(new BorderLayout());
560: return p;
561: }
562:
563:
568: protected Component createGlassPane()
569: {
570: JPanel p = new JPanel();
571: p.setName(this.getName() + ".glassPane");
572: p.setVisible(false);
573: p.setOpaque(false);
574: return p;
575: }
576:
577:
582: protected JLayeredPane createLayeredPane()
583: {
584: JLayeredPane l = new JLayeredPane();
585: l.setLayout(null);
586: return l;
587: }
588:
589:
594: public RootPaneUI getUI()
595: {
596: return (RootPaneUI) ui;
597: }
598:
599:
604: public void setUI(RootPaneUI ui)
605: {
606: super.setUI(ui);
607: }
608:
609:
612: public void updateUI()
613: {
614: setUI((RootPaneUI) UIManager.getUI(this));
615: }
616:
617:
622: public String getUIClassID()
623: {
624: return "RootPaneUI";
625: }
626:
627: public JButton getDefaultButton()
628: {
629: return defaultButton;
630: }
631:
632: public void setDefaultButton(JButton newButton)
633: {
634:
635:
636: if (defaultButton != newButton
637: && (newButton == null || newButton.isDefaultCapable()))
638: {
639: JButton oldButton = defaultButton;
640: defaultButton = newButton;
641: firePropertyChange("defaultButton", oldButton, newButton);
642: }
643: }
644:
645:
648: public int getWindowDecorationStyle()
649: {
650: return windowDecorationStyle;
651: }
652:
653:
656: public void setWindowDecorationStyle(int style)
657: {
658: if (style != NONE
659: && style != FRAME
660: && style != INFORMATION_DIALOG
661: && style != ERROR_DIALOG
662: && style != COLOR_CHOOSER_DIALOG
663: && style != FILE_CHOOSER_DIALOG
664: && style != QUESTION_DIALOG
665: && style != WARNING_DIALOG
666: && style != PLAIN_DIALOG)
667: throw new IllegalArgumentException("invalid style");
668:
669: int oldStyle = windowDecorationStyle;
670: windowDecorationStyle = style;
671: firePropertyChange("windowDecorationStyle", oldStyle, style);
672: }
673:
674:
683: public boolean isOptimizedDrawingEnable()
684: {
685: return ! glassPane.isVisible();
686: }
687:
688:
694: public AccessibleContext getAccessibleContext()
695: {
696: if (accessibleContext == null)
697: accessibleContext = new AccessibleJRootPane();
698: return accessibleContext;
699: }
700: }