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:
56:
66: public class JRootPane extends JComponent implements Accessible
67: {
68:
69: protected class AccessibleJRootPane extends AccessibleJComponent
70: {
71:
74: private static final long serialVersionUID = 1082432482784468088L;
75:
76:
79: protected AccessibleJRootPane()
80: {
81:
82: }
83:
84:
89: public AccessibleRole getAccessibleRole()
90: {
91: return AccessibleRole.ROOT_PANE;
92: }
93: }
94:
95:
96:
97: protected class RootLayout implements LayoutManager2, Serializable
98: {
99:
100: private static final long serialVersionUID = -4100116998559815027L;
101:
102:
105: private Rectangle glassPaneBounds;
106:
107:
110: private Rectangle layeredPaneBounds;
111:
112:
115: private Rectangle contentPaneBounds;
116:
117:
120: private Rectangle menuBarBounds;
121:
122:
125: private Dimension prefSize;
126:
127:
130: protected RootLayout()
131: {
132:
133: }
134:
135:
141: public void addLayoutComponent(Component comp, Object constraints)
142: {
143:
144: }
145:
146:
152: public void addLayoutComponent(String name, Component comp)
153: {
154:
155: }
156:
157:
164: public float getLayoutAlignmentX(Container target)
165: {
166: return 0.0F;
167: }
168:
169:
176: public float getLayoutAlignmentY(Container target)
177: {
178: return 0.0F;
179: }
180:
181:
186: public void invalidateLayout(Container target)
187: {
188: synchronized (this)
189: {
190: glassPaneBounds = null;
191: layeredPaneBounds = null;
192: contentPaneBounds = null;
193: menuBarBounds = null;
194: prefSize = null;
195: }
196: }
197:
198:
203: public void layoutContainer(Container c)
204: {
205: if (glassPaneBounds == null || layeredPaneBounds == null
206: || contentPaneBounds == null || menuBarBounds == null)
207: {
208: Insets i = getInsets();
209: int containerWidth = c.getBounds().width - i.left - i.right;
210: int containerHeight = c.getBounds().height - i.top - i.bottom;
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231: if (menuBar != null)
232: {
233: Dimension menuBarSize = menuBar.getPreferredSize();
234: if (menuBarSize.height > containerHeight)
235: menuBarSize.height = containerHeight;
236: menuBarBounds = new Rectangle(0, 0, containerWidth,
237: menuBarSize.height);
238: contentPaneBounds = new Rectangle(0, menuBarSize.height,
239: containerWidth,
240: containerHeight - menuBarSize.height);
241: }
242: else
243: contentPaneBounds = new Rectangle(0, 0, containerWidth,
244: containerHeight);
245:
246: glassPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
247: layeredPaneBounds = new Rectangle(i.left, i.top, containerWidth, containerHeight);
248: }
249:
250: glassPane.setBounds(glassPaneBounds);
251: layeredPane.setBounds(layeredPaneBounds);
252: if (menuBar != null)
253: menuBar.setBounds(menuBarBounds);
254: contentPane.setBounds(contentPaneBounds);
255: }
256:
257:
264: public Dimension maximumLayoutSize(Container target)
265: {
266: return preferredLayoutSize(target);
267: }
268:
269:
276: public Dimension minimumLayoutSize(Container target)
277: {
278: return preferredLayoutSize(target);
279: }
280:
281:
288: public Dimension preferredLayoutSize(Container c)
289: {
290:
291:
292: synchronized (this)
293: {
294: if (prefSize == null)
295: {
296: Insets i = getInsets();
297: prefSize = new Dimension(i.left + i.right, i.top + i.bottom);
298: Dimension contentPrefSize = contentPane.getPreferredSize();
299: prefSize.width += contentPrefSize.width;
300: prefSize.height += contentPrefSize.height;
301: if (menuBar != null)
302: {
303: Dimension menuBarSize = menuBar.getPreferredSize();
304: if (menuBarSize.width > contentPrefSize.width)
305: prefSize.width += menuBarSize.width - contentPrefSize.width;
306: prefSize.height += menuBarSize.height;
307: }
308: }
309:
310:
311: return new Dimension(prefSize);
312: }
313: }
314:
315:
320: public void removeLayoutComponent(Component comp)
321: {
322:
323: }
324: }
325:
326:
327: private static final long serialVersionUID = 8690748000348575668L;
328:
329: public static final int NONE = 0;
330: public static final int FRAME = 1;
331: public static final int PLAIN_DIALOG = 2;
332: public static final int INFORMATION_DIALOG = 3;
333: public static final int ERROR_DIALOG = 4;
334: public static final int COLOR_CHOOSER_DIALOG = 5;
335: public static final int FILE_CHOOSER_DIALOG = 6;
336: public static final int QUESTION_DIALOG = 7;
337: public static final int WARNING_DIALOG = 8;
338:
339:
340: protected Component glassPane;
341:
342:
343: protected JLayeredPane layeredPane;
344:
345:
346: protected JMenuBar menuBar;
347:
348:
349: protected Container contentPane;
350:
351: protected JButton defaultButton;
352:
353:
364: protected Action defaultPressAction;
365:
366:
377: protected Action defaultReleaseAction;
378:
379:
382: private int windowDecorationStyle = NONE;
383:
384:
389: public void setJMenuBar(JMenuBar m)
390: {
391: JLayeredPane jlPane = getLayeredPane();
392: if (menuBar != null)
393: jlPane.remove(menuBar);
394: menuBar = m;
395: if (menuBar != null)
396: jlPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
397: }
398:
399:
402: public void setMenuBar(JMenuBar m)
403: {
404: setJMenuBar(m);
405: }
406:
407:
412: public JMenuBar getJMenuBar()
413: {
414: return menuBar;
415: }
416:
417:
420: public JMenuBar getMenuBar()
421: {
422: return getJMenuBar();
423: }
424:
425:
430: public boolean isValidateRoot()
431: {
432: return true;
433: }
434:
435:
440: public Container getContentPane()
441: {
442: if (contentPane == null)
443: setContentPane(createContentPane());
444: return contentPane;
445: }
446:
447:
455: public void setContentPane(Container p)
456: {
457: if (p == null)
458: throw new IllegalComponentStateException ("cannot " +
459: "have a null content pane");
460: else
461: {
462: if (contentPane != null && contentPane.getParent() == layeredPane)
463: layeredPane.remove(contentPane);
464: contentPane = p;
465: getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
466: }
467: }
468:
469:
476: protected void addImpl(Component comp, Object constraints, int index)
477: {
478: super.addImpl(comp, constraints, index);
479: }
480:
481:
486: public Component getGlassPane()
487: {
488: if (glassPane == null)
489: setGlassPane(createGlassPane());
490: return glassPane;
491: }
492:
493:
498: public void setGlassPane(Component f)
499: {
500: if (glassPane != null)
501: remove(glassPane);
502:
503: glassPane = f;
504:
505: glassPane.setVisible(false);
506: add(glassPane, 0);
507: }
508:
509:
514: public JLayeredPane getLayeredPane()
515: {
516: if (layeredPane == null)
517: setLayeredPane(createLayeredPane());
518: return layeredPane;
519: }
520:
521:
526: public void setLayeredPane(JLayeredPane f)
527: {
528: if (layeredPane != null)
529: remove(layeredPane);
530:
531: layeredPane = f;
532: add(f, -1);
533: }
534:
535:
538: public JRootPane()
539: {
540: setLayout(createRootLayout());
541: getGlassPane();
542: getLayeredPane();
543: getContentPane();
544: updateUI();
545: }
546:
547:
552: protected LayoutManager createRootLayout()
553: {
554: return new RootLayout();
555: }
556:
557:
562: protected Container createContentPane()
563: {
564: JPanel p = new JPanel();
565: p.setName(this.getName() + ".contentPane");
566: p.setLayout(new BorderLayout());
567: return p;
568: }
569:
570:
575: protected Component createGlassPane()
576: {
577: JPanel p = new JPanel();
578: p.setName(this.getName() + ".glassPane");
579: p.setVisible(false);
580: p.setOpaque(false);
581: return p;
582: }
583:
584:
589: protected JLayeredPane createLayeredPane()
590: {
591: JLayeredPane l = new JLayeredPane();
592: l.setLayout(null);
593: return l;
594: }
595:
596:
601: public RootPaneUI getUI()
602: {
603: return (RootPaneUI) ui;
604: }
605:
606:
611: public void setUI(RootPaneUI ui)
612: {
613: super.setUI(ui);
614: }
615:
616:
619: public void updateUI()
620: {
621: setUI((RootPaneUI) UIManager.getUI(this));
622: }
623:
624:
629: public String getUIClassID()
630: {
631: return "RootPaneUI";
632: }
633:
634: public JButton getDefaultButton()
635: {
636: return defaultButton;
637: }
638:
639: public void setDefaultButton(JButton newButton)
640: {
641: if (defaultButton == newButton)
642: return;
643:
644: JButton oldButton = defaultButton;
645: defaultButton = newButton;
646: firePropertyChange("defaultButton", oldButton, newButton);
647: }
648:
649:
652: public int getWindowDecorationStyle()
653: {
654: return windowDecorationStyle;
655: }
656:
657:
660: public void setWindowDecorationStyle(int style)
661: {
662: if (style != NONE
663: && style != FRAME
664: && style != INFORMATION_DIALOG
665: && style != ERROR_DIALOG
666: && style != COLOR_CHOOSER_DIALOG
667: && style != FILE_CHOOSER_DIALOG
668: && style != QUESTION_DIALOG
669: && style != WARNING_DIALOG
670: && style != PLAIN_DIALOG)
671: throw new IllegalArgumentException("invalid style");
672:
673: int oldStyle = windowDecorationStyle;
674: windowDecorationStyle = style;
675: firePropertyChange("windowDecorationStyle", oldStyle, style);
676: }
677: }