1. /*
  2. * @(#)JRootPane.java 1.66 00/04/06
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package javax.swing;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. import javax.accessibility.*;
  14. import javax.swing.plaf.RootPaneUI;
  15. import java.util.Vector;
  16. import java.io.Serializable;
  17. /**
  18. * A lightweight container used behind the scenes by
  19. * JFrame, JDialog, JWindow, JApplet, and JInternalFrame.
  20. * For task-oriented information on functionality provided by root panes
  21. * see <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html">How to Use Root Panes</a>,
  22. * a section in <em>The Java Tutorial</em>.
  23. *
  24. * <p>
  25. * The following image shows the relationships between
  26. * the classes that use root panes.
  27. * <p align=center><img src="doc-files/JRootPane-1.gif" HEIGHT=484 WIDTH=629></p>
  28. * The "heavyweight" components (those that delegate to a peer, or native
  29. * component on the host system) are shown with a darker, heavier box. The four
  30. * heavyweight JFC/Swing containers (JFrame, JDialog, JWindow, and JApplet) are
  31. * shown in relation to the AWT classes they extend. These four components are the
  32. * only heavyweight containers in the Swing library. The lightweight container,
  33. * JInternalPane, is also shown. All 5 of these JFC/Swing containers implement the
  34. * RootPaneContainer interface, and they all delegate their operations to a
  35. * JRootPane (shown with a little "handle" on top).
  36. * <blockquote>
  37. * <b>Note:</b> The JComponent method <code>getRootPane</code> can be used to
  38. * obtain the JRootPane that contains a given component.
  39. * </blockquote>
  40. * <table align="right" border="0">
  41. * <tr>
  42. * <td align="center">
  43. * <img src="doc-files/JRootPane-2.gif" HEIGHT=386 WIDTH=349>
  44. * </td>
  45. * </tr>
  46. * </table>
  47. * The diagram at right shows the structure of a JRootPane.
  48. * A JRootpane is made up of a glassPane, an optional menuBar, and
  49. * a contentPane. (The JLayeredPane manages the menuBar and the contentPane.)
  50. * The glassPane sits over the top of everything, where it is in a position
  51. * to intercept mouse movements. Since the glassPane (like the contentPane)
  52. * can be an arbitrary component, it is also possible to set up the
  53. * glassPane for drawing. Lines and images on the glassPane can then range
  54. * over the frames underneath without being limited by their boundaries.
  55. * <p>
  56. * Although the menuBar component is optional, the layeredPane, contentPane,
  57. * and glassPane always exist. Attempting to set them to null generates an
  58. * exception.
  59. * <p>
  60. * The <code>contentPane</code> must be the parent of any children of
  61. * the JRootPane. Rather than adding directly to a JRootPane, like this:
  62. * <PRE>
  63. * rootPane.add(child);
  64. * </PRE>
  65. * You instead add to the contentPane of the JRootPane, like this:
  66. * <PRE>
  67. * rootPane.getContentPane().add(child);
  68. * </PRE>
  69. * The same priniciple holds true for setting layout managers, removing
  70. * components, listing children, etc. All these methods are invoked on
  71. * the <code>contentPane</code> instead of on the JRootPane.
  72. * <blockquote>
  73. * <b>Note:</b> The default layout manager for the <code>contentPane</code> is
  74. * a BorderLayout manager. However, the JRootPane uses a custom LayoutManager.
  75. * So, when you want to change the layout manager for the components you added
  76. * to a JRootPane, be sure to use code like this:<PRE>
  77. * rootPane.getContentPane().setLayout(new BoxLayout());
  78. * </PRE></blockquote>
  79. * If a JMenuBar component is set on the JRootPane, it is positioned
  80. * along the upper edge of the frame. The <code>contentPane</code> is
  81. * adjusted in location and size to fill the remaining area.
  82. * (The JMenuBar and the <code>contentPane</code> are added to the
  83. * <code>layeredPane</code> component at the JLayeredPane.FRAME_CONTENT_LAYER
  84. * layer.)
  85. * <p>
  86. * The <code>layeredPane</code> is the parent of all children in the JRootPane.
  87. * It is an instance of JLayeredPane, which provides the ability to add components
  88. * at several layers. This capability is very useful when working with menu popups,
  89. * dialog boxes, and dragging -- situations in which you need to place a component
  90. * on top of all other components in the pane.
  91. * <p>
  92. * The <code>glassPane</code> sits on top of all other components in the JRootPane.
  93. * That provides a convenient place to draw above all other components, and makes
  94. * it possible to intercept mouse events, which is useful both for dragging and
  95. * for drawing. Developers can use <code>setVisible</code> on the glassPane
  96. * to control when the <code>glassPane</code> displays over the other children.
  97. * By default the <code>glassPane</code> is not visible.
  98. * <p>
  99. * The custom LayoutManager used by JRootPane ensures that:
  100. * <OL>
  101. * <LI>The <code>glassPane</code>, if present, fills the entire viewable
  102. * area of the JRootPane (bounds - insets).
  103. * <LI>The <code>layeredPane</code> fills the entire viewable area of the
  104. * JRootPane. (bounds - insets)
  105. * <LI>The <code>menuBar</code> is positioned at the upper edge of the
  106. * layeredPane().
  107. * <LI>The <code>contentPane</code> fills the entire viewable area,
  108. * minus the MenuBar, if present.
  109. * </OL>
  110. * Any other views in the JRootPane view hierarchy are ignored.
  111. * <p>
  112. * If you replace the LayoutManager of the JRootPane, you are responsible for
  113. * managing all of these views. So ordinarily you will want to be sure that you
  114. * change the layout manager for the <code>contentPane</code> rather than
  115. * for the JRootPane itself!
  116. * <p>
  117. * <strong>Warning:</strong>
  118. * Serialized objects of this class will not be compatible with
  119. * future Swing releases. The current serialization support is appropriate
  120. * for short term storage or RMI between applications running the same
  121. * version of Swing. A future release of Swing will provide support for
  122. * long term persistence.
  123. *
  124. * @see JLayeredPane
  125. * @see JMenuBar
  126. * @see JWindow
  127. * @see JFrame
  128. * @see JDialog
  129. * @see JApplet
  130. * @see JInternalFrame
  131. * @see JComponent
  132. * @see BoxLayout
  133. *
  134. * @see <a href="http://java.sun.com/products/jfc/swingdoc-archive/mixing.html">
  135. * Mixing Heavy and Light Components</a>
  136. *
  137. * @version 1.66 04/06/00
  138. * @author David Kloba
  139. */
  140. /// PENDING(klobad) Who should be opaque in this component?
  141. public class JRootPane extends JComponent implements Accessible {
  142. private static final String uiClassID = "RootPaneUI";
  143. /** The subcomponent that currently has focus, or null if no subcomponent
  144. * currently has focus */
  145. private JComponent focusOwner;
  146. private JComponent previousFocusOwner;
  147. /** The menu bar. */
  148. protected JMenuBar menuBar;
  149. /** The content pane. */
  150. protected Container contentPane;
  151. /** The layered pane that manages the menu bar and content pane. */
  152. protected JLayeredPane layeredPane;
  153. /**
  154. * The glass pane that overlays the menu bar and content pane,
  155. * so it can intercept mouse movements and such.
  156. */
  157. protected Component glassPane;
  158. /**
  159. * The button that gets activated when the pane has the focus and
  160. * a UI-specific action like pressing the Enter key occurs.
  161. */
  162. protected JButton defaultButton;
  163. /**
  164. * As of Java 2 platform v1.3 this unusable field is no longer used.
  165. * To override the default button you should replace the Action
  166. * in the JRootPane's ActionMap. Please refer to
  167. * the key bindings specification for further details.
  168. *
  169. * @deprecated As of Java 2 platform v1.3.
  170. * @see #defaultButton
  171. */
  172. protected DefaultAction defaultPressAction;
  173. /**
  174. * As of Java 2 platform v1.3 this unusable field is no longer used.
  175. * To override the default button you should replace the Action
  176. * in the JRootPane's ActionMap. Please refer to
  177. * the key bindings specification for further details.
  178. *
  179. * @deprecated As of Java 2 platform v1.3.
  180. * @see #defaultButton
  181. */
  182. protected DefaultAction defaultReleaseAction;
  183. /**
  184. * Create a JRootPane, setting up its glassPane, LayeredPane, and contentPane.
  185. */
  186. public JRootPane() {
  187. setGlassPane(createGlassPane());
  188. setLayeredPane(createLayeredPane());
  189. setContentPane(createContentPane());
  190. setLayout(createRootLayout());
  191. setDoubleBuffered(true);
  192. updateUI();
  193. }
  194. /**
  195. * Returns the L&F object that renders this component.
  196. *
  197. * @return LabelUI object
  198. * @since 1.3
  199. */
  200. public RootPaneUI getUI() {
  201. return (RootPaneUI)ui;
  202. }
  203. /**
  204. * Sets the L&F object that renders this component.
  205. *
  206. * @since 1.3
  207. * @param ui the LabelUI L&F object
  208. * @see UIDefaults#getUI
  209. * @beaninfo
  210. * expert: true
  211. * description: The L&F object that renders this component.
  212. */
  213. public void setUI(RootPaneUI ui) {
  214. super.setUI(ui);
  215. }
  216. /**
  217. * Notification from the UIFactory that the L&F
  218. * has changed.
  219. *
  220. * @see JComponent#updateUI
  221. */
  222. public void updateUI() {
  223. setUI((RootPaneUI)UIManager.getUI(this));
  224. }
  225. /**
  226. * Returns a string that specifies the name of the l&f class
  227. * that renders this component.
  228. *
  229. * @return String "RootPaneUI"
  230. *
  231. * @see JComponent#getUIClassID
  232. * @see UIDefaults#getUI
  233. */
  234. public String getUIClassID() {
  235. return uiClassID;
  236. }
  237. /** Called by the constructor methods to create the default layeredPane.
  238. * Bt default it creates a new JLayeredPane.
  239. */
  240. protected JLayeredPane createLayeredPane() {
  241. JLayeredPane p = new JLayeredPane();
  242. p.setName(this.getName()+".layeredPane");
  243. return p;
  244. }
  245. /** Called by the constructor methods to create the default contentPane.
  246. * By default this method creates a new JComponent add sets a
  247. * BorderLayout as its LayoutManager.
  248. */
  249. protected Container createContentPane() {
  250. JComponent c = new JPanel();
  251. c.setName(this.getName()+".contentPane");
  252. c.setLayout(new BorderLayout() {
  253. /* This BorderLayout subclass maps a null constraint to CENTER.
  254. * Although the reference BorderLayout also does this, some VMs
  255. * throw an IllegalArgumentException.
  256. */
  257. public void addLayoutComponent(Component comp, Object constraints) {
  258. if (constraints == null) {
  259. constraints = BorderLayout.CENTER;
  260. }
  261. super.addLayoutComponent(comp, constraints);
  262. }
  263. });
  264. return c;
  265. }
  266. /** Called by the constructor methods to create the default glassPane.
  267. * By default this method creates a new JComponent with visibility
  268. * set to false.
  269. */
  270. protected Component createGlassPane() {
  271. JComponent c = new JPanel();
  272. c.setName(this.getName()+".glassPane");
  273. c.setVisible(false);
  274. ((JPanel)c).setOpaque(false);
  275. return c;
  276. }
  277. /** Called by the constructor methods to create the default layoutManager. */
  278. protected LayoutManager createRootLayout() {
  279. return new RootLayout();
  280. }
  281. /**
  282. * Adds or changes the menu bar used in the layered pane.
  283. * @param menu the JMenuBar to add
  284. */
  285. public void setJMenuBar(JMenuBar menu) {
  286. if(menuBar != null && menuBar.getParent() == layeredPane)
  287. layeredPane.remove(menuBar);
  288. menuBar = menu;
  289. if(menuBar != null)
  290. layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  291. }
  292. /**
  293. * Specifies the menu bar value.
  294. * @deprecated As of Swing version 1.0.3
  295. * replaced by <code>setJMenuBar(JMenuBar menu)</code>.
  296. */
  297. public void setMenuBar(JMenuBar menu){
  298. if(menuBar != null && menuBar.getParent() == layeredPane)
  299. layeredPane.remove(menuBar);
  300. menuBar = menu;
  301. if(menuBar != null)
  302. layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
  303. }
  304. /**
  305. * Returns the menu bar from the layered pane.
  306. * @return the JMenuBar used in the pane
  307. */
  308. public JMenuBar getJMenuBar() { return menuBar; }
  309. /**
  310. * Returns the menu bar value.
  311. * @deprecated As of Swing version 1.0.3
  312. * replaced by <code>getJMenubar()</code>.
  313. */
  314. public JMenuBar getMenuBar() { return menuBar; }
  315. /**
  316. * Sets the content pane -- the container that holds the components
  317. * parented by the root pane.
  318. *
  319. * @param content the Container to use for component-contents
  320. * @exception java.awt.IllegalComponentStateException (a runtime
  321. * exception) if the content pane parameter is null
  322. */
  323. public void setContentPane(Container content) {
  324. if(content == null)
  325. throw new IllegalComponentStateException("contentPane cannot be set to null.");
  326. if(contentPane != null && contentPane.getParent() == layeredPane)
  327. layeredPane.remove(contentPane);
  328. contentPane = content;
  329. layeredPane.add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
  330. }
  331. /**
  332. * Returns the content pane -- the container that holds the components
  333. * parented by the root pane.
  334. *
  335. * @return the Container that holds the component-contents
  336. */
  337. public Container getContentPane() { return contentPane; }
  338. // PENDING(klobad) Should this reparent the contentPane and MenuBar?
  339. /**
  340. * Set the layered pane for the root pane. The layered pane
  341. * typically holds a content pane and an optional JMenuBar.
  342. *
  343. * @param layered the JLayeredPane to use.
  344. * @exception java.awt.IllegalComponentStateException (a runtime
  345. * exception) if the layered pane parameter is null
  346. */
  347. public void setLayeredPane(JLayeredPane layered) {
  348. if(layered == null)
  349. throw new IllegalComponentStateException("layeredPane cannot be set to null.");
  350. if(layeredPane != null && layeredPane.getParent() == this)
  351. this.remove(layeredPane);
  352. layeredPane = layered;
  353. this.add(layeredPane, -1);
  354. }
  355. /**
  356. * Get the layered pane used by the root pane. The layered pane
  357. * typically holds a content pane and an optional JMenuBar.
  358. *
  359. * @return the JLayeredPane currently in use
  360. */
  361. public JLayeredPane getLayeredPane() { return layeredPane; }
  362. /**
  363. * Sets a specified Component to be the glass pane for this
  364. * root pane. The glass pane should normally be a lightweight,
  365. * transparent component, because it will be made visible when
  366. * ever the root pane needs to grab input events. For example,
  367. * only one JInternalFrame is ever active when using a
  368. * DefaultDesktop, and any inactive JInternalFrames' glass panes
  369. * are made visible so that clicking anywhere within an inactive
  370. * JInternalFrame can activate it.
  371. * @param glass the Component to use as the glass pane for this
  372. * JRootPane.
  373. */
  374. public void setGlassPane(Component glass) {
  375. if (glass == null) {
  376. throw new NullPointerException("glassPane cannot be set to null.");
  377. }
  378. boolean visible = false;
  379. if (glassPane != null && glassPane.getParent() == this) {
  380. this.remove(glassPane);
  381. visible = glassPane.isVisible();
  382. }
  383. glass.setVisible(visible);
  384. glassPane = glass;
  385. this.add(glassPane, 0);
  386. if (visible) {
  387. repaint();
  388. }
  389. }
  390. /**
  391. * Returns the current glass pane for this JRootPane.
  392. * @return the current glass pane.
  393. * @see #setGlassPane
  394. */
  395. public Component getGlassPane() {
  396. return glassPane;
  397. }
  398. /**
  399. * Make JRootPane be the root of a focus cycle.
  400. * That means that, by default, tabbing within the root
  401. * pane will move between components of the pane,
  402. * but not out of the pane.
  403. * @see JComponent#isFocusCycleRoot
  404. * @return true
  405. */
  406. public boolean isFocusCycleRoot() {
  407. return true;
  408. }
  409. /**
  410. * If a descendant of this JRootPane calls revalidate, validate
  411. * from here on down.
  412. *<p>
  413. * Deferred requests to relayout a component and it's descendants,
  414. * i.e. calls to revalidate(), are pushed upwards to either a JRootPane
  415. * or a JScrollPane because both classes override isValidateRoot() to
  416. * return true.
  417. *
  418. * @see JComponent#isValidateRoot
  419. * @return true
  420. */
  421. public boolean isValidateRoot() {
  422. return true;
  423. }
  424. /**
  425. * The GlassPane and ContentPane have the same bounds, which means
  426. * JRootPane does not tiles its children and this should return false.
  427. * On the other hand, the GlassPane is normally not visible, and so
  428. * this can return true if the GlassPane isn't visible. Therefore, the
  429. * return value here depends upon the visiblity of the GlassPane.
  430. *
  431. * @return true if this component's children don't overlap
  432. */
  433. public boolean isOptimizedDrawingEnabled() {
  434. return !glassPane.isVisible();
  435. }
  436. /**
  437. * Register ourselves with the SystemEventQueueUtils as a new
  438. * root pane.
  439. */
  440. public void addNotify() {
  441. SystemEventQueueUtilities.addRunnableCanvas(this);
  442. super.addNotify();
  443. enableEvents(AWTEvent.KEY_EVENT_MASK);
  444. }
  445. // Note: These links don't work because the target
  446. // class is package private
  447. // @see SystemEventQueueUtilities#addRunnableCanvas
  448. // @see SystemEventQueueUtilities#removeRunnableCanvas
  449. /**
  450. * Unregister ourselves from SystemEventQueueUtils.
  451. * @see #addNotify
  452. */
  453. public void removeNotify() {
  454. SystemEventQueueUtilities.removeRunnableCanvas(this);
  455. super.removeNotify();
  456. }
  457. /**
  458. * Sets the current default button for this <code>JRootPane</code>.
  459. * The default button is the button which will be activated
  460. * when a UI-defined activation event (typically the <b>Enter</b> key)
  461. * occurs in the RootPane regardless of whether or not the button
  462. * has keyboard focus (unless there is another component within
  463. * the RootPane which consumes the activation event, such as a JTextPane).
  464. * For default activation to work, the button must be an enabled
  465. * descendent of the RootPane when activation occurs.
  466. * To remove a default button from this RootPane, set this
  467. * property to <code>null</code>.
  468. *
  469. * @see JButton#isDefaultButton
  470. * @param default the JButton which is to be the default button
  471. */
  472. public void setDefaultButton(JButton defaultButton) {
  473. JButton oldDefault = this.defaultButton;
  474. if (oldDefault != defaultButton) {
  475. this.defaultButton = defaultButton;
  476. if (oldDefault != null) {
  477. oldDefault.repaint();
  478. }
  479. if (defaultButton != null) {
  480. defaultButton.repaint();
  481. }
  482. }
  483. firePropertyChange("defaultButton", oldDefault, defaultButton);
  484. }
  485. /**
  486. * Returns the current default button for this JRootPane.
  487. * @return the JButton which is currently the default button
  488. */
  489. public JButton getDefaultButton() {
  490. return defaultButton;
  491. }
  492. static class DefaultAction extends AbstractAction {
  493. JButton owner;
  494. JRootPane root;
  495. boolean press;
  496. DefaultAction(JRootPane root, boolean press) {
  497. this.root = root;
  498. this.press = press;
  499. }
  500. public void setOwner(JButton owner) {
  501. this.owner = owner;
  502. }
  503. public void actionPerformed(ActionEvent e) {
  504. if (owner != null && SwingUtilities.getRootPane(owner) == root) {
  505. ButtonModel model = owner.getModel();
  506. if (press) {
  507. model.setArmed(true);
  508. model.setPressed(true);
  509. } else {
  510. model.setPressed(false);
  511. }
  512. }
  513. }
  514. public boolean isEnabled() {
  515. return owner.getModel().isEnabled();
  516. }
  517. }
  518. /** Overridden to enforce the position of the glass component as the zero child. */
  519. protected void addImpl(Component comp, Object constraints, int index) {
  520. super.addImpl(comp, constraints, index);
  521. /// We are making sure the glassPane is on top.
  522. if(glassPane != null
  523. && glassPane.getParent() == this
  524. && getComponent(0) != glassPane) {
  525. add(glassPane, 0);
  526. }
  527. }
  528. ///////////////////////////////////////////////////////////////////////////////
  529. //// Begin Inner Classes
  530. ///////////////////////////////////////////////////////////////////////////////
  531. /**
  532. * A custom layout manager that is responsible for the layout of
  533. * layeredPane, glassPane, and menuBar.
  534. * <p>
  535. * <strong>Warning:</strong>
  536. * Serialized objects of this class will not be compatible with
  537. * future Swing releases. The current serialization support is appropriate
  538. * for short term storage or RMI between applications running the same
  539. * version of Swing. A future release of Swing will provide support for
  540. * long term persistence.
  541. */
  542. protected class RootLayout implements LayoutManager2, Serializable
  543. {
  544. /**
  545. * Returns the amount of space the layout would like to have.
  546. *
  547. * @param the Container for which this layout manager is being used
  548. * @return a Dimension object containing the layout's preferred size
  549. */
  550. public Dimension preferredLayoutSize(Container parent) {
  551. Dimension rd, mbd;
  552. Insets i = getInsets();
  553. if(contentPane != null) {
  554. rd = contentPane.getPreferredSize();
  555. } else {
  556. rd = parent.getSize();
  557. }
  558. if(menuBar != null) {
  559. mbd = menuBar.getPreferredSize();
  560. } else {
  561. mbd = new Dimension(0, 0);
  562. }
  563. return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right,
  564. rd.height + mbd.height + i.top + i.bottom);
  565. }
  566. /**
  567. * Returns the minimum amount of space the layout needs.
  568. *
  569. * @param the Container for which this layout manager is being used
  570. * @return a Dimension object containing the layout's minimum size
  571. */
  572. public Dimension minimumLayoutSize(Container parent) {
  573. Dimension rd, mbd;
  574. Insets i = getInsets();
  575. if(contentPane != null) {
  576. rd = contentPane.getMinimumSize();
  577. } else {
  578. rd = parent.getSize();
  579. }
  580. if(menuBar != null) {
  581. mbd = menuBar.getMinimumSize();
  582. } else {
  583. mbd = new Dimension(0, 0);
  584. }
  585. return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right,
  586. rd.height + mbd.height + i.top + i.bottom);
  587. }
  588. /**
  589. * Returns the maximum amount of space the layout can use.
  590. *
  591. * @param the Container for which this layout manager is being used
  592. * @return a Dimension object containing the layout's maximum size
  593. */
  594. public Dimension maximumLayoutSize(Container target) {
  595. Dimension rd, mbd;
  596. Insets i = getInsets();
  597. if(menuBar != null) {
  598. mbd = menuBar.getMaximumSize();
  599. } else {
  600. mbd = new Dimension(0, 0);
  601. }
  602. if(contentPane != null) {
  603. rd = contentPane.getMaximumSize();
  604. } else {
  605. // This is silly, but should stop an overflow error
  606. rd = new Dimension(Integer.MAX_VALUE,
  607. Integer.MAX_VALUE - i.top - i.bottom - mbd.height - 1);
  608. }
  609. return new Dimension(Math.min(rd.width, mbd.width) + i.left + i.right,
  610. rd.height + mbd.height + i.top + i.bottom);
  611. }
  612. /**
  613. * Instructs the layout manager to perform the layout for the specified
  614. * container.
  615. *
  616. * @param the Container for which this layout manager is being used
  617. */
  618. public void layoutContainer(Container parent) {
  619. Rectangle b = parent.getBounds();
  620. Insets i = getInsets();
  621. int contentY = 0;
  622. int w = b.width - i.right - i.left;
  623. int h = b.height - i.top - i.bottom;
  624. if(layeredPane != null) {
  625. layeredPane.setBounds(i.left, i.top, w, h);
  626. }
  627. if(glassPane != null) {
  628. glassPane.setBounds(i.left, i.top, w, h);
  629. }
  630. // Note: This is laying out the children in the layeredPane,
  631. // technically, these are not our chilren.
  632. if(menuBar != null) {
  633. Dimension mbd = menuBar.getPreferredSize();
  634. menuBar.setBounds(0, 0, w, mbd.height);
  635. contentY += mbd.height;
  636. }
  637. if(contentPane != null) {
  638. contentPane.setBounds(0, contentY, w, h - contentY);
  639. }
  640. }
  641. public void addLayoutComponent(String name, Component comp) {}
  642. public void removeLayoutComponent(Component comp) {}
  643. public void addLayoutComponent(Component comp, Object constraints) {}
  644. public float getLayoutAlignmentX(Container target) { return 0.0f; }
  645. public float getLayoutAlignmentY(Container target) { return 0.0f; }
  646. public void invalidateLayout(Container target) {}
  647. }
  648. /** set the current focus owner. Called with the event argument when
  649. * processing FOCUS_GAINED event in a Swing component; called with null
  650. * when processing FOCUS_LOST */
  651. void setCurrentFocusOwner(JComponent focusOwner) {
  652. this.focusOwner = focusOwner;
  653. }
  654. /** return the current focus owner */
  655. JComponent getCurrentFocusOwner() {
  656. return focusOwner;
  657. }
  658. void setPreviousFocusOwner(JComponent focusOwner) {
  659. this.previousFocusOwner = focusOwner;
  660. }
  661. /** return the current focus owner */
  662. JComponent getPreviousFocusOwner() {
  663. return previousFocusOwner;
  664. }
  665. /**
  666. * Returns a string representation of this JRootPane. This method
  667. * is intended to be used only for debugging purposes, and the
  668. * content and format of the returned string may vary between
  669. * implementations. The returned string may be empty but may not
  670. * be <code>null</code>.
  671. *
  672. * @return a string representation of this JRootPane.
  673. */
  674. protected String paramString() {
  675. return super.paramString();
  676. }
  677. /////////////////
  678. // Accessibility support
  679. ////////////////
  680. /**
  681. * Gets the AccessibleContext associated with this JRootPane.
  682. * For root panes, the AccessibleContext takes the form of an
  683. * AccessibleJRootPane.
  684. * A new AccessibleJRootPane instance is created if necessary.
  685. *
  686. * @return an AccessibleJRootPane that serves as the
  687. * AccessibleContext of this JRootPane
  688. */
  689. public AccessibleContext getAccessibleContext() {
  690. if (accessibleContext == null) {
  691. accessibleContext = new AccessibleJRootPane();
  692. }
  693. return accessibleContext;
  694. }
  695. /**
  696. * This class implements accessibility support for the
  697. * <code>JRootPane</code> class. It provides an implementation of the
  698. * Java Accessibility API appropriate to root pane user-interface elements.
  699. * <p>
  700. * <strong>Warning:</strong>
  701. * Serialized objects of this class will not be compatible with
  702. * future Swing releases. The current serialization support is appropriate
  703. * for short term storage or RMI between applications running the same
  704. * version of Swing. A future release of Swing will provide support for
  705. * long term persistence.
  706. */
  707. protected class AccessibleJRootPane extends AccessibleJComponent {
  708. /**
  709. * Get the role of this object.
  710. *
  711. * @return an instance of AccessibleRole describing the role of
  712. * the object
  713. */
  714. public AccessibleRole getAccessibleRole() {
  715. return AccessibleRole.ROOT_PANE;
  716. }
  717. } // inner class AccessibleJRootPane
  718. }