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