0N/A/*
2362N/A * Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing;
0N/A
0N/Aimport java.applet.Applet;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.beans.*;
0N/Aimport java.security.AccessController;
0N/Aimport javax.accessibility.*;
0N/Aimport javax.swing.plaf.RootPaneUI;
0N/Aimport java.util.Vector;
0N/Aimport java.io.Serializable;
0N/Aimport javax.swing.border.*;
886N/Aimport sun.awt.AWTAccessor;
0N/Aimport sun.security.action.GetBooleanAction;
0N/A
0N/A
0N/A/**
0N/A * A lightweight container used behind the scenes by
0N/A * <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>,
0N/A * <code>JApplet</code>, and <code>JInternalFrame</code>.
0N/A * For task-oriented information on functionality provided by root panes
0N/A * see <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html">How to Use Root Panes</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * <p>
0N/A * The following image shows the relationships between
0N/A * the classes that use root panes.
0N/A * <p align=center><img src="doc-files/JRootPane-1.gif"
0N/A * alt="The following text describes this graphic."
0N/A * HEIGHT=484 WIDTH=629></p>
0N/A * The &quot;heavyweight&quot; components (those that delegate to a peer, or native
0N/A * component on the host system) are shown with a darker, heavier box. The four
0N/A * heavyweight JFC/Swing containers (<code>JFrame</code>, <code>JDialog</code>,
0N/A * <code>JWindow</code>, and <code>JApplet</code>) are
0N/A * shown in relation to the AWT classes they extend.
0N/A * These four components are the
0N/A * only heavyweight containers in the Swing library. The lightweight container
0N/A * <code>JInternalFrame</code> is also shown.
0N/A * All five of these JFC/Swing containers implement the
0N/A * <code>RootPaneContainer</code> interface,
0N/A * and they all delegate their operations to a
0N/A * <code>JRootPane</code> (shown with a little "handle" on top).
0N/A * <blockquote>
0N/A * <b>Note:</b> The <code>JComponent</code> method <code>getRootPane</code>
0N/A * can be used to obtain the <code>JRootPane</code> that contains
0N/A * a given component.
0N/A * </blockquote>
0N/A * <table align="right" border="0" summary="layout">
0N/A * <tr>
0N/A * <td align="center">
0N/A * <img src="doc-files/JRootPane-2.gif"
0N/A * alt="The following text describes this graphic." HEIGHT=386 WIDTH=349>
0N/A * </td>
0N/A * </tr>
0N/A * </table>
0N/A * The diagram at right shows the structure of a <code>JRootPane</code>.
0N/A * A <code>JRootpane</code> is made up of a <code>glassPane</code>,
0N/A * an optional <code>menuBar</code>, and a <code>contentPane</code>.
0N/A * (The <code>JLayeredPane</code> manages the <code>menuBar</code>
0N/A * and the <code>contentPane</code>.)
0N/A * The <code>glassPane</code> sits over the top of everything,
0N/A * where it is in a position to intercept mouse movements.
0N/A * Since the <code>glassPane</code> (like the <code>contentPane</code>)
0N/A * can be an arbitrary component, it is also possible to set up the
0N/A * <code>glassPane</code> for drawing. Lines and images on the
0N/A * <code>glassPane</code> can then range
0N/A * over the frames underneath without being limited by their boundaries.
0N/A * <p>
0N/A * Although the <code>menuBar</code> component is optional,
0N/A * the <code>layeredPane</code>, <code>contentPane</code>,
0N/A * and <code>glassPane</code> always exist.
0N/A * Attempting to set them to <code>null</code> generates an exception.
0N/A * <p>
0N/A * To add components to the <code>JRootPane</code> (other than the
0N/A * optional menu bar), you add the object to the <code>contentPane</code>
0N/A * of the <code>JRootPane</code>, like this:
0N/A * <pre>
0N/A * rootPane.getContentPane().add(child);
0N/A * </pre>
0N/A * The same principle holds true for setting layout managers, removing
0N/A * components, listing children, etc. All these methods are invoked on
0N/A * the <code>contentPane</code> instead of on the <code>JRootPane</code>.
0N/A * <blockquote>
0N/A * <b>Note:</b> The default layout manager for the <code>contentPane</code> is
0N/A * a <code>BorderLayout</code> manager. However, the <code>JRootPane</code>
0N/A * uses a custom <code>LayoutManager</code>.
0N/A * So, when you want to change the layout manager for the components you added
0N/A * to a <code>JRootPane</code>, be sure to use code like this:
0N/A * <pre>
0N/A * rootPane.getContentPane().setLayout(new BoxLayout());
0N/A * </pre></blockquote>
0N/A * If a <code>JMenuBar</code> component is set on the <code>JRootPane</code>,
0N/A * it is positioned along the upper edge of the frame.
0N/A * The <code>contentPane</code> is adjusted in location and size to
0N/A * fill the remaining area.
0N/A * (The <code>JMenuBar</code> and the <code>contentPane</code> are added to the
0N/A * <code>layeredPane</code> component at the
0N/A * <code>JLayeredPane.FRAME_CONTENT_LAYER</code> layer.)
0N/A * <p>
0N/A * The <code>layeredPane</code> is the parent of all children in the
0N/A * <code>JRootPane</code> -- both as the direct parent of the menu and
0N/A * the grandparent of all components added to the <code>contentPane</code>.
0N/A * It is an instance of <code>JLayeredPane</code>,
0N/A * which provides the ability to add components at several layers.
0N/A * This capability is very useful when working with menu popups,
0N/A * dialog boxes, and dragging -- situations in which you need to place
0N/A * a component on top of all other components in the pane.
0N/A * <p>
0N/A * The <code>glassPane</code> sits on top of all other components in the
0N/A * <code>JRootPane</code>.
0N/A * That provides a convenient place to draw above all other components,
0N/A * and makes it possible to intercept mouse events,
0N/A * which is useful both for dragging and for drawing.
0N/A * Developers can use <code>setVisible</code> on the <code>glassPane</code>
0N/A * to control when the <code>glassPane</code> displays over the other children.
0N/A * By default the <code>glassPane</code> is not visible.
0N/A * <p>
0N/A * The custom <code>LayoutManager</code> used by <code>JRootPane</code>
0N/A * ensures that:
0N/A * <OL>
0N/A * <LI>The <code>glassPane</code> fills the entire viewable
0N/A * area of the <code>JRootPane</code> (bounds - insets).
0N/A * <LI>The <code>layeredPane</code> fills the entire viewable area of the
0N/A * <code>JRootPane</code>. (bounds - insets)
0N/A * <LI>The <code>menuBar</code> is positioned at the upper edge of the
0N/A * <code>layeredPane</code>.
0N/A * <LI>The <code>contentPane</code> fills the entire viewable area,
0N/A * minus the <code>menuBar</code>, if present.
0N/A * </OL>
0N/A * Any other views in the <code>JRootPane</code> view hierarchy are ignored.
0N/A * <p>
0N/A * If you replace the <code>LayoutManager</code> of the <code>JRootPane</code>,
0N/A * you are responsible for managing all of these views.
0N/A * So ordinarily you will want to be sure that you
0N/A * change the layout manager for the <code>contentPane</code> rather than
0N/A * for the <code>JRootPane</code> itself!
0N/A * <p>
0N/A * The painting architecture of Swing requires an opaque
0N/A * <code>JComponent</code>
0N/A * to exist in the containment hieararchy above all other components. This is
0N/A * typically provided by way of the content pane. If you replace the content
0N/A * pane, it is recommended that you make the content pane opaque
0N/A * by way of <code>setOpaque(true)</code>. Additionally, if the content pane
0N/A * overrides <code>paintComponent</code>, it
0N/A * will need to completely fill in the background in an opaque color in
0N/A * <code>paintComponent</code>.
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A *
0N/A * @see JLayeredPane
0N/A * @see JMenuBar
0N/A * @see JWindow
0N/A * @see JFrame
0N/A * @see JDialog
0N/A * @see JApplet
0N/A * @see JInternalFrame
0N/A * @see JComponent
0N/A * @see BoxLayout
0N/A *
0N/A * @see <a href="http://java.sun.com/products/jfc/tsc/articles/mixing/">
0N/A * Mixing Heavy and Light Components</a>
0N/A *
0N/A * @author David Kloba
0N/A */
0N/A/// PENDING(klobad) Who should be opaque in this component?
0N/Apublic class JRootPane extends JComponent implements Accessible {
0N/A
0N/A private static final String uiClassID = "RootPaneUI";
0N/A
0N/A /**
0N/A * Whether or not we should dump the stack when true double buffering
0N/A * is disabled. Default is false.
0N/A */
0N/A private static final boolean LOG_DISABLE_TRUE_DOUBLE_BUFFERING;
0N/A
0N/A /**
0N/A * Whether or not we should ignore requests to disable true double
0N/A * buffering. Default is false.
0N/A */
0N/A private static final boolean IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should not provide any sort of
0N/A * Window decorations.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int NONE = 0;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Frame.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int FRAME = 1;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Dialog.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int PLAIN_DIALOG = 2;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Dialog used to display an informational message.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int INFORMATION_DIALOG = 3;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Dialog used to display an error message.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int ERROR_DIALOG = 4;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Dialog used to display a <code>JColorChooser</code>.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int COLOR_CHOOSER_DIALOG = 5;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Dialog used to display a <code>JFileChooser</code>.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int FILE_CHOOSER_DIALOG = 6;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Dialog used to present a question to the user.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int QUESTION_DIALOG = 7;
0N/A
0N/A /**
0N/A * Constant used for the windowDecorationStyle property. Indicates that
0N/A * the <code>JRootPane</code> should provide decorations appropriate for
0N/A * a Dialog used to display a warning message.
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public static final int WARNING_DIALOG = 8;
0N/A
0N/A private int windowDecorationStyle;
0N/A
0N/A /** The menu bar. */
0N/A protected JMenuBar menuBar;
0N/A
0N/A /** The content pane. */
0N/A protected Container contentPane;
0N/A
0N/A /** The layered pane that manages the menu bar and content pane. */
0N/A protected JLayeredPane layeredPane;
0N/A
0N/A /**
0N/A * The glass pane that overlays the menu bar and content pane,
0N/A * so it can intercept mouse movements and such.
0N/A */
0N/A protected Component glassPane;
0N/A /**
0N/A * The button that gets activated when the pane has the focus and
0N/A * a UI-specific action like pressing the <b>Enter</b> key occurs.
0N/A */
0N/A protected JButton defaultButton;
0N/A /**
0N/A * As of Java 2 platform v1.3 this unusable field is no longer used.
0N/A * To override the default button you should replace the <code>Action</code>
0N/A * in the <code>JRootPane</code>'s <code>ActionMap</code>. Please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A * @see #defaultButton
0N/A */
0N/A @Deprecated
0N/A protected DefaultAction defaultPressAction;
0N/A /**
0N/A * As of Java 2 platform v1.3 this unusable field is no longer used.
0N/A * To override the default button you should replace the <code>Action</code>
0N/A * in the <code>JRootPane</code>'s <code>ActionMap</code>. Please refer to
0N/A * the key bindings specification for further details.
0N/A *
0N/A * @deprecated As of Java 2 platform v1.3.
0N/A * @see #defaultButton
0N/A */
0N/A @Deprecated
0N/A protected DefaultAction defaultReleaseAction;
0N/A
0N/A /**
0N/A * Whether or not true double buffering should be used. This is typically
0N/A * true, but may be set to false in special situations. For example,
0N/A * heavy weight popups (backed by a window) set this to false.
0N/A */
0N/A boolean useTrueDoubleBuffering = true;
0N/A
0N/A static {
0N/A LOG_DISABLE_TRUE_DOUBLE_BUFFERING =
0N/A AccessController.doPrivileged(new GetBooleanAction(
0N/A "swing.logDoubleBufferingDisable"));
0N/A IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING =
0N/A AccessController.doPrivileged(new GetBooleanAction(
0N/A "swing.ignoreDoubleBufferingDisable"));
0N/A }
0N/A
0N/A /**
0N/A * Creates a <code>JRootPane</code>, setting up its
0N/A * <code>glassPane</code>, <code>layeredPane</code>,
0N/A * and <code>contentPane</code>.
0N/A */
0N/A public JRootPane() {
0N/A setGlassPane(createGlassPane());
0N/A setLayeredPane(createLayeredPane());
0N/A setContentPane(createContentPane());
0N/A setLayout(createRootLayout());
0N/A setDoubleBuffered(true);
0N/A updateUI();
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A * @since 1.6
0N/A */
0N/A public void setDoubleBuffered(boolean aFlag) {
0N/A if (isDoubleBuffered() != aFlag) {
0N/A super.setDoubleBuffered(aFlag);
0N/A RepaintManager.currentManager(this).doubleBufferingChanged(this);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a constant identifying the type of Window decorations the
0N/A * <code>JRootPane</code> is providing.
0N/A *
0N/A * @return One of <code>NONE</code>, <code>FRAME</code>,
0N/A * <code>PLAIN_DIALOG</code>, <code>INFORMATION_DIALOG</code>,
0N/A * <code>ERROR_DIALOG</code>, <code>COLOR_CHOOSER_DIALOG</code>,
0N/A * <code>FILE_CHOOSER_DIALOG</code>, <code>QUESTION_DIALOG</code> or
0N/A * <code>WARNING_DIALOG</code>.
0N/A * @see #setWindowDecorationStyle
0N/A * @since 1.4
0N/A */
0N/A public int getWindowDecorationStyle() {
0N/A return windowDecorationStyle;
0N/A }
0N/A
0N/A /**
0N/A * Sets the type of Window decorations (such as borders, widgets for
0N/A * closing a Window, title ...) the <code>JRootPane</code> should
0N/A * provide. The default is to provide no Window decorations
0N/A * (<code>NONE</code>).
0N/A * <p>
0N/A * This is only a hint, and some look and feels may not support
0N/A * this.
0N/A * This is a bound property.
0N/A *
0N/A * @param windowDecorationStyle Constant identifying Window decorations
0N/A * to provide.
0N/A * @see JDialog#setDefaultLookAndFeelDecorated
0N/A * @see JFrame#setDefaultLookAndFeelDecorated
0N/A * @see LookAndFeel#getSupportsWindowDecorations
0N/A * @throws IllegalArgumentException if <code>style</code> is
0N/A * not one of: <code>NONE</code>, <code>FRAME</code>,
0N/A * <code>PLAIN_DIALOG</code>, <code>INFORMATION_DIALOG</code>,
0N/A * <code>ERROR_DIALOG</code>, <code>COLOR_CHOOSER_DIALOG</code>,
0N/A * <code>FILE_CHOOSER_DIALOG</code>, <code>QUESTION_DIALOG</code>, or
0N/A * <code>WARNING_DIALOG</code>.
0N/A * @since 1.4
0N/A * @beaninfo
0N/A * bound: true
0N/A * enum: NONE JRootPane.NONE
0N/A * FRAME JRootPane.FRAME
0N/A * PLAIN_DIALOG JRootPane.PLAIN_DIALOG
0N/A * INFORMATION_DIALOG JRootPane.INFORMATION_DIALOG
0N/A * ERROR_DIALOG JRootPane.ERROR_DIALOG
0N/A * COLOR_CHOOSER_DIALOG JRootPane.COLOR_CHOOSER_DIALOG
0N/A * FILE_CHOOSER_DIALOG JRootPane.FILE_CHOOSER_DIALOG
0N/A * QUESTION_DIALOG JRootPane.QUESTION_DIALOG
0N/A * WARNING_DIALOG JRootPane.WARNING_DIALOG
0N/A * expert: true
0N/A * attribute: visualUpdate true
0N/A * description: Identifies the type of Window decorations to provide
0N/A */
0N/A public void setWindowDecorationStyle(int windowDecorationStyle) {
0N/A if (windowDecorationStyle < 0 ||
0N/A windowDecorationStyle > WARNING_DIALOG) {
0N/A throw new IllegalArgumentException("Invalid decoration style");
0N/A }
0N/A int oldWindowDecorationStyle = getWindowDecorationStyle();
0N/A this.windowDecorationStyle = windowDecorationStyle;
0N/A firePropertyChange("windowDecorationStyle",
0N/A oldWindowDecorationStyle,
0N/A windowDecorationStyle);
0N/A }
0N/A
0N/A /**
0N/A * Returns the L&F object that renders this component.
0N/A *
0N/A * @return <code>LabelUI</code> object
0N/A * @since 1.3
0N/A */
0N/A public RootPaneUI getUI() {
0N/A return (RootPaneUI)ui;
0N/A }
0N/A
0N/A /**
0N/A * Sets the L&F object that renders this component.
0N/A *
0N/A * @param ui the <code>LabelUI</code> L&F object
0N/A * @see UIDefaults#getUI
0N/A * @beaninfo
0N/A * bound: true
0N/A * hidden: true
0N/A * expert: true
0N/A * attribute: visualUpdate true
0N/A * description: The UI object that implements the Component's LookAndFeel.
0N/A * @since 1.3
0N/A */
0N/A public void setUI(RootPaneUI ui) {
0N/A super.setUI(ui);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Resets the UI property to a value from the current look and feel.
0N/A *
0N/A * @see JComponent#updateUI
0N/A */
0N/A public void updateUI() {
0N/A setUI((RootPaneUI)UIManager.getUI(this));
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string that specifies the name of the L&F class
0N/A * that renders this component.
0N/A *
0N/A * @return the string "RootPaneUI"
0N/A *
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A /**
0N/A * Called by the constructor methods to create the default
0N/A * <code>layeredPane</code>.
0N/A * Bt default it creates a new <code>JLayeredPane</code>.
0N/A * @return the default <code>layeredPane</code>
0N/A */
0N/A protected JLayeredPane createLayeredPane() {
0N/A JLayeredPane p = new JLayeredPane();
0N/A p.setName(this.getName()+".layeredPane");
0N/A return p;
0N/A }
0N/A
0N/A /**
0N/A * Called by the constructor methods to create the default
0N/A * <code>contentPane</code>.
0N/A * By default this method creates a new <code>JComponent</code> add sets a
0N/A * <code>BorderLayout</code> as its <code>LayoutManager</code>.
0N/A * @return the default <code>contentPane</code>
0N/A */
0N/A protected Container createContentPane() {
0N/A JComponent c = new JPanel();
0N/A c.setName(this.getName()+".contentPane");
0N/A c.setLayout(new BorderLayout() {
0N/A /* This BorderLayout subclass maps a null constraint to CENTER.
0N/A * Although the reference BorderLayout also does this, some VMs
0N/A * throw an IllegalArgumentException.
0N/A */
0N/A public void addLayoutComponent(Component comp, Object constraints) {
0N/A if (constraints == null) {
0N/A constraints = BorderLayout.CENTER;
0N/A }
0N/A super.addLayoutComponent(comp, constraints);
0N/A }
0N/A });
0N/A return c;
0N/A }
0N/A
0N/A /**
0N/A * Called by the constructor methods to create the default
0N/A * <code>glassPane</code>.
0N/A * By default this method creates a new <code>JComponent</code>
0N/A * with visibility set to false.
0N/A * @return the default <code>glassPane</code>
0N/A */
0N/A protected Component createGlassPane() {
0N/A JComponent c = new JPanel();
0N/A c.setName(this.getName()+".glassPane");
0N/A c.setVisible(false);
0N/A ((JPanel)c).setOpaque(false);
0N/A return c;
0N/A }
0N/A
0N/A /**
0N/A * Called by the constructor methods to create the default
0N/A * <code>layoutManager</code>.
0N/A * @return the default <code>layoutManager</code>.
0N/A */
0N/A protected LayoutManager createRootLayout() {
0N/A return new RootLayout();
0N/A }
0N/A
0N/A /**
0N/A * Adds or changes the menu bar used in the layered pane.
0N/A * @param menu the <code>JMenuBar</code> to add
0N/A */
0N/A public void setJMenuBar(JMenuBar menu) {
0N/A if(menuBar != null && menuBar.getParent() == layeredPane)
0N/A layeredPane.remove(menuBar);
0N/A menuBar = menu;
0N/A
0N/A if(menuBar != null)
0N/A layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
0N/A }
0N/A
0N/A /**
0N/A * Specifies the menu bar value.
0N/A * @deprecated As of Swing version 1.0.3
0N/A * replaced by <code>setJMenuBar(JMenuBar menu)</code>.
0N/A * @param menu the <code>JMenuBar</code> to add.
0N/A */
0N/A @Deprecated
0N/A public void setMenuBar(JMenuBar menu){
0N/A if(menuBar != null && menuBar.getParent() == layeredPane)
0N/A layeredPane.remove(menuBar);
0N/A menuBar = menu;
0N/A
0N/A if(menuBar != null)
0N/A layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
0N/A }
0N/A
0N/A /**
0N/A * Returns the menu bar from the layered pane.
0N/A * @return the <code>JMenuBar</code> used in the pane
0N/A */
0N/A public JMenuBar getJMenuBar() { return menuBar; }
0N/A
0N/A /**
0N/A * Returns the menu bar value.
0N/A * @deprecated As of Swing version 1.0.3
0N/A * replaced by <code>getJMenuBar()</code>.
0N/A * @return the <code>JMenuBar</code> used in the pane
0N/A */
0N/A @Deprecated
0N/A public JMenuBar getMenuBar() { return menuBar; }
0N/A
0N/A /**
0N/A * Sets the content pane -- the container that holds the components
0N/A * parented by the root pane.
0N/A * <p>
0N/A * Swing's painting architecture requires an opaque <code>JComponent</code>
0N/A * in the containment hiearchy. This is typically provided by the
0N/A * content pane. If you replace the content pane it is recommended you
0N/A * replace it with an opaque <code>JComponent</code>.
0N/A *
0N/A * @param content the <code>Container</code> to use for component-contents
0N/A * @exception java.awt.IllegalComponentStateException (a runtime
0N/A * exception) if the content pane parameter is <code>null</code>
0N/A */
0N/A public void setContentPane(Container content) {
0N/A if(content == null)
0N/A throw new IllegalComponentStateException("contentPane cannot be set to null.");
0N/A if(contentPane != null && contentPane.getParent() == layeredPane)
0N/A layeredPane.remove(contentPane);
0N/A contentPane = content;
0N/A
0N/A layeredPane.add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
0N/A }
0N/A
0N/A /**
0N/A * Returns the content pane -- the container that holds the components
0N/A * parented by the root pane.
0N/A *
0N/A * @return the <code>Container</code> that holds the component-contents
0N/A */
0N/A public Container getContentPane() { return contentPane; }
0N/A
0N/A// PENDING(klobad) Should this reparent the contentPane and MenuBar?
0N/A /**
0N/A * Sets the layered pane for the root pane. The layered pane
0N/A * typically holds a content pane and an optional <code>JMenuBar</code>.
0N/A *
0N/A * @param layered the <code>JLayeredPane</code> to use
0N/A * @exception java.awt.IllegalComponentStateException (a runtime
0N/A * exception) if the layered pane parameter is <code>null</code>
0N/A */
0N/A public void setLayeredPane(JLayeredPane layered) {
0N/A if(layered == null)
0N/A throw new IllegalComponentStateException("layeredPane cannot be set to null.");
0N/A if(layeredPane != null && layeredPane.getParent() == this)
0N/A this.remove(layeredPane);
0N/A layeredPane = layered;
0N/A
0N/A this.add(layeredPane, -1);
0N/A }
0N/A /**
0N/A * Gets the layered pane used by the root pane. The layered pane
0N/A * typically holds a content pane and an optional <code>JMenuBar</code>.
0N/A *
0N/A * @return the <code>JLayeredPane</code> currently in use
0N/A */
0N/A public JLayeredPane getLayeredPane() { return layeredPane; }
0N/A
0N/A /**
0N/A * Sets a specified <code>Component</code> to be the glass pane for this
0N/A * root pane. The glass pane should normally be a lightweight,
0N/A * transparent component, because it will be made visible when
0N/A * ever the root pane needs to grab input events.
0N/A * <p>
0N/A * The new glass pane's visibility is changed to match that of
0N/A * the current glass pane. An implication of this is that care
0N/A * must be taken when you want to replace the glass pane and
0N/A * make it visible. Either of the following will work:
0N/A * <pre>
0N/A * root.setGlassPane(newGlassPane);
0N/A * newGlassPane.setVisible(true);
0N/A * </pre>
0N/A * or:
0N/A * <pre>
0N/A * root.getGlassPane().setVisible(true);
0N/A * root.setGlassPane(newGlassPane);
0N/A * </pre>
0N/A *
0N/A * @param glass the <code>Component</code> to use as the glass pane
0N/A * for this <code>JRootPane</code>
0N/A * @exception NullPointerException if the <code>glass</code> parameter is
0N/A * <code>null</code>
0N/A */
0N/A public void setGlassPane(Component glass) {
0N/A if (glass == null) {
0N/A throw new NullPointerException("glassPane cannot be set to null.");
0N/A }
0N/A
886N/A AWTAccessor.getComponentAccessor().setMixingCutoutShape(glass,
886N/A new Rectangle());
886N/A
0N/A boolean visible = false;
0N/A if (glassPane != null && glassPane.getParent() == this) {
0N/A this.remove(glassPane);
0N/A visible = glassPane.isVisible();
0N/A }
0N/A
0N/A glass.setVisible(visible);
0N/A glassPane = glass;
0N/A this.add(glassPane, 0);
0N/A if (visible) {
0N/A repaint();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the current glass pane for this <code>JRootPane</code>.
0N/A * @return the current glass pane
0N/A * @see #setGlassPane
0N/A */
0N/A public Component getGlassPane() {
0N/A return glassPane;
0N/A }
0N/A
0N/A /**
0N/A * If a descendant of this <code>JRootPane</code> calls
0N/A * <code>revalidate</code>, validate from here on down.
0N/A *<p>
0N/A * Deferred requests to layout a component and its descendents again.
0N/A * For example, calls to <code>revalidate</code>, are pushed upwards to
0N/A * either a <code>JRootPane</code> or a <code>JScrollPane</code>
0N/A * because both classes override <code>isValidateRoot</code> to return true.
0N/A *
0N/A * @see JComponent#isValidateRoot
1895N/A * @see java.awt.Container#isValidateRoot
0N/A * @return true
0N/A */
1895N/A @Override
0N/A public boolean isValidateRoot() {
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * The <code>glassPane</code> and <code>contentPane</code>
0N/A * have the same bounds, which means <code>JRootPane</code>
0N/A * does not tiles its children and this should return false.
0N/A * On the other hand, the <code>glassPane</code>
0N/A * is normally not visible, and so this can return true if the
0N/A * <code>glassPane</code> isn't visible. Therefore, the
0N/A * return value here depends upon the visiblity of the
0N/A * <code>glassPane</code>.
0N/A *
0N/A * @return true if this component's children don't overlap
0N/A */
0N/A public boolean isOptimizedDrawingEnabled() {
0N/A return !glassPane.isVisible();
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A public void addNotify() {
0N/A super.addNotify();
0N/A enableEvents(AWTEvent.KEY_EVENT_MASK);
0N/A }
0N/A
0N/A /**
0N/A * {@inheritDoc}
0N/A */
0N/A public void removeNotify() {
0N/A super.removeNotify();
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the <code>defaultButton</code> property,
0N/A * which determines the current default button for this <code>JRootPane</code>.
0N/A * The default button is the button which will be activated
0N/A * when a UI-defined activation event (typically the <b>Enter</b> key)
0N/A * occurs in the root pane regardless of whether or not the button
0N/A * has keyboard focus (unless there is another component within
0N/A * the root pane which consumes the activation event,
0N/A * such as a <code>JTextPane</code>).
0N/A * For default activation to work, the button must be an enabled
0N/A * descendent of the root pane when activation occurs.
0N/A * To remove a default button from this root pane, set this
0N/A * property to <code>null</code>.
0N/A *
0N/A * @see JButton#isDefaultButton
0N/A * @param defaultButton the <code>JButton</code> which is to be the default button
0N/A *
0N/A * @beaninfo
0N/A * description: The button activated by default in this root pane
0N/A */
0N/A public void setDefaultButton(JButton defaultButton) {
0N/A JButton oldDefault = this.defaultButton;
0N/A
0N/A if (oldDefault != defaultButton) {
0N/A this.defaultButton = defaultButton;
0N/A
0N/A if (oldDefault != null) {
0N/A oldDefault.repaint();
0N/A }
0N/A if (defaultButton != null) {
0N/A defaultButton.repaint();
0N/A }
0N/A }
0N/A
0N/A firePropertyChange("defaultButton", oldDefault, defaultButton);
0N/A }
0N/A
0N/A /**
0N/A * Returns the value of the <code>defaultButton</code> property.
0N/A * @return the <code>JButton</code> which is currently the default button
0N/A * @see #setDefaultButton
0N/A */
0N/A public JButton getDefaultButton() {
0N/A return defaultButton;
0N/A }
0N/A
0N/A final void setUseTrueDoubleBuffering(boolean useTrueDoubleBuffering) {
0N/A this.useTrueDoubleBuffering = useTrueDoubleBuffering;
0N/A }
0N/A
0N/A final boolean getUseTrueDoubleBuffering() {
0N/A return useTrueDoubleBuffering;
0N/A }
0N/A
0N/A final void disableTrueDoubleBuffering() {
0N/A if (useTrueDoubleBuffering) {
0N/A if (!IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING) {
0N/A if (LOG_DISABLE_TRUE_DOUBLE_BUFFERING) {
0N/A System.out.println("Disabling true double buffering for " +
0N/A this);
0N/A Thread.dumpStack();
0N/A }
0N/A useTrueDoubleBuffering = false;
0N/A RepaintManager.currentManager(this).
0N/A doubleBufferingChanged(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A static class DefaultAction extends AbstractAction {
0N/A JButton owner;
0N/A JRootPane root;
0N/A boolean press;
0N/A DefaultAction(JRootPane root, boolean press) {
0N/A this.root = root;
0N/A this.press = press;
0N/A }
0N/A public void setOwner(JButton owner) {
0N/A this.owner = owner;
0N/A }
0N/A public void actionPerformed(ActionEvent e) {
0N/A if (owner != null && SwingUtilities.getRootPane(owner) == root) {
0N/A ButtonModel model = owner.getModel();
0N/A if (press) {
0N/A model.setArmed(true);
0N/A model.setPressed(true);
0N/A } else {
0N/A model.setPressed(false);
0N/A }
0N/A }
0N/A }
0N/A public boolean isEnabled() {
0N/A return owner.getModel().isEnabled();
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Overridden to enforce the position of the glass component as
0N/A * the zero child.
0N/A *
0N/A * @param comp the component to be enhanced
0N/A * @param constraints the constraints to be respected
0N/A * @param index the index
0N/A */
0N/A protected void addImpl(Component comp, Object constraints, int index) {
0N/A super.addImpl(comp, constraints, index);
0N/A
0N/A /// We are making sure the glassPane is on top.
0N/A if(glassPane != null
0N/A && glassPane.getParent() == this
0N/A && getComponent(0) != glassPane) {
0N/A add(glassPane, 0);
0N/A }
0N/A }
0N/A
0N/A
0N/A///////////////////////////////////////////////////////////////////////////////
0N/A//// Begin Inner Classes
0N/A///////////////////////////////////////////////////////////////////////////////
0N/A
0N/A
0N/A /**
0N/A * A custom layout manager that is responsible for the layout of
0N/A * layeredPane, glassPane, and menuBar.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class RootLayout implements LayoutManager2, Serializable
0N/A {
0N/A /**
0N/A * Returns the amount of space the layout would like to have.
0N/A *
0N/A * @param parent the Container for which this layout manager
0N/A * is being used
0N/A * @return a Dimension object containing the layout's preferred size
0N/A */
0N/A public Dimension preferredLayoutSize(Container parent) {
0N/A Dimension rd, mbd;
0N/A Insets i = getInsets();
0N/A
0N/A if(contentPane != null) {
0N/A rd = contentPane.getPreferredSize();
0N/A } else {
0N/A rd = parent.getSize();
0N/A }
0N/A if(menuBar != null && menuBar.isVisible()) {
0N/A mbd = menuBar.getPreferredSize();
0N/A } else {
0N/A mbd = new Dimension(0, 0);
0N/A }
0N/A return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right,
0N/A rd.height + mbd.height + i.top + i.bottom);
0N/A }
0N/A
0N/A /**
0N/A * Returns the minimum amount of space the layout needs.
0N/A *
0N/A * @param parent the Container for which this layout manager
0N/A * is being used
0N/A * @return a Dimension object containing the layout's minimum size
0N/A */
0N/A public Dimension minimumLayoutSize(Container parent) {
0N/A Dimension rd, mbd;
0N/A Insets i = getInsets();
0N/A if(contentPane != null) {
0N/A rd = contentPane.getMinimumSize();
0N/A } else {
0N/A rd = parent.getSize();
0N/A }
0N/A if(menuBar != null && menuBar.isVisible()) {
0N/A mbd = menuBar.getMinimumSize();
0N/A } else {
0N/A mbd = new Dimension(0, 0);
0N/A }
0N/A return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right,
0N/A rd.height + mbd.height + i.top + i.bottom);
0N/A }
0N/A
0N/A /**
0N/A * Returns the maximum amount of space the layout can use.
0N/A *
0N/A * @param target the Container for which this layout manager
0N/A * is being used
0N/A * @return a Dimension object containing the layout's maximum size
0N/A */
0N/A public Dimension maximumLayoutSize(Container target) {
0N/A Dimension rd, mbd;
0N/A Insets i = getInsets();
0N/A if(menuBar != null && menuBar.isVisible()) {
0N/A mbd = menuBar.getMaximumSize();
0N/A } else {
0N/A mbd = new Dimension(0, 0);
0N/A }
0N/A if(contentPane != null) {
0N/A rd = contentPane.getMaximumSize();
0N/A } else {
0N/A // This is silly, but should stop an overflow error
0N/A rd = new Dimension(Integer.MAX_VALUE,
0N/A Integer.MAX_VALUE - i.top - i.bottom - mbd.height - 1);
0N/A }
0N/A return new Dimension(Math.min(rd.width, mbd.width) + i.left + i.right,
0N/A rd.height + mbd.height + i.top + i.bottom);
0N/A }
0N/A
0N/A /**
0N/A * Instructs the layout manager to perform the layout for the specified
0N/A * container.
0N/A *
0N/A * @param parent the Container for which this layout manager
0N/A * is being used
0N/A */
0N/A public void layoutContainer(Container parent) {
0N/A Rectangle b = parent.getBounds();
0N/A Insets i = getInsets();
0N/A int contentY = 0;
0N/A int w = b.width - i.right - i.left;
0N/A int h = b.height - i.top - i.bottom;
0N/A
0N/A if(layeredPane != null) {
0N/A layeredPane.setBounds(i.left, i.top, w, h);
0N/A }
0N/A if(glassPane != null) {
0N/A glassPane.setBounds(i.left, i.top, w, h);
0N/A }
0N/A // Note: This is laying out the children in the layeredPane,
0N/A // technically, these are not our children.
0N/A if(menuBar != null && menuBar.isVisible()) {
0N/A Dimension mbd = menuBar.getPreferredSize();
0N/A menuBar.setBounds(0, 0, w, mbd.height);
0N/A contentY += mbd.height;
0N/A }
0N/A if(contentPane != null) {
0N/A contentPane.setBounds(0, contentY, w, h - contentY);
0N/A }
0N/A }
0N/A
0N/A public void addLayoutComponent(String name, Component comp) {}
0N/A public void removeLayoutComponent(Component comp) {}
0N/A public void addLayoutComponent(Component comp, Object constraints) {}
0N/A public float getLayoutAlignmentX(Container target) { return 0.0f; }
0N/A public float getLayoutAlignmentY(Container target) { return 0.0f; }
0N/A public void invalidateLayout(Container target) {}
0N/A }
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>JRootPane</code>.
0N/A * This method is intended to be used only for debugging purposes,
0N/A * and the content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this <code>JRootPane</code>.
0N/A */
0N/A protected String paramString() {
0N/A return super.paramString();
0N/A }
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A /**
0N/A * Gets the <code>AccessibleContext</code> associated with this
0N/A * <code>JRootPane</code>. For root panes, the
0N/A * <code>AccessibleContext</code> takes the form of an
0N/A * <code>AccessibleJRootPane</code>.
0N/A * A new <code>AccessibleJRootPane</code> instance is created if necessary.
0N/A *
0N/A * @return an <code>AccessibleJRootPane</code> that serves as the
0N/A * <code>AccessibleContext</code> of this <code>JRootPane</code>
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJRootPane();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JRootPane</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to root pane user-interface elements.
0N/A * <p>
0N/A * <strong>Warning:</strong>
0N/A * Serialized objects of this class will not be compatible with
0N/A * future Swing releases. The current serialization support is
0N/A * appropriate for short term storage or RMI between applications running
0N/A * the same version of Swing. As of 1.4, support for long term storage
0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup>
0N/A * has been added to the <code>java.beans</code> package.
0N/A * Please see {@link java.beans.XMLEncoder}.
0N/A */
0N/A protected class AccessibleJRootPane extends AccessibleJComponent {
0N/A /**
0N/A * Get the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of
0N/A * the object
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.ROOT_PANE;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of accessible children of the object.
0N/A *
0N/A * @return the number of accessible children of the object.
0N/A */
0N/A public int getAccessibleChildrenCount() {
0N/A return super.getAccessibleChildrenCount();
0N/A }
0N/A
0N/A /**
0N/A * Returns the specified Accessible child of the object. The Accessible
0N/A * children of an Accessible object are zero-based, so the first child
0N/A * of an Accessible child is at index 0, the second child is at index 1,
0N/A * and so on.
0N/A *
0N/A * @param i zero-based index of child
0N/A * @return the Accessible child of the object
0N/A * @see #getAccessibleChildrenCount
0N/A */
0N/A public Accessible getAccessibleChild(int i) {
0N/A return super.getAccessibleChild(i);
0N/A }
0N/A } // inner class AccessibleJRootPane
0N/A}