jdk/src/share/classes/java/awt/Frame.java
author ant
Thu, 17 May 2012 21:48:57 +0400
changeset 12661 6cf8b7116579
parent 7668 d4a77089c587
child 15318 607db339afcc
permissions -rw-r--r--
7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application. Summary: forward port from 7u4 Reviewed-by: art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 7239
diff changeset
     2
 * Copyright (c) 1995, 2010, 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: 4255
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: 4255
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: 4255
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4255
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4255
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package java.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.peer.FramePeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.SunToolkit;
2453
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
    39
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A <code>Frame</code> is a top-level window with a title and a border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * The size of the frame includes any area designated for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * border.  The dimensions of the border area may be obtained
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * using the <code>getInsets</code> method, however, since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * these dimensions are platform-dependent, a valid insets
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * value cannot be obtained until the frame is made displayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * by either calling <code>pack</code> or <code>show</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Since the border area is included in the overall size of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * frame, the border effectively obscures a portion of the frame,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * constraining the area available for rendering and/or displaying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * subcomponents to the rectangle which has an upper-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * location of <code>(insets.left, insets.top)</code>, and has a size of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>width - (insets.left + insets.right)</code> by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <code>height - (insets.top + insets.bottom)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * The default layout for a frame is <code>BorderLayout</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * A frame may have its native decorations (i.e. <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * and <code>Titlebar</code>) turned off
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * with <code>setUndecorated</code>. This can only be done while the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * is not {@link Component#isDisplayable() displayable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * In a multi-screen environment, you can create a <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * on a different screen device by constructing the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * with {@link #Frame(GraphicsConfiguration)} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * {@link #Frame(String title, GraphicsConfiguration)}.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * <code>GraphicsConfiguration</code> object is one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <code>GraphicsConfiguration</code> objects of the target screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * In a virtual device multi-screen environment in which the desktop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * area could span multiple physical screen devices, the bounds of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * configurations are relative to the virtual-coordinate system.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * origin of the virtual-coordinate system is at the upper left-hand
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * corner of the primary physical screen.  Depending on the location
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * of the primary screen in the virtual device, negative coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * are possible, as shown in the following figure.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <img src="doc-files/MultiScreen.gif"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * alt="Diagram of virtual device encompassing three physical screens and one primary physical screen. The primary physical screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * shows (0,0) coords while a different physical screen shows (-80,-100) coords."
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * ALIGN=center HSPACE=10 VSPACE=7>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * In such an environment, when calling <code>setLocation</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * you must pass a virtual coordinate to this method.  Similarly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * calling <code>getLocationOnScreen</code> on a <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * returns virtual device coordinates.  Call the <code>getBounds</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * method of a <code>GraphicsConfiguration</code> to find its origin in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * the virtual coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * The following code sets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * location of the <code>Frame</code> at (10, 10) relative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * to the origin of the physical screen of the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * <code>GraphicsConfiguration</code>.  If the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * <code>GraphicsConfiguration</code> is not taken into account, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <code>Frame</code> location would be set at (10, 10) relative to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * virtual-coordinate system and would appear on the primary physical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * screen, which might be different from the physical screen of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * specified <code>GraphicsConfiguration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *      Frame f = new Frame(GraphicsConfiguration gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *      Rectangle bounds = gc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *      f.setLocation(10 + bounds.x, 10 + bounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * Frames are capable of generating the following types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * <code>WindowEvent</code>s:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * <li><code>WINDOW_OPENED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <li><code>WINDOW_CLOSING</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *     <br>If the program doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *     explicitly hide or dispose the window while processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *     this event, the window close operation is canceled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <li><code>WINDOW_CLOSED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <li><code>WINDOW_ICONIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <li><code>WINDOW_DEICONIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <li><code>WINDOW_ACTIVATED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * <li><code>WINDOW_DEACTIVATED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * <li><code>WINDOW_GAINED_FOCUS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <li><code>WINDOW_LOST_FOCUS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * <li><code>WINDOW_STATE_CHANGED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * @author      Sami Shaio
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * @see WindowEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * @see Window#addWindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * @since       JDK1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
public class Frame extends Window implements MenuContainer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /* Note: These are being obsoleted;  programs should use the Cursor class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * variables going forward. See Cursor and Component.setCursor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    * @deprecated   replaced by <code>Cursor.DEFAULT_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public static final int     DEFAULT_CURSOR                  = Cursor.DEFAULT_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    * @deprecated   replaced by <code>Cursor.CROSSHAIR_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public static final int     CROSSHAIR_CURSOR                = Cursor.CROSSHAIR_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    * @deprecated   replaced by <code>Cursor.TEXT_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public static final int     TEXT_CURSOR                     = Cursor.TEXT_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    * @deprecated   replaced by <code>Cursor.WAIT_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static final int     WAIT_CURSOR                     = Cursor.WAIT_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    * @deprecated   replaced by <code>Cursor.SW_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public static final int     SW_RESIZE_CURSOR                = Cursor.SW_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    * @deprecated   replaced by <code>Cursor.SE_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public static final int     SE_RESIZE_CURSOR                = Cursor.SE_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    * @deprecated   replaced by <code>Cursor.NW_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public static final int     NW_RESIZE_CURSOR                = Cursor.NW_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    * @deprecated   replaced by <code>Cursor.NE_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public static final int     NE_RESIZE_CURSOR                = Cursor.NE_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    * @deprecated   replaced by <code>Cursor.N_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public static final int     N_RESIZE_CURSOR                 = Cursor.N_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    * @deprecated   replaced by <code>Cursor.S_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public static final int     S_RESIZE_CURSOR                 = Cursor.S_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    * @deprecated   replaced by <code>Cursor.W_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public static final int     W_RESIZE_CURSOR                 = Cursor.W_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    * @deprecated   replaced by <code>Cursor.E_RESIZE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public static final int     E_RESIZE_CURSOR                 = Cursor.E_RESIZE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    * @deprecated   replaced by <code>Cursor.HAND_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public static final int     HAND_CURSOR                     = Cursor.HAND_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    * @deprecated   replaced by <code>Cursor.MOVE_CURSOR</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    public static final int     MOVE_CURSOR                     = Cursor.MOVE_CURSOR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Frame is in the "normal" state.  This symbolic constant names a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * frame state with all state bits cleared.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @see #setExtendedState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @see #getExtendedState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public static final int NORMAL = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * This state bit indicates that frame is iconified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @see #setExtendedState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @see #getExtendedState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    public static final int ICONIFIED = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * This state bit indicates that frame is maximized in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * horizontal direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @see #setExtendedState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @see #getExtendedState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public static final int MAXIMIZED_HORIZ = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * This state bit indicates that frame is maximized in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * vertical direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @see #setExtendedState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @see #getExtendedState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public static final int MAXIMIZED_VERT = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * This state bit mask indicates that frame is fully maximized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * (that is both horizontally and vertically).  It is just a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * convenience alias for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <code>MAXIMIZED_VERT&nbsp;|&nbsp;MAXIMIZED_HORIZ</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * <p>Note that the correct test for frame being fully maximized is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *     (state & Frame.MAXIMIZED_BOTH) == Frame.MAXIMIZED_BOTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <p>To test is frame is maximized in <em>some</em> direction use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *     (state & Frame.MAXIMIZED_BOTH) != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @see #setExtendedState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see #getExtendedState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public static final int MAXIMIZED_BOTH = MAXIMIZED_VERT | MAXIMIZED_HORIZ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Maximized bounds for this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @see     #setMaximizedBounds(Rectangle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @see     #getMaximizedBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    Rectangle maximizedBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * This is the title of the frame.  It can be changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * at any time.  <code>title</code> can be null and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * this is the case the <code>title</code> = "".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see #getTitle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @see #setTitle(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    String      title = "Untitled";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * The frames menubar.  If <code>menuBar</code> = null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * the frame will not have a menubar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @see #getMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see #setMenuBar(MenuBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    MenuBar     menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * This field indicates whether the frame is resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * This property can be changed at any time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * <code>resizable</code> will be true if the frame is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * resizable, otherwise it will be false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @see #isResizable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    boolean     resizable = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * This field indicates whether the frame is undecorated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * This property can only be changed while the frame is not displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <code>undecorated</code> will be true if the frame is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * undecorated, otherwise it will be false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @see #setUndecorated(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @see #isUndecorated()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @see Component#isDisplayable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    boolean undecorated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <code>mbManagement</code> is only used by the Motif implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    boolean     mbManagement = false;   /* used only by the Motif impl. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    // XXX: uwe: abuse old field for now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    // will need to take care of serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    private int state = NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * The Windows owned by the Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Note: in 1.2 this has been superceded by Window.ownedWindowList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @see java.awt.Window#ownedWindowList
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    Vector ownedWindows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    private static final String base = "frame";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    private static int nameCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     private static final long serialVersionUID = 2673458971256075116L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        /* ensure that the necessary native libraries are loaded */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        Toolkit.loadLibraries();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (!GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * Constructs a new instance of <code>Frame</code> that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * initially invisible.  The title of the <code>Frame</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * is empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * @see java.awt.GraphicsEnvironment#isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @see Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @see Component#setVisible(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public Frame() throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        this("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Constructs a new, initially invisible {@code Frame} with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * specified {@code GraphicsConfiguration}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @param gc the <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * of the target screen device. If <code>gc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * is <code>null</code>, the system default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * <code>GraphicsConfiguration</code> is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * <code>gc</code> is not from a screen device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @see java.awt.GraphicsEnvironment#isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * @since     1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public Frame(GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        this("", gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Constructs a new, initially invisible <code>Frame</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * with the specified title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @param title the title to be displayed in the frame's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *              A <code>null</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     *              is treated as an empty string, "".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see java.awt.GraphicsEnvironment#isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see java.awt.Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see java.awt.Component#setVisible(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see java.awt.GraphicsConfiguration#getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public Frame(String title) throws HeadlessException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        init(title, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Constructs a new, initially invisible <code>Frame</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * with the specified title and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <code>GraphicsConfiguration</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @param title the title to be displayed in the frame's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *              A <code>null</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *              is treated as an empty string, "".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @param gc the <code>GraphicsConfiguration</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * of the target screen device.  If <code>gc</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * <code>null</code>, the system default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * <code>GraphicsConfiguration</code> is assumed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @exception IllegalArgumentException if <code>gc</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * is not from a screen device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @exception HeadlessException when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     *     <code>GraphicsEnvironment.isHeadless()</code> returns <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @see java.awt.GraphicsEnvironment#isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @see java.awt.Component#setSize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * @see java.awt.Component#setVisible(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * @see java.awt.GraphicsConfiguration#getBounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public Frame(String title, GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        super(gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        init(title, gc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    private void init(String title, GraphicsConfiguration gc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        this.title = title;
12661
6cf8b7116579 7125044: [macosx] Test failure because Component.transferFocus() works differently in applet and application.
ant
parents: 7668
diff changeset
   452
        SunToolkit.checkAndSetPolicy(this);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Construct a name for this component.  Called by getName() when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    String constructComponentName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        synchronized (Frame.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return base + nameCounter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Makes this Frame displayable by connecting it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * a native screen resource.  Making a frame displayable will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * cause any of its children to be made displayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * This method is called internally by the toolkit and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * not be called directly by programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @see #removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public void addNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            if (peer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                peer = getToolkit().createFrame(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            FramePeer p = (FramePeer)peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            MenuBar menuBar = this.menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            if (menuBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                mbManagement = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                menuBar.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                p.setMenuBar(menuBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            p.setMaximizedBounds(maximizedBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            super.addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Gets the title of the frame.  The title is displayed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * frame's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @return    the title of this frame, or an empty string ("")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *                if this frame doesn't have a title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @see       #setTitle(String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public String getTitle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        return title;
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
     * Sets the title for this frame to the specified string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * @param title the title to be displayed in the frame's border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     *              A <code>null</code> value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *              is treated as an empty string, "".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @see      #getTitle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    public void setTitle(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        String oldTitle = this.title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        if (title == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            title = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            this.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            FramePeer peer = (FramePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                peer.setTitle(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        firePropertyChange("title", oldTitle, title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * Returns the image to be displayed as the icon for this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * This method is obsolete and kept for backward compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * only. Use {@link Window#getIconImages Window.getIconImages()} instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * If a list of several images was specified as a Window's icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * this method will return the first item of the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @return    the icon image for this frame, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     *                    if this frame doesn't have an icon image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @see       #setIconImage(Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @see       Window#getIconImages()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @see       Window#setIconImages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    public Image getIconImage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        java.util.List<Image> icons = this.icons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (icons != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            if (icons.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                return icons.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public void setIconImage(Image image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        super.setIconImage(image);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * Gets the menu bar for this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     * @return    the menu bar for this frame, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     *                   if this frame doesn't have a menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * @see       #setMenuBar(MenuBar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public MenuBar getMenuBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        return menuBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * Sets the menu bar for this frame to the specified menu bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @param     mb the menu bar being set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *            If this parameter is <code>null</code> then any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     *            existing menu bar on this frame is removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @see       #getMenuBar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    public void setMenuBar(MenuBar mb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            if (menuBar == mb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            if ((mb != null) && (mb.parent != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                mb.parent.remove(mb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            if (menuBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                remove(menuBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            menuBar = mb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            if (menuBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                menuBar.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                FramePeer peer = (FramePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    mbManagement = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    menuBar.addNotify();
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   594
                    invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    peer.setMenuBar(menuBar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * Indicates whether this frame is resizable by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * By default, all frames are initially resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @return    <code>true</code> if the user can resize this frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *                        <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * @see       java.awt.Frame#setResizable(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    public boolean isResizable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        return resizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * Sets whether this frame is resizable by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @param    resizable   <code>true</code> if this frame is resizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *                       <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @see      java.awt.Frame#isResizable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    public void setResizable(boolean resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        boolean oldResizable = this.resizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        boolean testvalid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            this.resizable = resizable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            FramePeer peer = (FramePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                peer.setResizable(resizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                testvalid = true;
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
        // On some platforms, changing the resizable state affects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        // the insets of the Frame. If we could, we'd call invalidate()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        // from the peer, but we need to guarantee that we're not holding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        // the Frame lock when we call invalidate().
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   635
        if (testvalid) {
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
   636
            invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        firePropertyChange("resizable", oldResizable, resizable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Sets the state of this frame (obsolete).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * In older versions of JDK a frame state could only be NORMAL or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * ICONIFIED.  Since JDK 1.4 set of supported frame states is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * expanded and frame state is represented as a bitwise mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * For compatibility with applications developed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     * earlier this method still accepts
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * {@code Frame.NORMAL} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * {@code Frame.ICONIFIED} only.  The iconic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * state of the frame is only changed, other aspects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * of frame state are not affected by this method. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * the state passed to this method is neither {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Frame.NORMAL} nor {@code Frame.ICONIFIED} the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * method performs no actions at all.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * <p>Note that if the state is not supported on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * given platform, neither the state nor the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * value of the {@link #getState} method will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * changed. The application may determine whether a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * specific state is supported via the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * java.awt.Toolkit#isFrameStateSupported} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * <p><b>If the frame is currently visible on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * screen</b> (the {@link #isShowing} method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * {@code true}), the developer should examine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * return value of the  {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * java.awt.event.WindowEvent#getNewState} method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * the {@code WindowEvent} received through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * {@link java.awt.event.WindowStateListener} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * determine that the state has actually been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * <p><b>If the frame is not visible on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * screen</b>, the events may or may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * generated.  In this case the developer may assume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * that the state changes immediately after this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * method returns.  Later, when the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * setVisible(true)} method is invoked, the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * will attempt to apply this state. Receiving any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * java.awt.event.WindowEvent#WINDOW_STATE_CHANGED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * events is not guaranteed in this case also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @param state either <code>Frame.NORMAL</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *     <code>Frame.ICONIFIED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @see #setExtendedState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * @see java.awt.Window#addWindowStateListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    public synchronized void setState(int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        int current = getExtendedState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if (state == ICONIFIED && (current & ICONIFIED) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            setExtendedState(current | ICONIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        else if (state == NORMAL && (current & ICONIFIED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            setExtendedState(current & ~ICONIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * Sets the state of this frame. The state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * represented as a bitwise mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * <li><code>NORMAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     * <br>Indicates that no state bits are set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * <li><code>ICONIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * <li><code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * <li><code>MAXIMIZED_VERT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * <li><code>MAXIMIZED_BOTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * <br>Concatenates <code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * and <code>MAXIMIZED_VERT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * <p>Note that if the state is not supported on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * given platform, neither the state nor the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * value of the {@link #getExtendedState} method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * be changed. The application may determine whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * a specific state is supported via the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * java.awt.Toolkit#isFrameStateSupported} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * <p><b>If the frame is currently visible on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * screen</b> (the {@link #isShowing} method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * {@code true}), the developer should examine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * return value of the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * java.awt.event.WindowEvent#getNewState} method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * the {@code WindowEvent} received through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * {@link java.awt.event.WindowStateListener} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * determine that the state has actually been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * <p><b>If the frame is not visible on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * screen</b>, the events may or may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * generated.  In this case the developer may assume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * that the state changes immediately after this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * method returns.  Later, when the {@code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * setVisible(true)} method is invoked, the frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * will attempt to apply this state. Receiving any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * java.awt.event.WindowEvent#WINDOW_STATE_CHANGED}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * events is not guaranteed in this case also.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @param state a bitwise mask of frame state constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * @since   1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @see java.awt.Window#addWindowStateListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
2453
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   742
    public void setExtendedState(int state) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        if ( !isFrameStateSupported( state ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
2453
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   746
        synchronized (getObjectLock()) {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   747
            this.state = state;
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   748
        }
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   749
        // peer.setState must be called outside of object lock
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   750
        // synchronization block to avoid possible deadlock
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        FramePeer peer = (FramePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            peer.setState(state);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    private boolean isFrameStateSupported(int state) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        if( !getToolkit().isFrameStateSupported( state ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            // * Toolkit.isFrameStateSupported returns always false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            // on compound state even if all parts are supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            // * if part of state is not supported, state is not supported;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            // * MAXIMIZED_BOTH is not a compound state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if( ((state & ICONIFIED) != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                !getToolkit().isFrameStateSupported( ICONIFIED )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            }else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                state &= ~ICONIFIED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            return getToolkit().isFrameStateSupported( state );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * Gets the state of this frame (obsolete).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * In older versions of JDK a frame state could only be NORMAL or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * ICONIFIED.  Since JDK 1.4 set of supported frame states is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * expanded and frame state is represented as a bitwise mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * For compatibility with old programs this method still returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * <code>Frame.NORMAL</code> and <code>Frame.ICONIFIED</code> but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * it only reports the iconic state of the frame, other aspects of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * frame state are not reported by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * @return  <code>Frame.NORMAL</code> or <code>Frame.ICONIFIED</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @see     #setState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @see     #getExtendedState
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    public synchronized int getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        return (getExtendedState() & ICONIFIED) != 0 ? ICONIFIED : NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * Gets the state of this frame. The state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * represented as a bitwise mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * <li><code>NORMAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * <br>Indicates that no state bits are set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * <li><code>ICONIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * <li><code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * <li><code>MAXIMIZED_VERT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * <li><code>MAXIMIZED_BOTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * <br>Concatenates <code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * and <code>MAXIMIZED_VERT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * @return  a bitwise mask of frame state constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @see     #setExtendedState(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     */
2453
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   812
    public int getExtendedState() {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   813
        synchronized (getObjectLock()) {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   814
            return state;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        }
2453
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   816
    }
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   817
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   818
    static {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   819
        AWTAccessor.setFrameAccessor(
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   820
            new AWTAccessor.FrameAccessor() {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   821
                public void setExtendedState(Frame frame, int state) {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   822
                    synchronized(frame.getObjectLock()) {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   823
                        frame.state = state;
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   824
                    }
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   825
                }
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   826
                public int getExtendedState(Frame frame) {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   827
                    synchronized(frame.getObjectLock()) {
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   828
                        return frame.state;
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   829
                    }
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   830
                }
7239
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   831
                public Rectangle getMaximizedBounds(Frame frame) {
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   832
                    synchronized(frame.getObjectLock()) {
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   833
                        return frame.maximizedBounds;
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   834
                    }
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   835
                }
2453
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   836
            }
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
   837
        );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * Sets the maximized bounds for this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * When a frame is in maximized state the system supplies some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * defaults bounds.  This method allows some or all of those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * system supplied values to be overridden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * If <code>bounds</code> is <code>null</code>, accept bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * supplied by the system.  If non-<code>null</code> you can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * override some of the system supplied values while accepting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * others by setting those fields you want to accept from system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * to <code>Integer.MAX_VALUE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * <p>
4255
69e00373e85b 6684916: jframe.setMaximizedBounds() has no effect in linux
anthony
parents: 2453
diff changeset
   853
     * Note, the given maximized bounds are used as a hint for the native
69e00373e85b 6684916: jframe.setMaximizedBounds() has no effect in linux
anthony
parents: 2453
diff changeset
   854
     * system, because the underlying platform may not support setting the
69e00373e85b 6684916: jframe.setMaximizedBounds() has no effect in linux
anthony
parents: 2453
diff changeset
   855
     * location and/or size of the maximized windows.  If that is the case, the
69e00373e85b 6684916: jframe.setMaximizedBounds() has no effect in linux
anthony
parents: 2453
diff changeset
   856
     * provided values do not affect the appearance of the frame in the
69e00373e85b 6684916: jframe.setMaximizedBounds() has no effect in linux
anthony
parents: 2453
diff changeset
   857
     * maximized state.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * @param bounds  bounds for the maximized state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @see #getMaximizedBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
7239
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   863
    public void setMaximizedBounds(Rectangle bounds) {
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   864
        synchronized(getObjectLock()) {
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   865
            this.maximizedBounds = bounds;
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   866
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        FramePeer peer = (FramePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            peer.setMaximizedBounds(bounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * Gets maximized bounds for this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * Some fields may contain <code>Integer.MAX_VALUE</code> to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * that system supplied values for this field must be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @return  maximized bounds for this frame;  may be <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @see     #setMaximizedBounds(Rectangle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * @since   1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
    public Rectangle getMaximizedBounds() {
7239
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   883
        synchronized(getObjectLock()) {
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   884
            return maximizedBounds;
514eb274caa1 6699851: setMaximizedbounds not working properly on dual screen environment
dcherepanov
parents: 7236
diff changeset
   885
        }
2
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * Disables or enables decorations for this frame.
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   891
     * <p>
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   892
     * This method can only be called while the frame is not displayable. To
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   893
     * make this frame decorated, it must be opaque and have the default shape,
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   894
     * otherwise the {@code IllegalComponentStateException} will be thrown.
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   895
     * Refer to {@link Window#setShape}, {@link Window#setOpacity} and {@link
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   896
     * Window#setBackground} for details
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   897
     *
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   898
     * @param  undecorated {@code true} if no frame decorations are to be
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   899
     *         enabled; {@code false} if frame decorations are to be enabled
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   900
     *
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   901
     * @throws IllegalComponentStateException if the frame is displayable
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   902
     * @throws IllegalComponentStateException if {@code undecorated} is
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   903
     *      {@code false}, and this frame does not have the default shape
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   904
     * @throws IllegalComponentStateException if {@code undecorated} is
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   905
     *      {@code false}, and this frame opacity is less than {@code 1.0f}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   906
     * @throws IllegalComponentStateException if {@code undecorated} is
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   907
     *      {@code false}, and the alpha value of this frame background
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   908
     *      color is less than {@code 1.0f}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   909
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @see    #isUndecorated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * @see    Component#isDisplayable
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   912
     * @see    Window#getShape
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   913
     * @see    Window#getOpacity
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   914
     * @see    Window#getBackground
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @see    javax.swing.JFrame#setDefaultLookAndFeelDecorated(boolean)
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   916
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    public void setUndecorated(boolean undecorated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        /* Make sure we don't run in the middle of peer creation.*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            if (isDisplayable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                throw new IllegalComponentStateException("The frame is displayable.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            }
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   925
            if (!undecorated) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   926
                if (getOpacity() < 1.0f) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   927
                    throw new IllegalComponentStateException("The frame is not opaque");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   928
                }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   929
                if (getShape() != null) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   930
                    throw new IllegalComponentStateException("The frame does not have a default shape");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   931
                }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   932
                Color bg = getBackground();
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   933
                if ((bg != null) && (bg.getAlpha() < 255)) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   934
                    throw new IllegalComponentStateException("The frame background color is not opaque");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   935
                }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   936
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            this.undecorated = undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * Indicates whether this frame is undecorated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * By default, all frames are initially decorated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * @return    <code>true</code> if frame is undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *                        <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @see       java.awt.Frame#setUndecorated(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    public boolean isUndecorated() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        return undecorated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    /**
7236
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   954
     * {@inheritDoc}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   955
     */
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   956
    @Override
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   957
    public void setOpacity(float opacity) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   958
        synchronized (getTreeLock()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   959
            if ((opacity < 1.0f) && !isUndecorated()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   960
                throw new IllegalComponentStateException("The frame is decorated");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   961
            }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   962
            super.setOpacity(opacity);
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   963
        }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   964
    }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   965
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   966
    /**
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   967
     * {@inheritDoc}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   968
     */
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   969
    @Override
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   970
    public void setShape(Shape shape) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   971
        synchronized (getTreeLock()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   972
            if ((shape != null) && !isUndecorated()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   973
                throw new IllegalComponentStateException("The frame is decorated");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   974
            }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   975
            super.setShape(shape);
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   976
        }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   977
    }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   978
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   979
    /**
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   980
     * {@inheritDoc}
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   981
     */
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   982
    @Override
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   983
    public void setBackground(Color bgColor) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   984
        synchronized (getTreeLock()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   985
            if ((bgColor != null) && (bgColor.getAlpha() < 255) && !isUndecorated()) {
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   986
                throw new IllegalComponentStateException("The frame is decorated");
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   987
            }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   988
            super.setBackground(bgColor);
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   989
        }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   990
    }
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   991
e7c280629f58 6993784: Clarification to shaped/translucent windows specification is required
art
parents: 5506
diff changeset
   992
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * Removes the specified menu bar from this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @param    m   the menu component to remove.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     *           If <code>m</code> is <code>null</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     *           no action is taken
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    public void remove(MenuComponent m) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        if (m == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
            if (m == menuBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
                menuBar = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
                FramePeer peer = (FramePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
                if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                    mbManagement = true;
1183
80d6aafba03a 6682046: Mixing code does not always recalculate shapes correctly when resizing components
anthony
parents: 2
diff changeset
  1008
                    invalidateIfValid();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    peer.setMenuBar(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                    m.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
                m.parent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                super.remove(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * Makes this Frame undisplayable by removing its connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * to its native screen resource. Making a Frame undisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     * will cause any of its children to be made undisplayable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * This method is called by the toolkit internally and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * not be called directly by programs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * @see Component#isDisplayable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * @see #addNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    public void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        synchronized (getTreeLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            FramePeer peer = (FramePeer)this.peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                // get the latest Frame state before disposing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                if (menuBar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                    mbManagement = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    peer.setMenuBar(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                    menuBar.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            super.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
    void postProcessKeyEvent(KeyEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        if (menuBar != null && menuBar.handleShortcut(e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            e.consume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        super.postProcessKeyEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * Returns a string representing the state of this <code>Frame</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     * This method is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * implementations. The returned string may be empty but may not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     * <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     * @return the parameter string of this frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        String str = super.paramString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        if (title != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            str += ",title=" + title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        if (resizable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            str += ",resizable";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
2453
35e5fab82613 6724890: Deadlock between AWT-EventQueue-1 and AWT-XAWT threads during IDE start
dcherepanov
parents: 1183
diff changeset
  1070
        int state = getExtendedState();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        if (state == NORMAL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            str += ",normal";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            if ((state & ICONIFIED) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                str += ",iconified";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            if ((state & MAXIMIZED_BOTH) == MAXIMIZED_BOTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                str += ",maximized";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            else if ((state & MAXIMIZED_HORIZ) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                str += ",maximized_horiz";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            else if ((state & MAXIMIZED_VERT) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                str += ",maximized_vert";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        return str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     * replaced by <code>Component.setCursor(Cursor)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    public void setCursor(int cursorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        if (cursorType < DEFAULT_CURSOR || cursorType > MOVE_CURSOR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            throw new IllegalArgumentException("illegal cursor type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
        setCursor(Cursor.getPredefinedCursor(cursorType));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @deprecated As of JDK version 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * replaced by <code>Component.getCursor()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    public int getCursorType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        return (getCursor().getType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * Returns an array of all {@code Frame}s created by this application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * If called from an applet, the array includes only the {@code Frame}s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     * accessible by that applet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * <b>Warning:</b> this method may return system created frames, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * as a shared, hidden frame which is used by Swing. Applications
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * should not assume the existence of these frames, nor should an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
     * application assume anything about these frames such as component
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
     * positions, <code>LayoutManager</code>s or serialization.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * <b>Note</b>: To obtain a list of all ownerless windows, including
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * ownerless {@code Dialog}s (introduced in release 1.6), use {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * Window#getOwnerlessWindows Window.getOwnerlessWindows}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * @see Window#getWindows()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * @see Window#getOwnerlessWindows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    public static Frame[] getFrames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        Window[] allWindows = Window.getWindows();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        int frameCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        for (Window w : allWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
            if (w instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
                frameCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        Frame[] frames = new Frame[frameCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        int c = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        for (Window w : allWindows) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            if (w instanceof Frame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                frames[c++] = (Frame)w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        return frames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
    /* Serialization support.  If there's a MenuBar we restore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * its (transient) parent field here.  Likewise for top level
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     * windows that are "owned" by this frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
     * <code>Frame</code>'s Serialized Data Version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    private int frameSerializedDataVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * Writes default serializable fields to stream.  Writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * an optional serializable icon <code>Image</code>, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * available as of 1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * @param s the <code>ObjectOutputStream</code> to write
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * @serialData an optional icon <code>Image</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @see java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     * @see #getIconImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @see #setIconImage(Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @see #readObject(ObjectInputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
    private void writeObject(ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
      throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        if (icons != null && icons.size() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            Image icon1 = icons.get(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            if (icon1 instanceof Serializable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                s.writeObject(icon1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        s.writeObject(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
     * Reads the <code>ObjectInputStream</code>.  Tries
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * to read an icon <code>Image</code>, which is optional
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
     * data available as of 1.4.  If an icon <code>Image</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
     * is not available, but anything other than an EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     * is detected, an <code>OptionalDataException</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * will be thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * Unrecognized keys or values will be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     * @param s the <code>ObjectInputStream</code> to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * @exception java.io.OptionalDataException if an icon <code>Image</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     *   is not available, but anything other than an EOF
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     *   is detected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * @exception HeadlessException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
     *   <code>GraphicsEnvironment.isHeadless</code> returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     *   <code>true</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * @see java.awt.GraphicsEnvironment#isHeadless()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @see java.awt.Image
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @see #getIconImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @see #setIconImage(Image)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @see #writeObject(ObjectOutputStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
    private void readObject(ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
      throws ClassNotFoundException, IOException, HeadlessException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
      // HeadlessException is thrown by Window's readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
      s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
      try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
          Image icon = (Image) s.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
          if (icons == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
              icons = new ArrayList<Image>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
              icons.add(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
      } catch (java.io.OptionalDataException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
          // pre-1.4 instances will not have this optional data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
          // 1.6 and later instances serialize icons in the Window class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
          // e.eof will be true to indicate that there is no more
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
          // data available for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
          // If e.eof is not true, throw the exception as it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
          // might have been caused by unrelated reasons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
          if (!e.eof) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
              throw (e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
      if (menuBar != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        menuBar.parent = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
      // Ensure 1.1 serialized Frames can read & hook-up
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
      // owned windows properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
      //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
      if (ownedWindows != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
          for (int i = 0; i < ownedWindows.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
              connectOwnedWindow((Window) ownedWindows.elementAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
          ownedWindows = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * Gets the AccessibleContext associated with this Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * For frames, the AccessibleContext takes the form of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * AccessibleAWTFrame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     * A new AccessibleAWTFrame instance is created if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * @return an AccessibleAWTFrame that serves as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     *         AccessibleContext of this Frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            accessibleContext = new AccessibleAWTFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * This class implements accessibility support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * <code>Frame</code> class.  It provides an implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * Java Accessibility API appropriate to frame user-interface elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    protected class AccessibleAWTFrame extends AccessibleAWTWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
         * JDK 1.3 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        private static final long serialVersionUID = -6172960752956030250L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            return AccessibleRole.FRAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
         * Get the state of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
         * @return an instance of AccessibleStateSet containing the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
         * state set of the object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
         * @see AccessibleState
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        public AccessibleStateSet getAccessibleStateSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            AccessibleStateSet states = super.getAccessibleStateSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            if (getFocusOwner() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                states.add(AccessibleState.ACTIVE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            if (isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                states.add(AccessibleState.RESIZABLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            return states;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    } // inner class AccessibleAWTFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
}