jdk/src/share/classes/javax/swing/JRootPane.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1978 8b981ce05cd0
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.applet.Applet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.RootPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.action.GetBooleanAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * A lightweight container used behind the scenes by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>JFrame</code>, <code>JDialog</code>, <code>JWindow</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>JApplet</code>, and <code>JInternalFrame</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * For task-oriented information on functionality provided by root panes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * see <a href="http://java.sun.com/docs/books/tutorial/uiswing/components/rootpane.html">How to Use Root Panes</a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a section in <em>The Java Tutorial</em>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * The following image shows the relationships between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * the classes that use root panes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p align=center><img src="doc-files/JRootPane-1.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * alt="The following text describes this graphic."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * HEIGHT=484 WIDTH=629></p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The &quot;heavyweight&quot; components (those that delegate to a peer, or native
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * component on the host system) are shown with a darker, heavier box. The four
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * heavyweight JFC/Swing containers (<code>JFrame</code>, <code>JDialog</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>JWindow</code>, and <code>JApplet</code>) are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * shown in relation to the AWT classes they extend.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * These four components are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * only heavyweight containers in the Swing library. The lightweight container
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>JInternalFrame</code> is also shown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * All five of these JFC/Swing containers implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <code>RootPaneContainer</code> interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * and they all delegate their operations to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <code>JRootPane</code> (shown with a little "handle" on top).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <b>Note:</b> The <code>JComponent</code> method <code>getRootPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * can be used to obtain the <code>JRootPane</code> that contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * a given component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <table align="right" border="0" summary="layout">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <td align="center">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <img src="doc-files/JRootPane-2.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * alt="The following text describes this graphic." HEIGHT=386 WIDTH=349>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * </td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * The diagram at right shows the structure of a <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * A <code>JRootpane</code> is made up of a <code>glassPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * an optional <code>menuBar</code>, and a <code>contentPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * (The <code>JLayeredPane</code> manages the <code>menuBar</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * and the <code>contentPane</code>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * The <code>glassPane</code> sits over the top of everything,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * where it is in a position to intercept mouse movements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Since the <code>glassPane</code> (like the <code>contentPane</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * can be an arbitrary component, it is also possible to set up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * <code>glassPane</code> for drawing. Lines and images on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * <code>glassPane</code> can then range
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * over the frames underneath without being limited by their boundaries.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Although the <code>menuBar</code> component is optional,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * the <code>layeredPane</code>, <code>contentPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * and <code>glassPane</code> always exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * Attempting to set them to <code>null</code> generates an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * To add components to the <code>JRootPane</code> (other than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * optional menu bar), you add the object to the <code>contentPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * of the <code>JRootPane</code>, like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *       rootPane.getContentPane().add(child);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * The same principle holds true for setting layout managers, removing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * components, listing children, etc. All these methods are invoked on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * the <code>contentPane</code> instead of on the <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * <b>Note:</b> The default layout manager for the <code>contentPane</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *  a <code>BorderLayout</code> manager. However, the <code>JRootPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *  uses a custom <code>LayoutManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *  So, when you want to change the layout manager for the components you added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *  to a <code>JRootPane</code>, be sure to use code like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *    rootPane.getContentPane().setLayout(new BoxLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * </pre></blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * If a <code>JMenuBar</code> component is set on the <code>JRootPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * it is positioned along the upper edge of the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * The <code>contentPane</code> is adjusted in location and size to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * fill the remaining area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * (The <code>JMenuBar</code> and the <code>contentPane</code> are added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <code>layeredPane</code> component at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <code>JLayeredPane.FRAME_CONTENT_LAYER</code> layer.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * The <code>layeredPane</code> is the parent of all children in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <code>JRootPane</code> -- both as the direct parent of the menu and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * the grandparent of all components added to the <code>contentPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * It is an instance of <code>JLayeredPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * which provides the ability to add components at several layers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * This capability is very useful when working with menu popups,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * dialog boxes, and dragging -- situations in which you need to place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * a component on top of all other components in the pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * The <code>glassPane</code> sits on top of all other components in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * That provides a convenient place to draw above all other components,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * and makes it possible to intercept mouse events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * which is useful both for dragging and for drawing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * Developers can use <code>setVisible</code> on the <code>glassPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * to control when the <code>glassPane</code> displays over the other children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * By default the <code>glassPane</code> is not visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * The custom <code>LayoutManager</code> used by <code>JRootPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * ensures that:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * <OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * <LI>The <code>glassPane</code> fills the entire viewable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 *     area of the <code>JRootPane</code> (bounds - insets).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <LI>The <code>layeredPane</code> fills the entire viewable area of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *     <code>JRootPane</code>. (bounds - insets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <LI>The <code>menuBar</code> is positioned at the upper edge of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 *     <code>layeredPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * <LI>The <code>contentPane</code> fills the entire viewable area,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 *     minus the <code>menuBar</code>, if present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * </OL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 * Any other views in the <code>JRootPane</code> view hierarchy are ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * If you replace the <code>LayoutManager</code> of the <code>JRootPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * you are responsible for managing all of these views.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * So ordinarily you will want to be sure that you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * change the layout manager for the <code>contentPane</code> rather than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * for the <code>JRootPane</code> itself!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * The painting architecture of Swing requires an opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 * <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 * to exist in the containment hieararchy above all other components. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 * typically provided by way of the content pane. If you replace the content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 * pane, it is recommended that you make the content pane opaque
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 * by way of <code>setOpaque(true)</code>. Additionally, if the content pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * overrides <code>paintComponent</code>, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * will need to completely fill in the background in an opaque color in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * <code>paintComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 * @see JLayeredPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
 * @see JMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 * @see JWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * @see JFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 * @see JDialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
 * @see JApplet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
 * @see JInternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * @see JComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * @see BoxLayout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * @see <a href="http://java.sun.com/products/jfc/tsc/articles/mixing/">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * Mixing Heavy and Light Components</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
/// PENDING(klobad) Who should be opaque in this component?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
public class JRootPane extends JComponent implements Accessible {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    private static final String uiClassID = "RootPaneUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Whether or not we should dump the stack when true double buffering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * is disabled. Default is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    private static final boolean LOG_DISABLE_TRUE_DOUBLE_BUFFERING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * Whether or not we should ignore requests to disable true double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * buffering. Default is false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    private static final boolean IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * the <code>JRootPane</code> should not provide any sort of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * Window decorations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public static final int NONE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * a Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public static final int FRAME = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * a Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public static final int PLAIN_DIALOG = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * a Dialog used to display an informational message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public static final int INFORMATION_DIALOG = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * a Dialog used to display an error message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public static final int ERROR_DIALOG = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * a Dialog used to display a <code>JColorChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public static final int COLOR_CHOOSER_DIALOG = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * a Dialog used to display a <code>JFileChooser</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public static final int FILE_CHOOSER_DIALOG = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * a Dialog used to present a question to the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    public static final int QUESTION_DIALOG = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Constant used for the windowDecorationStyle property. Indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * the <code>JRootPane</code> should provide decorations appropriate for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * a Dialog used to display a warning message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public static final int WARNING_DIALOG = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    private int windowDecorationStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /** The menu bar. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    protected JMenuBar menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /** The content pane. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    protected Container contentPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    /** The layered pane that manages the menu bar and content pane. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected JLayeredPane layeredPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * The glass pane that overlays the menu bar and content pane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *  so it can intercept mouse movements and such.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    protected Component glassPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * The button that gets activated when the pane has the focus and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * a UI-specific action like pressing the <b>Enter</b> key occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    protected JButton defaultButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * As of Java 2 platform v1.3 this unusable field is no longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * To override the default button you should replace the <code>Action</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * in the <code>JRootPane</code>'s <code>ActionMap</code>. Please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *  @see #defaultButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    protected DefaultAction defaultPressAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * As of Java 2 platform v1.3 this unusable field is no longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * To override the default button you should replace the <code>Action</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * in the <code>JRootPane</code>'s <code>ActionMap</code>. Please refer to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * the key bindings specification for further details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @deprecated As of Java 2 platform v1.3.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *  @see #defaultButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    protected DefaultAction defaultReleaseAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Whether or not true double buffering should be used.  This is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * true, but may be set to false in special situations.  For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * heavy weight popups (backed by a window) set this to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    boolean useTrueDoubleBuffering = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        LOG_DISABLE_TRUE_DOUBLE_BUFFERING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            AccessController.doPrivileged(new GetBooleanAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                                   "swing.logDoubleBufferingDisable"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            AccessController.doPrivileged(new GetBooleanAction(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                   "swing.ignoreDoubleBufferingDisable"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * Creates a <code>JRootPane</code>, setting up its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <code>glassPane</code>, <code>layeredPane</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * and <code>contentPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    public JRootPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        setGlassPane(createGlassPane());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        setLayeredPane(createLayeredPane());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        setContentPane(createContentPane());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        setLayout(createRootLayout());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        setDoubleBuffered(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    public void setDoubleBuffered(boolean aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (isDoubleBuffered() != aFlag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            super.setDoubleBuffered(aFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            RepaintManager.currentManager(this).doubleBufferingChanged(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Returns a constant identifying the type of Window decorations the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * <code>JRootPane</code> is providing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @return One of <code>NONE</code>, <code>FRAME</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     *        <code>PLAIN_DIALOG</code>, <code>INFORMATION_DIALOG</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *        <code>ERROR_DIALOG</code>, <code>COLOR_CHOOSER_DIALOG</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     *        <code>FILE_CHOOSER_DIALOG</code>, <code>QUESTION_DIALOG</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *        <code>WARNING_DIALOG</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @see #setWindowDecorationStyle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    public int getWindowDecorationStyle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return windowDecorationStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Sets the type of Window decorations (such as borders, widgets for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * closing a Window, title ...) the <code>JRootPane</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * provide. The default is to provide no Window decorations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * (<code>NONE</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * This is only a hint, and some look and feels may not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * This is a bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param windowDecorationStyle Constant identifying Window decorations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *        to provide.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see JDialog#setDefaultLookAndFeelDecorated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @see JFrame#setDefaultLookAndFeelDecorated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @see LookAndFeel#getSupportsWindowDecorations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @throws IllegalArgumentException if <code>style</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *        not one of: <code>NONE</code>, <code>FRAME</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *        <code>PLAIN_DIALOG</code>, <code>INFORMATION_DIALOG</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *        <code>ERROR_DIALOG</code>, <code>COLOR_CHOOSER_DIALOG</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *        <code>FILE_CHOOSER_DIALOG</code>, <code>QUESTION_DIALOG</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *        <code>WARNING_DIALOG</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *         enum: NONE                   JRootPane.NONE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *               FRAME                  JRootPane.FRAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     *               PLAIN_DIALOG           JRootPane.PLAIN_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *               INFORMATION_DIALOG     JRootPane.INFORMATION_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *               ERROR_DIALOG           JRootPane.ERROR_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *               COLOR_CHOOSER_DIALOG   JRootPane.COLOR_CHOOSER_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *               FILE_CHOOSER_DIALOG    JRootPane.FILE_CHOOSER_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *               QUESTION_DIALOG        JRootPane.QUESTION_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *               WARNING_DIALOG         JRootPane.WARNING_DIALOG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *       expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *  description: Identifies the type of Window decorations to provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    public void setWindowDecorationStyle(int windowDecorationStyle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (windowDecorationStyle < 0 ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                  windowDecorationStyle > WARNING_DIALOG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            throw new IllegalArgumentException("Invalid decoration style");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        int oldWindowDecorationStyle = getWindowDecorationStyle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        this.windowDecorationStyle = windowDecorationStyle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        firePropertyChange("windowDecorationStyle",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                            oldWindowDecorationStyle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                            windowDecorationStyle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Returns the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @return <code>LabelUI</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    public RootPaneUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        return (RootPaneUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * Sets the L&F object that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @param ui  the <code>LabelUI</code> L&F object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *        bound: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *       hidden: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *      expert: true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *    attribute: visualUpdate true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *  description: The UI object that implements the Component's LookAndFeel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    public void setUI(RootPaneUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        setUI((RootPaneUI)UIManager.getUI(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * Returns a string that specifies the name of the L&F class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * @return the string "RootPaneUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
      * Called by the constructor methods to create the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
      * <code>layeredPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
      * Bt default it creates a new <code>JLayeredPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
      * @return the default <code>layeredPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    protected JLayeredPane createLayeredPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        JLayeredPane p = new JLayeredPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        p.setName(this.getName()+".layeredPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return p;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Called by the constructor methods to create the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * <code>contentPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * By default this method creates a new <code>JComponent</code> add sets a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * <code>BorderLayout</code> as its <code>LayoutManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @return the default <code>contentPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    protected Container createContentPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        JComponent c = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        c.setName(this.getName()+".contentPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        c.setLayout(new BorderLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            /* This BorderLayout subclass maps a null constraint to CENTER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
             * Although the reference BorderLayout also does this, some VMs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
             * throw an IllegalArgumentException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            public void addLayoutComponent(Component comp, Object constraints) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                if (constraints == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    constraints = BorderLayout.CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                super.addLayoutComponent(comp, constraints);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
      * Called by the constructor methods to create the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
      * <code>glassPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
      * By default this method creates a new <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
      * with visibility set to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
      * @return the default <code>glassPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    protected Component createGlassPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        JComponent c = new JPanel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        c.setName(this.getName()+".glassPane");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        c.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        ((JPanel)c).setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * Called by the constructor methods to create the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * <code>layoutManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @return the default <code>layoutManager</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    protected LayoutManager createRootLayout() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        return new RootLayout();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Adds or changes the menu bar used in the layered pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @param menu the <code>JMenuBar</code> to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public void setJMenuBar(JMenuBar menu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if(menuBar != null && menuBar.getParent() == layeredPane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            layeredPane.remove(menuBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        menuBar = menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        if(menuBar != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * Specifies the menu bar value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @deprecated As of Swing version 1.0.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *  replaced by <code>setJMenuBar(JMenuBar menu)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @param menu the <code>JMenuBar</code> to add.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public void setMenuBar(JMenuBar menu){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if(menuBar != null && menuBar.getParent() == layeredPane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            layeredPane.remove(menuBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        menuBar = menu;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        if(menuBar != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            layeredPane.add(menuBar, JLayeredPane.FRAME_CONTENT_LAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Returns the menu bar from the layered pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @return the <code>JMenuBar</code> used in the pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public JMenuBar getJMenuBar() { return menuBar; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * Returns the menu bar value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * @deprecated As of Swing version 1.0.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *  replaced by <code>getJMenuBar()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @return the <code>JMenuBar</code> used in the pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    public JMenuBar getMenuBar() { return menuBar; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Sets the content pane -- the container that holds the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * parented by the root pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Swing's painting architecture requires an opaque <code>JComponent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * in the containment hiearchy. This is typically provided by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * content pane. If you replace the content pane it is recommended you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * replace it with an opaque <code>JComponent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @param content the <code>Container</code> to use for component-contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @exception java.awt.IllegalComponentStateException (a runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *            exception) if the content pane parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    public void setContentPane(Container content) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if(content == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            throw new IllegalComponentStateException("contentPane cannot be set to null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        if(contentPane != null && contentPane.getParent() == layeredPane)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            layeredPane.remove(contentPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        contentPane = content;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        layeredPane.add(contentPane, JLayeredPane.FRAME_CONTENT_LAYER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * Returns the content pane -- the container that holds the components
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * parented by the root pane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * @return the <code>Container</code> that holds the component-contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    public Container getContentPane() { return contentPane; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
// PENDING(klobad) Should this reparent the contentPane and MenuBar?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * Sets the layered pane for the root pane. The layered pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * typically holds a content pane and an optional <code>JMenuBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @param layered  the <code>JLayeredPane</code> to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @exception java.awt.IllegalComponentStateException (a runtime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *            exception) if the layered pane parameter is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public void setLayeredPane(JLayeredPane layered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        if(layered == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            throw new IllegalComponentStateException("layeredPane cannot be set to null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        if(layeredPane != null && layeredPane.getParent() == this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            this.remove(layeredPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        layeredPane = layered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        this.add(layeredPane, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * Gets the layered pane used by the root pane. The layered pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * typically holds a content pane and an optional <code>JMenuBar</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * @return the <code>JLayeredPane</code> currently in use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    public JLayeredPane getLayeredPane() { return layeredPane; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * Sets a specified <code>Component</code> to be the glass pane for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * root pane.  The glass pane should normally be a lightweight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * transparent component, because it will be made visible when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * ever the root pane needs to grab input events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * The new glass pane's visibility is changed to match that of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * the current glass pane.  An implication of this is that care
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * must be taken when you want to replace the glass pane and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * make it visible.  Either of the following will work:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     *   root.setGlassPane(newGlassPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *   newGlassPane.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * or:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *   root.getGlassPane().setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *   root.setGlassPane(newGlassPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @param glass the <code>Component</code> to use as the glass pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *              for this <code>JRootPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @exception NullPointerException if the <code>glass</code> parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *          <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public void setGlassPane(Component glass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        if (glass == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            throw new NullPointerException("glassPane cannot be set to null.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        boolean visible = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if (glassPane != null && glassPane.getParent() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            this.remove(glassPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            visible = glassPane.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        glass.setVisible(visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        glassPane = glass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        this.add(glassPane, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        if (visible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Returns the current glass pane for this <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * @return the current glass pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @see #setGlassPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public Component getGlassPane() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        return glassPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * If a descendant of this <code>JRootPane</code> calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * <code>revalidate</code>, validate from here on down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * Deferred requests to layout a component and its descendents again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * For example, calls to <code>revalidate</code>, are pushed upwards to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * either a <code>JRootPane</code> or a <code>JScrollPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * because both classes override <code>isValidateRoot</code> to return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * @see JComponent#isValidateRoot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * @return true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    public boolean isValidateRoot() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * The <code>glassPane</code> and <code>contentPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * have the same bounds, which means <code>JRootPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * does not tiles its children and this should return false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * On the other hand, the <code>glassPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * is normally not visible, and so this can return true if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * <code>glassPane</code> isn't visible. Therefore, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * return value here depends upon the visiblity of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * <code>glassPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @return true if this component's children don't overlap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    public boolean isOptimizedDrawingEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        return !glassPane.isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        enableEvents(AWTEvent.KEY_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Sets the <code>defaultButton</code> property,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * which determines the current default button for this <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * The default button is the button which will be activated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * when a UI-defined activation event (typically the <b>Enter</b> key)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * occurs in the root pane regardless of whether or not the button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * has keyboard focus (unless there is another component within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * the root pane which consumes the activation event,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * such as a <code>JTextPane</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * For default activation to work, the button must be an enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * descendent of the root pane when activation occurs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * To remove a default button from this root pane, set this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * property to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @see JButton#isDefaultButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @param defaultButton the <code>JButton</code> which is to be the default button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @beaninfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     *  description: The button activated by default in this root pane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    public void setDefaultButton(JButton defaultButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        JButton oldDefault = this.defaultButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        if (oldDefault != defaultButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            this.defaultButton = defaultButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
            if (oldDefault != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                oldDefault.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (defaultButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                defaultButton.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        firePropertyChange("defaultButton", oldDefault, defaultButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * Returns the value of the <code>defaultButton</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * @return the <code>JButton</code> which is currently the default button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @see #setDefaultButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public JButton getDefaultButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        return defaultButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    final void setUseTrueDoubleBuffering(boolean useTrueDoubleBuffering) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        this.useTrueDoubleBuffering = useTrueDoubleBuffering;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    final boolean getUseTrueDoubleBuffering() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        return useTrueDoubleBuffering;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    final void disableTrueDoubleBuffering() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        if (useTrueDoubleBuffering) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            if (!IGNORE_DISABLE_TRUE_DOUBLE_BUFFERING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                if (LOG_DISABLE_TRUE_DOUBLE_BUFFERING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    System.out.println("Disabling true double buffering for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                                       this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                    Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                useTrueDoubleBuffering = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                RepaintManager.currentManager(this).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                        doubleBufferingChanged(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    static class DefaultAction extends AbstractAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        JButton owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        JRootPane root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        boolean press;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        DefaultAction(JRootPane root, boolean press) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            this.root = root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            this.press = press;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        public void setOwner(JButton owner) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            this.owner = owner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            if (owner != null && SwingUtilities.getRootPane(owner) == root) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                ButtonModel model = owner.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                if (press) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                    model.setArmed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    model.setPressed(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                    model.setPressed(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        public boolean isEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            return owner.getModel().isEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * Overridden to enforce the position of the glass component as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * the zero child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @param comp the component to be enhanced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @param constraints the constraints to be respected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @param index the index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    protected void addImpl(Component comp, Object constraints, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        super.addImpl(comp, constraints, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        /// We are making sure the glassPane is on top.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        if(glassPane != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            && glassPane.getParent() == this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            && getComponent(0) != glassPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            add(glassPane, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
///////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
//// Begin Inner Classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
///////////////////////////////////////////////////////////////////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * A custom layout manager that is responsible for the layout of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * layeredPane, glassPane, and menuBar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
    protected class RootLayout implements LayoutManager2, Serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         * Returns the amount of space the layout would like to have.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         * @param parent the Container for which this layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         * is being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
         * @return a Dimension object containing the layout's preferred size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        public Dimension preferredLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            Dimension rd, mbd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            if(contentPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                rd = contentPane.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                rd = parent.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            if(menuBar != null && menuBar.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                mbd = menuBar.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                mbd = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                                        rd.height + mbd.height + i.top + i.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
         * Returns the minimum amount of space the layout needs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
         * @param parent the Container for which this layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
         * is being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
         * @return a Dimension object containing the layout's minimum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        public Dimension minimumLayoutSize(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            Dimension rd, mbd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            if(contentPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                rd = contentPane.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                rd = parent.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            if(menuBar != null && menuBar.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                mbd = menuBar.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                mbd = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            return new Dimension(Math.max(rd.width, mbd.width) + i.left + i.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                        rd.height + mbd.height + i.top + i.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
         * Returns the maximum amount of space the layout can use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * @param target the Container for which this layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         * is being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         * @return a Dimension object containing the layout's maximum size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        public Dimension maximumLayoutSize(Container target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            Dimension rd, mbd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            if(menuBar != null && menuBar.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                mbd = menuBar.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                mbd = new Dimension(0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if(contentPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                rd = contentPane.getMaximumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                // This is silly, but should stop an overflow error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                rd = new Dimension(Integer.MAX_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                        Integer.MAX_VALUE - i.top - i.bottom - mbd.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            return new Dimension(Math.min(rd.width, mbd.width) + i.left + i.right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                         rd.height + mbd.height + i.top + i.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
         * Instructs the layout manager to perform the layout for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
         * container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
         * @param parent the Container for which this layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
         * is being used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            Rectangle b = parent.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            Insets i = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            int contentY = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            int w = b.width - i.right - i.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            int h = b.height - i.top - i.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            if(layeredPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                layeredPane.setBounds(i.left, i.top, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            if(glassPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                glassPane.setBounds(i.left, i.top, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            // Note: This is laying out the children in the layeredPane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            // technically, these are not our children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            if(menuBar != null && menuBar.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                Dimension mbd = menuBar.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                menuBar.setBounds(0, 0, w, mbd.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                contentY += mbd.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            if(contentPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                contentPane.setBounds(0, contentY, w, h - contentY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        public void addLayoutComponent(String name, Component comp) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        public void removeLayoutComponent(Component comp) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        public void addLayoutComponent(Component comp, Object constraints) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        public float getLayoutAlignmentX(Container target) { return 0.0f; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        public float getLayoutAlignmentY(Container target) { return 0.0f; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        public void invalidateLayout(Container target) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * Returns a string representation of this <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * This method is intended to be used only for debugging purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * and the content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @return  a string representation of this <code>JRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        return super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
/////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
// Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
////////////////
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * Gets the <code>AccessibleContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * <code>JRootPane</code>. For root panes, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * <code>AccessibleContext</code> takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * <code>AccessibleJRootPane</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * A new <code>AccessibleJRootPane</code> instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @return an <code>AccessibleJRootPane</code> that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     *         <code>AccessibleContext</code> of this <code>JRootPane</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            accessibleContext = new AccessibleJRootPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * <code>JRootPane</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * Java Accessibility API appropriate to root pane user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    protected class AccessibleJRootPane extends AccessibleJComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
         * @return an instance of AccessibleRole describing the role of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
         * the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            return AccessibleRole.ROOT_PANE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
         * Returns the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
         * @return the number of accessible children of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        public int getAccessibleChildrenCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            return super.getAccessibleChildrenCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
         * Returns the specified Accessible child of the object.  The Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
         * children of an Accessible object are zero-based, so the first child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
         * of an Accessible child is at index 0, the second child is at index 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
         * and so on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
         * @param i zero-based index of child
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
         * @return the Accessible child of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
         * @see #getAccessibleChildrenCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        public Accessible getAccessibleChild(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            return super.getAccessibleChild(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    } // inner class AccessibleJRootPane
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
}