GNU Classpath (0.95) | |
Frames | No Frames |
1: /* WindowEvent.java -- window change event 2: Copyright (C) 1999, 2002, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 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.Frame; 42: import java.awt.Window; 43: 44: /** 45: * This event is generated when there is a change in a window. This includes 46: * creation, closing, iconification, activation, and focus changes. There 47: * are three listeners, for three types of events: WindowListeners deal with 48: * the lifecycle of a window, WindowStateListeners deal with window state 49: * like maximization, and WindowFocusListeners deal with focus switching to 50: * or from a window. 51: * 52: * @author Aaron M. Renn (arenn@urbanophile.com) 53: * @see WindowAdapter 54: * @see WindowListener 55: * @see WindowFocusListener 56: * @see WindowStateListener 57: * @since 1.1 58: * @status updated to 1.4 59: */ 60: public class WindowEvent extends ComponentEvent 61: { 62: /** 63: * Compatible with JDK 1.1+. 64: */ 65: private static final long serialVersionUID = -1567959133147912127L; 66: 67: /** This is the first id in the range of event ids used by this class. */ 68: public static final int WINDOW_FIRST = 200; 69: 70: /** This is the id for a window that is opened. */ 71: public static final int WINDOW_OPENED = 200; 72: 73: /** This is the id for a window that is about to close. */ 74: public static final int WINDOW_CLOSING = 201; 75: 76: /** This is the id for a window that finished closing. */ 77: public static final int WINDOW_CLOSED = 202; 78: 79: /** This is the id for a window that is iconified. */ 80: public static final int WINDOW_ICONIFIED = 203; 81: 82: /** This is the id for a window that is de-iconified. */ 83: public static final int WINDOW_DEICONIFIED = 204; 84: 85: /** This is the id for a window that is activated. */ 86: public static final int WINDOW_ACTIVATED = 205; 87: 88: /** This is the id for a window that is de-activated. */ 89: public static final int WINDOW_DEACTIVATED = 206; 90: 91: /** 92: * This is the id for a window becoming the focused window. 93: * 94: * @since 1.4 95: */ 96: public static final int WINDOW_GAINED_FOCUS = 207; 97: 98: /** 99: * This is the id for a window losing all focus. 100: * 101: * @since 1.4 102: */ 103: public static final int WINDOW_LOST_FOCUS = 208; 104: 105: /** 106: * This is the id for a window state change, such as maximization. 107: * 108: * @since 1.4 109: */ 110: public static final int WINDOW_STATE_CHANGED = 209; 111: 112: /** This is the last id in the range of event ids used by this class. */ 113: public static final int WINDOW_LAST = 209; 114: 115: /** 116: * The other Window involved in a focus or activation change. For 117: * WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events, this is the window that 118: * lost focus; for WINDOW_DEACTIVATED and WINDOW_LOST_FOCUS, this is the 119: * window that stole focus; and for other events (or when native 120: * implementation does not have the data available), this is null. 121: * 122: * @see #getOppositeWindow() 123: * @serial the opposite window, or null 124: * @since 1.4 125: */ 126: private final Window opposite; 127: 128: /** 129: * The former state of the window. 130: * 131: * @serial bitmask of the old window state 132: * @since 1.4 133: */ 134: private final int oldState; 135: 136: /** 137: * The present state of the window. 138: * 139: * @serial bitmask of the new window state 140: * @since 1.4 141: */ 142: private final int newState; 143: 144: /** 145: * Initializes a new instance of <code>WindowEvent</code> with the specified 146: * parameters. Note that an invalid id leads to unspecified results. 147: * 148: * @param source the window that generated this event 149: * @param id the event id 150: * @param opposite the window that received the opposite event, or null 151: * @param oldState the previous state of this window 152: * @param newState the new state of this window 153: * @throws IllegalArgumentException if source is null 154: * @since 1.4 155: */ 156: public WindowEvent(Window source, int id, Window opposite, 157: int oldState, int newState) 158: { 159: super(source, id); 160: this.opposite = opposite; 161: this.oldState = oldState; 162: this.newState = newState; 163: } 164: 165: /** 166: * Initializes a new instance of <code>WindowEvent</code> with the specified 167: * parameters. Note that an invalid id leads to unspecified results. 168: * 169: * @param source the window that generated this event 170: * @param id the event id 171: * @param opposite the window that received the opposite event, or null 172: * @throws IllegalArgumentException if source is null 173: * @since 1.4 174: */ 175: public WindowEvent(Window source, int id, Window opposite) 176: { 177: this(source, id, opposite, 0, 0); 178: } 179: 180: /** 181: * Initializes a new instance of <code>WindowEvent</code> with the specified 182: * parameters. Note that an invalid id leads to unspecified results. 183: * 184: * @param source the window that generated this event 185: * @param id the event id 186: * @param oldState the previous state of this window 187: * @param newState the new state of this window 188: * @throws IllegalArgumentException if source is null 189: * @since 1.4 190: */ 191: public WindowEvent(Window source, int id, int oldState, int newState) 192: { 193: this(source, id, null, oldState, newState); 194: } 195: 196: /** 197: * Initializes a new instance of <code>WindowEvent</code> with the specified 198: * parameters. Note that an invalid id leads to unspecified results. 199: * 200: * @param source the window that generated this event 201: * @param id the event id 202: * @throws IllegalArgumentException if source is null 203: */ 204: public WindowEvent(Window source, int id) 205: { 206: this(source, id, null, 0, 0); 207: } 208: 209: /** 210: * Returns the event source as a <code>Window</code>. If the source has 211: * subsequently been modified to a non-Window, this returns null. 212: * 213: * @return the event source as a <code>Window</code> 214: */ 215: public Window getWindow() 216: { 217: return source instanceof Window ? (Window) source : null; 218: } 219: 220: /** 221: * Returns the opposite window if this window was involved in an activation 222: * or focus change. For WINDOW_ACTIVATED and WINDOW_GAINED_FOCUS events, 223: * this is the window that lost focus; for WINDOW_DEACTIVATED and 224: * WINDOW_LOST_FOCUS, this is the window that stole focus; and for other 225: * events (or when native implementation does not have the data available), 226: * this is null. 227: * 228: * @return the opposite window, or null 229: * @since 1.4 230: */ 231: public Window getOppositeWindow() 232: { 233: return opposite; 234: } 235: 236: /** 237: * Returns the state of this window before the event. This is the bitwise 238: * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT, 239: * and MAXIMIZED_BOTH. 240: * 241: * @return the former state 242: * @see Frame#getExtendedState() 243: * @since 1.4 244: */ 245: public int getOldState() 246: { 247: return oldState; 248: } 249: 250: /** 251: * Returns the state of this window after the event. This is the bitwise 252: * or of fields in Frame: NORMAL, ICONIFIED, MAXIMIZED_HORIZ, MAXIMIZED_VERT, 253: * and MAXIMIZED_BOTH. 254: * 255: * @return the updated state 256: * @see Frame#getExtendedState() 257: * @since 1.4 258: */ 259: public int getNewState() 260: { 261: return newState; 262: } 263: 264: /** 265: * Returns a string that identifies this event. This is formatted as the 266: * field name of the id, followed by the opposite window, old state, and 267: * new state. 268: * 269: * @return a string that identifies this event 270: */ 271: public String paramString() 272: { 273: StringBuffer s = new StringBuffer(); 274: switch (id) 275: { 276: case WINDOW_OPENED: 277: s.append("WINDOW_OPENED,opposite="); 278: break; 279: case WINDOW_CLOSING: 280: s.append("WINDOW_CLOSING,opposite="); 281: break; 282: case WINDOW_CLOSED: 283: s.append("WINDOW_CLOSED,opposite="); 284: break; 285: case WINDOW_ICONIFIED: 286: s.append("WINDOW_ICONIFIED,opposite="); 287: break; 288: case WINDOW_DEICONIFIED: 289: s.append("WINDOW_DEICONIFIED,opposite="); 290: break; 291: case WINDOW_ACTIVATED: 292: s.append("WINDOW_ACTIVATED,opposite="); 293: break; 294: case WINDOW_DEACTIVATED: 295: s.append("WINDOW_DEACTIVATED,opposite="); 296: break; 297: case WINDOW_GAINED_FOCUS: 298: s.append("WINDOW_GAINED_FOCUS,opposite="); 299: break; 300: case WINDOW_LOST_FOCUS: 301: s.append("WINDOW_LOST_FOCUS,opposite="); 302: break; 303: case WINDOW_STATE_CHANGED: 304: s.append("WINDOW_STATE_CHANGED,opposite="); 305: break; 306: default: 307: s.append("unknown type,opposite="); 308: } 309: return s.append(opposite).append(",oldState=").append(oldState) 310: .append(",newState=").append(newState).toString(); 311: } 312: } // class WindowEvent
GNU Classpath (0.95) |