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