1 7 8 package java.awt.event; 9 10 import java.awt.Component ; 11 import java.awt.Event ; 12 import java.awt.Window ; 13 14 import sun.awt.AppContext; 15 import sun.awt.SunToolkit; 16 17 41 public class WindowEvent extends ComponentEvent { 42 43 46 public static final int WINDOW_FIRST = 200; 47 48 52 public static final int WINDOW_OPENED = WINDOW_FIRST; 54 61 public static final int WINDOW_CLOSING = 1 + WINDOW_FIRST; 63 67 public static final int WINDOW_CLOSED = 2 + WINDOW_FIRST; 68 69 76 public static final int WINDOW_ICONIFIED = 3 + WINDOW_FIRST; 78 82 public static final int WINDOW_DEICONIFIED = 4 + WINDOW_FIRST; 84 92 public static final int WINDOW_ACTIVATED = 5 + WINDOW_FIRST; 93 94 102 public static final int WINDOW_DEACTIVATED = 6 + WINDOW_FIRST; 103 104 109 public static final int WINDOW_GAINED_FOCUS = 7 + WINDOW_FIRST; 110 111 116 public static final int WINDOW_LOST_FOCUS = 8 + WINDOW_FIRST; 117 118 124 public static final int WINDOW_STATE_CHANGED = 9 + WINDOW_FIRST; 125 126 129 public static final int WINDOW_LAST = WINDOW_STATE_CHANGED; 130 131 143 transient Window opposite; 144 145 148 int oldState; 149 int newState; 150 151 152 155 private static final long serialVersionUID = -1567959133147912127L; 156 157 158 176 public WindowEvent(Window source, int id, Window opposite, 177 int oldState, int newState) 178 { 179 super(source, id); 180 this.opposite = opposite; 181 this.oldState = oldState; 182 this.newState = newState; 183 } 184 185 218 public WindowEvent(Window source, int id, Window opposite) { 219 this(source, id, opposite, 0, 0); 220 } 221 222 242 public WindowEvent(Window source, int id, int oldState, int newState) { 243 this(source, id, null, oldState, newState); 244 } 245 246 257 public WindowEvent(Window source, int id) { 258 this(source, id, null, 0, 0); 259 } 260 261 266 public Window getWindow() { 267 return (source instanceof Window ) ? (Window )source : null; 268 } 269 270 283 public Window getOppositeWindow() { 284 if (opposite == null) { 285 return null; 286 } 287 288 return (SunToolkit.targetToAppContext(opposite) == 289 AppContext.getAppContext()) 290 ? opposite 291 : null; 292 } 293 294 313 public int getOldState() { 314 return oldState; 315 } 316 317 336 public int getNewState() { 337 return newState; 338 } 339 340 346 public String paramString() { 347 String typeStr; 348 switch(id) { 349 case WINDOW_OPENED: 350 typeStr = "WINDOW_OPENED"; 351 break; 352 case WINDOW_CLOSING: 353 typeStr = "WINDOW_CLOSING"; 354 break; 355 case WINDOW_CLOSED: 356 typeStr = "WINDOW_CLOSED"; 357 break; 358 case WINDOW_ICONIFIED: 359 typeStr = "WINDOW_ICONIFIED"; 360 break; 361 case WINDOW_DEICONIFIED: 362 typeStr = "WINDOW_DEICONIFIED"; 363 break; 364 case WINDOW_ACTIVATED: 365 typeStr = "WINDOW_ACTIVATED"; 366 break; 367 case WINDOW_DEACTIVATED: 368 typeStr = "WINDOW_DEACTIVATED"; 369 break; 370 case WINDOW_GAINED_FOCUS: 371 typeStr = "WINDOW_GAINED_FOCUS"; 372 break; 373 case WINDOW_LOST_FOCUS: 374 typeStr = "WINDOW_LOST_FOCUS"; 375 break; 376 case WINDOW_STATE_CHANGED: 377 typeStr = "WINDOW_STATE_CHANGED"; 378 break; 379 default: 380 typeStr = "unknown type"; 381 } 382 typeStr += ",opposite=" + getOppositeWindow() 383 + ",oldState=" + oldState + ",newState=" + newState; 384 385 return typeStr; 386 } 387 } 388 | Popular Tags |