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