| 1 | /* WindowEvent.java -- window change event
|
|---|
| 2 | Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.awt.event;
|
|---|
| 40 |
|
|---|
| 41 | import java.awt.Window;
|
|---|
| 42 |
|
|---|
| 43 | /**
|
|---|
| 44 | * This event is generated when there is a change in a window. This includes
|
|---|
| 45 | * creation, closing, iconification, activation, and focus changes. There
|
|---|
| 46 | * are three listeners, for three types of events: WindowListeners deal with
|
|---|
| 47 | * the lifecycle of a window, WindowStateListeners deal with window state
|
|---|
| 48 | * like maximization, and WindowFocusListeners deal with focus switching to
|
|---|
| 49 | * or from a window.
|
|---|
| 50 | *
|
|---|
| 51 | * @author Aaron M. Renn <[email protected]>
|
|---|
| 52 | * @see WindowAdapter
|
|---|
| 53 | * @see WindowListener
|
|---|
| 54 | * @see WindowFocusListener
|
|---|
| 55 | * @see WindowStateListener
|
|---|
| 56 | * @since 1.1
|
|---|
| 57 | * @status updated to 1.4
|
|---|
| 58 | */
|
|---|
| 59 | public class WindowEvent extends ComponentEvent
|
|---|
| 60 | {
|
|---|
| 61 | /**
|
|---|
| 62 | * Compatible with JDK 1.1+.
|
|---|
| 63 | */
|
|---|
| 64 | private static final long serialVersionUID = -1567959133147912127L;
|
|---|
| 65 |
|
|---|
| 66 | /** This is the first id in the range of event ids used by this class. */
|
|---|
| 67 | public static final int WINDOW_FIRST = 200;
|
|---|
| 68 |
|
|---|
| 69 | /** This is the id for a window that is opened. */
|
|---|
| 70 | public static final int WINDOW_OPENED = 200;
|
|---|
| 71 |
|
|---|
| 72 | /** This is the id for a window that is about to close. */
|
|---|
| 73 | public static final int WINDOW_CLOSING = 201;
|
|---|
| 74 |
|
|---|
| 75 | /** This is the id for a window that finished closing. */
|
|---|
| 76 | public static final int WINDOW_CLOSED = 202;
|
|---|
| 77 |
|
|---|
| 78 | /** This is the id for a window that is iconified. */
|
|---|
| 79 | public static final int WINDOW_ICONIFIED = 203;
|
|---|
| 80 |
|
|---|
| 81 | /** This is the id for a window that is de-iconified. */
|
|---|
| 82 | public static final int WINDOW_DEICONIFIED = 204;
|
|---|
| 83 |
|
|---|
| 84 | /** This is the id for a window that is activated. */
|
|---|
| 85 | public static final int WINDOW_ACTIVATED = 205;
|
|---|
| 86 |
|
|---|
| 87 | /** This is the id for a window that is de-activated. */
|
|---|
| 88 | public static final int WINDOW_DEACTIVATED = 206;
|
|---|
| 89 |
|
|---|
| 90 | /**
|
|---|
| 91 | * This is the id for a window becoming the focused window.
|
|---|
| 92 | *
|
|---|
| 93 | * @since 1.4
|
|---|
| 94 | */
|
|---|
| 95 | public static final int WINDOW_GAINED_FOCUS = 207;
|
|---|
| 96 |
|
|---|
| 97 | /**
|
|---|
| 98 | * This is the id for a window losing all focus.
|
|---|
| 99 | *
|
|---|
| 100 | * @since 1.4
|
|---|
| 101 | */
|
|---|
| 102 | public static final int WINDOW_LOST_FOCUS = 208;
|
|---|
| 103 |
|
|---|
| 104 | /**
|
|---|
| 105 | * This is the id for a window state change, such as maximization.
|
|---|
| 106 | *
|
|---|
| 107 | * @since 1.4
|
|---|
| 108 | */
|
|---|
| 109 | public static final int WINDOW_STATE_CHANGED = 209;
|
|---|
| 110 |
|
|---|
| 111 | /** This is the last id in the range of event ids used by this class. */
|
|---|
| 112 | public static final int WINDOW_LAST = 209;
|
|---|
| 113 |
|
|---|
| 114 | /**
|
|---|
| 115 | * The other Window involved in a focus or activation change. For
|
|---|
| 116 | * WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events, this is the window that
|
|---|
| 117 | * lost focus; for WINDOW_DEACTIVATED and WINDOW_LOST_FOCUS, this is the
|
|---|
| 118 | * window that stole focus; and for other events (or when native
|
|---|
| 119 | * implementation does not have the data available), this is null.
|
|---|
| 120 | *
|
|---|
| 121 | * @see #getOppositeWindow()
|
|---|
| 122 | * @serial the opposite window, or null
|
|---|
| 123 | * @since 1.4
|
|---|
| 124 | */
|
|---|
| 125 | private final Window opposite;
|
|---|
| 126 |
|
|---|
| 127 | /**
|
|---|
| 128 | * The former state of the window.
|
|---|
| 129 | *
|
|---|
| 130 | * @serial bitmask of the old window state
|
|---|
| 131 | * @since 1.4
|
|---|
| 132 | */
|
|---|
| 133 | private final int oldState;
|
|---|
| 134 |
|
|---|
| 135 | /**
|
|---|
| 136 | * The present state of the window.
|
|---|
| 137 | *
|
|---|
| 138 | * @serial bitmask of the new window state
|
|---|
| 139 | * @since 1.4
|
|---|
| 140 | */
|
|---|
| 141 | private final int newState;
|
|---|
| 142 |
|
|---|
| 143 | /**
|
|---|
| 144 | * Initializes a new instance of <code>WindowEvent</code> with the specified
|
|---|
| 145 | * parameters. Note that an invalid id leads to unspecified results.
|
|---|
| 146 | *
|
|---|
| 147 | * @param source the window that generated this event
|
|---|
| 148 | * @param id the event id
|
|---|
| 149 | * @param opposite the window that received the opposite event, or null
|
|---|
| 150 | * @param oldState the previous state of this window
|
|---|
| 151 | * @param newState the new state of this window
|
|---|
| 152 | * @throws IllegalArgumentException if source is null
|
|---|
| 153 | * @since 1.4
|
|---|
| 154 | */
|
|---|
| 155 | public WindowEvent(Window source, int id, Window opposite,
|
|---|
| 156 | int oldState, int newState)
|
|---|
| 157 | {
|
|---|
| 158 | super(source, id);
|
|---|
| 159 | this.opposite = opposite;
|
|---|
| 160 | this.oldState = oldState;
|
|---|
| 161 | this.newState = newState;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | /**
|
|---|
| 165 | * Initializes a new instance of <code>WindowEvent</code> with the specified
|
|---|
| 166 | * parameters. Note that an invalid id leads to unspecified results.
|
|---|
| 167 | *
|
|---|
| 168 | * @param source the window that generated this event
|
|---|
| 169 | * @param id the event id
|
|---|
| 170 | * @param opposite the window that received the opposite event, or null
|
|---|
| 171 | * @throws IllegalArgumentException if source is null
|
|---|
| 172 | * @since 1.4
|
|---|
| 173 | */
|
|---|
| 174 | public WindowEvent(Window source, int id, Window opposite)
|
|---|
| 175 | {
|
|---|
| 176 | this(source, id, opposite, 0, 0);
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | /**
|
|---|
| 180 | * Initializes a new instance of <code>WindowEvent</code> with the specified
|
|---|
| 181 | * parameters. Note that an invalid id leads to unspecified results.
|
|---|
| 182 | *
|
|---|
| 183 | * @param source the window that generated this event
|
|---|
| 184 | * @param id the event id
|
|---|
| 185 | * @param oldState the previous state of this window
|
|---|
| 186 | * @param newState the new state of this window
|
|---|
| 187 | * @throws IllegalArgumentException if source is null
|
|---|
| 188 | * @since 1.4
|
|---|
| 189 | */
|
|---|
| 190 | public WindowEvent(Window source, int id, int oldState, int newState)
|
|---|
| 191 | {
|
|---|
| 192 | this(source, id, null, oldState, newState);
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | /**
|
|---|
| 196 | * Initializes a new instance of <code>WindowEvent</code> with the specified
|
|---|
| 197 | * parameters. Note that an invalid id leads to unspecified results.
|
|---|
| 198 | *
|
|---|
| 199 | * @param source the window that generated this event
|
|---|
| 200 | * @param id the event id
|
|---|
| 201 | * @throws IllegalArgumentException if source is null
|
|---|
| 202 | */
|
|---|
| 203 | public WindowEvent(Window source, int id)
|
|---|
| 204 | {
|
|---|
| 205 | this(source, id, null, 0, 0);
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | /**
|
|---|
| 209 | * Returns the event source as a <code>Window</code>. If the source has
|
|---|
| 210 | * subsequently been modified to a non-Window, this returns null.
|
|---|
| 211 | *
|
|---|
| 212 | * @return the event source as a <code>Window</code>
|
|---|
| 213 | */
|
|---|
| 214 | public Window getWindow()
|
|---|
| 215 | {
|
|---|
| 216 | return source instanceof Window ? (Window) source : null;
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | /**
|
|---|
| 220 | * Returns the opposite window if this window was involved in an activation
|
|---|
| 221 | * or focus change. For WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events,
|
|---|
| 222 | * this is the window that lost focus; for WINDOW_DEACTIVATED and
|
|---|
| 223 | * WINDOW_LOST_FOCUS, this is the window that stole focus; and for other
|
|---|
| 224 | * events (or when native implementation does not have the data available),
|
|---|
| 225 | * this is null.
|
|---|
| 226 | *
|
|---|
| 227 | * @return the opposite window, or null
|
|---|
| 228 | * @since 1.4
|
|---|
| 229 | */
|
|---|
| 230 | public Window getOppositeWindow()
|
|---|
| 231 | {
|
|---|
| 232 | return opposite;
|
|---|
| 233 | }
|
|---|
| 234 |
|
|---|
| 235 | /**
|
|---|
| 236 | * Returns the state of this window before the event. This is the bitwise
|
|---|
| 237 | * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT,
|
|---|
| 238 | * and MAXIMIZED_BOTH.
|
|---|
| 239 | *
|
|---|
| 240 | * @return the former state
|
|---|
| 241 | * @see Frame#getExtendedState()
|
|---|
| 242 | * @since 1.4
|
|---|
| 243 | */
|
|---|
| 244 | public int getOldState()
|
|---|
| 245 | {
|
|---|
| 246 | return oldState;
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | /**
|
|---|
| 250 | * Returns the state of this window after the event. This is the bitwise
|
|---|
| 251 | * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT,
|
|---|
| 252 | * and MAXIMIZED_BOTH.
|
|---|
| 253 | *
|
|---|
| 254 | * @return the updated state
|
|---|
| 255 | * @see Frame#getExtendedState()
|
|---|
| 256 | * @since 1.4
|
|---|
| 257 | */
|
|---|
| 258 | public int getNewState()
|
|---|
| 259 | {
|
|---|
| 260 | return newState;
|
|---|
| 261 | }
|
|---|
| 262 |
|
|---|
| 263 | /**
|
|---|
| 264 | * Returns a string that identifies this event. This is formatted as the
|
|---|
| 265 | * field name of the id, followed by the opposite window, old state, and
|
|---|
| 266 | * new state.
|
|---|
| 267 | *
|
|---|
| 268 | * @return a string that identifies this event
|
|---|
| 269 | */
|
|---|
| 270 | public String paramString()
|
|---|
| 271 | {
|
|---|
| 272 | StringBuffer s = new StringBuffer();
|
|---|
| 273 | switch (id)
|
|---|
| 274 | {
|
|---|
| 275 | case WINDOW_OPENED:
|
|---|
| 276 | s.append("WINDOW_OPENED,opposite=");
|
|---|
| 277 | break;
|
|---|
| 278 | case WINDOW_CLOSING:
|
|---|
| 279 | s.append("WINDOW_CLOSING,opposite=");
|
|---|
| 280 | break;
|
|---|
| 281 | case WINDOW_CLOSED:
|
|---|
| 282 | s.append("WINDOW_CLOSED,opposite=");
|
|---|
| 283 | break;
|
|---|
| 284 | case WINDOW_ICONIFIED:
|
|---|
| 285 | s.append("WINDOW_ICONIFIED,opposite=");
|
|---|
| 286 | break;
|
|---|
| 287 | case WINDOW_DEICONIFIED:
|
|---|
| 288 | s.append("WINDOW_DEICONIFIED,opposite=");
|
|---|
| 289 | break;
|
|---|
| 290 | case WINDOW_ACTIVATED:
|
|---|
| 291 | s.append("WINDOW_ACTIVATED,opposite=");
|
|---|
| 292 | break;
|
|---|
| 293 | case WINDOW_DEACTIVATED:
|
|---|
| 294 | s.append("WINDOW_DEACTIVATED,opposite=");
|
|---|
| 295 | break;
|
|---|
| 296 | case WINDOW_GAINED_FOCUS:
|
|---|
| 297 | s.append("WINDOW_GAINED_FOCUS,opposite=");
|
|---|
| 298 | break;
|
|---|
| 299 | case WINDOW_LOST_FOCUS:
|
|---|
| 300 | s.append("WINDOW_LOST_FOCUS,opposite=");
|
|---|
| 301 | break;
|
|---|
| 302 | case WINDOW_STATE_CHANGED:
|
|---|
| 303 | s.append("WINDOW_STATE_CHANGED,opposite=");
|
|---|
| 304 | break;
|
|---|
| 305 | default:
|
|---|
| 306 | s.append("unknown type,opposite=");
|
|---|
| 307 | }
|
|---|
| 308 | return s.append(opposite).append(",oldState=").append(oldState)
|
|---|
| 309 | .append(",newState=").append(newState).toString();
|
|---|
| 310 | }
|
|---|
| 311 | } // class WindowEvent
|
|---|