jdk/src/share/classes/java/awt/event/ComponentEvent.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 5506 202f599c92aa
child 16734 da1901d79073
permissions -rw-r--r--
7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI Reviewed-by: ohair, ohrstrom, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     2
 * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.event;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Rectangle;
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    31
import javax.tools.annotation.GenerateNativeHeader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * A low-level event which indicates that a component moved, changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * size, or changed visibility (also, the root class for the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * component-level events).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Component events are provided for notification purposes ONLY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The AWT will automatically handle component moves and resizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * internally so that GUI layout works properly regardless of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * whether a program is receiving these events or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * In addition to serving as the base class for other component-related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * events (InputEvent, FocusEvent, WindowEvent, ContainerEvent),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * this class defines the events that indicate changes in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * a component's size, position, or visibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This low-level event is generated by a component object (such as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * List) when the component is moved, resized, rendered invisible, or made
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * visible again. The event is passed to every <code>ComponentListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * or <code>ComponentAdapter</code> object which registered to receive such
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * events using the component's <code>addComponentListener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * (<code>ComponentAdapter</code> objects implement the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <code>ComponentListener</code> interface.) Each such listener object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * gets this <code>ComponentEvent</code> when the event occurs.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    56
 * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    57
 * An unspecified behavior will be caused if the {@code id} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    58
 * of any particular {@code ComponentEvent} instance is not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    59
 * in the range from {@code COMPONENT_FIRST} to {@code COMPONENT_LAST}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * @see ComponentAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * @see ComponentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/componentlistener.html">Tutorial: Writing a Component Listener</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * @author Carl Quinn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 */
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    68
/* No native methods here, but the constants are needed in the supporting JNI code */
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 5506
diff changeset
    69
@GenerateNativeHeader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class ComponentEvent extends AWTEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The first number in the range of ids used for component events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public static final int COMPONENT_FIRST             = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * The last number in the range of ids used for component events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final int COMPONENT_LAST              = 103;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * This event indicates that the component's position changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static final int COMPONENT_MOVED     = COMPONENT_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * This event indicates that the component's size changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final int COMPONENT_RESIZED   = 1 + COMPONENT_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * This event indicates that the component was made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final int COMPONENT_SHOWN     = 2 + COMPONENT_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * This event indicates that the component was rendered invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final int COMPONENT_HIDDEN    = 3 + COMPONENT_FIRST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    private static final long serialVersionUID = 8101406823902992965L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Constructs a <code>ComponentEvent</code> object.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   109
     * <p> This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   113
     * @param source The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   114
     * @param id     An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   115
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   116
     *                     the class description for {@link ComponentEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   118
     * @see #getComponent()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   119
     * @see #getID()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public ComponentEvent(Component source, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Returns the originator of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @return the <code>Component</code> object that originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * the event, or <code>null</code> if the object is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return (source instanceof Component) ? (Component)source : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @return a string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        Rectangle b = (source !=null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                       ? ((Component)source).getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                       : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
          case COMPONENT_SHOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
              typeStr = "COMPONENT_SHOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
          case COMPONENT_HIDDEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
              typeStr = "COMPONENT_HIDDEN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
          case COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
              typeStr = "COMPONENT_MOVED ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                         b.x+","+b.y+" "+b.width+"x"+b.height+")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
          case COMPONENT_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
              typeStr = "COMPONENT_RESIZED ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                         b.x+","+b.y+" "+b.width+"x"+b.height+")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
              typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        return typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
}