1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50: import ;
51: import ;
52: import ;
53:
54:
64: public class JRootPane extends JComponent implements Accessible
65: {
66:
67: protected class AccessibleJRootPane extends AccessibleJComponent
68: {
69:
72: private static final long serialVersionUID = 1082432482784468088L;
73:
74:
77: protected AccessibleJRootPane()
78: {
79:
80: }
81:
82:
87: public AccessibleRole getAccessibleRole()
88: {
89: return AccessibleRole.ROOT_PANE;
90: }
91: }
92:
93:
94:
95: protected class RootLayout implements LayoutManager2, Serializable
96: {
97:
98: private static final long serialVersionUID = -4100116998559815027L;
99:
100:
103: protected RootLayout()
104: {
105:
106: }
107:
108:
114: public void addLayoutComponent(Component comp, Object constraints)
115: {
116:
117: }
118:
119:
125: public void addLayoutComponent(String name, Component comp)
126: {
127:
128: }
129:
130:
137: public float getLayoutAlignmentX(Container target)
138: {
139: return target.getAlignmentX();
140: }
141:
142:
149: public float getLayoutAlignmentY(Container target)
150: {
151: return target.getAlignmentY();
152: }
153:
154:
159: public void invalidateLayout(Container target)
160: {
161:
162: }
163:
164:
169: public void layoutContainer(Container c)
170: {
171: Dimension menuBarSize;
172: int containerWidth = c.getBounds().width - getInsets().left
173: - getInsets().right;
174: int containerHeight = c.getBounds().height - getInsets().top
175: - getInsets().bottom;
176: Dimension contentPaneSize = contentPane.getPreferredSize();
177:
178:
179:
180:
181:
182:
183:
205: if (containerWidth == 0 && containerHeight == 0)
206: {
207: if (menuBar != null)
208: {
209: int maxWidth;
210: menuBarSize = menuBar.getPreferredSize();
211: maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
212: menuBar.setBounds(0, 0, maxWidth, menuBarSize.height);
213: glassPane.setBounds(0, 0, maxWidth, menuBarSize.height
214: + contentPaneSize.height);
215: contentPane.setBounds(0, menuBarSize.height, maxWidth,
216: contentPaneSize.height);
217: layeredPane.setBounds(0, 0, maxWidth, menuBarSize.height
218: + contentPaneSize.height);
219: }
220: else
221: {
222: glassPane.setBounds(0, 0, contentPaneSize.width,
223: contentPaneSize.height);
224: contentPane.setBounds(0, 0, contentPaneSize.width,
225: contentPaneSize.height);
226: layeredPane.setBounds(0, 0, contentPaneSize.width,
227: contentPaneSize.height);
228: }
229: }
230: else
231: {
232: if (menuBar != null)
233: {
234: menuBarSize = menuBar.getPreferredSize();
235: if (menuBarSize.height > containerHeight)
236: menuBarSize.height = containerHeight;
237: menuBar.setBounds(0, 0, containerWidth, menuBarSize.height);
238: glassPane.setBounds(0, 0, containerWidth, containerHeight);
239: contentPane.setBounds(0, menuBarSize.height, containerWidth,
240: (containerHeight - menuBarSize.height));
241: }
242: else
243: {
244: glassPane.setBounds(0, 0, containerWidth, containerHeight);
245: contentPane.setBounds(0, 0, containerWidth, containerHeight);
246: }
247: layeredPane.setBounds(0, 0, containerWidth, containerHeight);
248: }
249: }
250:
251:
258: public Dimension maximumLayoutSize(Container target)
259: {
260: return preferredLayoutSize(target);
261: }
262:
263:
270: public Dimension minimumLayoutSize(Container target)
271: {
272: return preferredLayoutSize(target);
273: }
274:
275:
282: public Dimension preferredLayoutSize(Container c)
283: {
284: Dimension menuBarSize;
285: Dimension prefSize;
286:
287: Dimension containerSize = c.getSize();
288: Dimension contentPaneSize = contentPane.getPreferredSize();
289:
290: if (containerSize.width == 0 && containerSize.height == 0)
291: {
292: if (menuBar != null)
293: {
294: int maxWidth;
295: menuBarSize = menuBar.getPreferredSize();
296: maxWidth = Math.max(menuBarSize.width, contentPaneSize.width);
297: prefSize = new Dimension(maxWidth,
298: contentPaneSize.height
299: + menuBarSize.height);
300: }
301: else
302: prefSize = contentPaneSize;
303: }
304: else
305: prefSize = c.getSize();
306:
307: return prefSize;
308: }
309:
310:
315: public void removeLayoutComponent(Component comp)
316: {
317:
318: }
319: }
320:
321:
322: private static final long serialVersionUID = 8690748000348575668L;
323:
324: public static final int NONE = 0;
325: public static final int FRAME = 1;
326: public static final int PLAIN_DIALOG = 2;
327: public static final int INFORMATION_DIALOG = 3;
328: public static final int ERROR_DIALOG = 4;
329: public static final int COLOR_CHOOSER_DIALOG = 5;
330: public static final int FILE_CHOOSER_DIALOG = 6;
331: public static final int QUESTION_DIALOG = 7;
332: public static final int WARNING_DIALOG = 8;
333:
334:
335: protected Component glassPane;
336:
337:
338: protected JLayeredPane layeredPane;
339:
340:
341: protected JMenuBar menuBar;
342:
343:
344: protected Container contentPane;
345:
346: protected JButton defaultButton;
347:
348:
359: protected Action defaultPressAction;
360:
361:
372: protected Action defaultReleaseAction;
373:
374:
377: private int windowDecorationStyle = NONE;
378:
379:
384: public void setJMenuBar(JMenuBar m)
385: {
386: JLayeredPane jlPane = getLayeredPane();
387: if (menuBar != null)
388: jlPane.remove(menuBar);
389: menuBar = m;
390: if (menuBar != null)
391: jlPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
392: }
393:
394:
397: public void setMenuBar(JMenuBar m)
398: {
399: setJMenuBar(m);
400: }
401:
402:
407: public JMenuBar getJMenuBar()
408: {
409: return menuBar;
410: }
411:
412:
415: public JMenuBar getMenuBar()
416: {
417: return getJMenuBar();
418: }
419:
420:
425: public boolean isValidateRoot()
426: {
427: return true;
428: }
429:
430:
435: public Container getContentPane()
436: {
437: if (contentPane == null)
438: setContentPane(createContentPane());
439: return contentPane;
440: }
441:
442:
450: public void setContentPane(Container p)
451: {
452: if (p == null)
453: throw new IllegalComponentStateException ("cannot " +
454: "have a null content pane");
455: else
456: {
457: if (contentPane != null && contentPane.getParent() == layeredPane)
458: layeredPane.remove(contentPane);
459: contentPane = p;
460: getLayeredPane().add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
461: }
462: }
463:
464:
471: protected void addImpl(Component comp, Object constraints, int index)
472: {
473: super.addImpl(comp, constraints, index);
474: }
475:
476:
481: public Component getGlassPane()
482: {
483: if (glassPane == null)
484: setGlassPane(createGlassPane());
485: return glassPane;
486: }
487:
488:
493: public void setGlassPane(Component f)
494: {
495: if (glassPane != null)
496: remove(glassPane);
497:
498: glassPane = f;
499:
500: glassPane.setVisible(false);
501: add(glassPane, 0);
502: }
503:
504:
509: public JLayeredPane getLayeredPane()
510: {
511: if (layeredPane == null)
512: setLayeredPane(createLayeredPane());
513: return layeredPane;
514: }
515:
516:
521: public void setLayeredPane(JLayeredPane f)
522: {
523: if (layeredPane != null)
524: remove(layeredPane);
525:
526: layeredPane = f;
527: add(f, -1);
528: }
529:
530:
533: public JRootPane()
534: {
535: setLayout(createRootLayout());
536: getGlassPane();
537: getLayeredPane();
538: getContentPane();
539: updateUI();
540: }
541:
542:
547: protected LayoutManager createRootLayout()
548: {
549: return new RootLayout();
550: }
551:
552:
557: protected Container createContentPane()
558: {
559: JPanel p = new JPanel();
560: p.setName(this.getName() + ".contentPane");
561: p.setLayout(new BorderLayout());
562: return p;
563: }
564:
565:
570: protected Component createGlassPane()
571: {
572: JPanel p = new JPanel();
573: p.setName(this.getName() + ".glassPane");
574: p.setVisible(false);
575: p.setOpaque(false);
576: return p;
577: }
578:
579:
584: protected JLayeredPane createLayeredPane()
585: {
586: JLayeredPane l = new JLayeredPane();
587: l.setLayout(null);
588: return l;
589: }
590:
591:
596: public RootPaneUI getUI()
597: {
598: return (RootPaneUI) ui;
599: }
600:
601:
606: public void setUI(RootPaneUI ui)
607: {
608: super.setUI(ui);
609: }
610:
611:
614: public void updateUI()
615: {
616: setUI((RootPaneUI) UIManager.getUI(this));
617: }
618:
619:
624: public String getUIClassID()
625: {
626: return "RootPaneUI";
627: }
628:
629: public JButton getDefaultButton()
630: {
631: return defaultButton;
632: }
633:
634: public void setDefaultButton(JButton newButton)
635: {
636: if (defaultButton == newButton)
637: return;
638:
639: JButton oldButton = defaultButton;
640: defaultButton = newButton;
641: firePropertyChange("defaultButton", oldButton, newButton);
642: }
643:
644:
647: public int getWindowDecorationStyle()
648: {
649: return windowDecorationStyle;
650: }
651:
652:
655: public void setWindowDecorationStyle(int style)
656: {
657: if (style != NONE
658: && style != FRAME
659: && style != INFORMATION_DIALOG
660: && style != ERROR_DIALOG
661: && style != COLOR_CHOOSER_DIALOG
662: && style != FILE_CHOOSER_DIALOG
663: && style != QUESTION_DIALOG
664: && style != WARNING_DIALOG
665: && style != PLAIN_DIALOG)
666: throw new IllegalArgumentException("invalid style");
667:
668: int oldStyle = windowDecorationStyle;
669: windowDecorationStyle = style;
670: firePropertyChange("windowDecorationStyle", oldStyle, style);
671: }
672: }