1 /*
   2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package javax.swing.event;
  26 
  27 import java.awt.AWTEvent;
  28 import javax.swing.JInternalFrame;
  29 
  30 /**
  31  * An <code>AWTEvent</code> that adds support for
  32  * <code>JInternalFrame</code> objects as the event source.  This class has the
  33  * same event types as <code>WindowEvent</code>,
  34  * although different IDs are used.
  35  * Help on handling internal frame events
  36  * is in
  37  * <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/internalframelistener.html" target="_top">How to Write an Internal Frame Listener</a>,
  38  * a section in <em>The Java Tutorial</em>.
  39  * <p>
  40  * <strong>Warning:</strong>
  41  * Serialized objects of this class will not be compatible with
  42  * future Swing releases. The current serialization support is
  43  * appropriate for short term storage or RMI between applications running
  44  * the same version of Swing.  As of 1.4, support for long term storage
  45  * of all JavaBeans&trade;
  46  * has been added to the <code>java.beans</code> package.
  47  * Please see {@link java.beans.XMLEncoder}.
  48  *
  49  * @see java.awt.event.WindowEvent
  50  * @see java.awt.event.WindowListener
  51  * @see JInternalFrame
  52  * @see InternalFrameListener
  53  *
  54  * @author Thomas Ball
  55  */
  56 @SuppressWarnings("serial") // Same-version serialization only
  57 public class InternalFrameEvent extends AWTEvent {
  58 
  59     /**
  60      * The first number in the range of IDs used for internal frame events.
  61      */
  62     public static final int INTERNAL_FRAME_FIRST        = 25549;
  63 
  64     /**
  65      * The last number in the range of IDs used for internal frame events.
  66      */
  67     public static final int INTERNAL_FRAME_LAST         = 25555;
  68 
  69     /**
  70      * The "window opened" event.  This event is delivered only
  71      * the first time the internal frame is made visible.
  72      *
  73      * @see JInternalFrame#show
  74      */
  75     public static final int INTERNAL_FRAME_OPENED       = INTERNAL_FRAME_FIRST;
  76 
  77     /**
  78      * The "window is closing" event. This event is delivered when
  79      * the user attempts to close the internal frame, such as by
  80      * clicking the internal frame's close button,
  81      * or when a program attempts to close the internal frame
  82      * by invoking the <code>setClosed</code> method.
  83      *
  84      * @see JInternalFrame#setDefaultCloseOperation
  85      * @see JInternalFrame#doDefaultCloseAction
  86      * @see JInternalFrame#setClosed
  87      */
  88     public static final int INTERNAL_FRAME_CLOSING      = 1 + INTERNAL_FRAME_FIRST;
  89 
  90     /**
  91      * The "window closed" event. This event is delivered after
  92      * the internal frame has been closed as the result of a call to
  93      * the <code>setClosed</code> or
  94      * <code>dispose</code> method.
  95      *
  96      * @see JInternalFrame#setClosed
  97      * @see JInternalFrame#dispose
  98      */
  99     public static final int INTERNAL_FRAME_CLOSED       = 2 + INTERNAL_FRAME_FIRST;
 100 
 101     /**
 102      * The "window iconified" event.
 103      * This event indicates that the internal frame
 104      * was shrunk down to a small icon.
 105      *
 106      * @see JInternalFrame#setIcon
 107      */
 108     public static final int INTERNAL_FRAME_ICONIFIED    = 3 + INTERNAL_FRAME_FIRST;
 109 
 110     /**
 111      * The "window deiconified" event type. This event indicates that the
 112      * internal frame has been restored to its normal size.
 113      *
 114      * @see JInternalFrame#setIcon
 115      */
 116     public static final int INTERNAL_FRAME_DEICONIFIED  = 4 + INTERNAL_FRAME_FIRST;
 117 
 118     /**
 119      * The "window activated" event type. This event indicates that keystrokes
 120      * and mouse clicks are directed towards this internal frame.
 121      *
 122      * @see JInternalFrame#show
 123      * @see JInternalFrame#setSelected
 124      */
 125     public static final int INTERNAL_FRAME_ACTIVATED    = 5 + INTERNAL_FRAME_FIRST;
 126 
 127     /**
 128      * The "window deactivated" event type. This event indicates that keystrokes
 129      * and mouse clicks are no longer directed to the internal frame.
 130      *
 131      * @see JInternalFrame#setSelected
 132      */
 133     public static final int INTERNAL_FRAME_DEACTIVATED  = 6 + INTERNAL_FRAME_FIRST;
 134 
 135     /**
 136      * Constructs an <code>InternalFrameEvent</code> object.
 137      * @param source the <code>JInternalFrame</code> object that originated the event
 138      * @param id     an integer indicating the type of event
 139      */
 140     public InternalFrameEvent(JInternalFrame source, int id) {
 141         super(source, id);
 142     }
 143 
 144     /**
 145      * Returns a parameter string identifying this event.
 146      * This method is useful for event logging and for debugging.
 147      *
 148      * @return a string identifying the event and its attributes
 149      */
 150     public String paramString() {
 151         String typeStr;
 152         switch(id) {
 153           case INTERNAL_FRAME_OPENED:
 154               typeStr = "INTERNAL_FRAME_OPENED";
 155               break;
 156           case INTERNAL_FRAME_CLOSING:
 157               typeStr = "INTERNAL_FRAME_CLOSING";
 158               break;
 159           case INTERNAL_FRAME_CLOSED:
 160               typeStr = "INTERNAL_FRAME_CLOSED";
 161               break;
 162           case INTERNAL_FRAME_ICONIFIED:
 163               typeStr = "INTERNAL_FRAME_ICONIFIED";
 164               break;
 165           case INTERNAL_FRAME_DEICONIFIED:
 166               typeStr = "INTERNAL_FRAME_DEICONIFIED";
 167               break;
 168           case INTERNAL_FRAME_ACTIVATED:
 169               typeStr = "INTERNAL_FRAME_ACTIVATED";
 170               break;
 171           case INTERNAL_FRAME_DEACTIVATED:
 172               typeStr = "INTERNAL_FRAME_DEACTIVATED";
 173               break;
 174           default:
 175               typeStr = "unknown type";
 176         }
 177         return typeStr;
 178     }
 179 
 180 
 181     /**
 182      * Returns the originator of the event.
 183      *
 184      * @return the <code>JInternalFrame</code> object that originated the event
 185      * @since 1.3
 186      */
 187 
 188     public JInternalFrame getInternalFrame () {
 189       return (source instanceof JInternalFrame)? (JInternalFrame)source : null;
 190     }
 191 
 192 
 193 }