jdk/src/share/classes/java/awt/event/WindowEvent.java
author flar
Fri, 29 Apr 2011 10:58:33 -0700
changeset 9465 d336b679b605
parent 5506 202f599c92aa
child 12317 9670c1610c53
permissions -rw-r--r--
6522514: Extending Arc2D.Double and serializing the object causes InvalidClassException Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 1996, 2008, 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: 715
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: 715
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: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import sun.awt.AppContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A low-level event that indicates that a window has changed its status. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * low-level event is generated by a Window object when it is opened, closed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * activated, deactivated, iconified, or deiconified, or when focus is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * transfered into or out of the Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The event is passed to every <code>WindowListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * or <code>WindowAdapter</code> object which registered to receive such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * events using the window's <code>addWindowListener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * (<code>WindowAdapter</code> objects implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>WindowListener</code> interface.) Each such listener object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * gets this <code>WindowEvent</code> when the event occurs.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    44
 * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    45
 * An unspecified behavior will be caused if the {@code id} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    46
 * of any particular {@code WindowEvent} instance is not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    47
 * in the range from {@code WINDOW_FIRST} to {@code WINDOW_LAST}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Carl Quinn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see WindowAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @see WindowListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/windowlistener.html">Tutorial: Writing a Window Listener</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * @since JDK1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class WindowEvent extends ComponentEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * The first number in the range of ids used for window events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static final int WINDOW_FIRST        = 200;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The window opened event.  This event is delivered only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * the first time a window is made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public static final int WINDOW_OPENED       = WINDOW_FIRST; // 200
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * The "window is closing" event. This event is delivered when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * the user attempts to close the window from the window's system menu.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * If the program does not explicitly hide or dispose the window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * while processing this event, the window close operation will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * cancelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int WINDOW_CLOSING      = 1 + WINDOW_FIRST; //Event.WINDOW_DESTROY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * The window closed event. This event is delivered after
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * the window has been closed as the result of a call to dispose.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static final int WINDOW_CLOSED       = 2 + WINDOW_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * The window iconified event. This event is delivered when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * the window has been changed from a normal to a minimized state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * For many platforms, a minimized window is displayed as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * the icon specified in the window's iconImage property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @see java.awt.Frame#setIconImage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final int WINDOW_ICONIFIED    = 3 + WINDOW_FIRST; //Event.WINDOW_ICONIFY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * The window deiconified event type. This event is delivered when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * the window has been changed from a minimized to a normal state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public static final int WINDOW_DEICONIFIED  = 4 + WINDOW_FIRST; //Event.WINDOW_DEICONIFY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * The window-activated event type. This event is delivered when the Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * becomes the active Window. Only a Frame or a Dialog can be the active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Window. The native windowing system may denote the active Window or its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * children with special decorations, such as a highlighted title bar. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * active Window is always either the focused Window, or the first Frame or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * Dialog that is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public static final int WINDOW_ACTIVATED    = 5 + WINDOW_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * The window-deactivated event type. This event is delivered when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Window is no longer the active Window. Only a Frame or a Dialog can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * the active Window. The native windowing system may denote the active
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Window or its children with special decorations, such as a highlighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * title bar. The active Window is always either the focused Window, or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * first Frame or Dialog that is an owner of the focused Window.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static final int WINDOW_DEACTIVATED  = 6 + WINDOW_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * The window-gained-focus event type. This event is delivered when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * Window becomes the focused Window, which means that the Window, or one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * of its subcomponents, will receive keyboard events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public static final int WINDOW_GAINED_FOCUS = 7 + WINDOW_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The window-lost-focus event type. This event is delivered when a Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * is no longer the focused Window, which means keyboard events will no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * longer be delivered to the Window or any of its subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public static final int WINDOW_LOST_FOCUS   = 8 + WINDOW_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * The window-state-changed event type.  This event is delivered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * when a Window's state is changed by virtue of it being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * iconified, maximized etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    public static final int WINDOW_STATE_CHANGED = 9 + WINDOW_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * The last number in the range of ids used for window events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static final int WINDOW_LAST         = WINDOW_STATE_CHANGED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * The other Window involved in this focus or activation change. For a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * WINDOW_ACTIVATED or WINDOW_GAINED_FOCUS event, this is the Window that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * lost activation or focus. For a WINDOW_DEACTIVATED or WINDOW_LOST_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * event, this is the Window that gained activation or focus. For any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * type of WindowEvent, or if the focus or activation change occurs with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * native application, a Java application in a different VM, or with no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * other Window, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @see #getOppositeWindow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    transient Window opposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * TBS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    int oldState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    int newState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    private static final long serialVersionUID = -1567959133147912127L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Constructs a <code>WindowEvent</code> object.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   177
     * <p>This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   181
     * @param source    The <code>Window</code> object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *                    that originated the event
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   183
     * @param id        An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   184
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   185
     *                     the class description for {@link WindowEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   186
     * @param opposite  The other window involved in the focus or activation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *                      change, or <code>null</code>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   188
     * @param oldState  Previous state of the window for window state change event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   189
     *                  See {@code #getOldState()} for allowable values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   190
     * @param newState  New state of the window for window state change event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   191
     *                  See {@code #getNewState()} for allowable values
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   193
     * @see #getWindow()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   194
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   195
     * @see #getOppositeWindow()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   196
     * @see #getOldState()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   197
     * @see #getNewState()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public WindowEvent(Window source, int id, Window opposite,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                       int oldState, int newState)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        this.opposite = opposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        this.oldState = oldState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        this.newState = newState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Constructs a <code>WindowEvent</code> object with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * specified opposite <code>Window</code>. The opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <code>Window</code> is the other <code>Window</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * involved in this focus or activation change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * For a <code>WINDOW_ACTIVATED</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <code>WINDOW_GAINED_FOCUS</code> event, this is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * <code>Window</code> that lost activation or focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * For a <code>WINDOW_DEACTIVATED</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <code>WINDOW_LOST_FOCUS</code> event, this is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <code>Window</code> that gained activation or focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * If this focus change occurs with a native application, with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Java application in a different VM, or with no other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * <code>Window</code>, then the opposite Window is <code>null</code>.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   223
     * <p>This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   227
     * @param source     The <code>Window</code> object that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *                   originated the event
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   229
     * @param id        An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   230
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   231
     *                     the class description for {@link WindowEvent}.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   232
     *                  It is expected that this constructor will not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   233
     *                  be used for other then
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   234
     *                  {@code WINDOW_ACTIVATED},{@code WINDOW_DEACTIVATED},
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   235
     *                  {@code WINDOW_GAINED_FOCUS}, or {@code WINDOW_LOST_FOCUS}.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   236
     *                  {@code WindowEvent} types,
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   237
     *                  because the opposite <code>Window</code> of other event types
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   238
     *                  will always be {@code null}.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   239
     * @param opposite   The other <code>Window</code> involved in the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *                   focus or activation change, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   242
     * @see #getWindow()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   243
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   244
     * @see #getOppositeWindow()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public WindowEvent(Window source, int id, Window opposite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        this(source, id, opposite, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Constructs a <code>WindowEvent</code> object with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * previous and new window states.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   254
     * <p>This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   258
     * @param source    The <code>Window</code> object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *                  that originated the event
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   260
     * @param id        An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   261
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   262
     *                     the class description for {@link WindowEvent}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *                  It is expected that this constructor will not
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   264
     *                  be used for other then
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   265
     *                  {@code WINDOW_STATE_CHANGED}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   266
     *                  {@code WindowEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *                  types, because the previous and new window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *                  states are meaningless for other event types.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   269
     * @param oldState  An integer representing the previous window state.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   270
     *                  See {@code #getOldState()} for allowable values
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   271
     * @param newState  An integer representing the new window state.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   272
     *                  See {@code #getNewState()} for allowable values
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   274
     * @see #getWindow()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   275
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   276
     * @see #getOldState()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   277
     * @see #getNewState()
2
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 WindowEvent(Window source, int id, int oldState, int newState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        this(source, id, null, oldState, newState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * Constructs a <code>WindowEvent</code> object.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   286
     * <p>This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   290
     * @param source The <code>Window</code> object that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   291
     * @param id     An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   292
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   293
     *                     the class description for {@link WindowEvent}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   295
     * @see #getWindow()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   296
     * @see #getID()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    public WindowEvent(Window source, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        this(source, id, null, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Returns the originator of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return the Window object that originated the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public Window getWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        return (source instanceof Window) ? (Window)source : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Returns the other Window involved in this focus or activation change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * For a WINDOW_ACTIVATED or WINDOW_GAINED_FOCUS event, this is the Window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * that lost activation or focus. For a WINDOW_DEACTIVATED or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * WINDOW_LOST_FOCUS event, this is the Window that gained activation or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * focus. For any other type of WindowEvent, or if the focus or activation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * change occurs with a native application, with a Java application in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * different VM or context, or with no other Window, null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * @return the other Window involved in the focus or activation change, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     *         null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    public Window getOppositeWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        if (opposite == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        return (SunToolkit.targetToAppContext(opposite) ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                AppContext.getAppContext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            ? opposite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * For <code>WINDOW_STATE_CHANGED</code> events returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * previous state of the window. The state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * represented as a bitwise mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <li><code>NORMAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * <br>Indicates that no state bits are set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * <li><code>ICONIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * <li><code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * <li><code>MAXIMIZED_VERT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * <li><code>MAXIMIZED_BOTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * <br>Concatenates <code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * and <code>MAXIMIZED_VERT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * @return a bitwise mask of the previous window state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * @see java.awt.Frame#getExtendedState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    public int getOldState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return oldState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * For <code>WINDOW_STATE_CHANGED</code> events returns the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * new state of the window. The state is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * represented as a bitwise mask.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <li><code>NORMAL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <br>Indicates that no state bits are set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <li><code>ICONIFIED</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * <li><code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * <li><code>MAXIMIZED_VERT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <li><code>MAXIMIZED_BOTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * <br>Concatenates <code>MAXIMIZED_HORIZ</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * and <code>MAXIMIZED_VERT</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @return a bitwise mask of the new window state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @see java.awt.Frame#getExtendedState()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public int getNewState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return newState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @return a string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
          case WINDOW_OPENED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
              typeStr = "WINDOW_OPENED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
          case WINDOW_CLOSING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
              typeStr = "WINDOW_CLOSING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
          case WINDOW_CLOSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
              typeStr = "WINDOW_CLOSED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
          case WINDOW_ICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
              typeStr = "WINDOW_ICONIFIED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
          case WINDOW_DEICONIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
              typeStr = "WINDOW_DEICONIFIED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
          case WINDOW_ACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
              typeStr = "WINDOW_ACTIVATED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
          case WINDOW_DEACTIVATED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
              typeStr = "WINDOW_DEACTIVATED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
          case WINDOW_GAINED_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
              typeStr = "WINDOW_GAINED_FOCUS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
          case WINDOW_LOST_FOCUS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
              typeStr = "WINDOW_LOST_FOCUS";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
          case WINDOW_STATE_CHANGED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
              typeStr = "WINDOW_STATE_CHANGED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
              typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        typeStr += ",opposite=" + getOppositeWindow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            + ",oldState=" + oldState + ",newState=" + newState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
}