1. /*
  2. * @(#)InternalFrameEvent.java 1.16 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing.event;
  8. import java.awt.AWTEvent;
  9. import javax.swing.JInternalFrame;
  10. /**
  11. * An <code>AWTEvent</code> that adds support for
  12. * <code>JInternalFrame</code> objects as the event source. This class has the
  13. * same event types as <code>WindowEvent</code>,
  14. * although different IDs are used.
  15. * Help on handling internal frame events
  16. * is in
  17. * <a href="http://java.sun.com/docs/books/tutorial/uiswing/events/internalframelistener.html" target="_top">How to Write an Internal Frame Listener</a>,
  18. * a section in <em>The Java Tutorial</em>.
  19. * <p>
  20. * <strong>Warning:</strong>
  21. * Serialized objects of this class will not be compatible with
  22. * future Swing releases. The current serialization support is
  23. * appropriate for short term storage or RMI between applications running
  24. * the same version of Swing. As of 1.4, support for long term storage
  25. * of all JavaBeans<sup><font size="-2">TM</font></sup>
  26. * has been added to the <code>java.beans</code> package.
  27. * Please see {@link java.beans.XMLEncoder}.
  28. *
  29. * @see java.awt.event.WindowEvent
  30. * @see java.awt.event.WindowListener
  31. * @see JInternalFrame
  32. * @see InternalFrameListener
  33. *
  34. * @version 1.16 12/19/03
  35. * @author Thomas Ball
  36. */
  37. public class InternalFrameEvent extends AWTEvent {
  38. /**
  39. * The first number in the range of IDs used for internal frame events.
  40. */
  41. public static final int INTERNAL_FRAME_FIRST = 25549;
  42. /**
  43. * The last number in the range of IDs used for internal frame events.
  44. */
  45. public static final int INTERNAL_FRAME_LAST = 25555;
  46. /**
  47. * The "window opened" event. This event is delivered only
  48. * the first time the internal frame is made visible.
  49. *
  50. * @see JInternalFrame#show
  51. */
  52. public static final int INTERNAL_FRAME_OPENED = INTERNAL_FRAME_FIRST;
  53. /**
  54. * The "window is closing" event. This event is delivered when
  55. * the user attempts to close the internal frame, such as by
  56. * clicking the internal frame's close button,
  57. * or when a program attempts to close the internal frame
  58. * by invoking the <code>setClosed</code> method.
  59. *
  60. * @see JInternalFrame#setDefaultCloseOperation
  61. * @see JInternalFrame#doDefaultCloseAction
  62. * @see JInternalFrame#setClosed
  63. */
  64. public static final int INTERNAL_FRAME_CLOSING = 1 + INTERNAL_FRAME_FIRST;
  65. /**
  66. * The "window closed" event. This event is delivered after
  67. * the internal frame has been closed as the result of a call to
  68. * the <code>setClosed</code> or
  69. * <code>dispose</code> method.
  70. *
  71. * @see JInternalFrame#setClosed
  72. * @see JInternalFrame#dispose
  73. */
  74. public static final int INTERNAL_FRAME_CLOSED = 2 + INTERNAL_FRAME_FIRST;
  75. /**
  76. * The "window iconified" event.
  77. * This event indicates that the internal frame
  78. * was shrunk down to a small icon.
  79. *
  80. * @see JInternalFrame#setIcon
  81. */
  82. public static final int INTERNAL_FRAME_ICONIFIED = 3 + INTERNAL_FRAME_FIRST;
  83. /**
  84. * The "window deiconified" event type. This event indicates that the
  85. * internal frame has been restored to its normal size.
  86. *
  87. * @see JInternalFrame#setIcon
  88. */
  89. public static final int INTERNAL_FRAME_DEICONIFIED = 4 + INTERNAL_FRAME_FIRST;
  90. /**
  91. * The "window activated" event type. This event indicates that keystrokes
  92. * and mouse clicks are directed towards this internal frame.
  93. *
  94. * @see JInternalFrame#show
  95. * @see JInternalFrame#setSelected
  96. */
  97. public static final int INTERNAL_FRAME_ACTIVATED = 5 + INTERNAL_FRAME_FIRST;
  98. /**
  99. * The "window deactivated" event type. This event indicates that keystrokes
  100. * and mouse clicks are no longer directed to the internal frame.
  101. *
  102. * @see JInternalFrame#setSelected
  103. */
  104. public static final int INTERNAL_FRAME_DEACTIVATED = 6 + INTERNAL_FRAME_FIRST;
  105. /**
  106. * Constructs an <code>InternalFrameEvent</code> object.
  107. * @param source the <code>JInternalFrame</code> object that originated the event
  108. * @param id an integer indicating the type of event
  109. */
  110. public InternalFrameEvent(JInternalFrame source, int id) {
  111. super(source, id);
  112. }
  113. /**
  114. * Returns a parameter string identifying this event.
  115. * This method is useful for event logging and for debugging.
  116. *
  117. * @return a string identifying the event and its attributes
  118. */
  119. public String paramString() {
  120. String typeStr;
  121. switch(id) {
  122. case INTERNAL_FRAME_OPENED:
  123. typeStr = "INTERNAL_FRAME_OPENED";
  124. break;
  125. case INTERNAL_FRAME_CLOSING:
  126. typeStr = "INTERNAL_FRAME_CLOSING";
  127. break;
  128. case INTERNAL_FRAME_CLOSED:
  129. typeStr = "INTERNAL_FRAME_CLOSED";
  130. break;
  131. case INTERNAL_FRAME_ICONIFIED:
  132. typeStr = "INTERNAL_FRAME_ICONIFIED";
  133. break;
  134. case INTERNAL_FRAME_DEICONIFIED:
  135. typeStr = "INTERNAL_FRAME_DEICONIFIED";
  136. break;
  137. case INTERNAL_FRAME_ACTIVATED:
  138. typeStr = "INTERNAL_FRAME_ACTIVATED";
  139. break;
  140. case INTERNAL_FRAME_DEACTIVATED:
  141. typeStr = "INTERNAL_FRAME_DEACTIVATED";
  142. break;
  143. default:
  144. typeStr = "unknown type";
  145. }
  146. return typeStr;
  147. }
  148. /**
  149. * Returns the originator of the event.
  150. *
  151. * @return the <code>JInternalFrame</code> object that originated the event
  152. * @since 1.3
  153. */
  154. public JInternalFrame getInternalFrame () {
  155. return (source instanceof JInternalFrame)? (JInternalFrame)source : null;
  156. }
  157. }