1. /*
  2. * @(#)WindowEvent.java 1.21 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.awt.event;
  11. import java.awt.Event;
  12. import java.awt.Window;
  13. /**
  14. * A low-level event which indicates that a window has changed its status.
  15. * This low-level event is generated by a Window object when it is opened,
  16. * closed, about to close, activated or deactivated, iconified or deconified.
  17. * <P>
  18. * The event is passed to every <code>WindowListener</code>
  19. * or <code>WindowAdapter</code> object which registered to receive such
  20. * events using the window's <code>addWindowListener</code> method.
  21. * (<code>WindowAdapter</code> objects implement the
  22. * <code>WindowListener</code> interface.) Each such listener object
  23. * gets this <code>WindowEvent</code> when the event occurs.
  24. *
  25. * @author Carl Quinn
  26. * @author Amy Fowler
  27. * @version 1.21, 02/02/00
  28. *
  29. * @see WindowAdapter
  30. * @see WindowListener
  31. * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/windowlistener.html">Tutorial: Writing a Window Listener</a>
  32. * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
  33. *
  34. * @since 1.1
  35. */
  36. public class WindowEvent extends ComponentEvent {
  37. /**
  38. * The first number in the range of ids used for window events.
  39. */
  40. public static final int WINDOW_FIRST = 200;
  41. /**
  42. * The last number in the range of ids used for window events.
  43. */
  44. public static final int WINDOW_LAST = 206;
  45. /**
  46. * The window opened event. This event is delivered only
  47. * the first time a window is made visible.
  48. */
  49. public static final int WINDOW_OPENED = WINDOW_FIRST; // 200
  50. /**
  51. * The "window is closing" event. This event is delivered when
  52. * the user attempts to close the window from the window's system menu.
  53. * If the program does not explicitly hide or dispose the window
  54. * while processing this event, the window close operation will be
  55. * cancelled.
  56. */
  57. public static final int WINDOW_CLOSING = 1 + WINDOW_FIRST; //Event.WINDOW_DESTROY
  58. /**
  59. * The window closed event. This event is delivered after
  60. * the window has been closed as the result of a call to dispose.
  61. */
  62. public static final int WINDOW_CLOSED = 2 + WINDOW_FIRST;
  63. /**
  64. * The window iconified event. This event is delivered when
  65. * the window has been changed from a normal to a minimized state.
  66. * For many platforms, a minimized window is displayed as
  67. * the icon specified in the window's iconImage property.
  68. * @see java.awt.Frame#setIconImage
  69. */
  70. public static final int WINDOW_ICONIFIED = 3 + WINDOW_FIRST; //Event.WINDOW_ICONIFY
  71. /**
  72. * The window deiconified event type. This event is delivered when
  73. * the window has been changed from a minimized to a normal state.
  74. */
  75. public static final int WINDOW_DEICONIFIED = 4 + WINDOW_FIRST; //Event.WINDOW_DEICONIFY
  76. /**
  77. * The window activated event type. This event is delivered
  78. * when the window becomes the user's active window, which means
  79. * that the window (or one of its subcomponents) will receive
  80. * keyboard events.
  81. */
  82. public static final int WINDOW_ACTIVATED = 5 + WINDOW_FIRST;
  83. /**
  84. * The window deactivated event type. This event is delivered
  85. * when a window is no longer the user's active window, which
  86. * means keyboard events will no longer be delivered to the
  87. * window or its subcomponents.
  88. */
  89. public static final int WINDOW_DEACTIVATED = 6 + WINDOW_FIRST;
  90. /*
  91. * JDK 1.1 serialVersionUID
  92. */
  93. private static final long serialVersionUID = -1567959133147912127L;
  94. /**
  95. * Constructs a WindowEvent object.
  96. * @param source the Window object that originated the event
  97. * @param id an integer indicating the type of event
  98. */
  99. public WindowEvent(Window source, int id) {
  100. super(source, id);
  101. }
  102. /**
  103. * Returns the originator of the event.
  104. *
  105. * @return the Window object that originated the event
  106. */
  107. public Window getWindow() {
  108. return (source instanceof Window) ? (Window)source : null;
  109. }
  110. /**
  111. * Returns a parameter string identifying this event.
  112. * This method is useful for event-logging and for debugging.
  113. *
  114. * @return a string identifying the event and its attributes
  115. */
  116. public String paramString() {
  117. String typeStr;
  118. switch(id) {
  119. case WINDOW_OPENED:
  120. typeStr = "WINDOW_OPENED";
  121. break;
  122. case WINDOW_CLOSING:
  123. typeStr = "WINDOW_CLOSING";
  124. break;
  125. case WINDOW_CLOSED:
  126. typeStr = "WINDOW_CLOSED";
  127. break;
  128. case WINDOW_ICONIFIED:
  129. typeStr = "WINDOW_ICONIFIED";
  130. break;
  131. case WINDOW_DEICONIFIED:
  132. typeStr = "WINDOW_DEICONIFIED";
  133. break;
  134. case WINDOW_ACTIVATED:
  135. typeStr = "WINDOW_ACTIVATED";
  136. break;
  137. case WINDOW_DEACTIVATED:
  138. typeStr = "WINDOW_DEACTIVATED";
  139. break;
  140. default:
  141. typeStr = "unknown type";
  142. }
  143. return typeStr;
  144. }
  145. }