Merge from the pain train
[official-gcc.git] / libjava / java / awt / event / WindowEvent.java
blob68a8c25d08bebf838c101d59d7a6e65403bae7df
1 /* WindowEvent.java -- window change event
2 Copyright (C) 1999, 2002, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package java.awt.event;
41 import java.awt.Window;
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.
51 * @author Aaron M. Renn (arenn@urbanophile.com)
52 * @see WindowAdapter
53 * @see WindowListener
54 * @see WindowFocusListener
55 * @see WindowStateListener
56 * @since 1.1
57 * @status updated to 1.4
59 public class WindowEvent extends ComponentEvent
61 /**
62 * Compatible with JDK 1.1+.
64 private static final long serialVersionUID = -1567959133147912127L;
66 /** This is the first id in the range of event ids used by this class. */
67 public static final int WINDOW_FIRST = 200;
69 /** This is the id for a window that is opened. */
70 public static final int WINDOW_OPENED = 200;
72 /** This is the id for a window that is about to close. */
73 public static final int WINDOW_CLOSING = 201;
75 /** This is the id for a window that finished closing. */
76 public static final int WINDOW_CLOSED = 202;
78 /** This is the id for a window that is iconified. */
79 public static final int WINDOW_ICONIFIED = 203;
81 /** This is the id for a window that is de-iconified. */
82 public static final int WINDOW_DEICONIFIED = 204;
84 /** This is the id for a window that is activated. */
85 public static final int WINDOW_ACTIVATED = 205;
87 /** This is the id for a window that is de-activated. */
88 public static final int WINDOW_DEACTIVATED = 206;
90 /**
91 * This is the id for a window becoming the focused window.
93 * @since 1.4
95 public static final int WINDOW_GAINED_FOCUS = 207;
97 /**
98 * This is the id for a window losing all focus.
100 * @since 1.4
102 public static final int WINDOW_LOST_FOCUS = 208;
105 * This is the id for a window state change, such as maximization.
107 * @since 1.4
109 public static final int WINDOW_STATE_CHANGED = 209;
111 /** This is the last id in the range of event ids used by this class. */
112 public static final int WINDOW_LAST = 209;
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.
121 * @see #getOppositeWindow()
122 * @serial the opposite window, or null
123 * @since 1.4
125 private final Window opposite;
128 * The former state of the window.
130 * @serial bitmask of the old window state
131 * @since 1.4
133 private final int oldState;
136 * The present state of the window.
138 * @serial bitmask of the new window state
139 * @since 1.4
141 private final int newState;
144 * Initializes a new instance of <code>WindowEvent</code> with the specified
145 * parameters. Note that an invalid id leads to unspecified results.
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
155 public WindowEvent(Window source, int id, Window opposite,
156 int oldState, int newState)
158 super(source, id);
159 this.opposite = opposite;
160 this.oldState = oldState;
161 this.newState = newState;
165 * Initializes a new instance of <code>WindowEvent</code> with the specified
166 * parameters. Note that an invalid id leads to unspecified results.
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
174 public WindowEvent(Window source, int id, Window opposite)
176 this(source, id, opposite, 0, 0);
180 * Initializes a new instance of <code>WindowEvent</code> with the specified
181 * parameters. Note that an invalid id leads to unspecified results.
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
190 public WindowEvent(Window source, int id, int oldState, int newState)
192 this(source, id, null, oldState, newState);
196 * Initializes a new instance of <code>WindowEvent</code> with the specified
197 * parameters. Note that an invalid id leads to unspecified results.
199 * @param source the window that generated this event
200 * @param id the event id
201 * @throws IllegalArgumentException if source is null
203 public WindowEvent(Window source, int id)
205 this(source, id, null, 0, 0);
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.
212 * @return the event source as a <code>Window</code>
214 public Window getWindow()
216 return source instanceof Window ? (Window) source : null;
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.
227 * @return the opposite window, or null
228 * @since 1.4
230 public Window getOppositeWindow()
232 return opposite;
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.
240 * @return the former state
241 * @see Frame#getExtendedState()
242 * @since 1.4
244 public int getOldState()
246 return oldState;
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.
254 * @return the updated state
255 * @see Frame#getExtendedState()
256 * @since 1.4
258 public int getNewState()
260 return newState;
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.
268 * @return a string that identifies this event
270 public String paramString()
272 StringBuffer s = new StringBuffer();
273 switch (id)
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=");
308 return s.append(opposite).append(",oldState=").append(oldState)
309 .append(",newState=").append(newState).toString();
311 } // class WindowEvent