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