jdk/src/share/classes/java/awt/event/ComponentEvent.java
author dxu
Thu, 04 Apr 2013 15:39:17 -0700
changeset 16734 da1901d79073
parent 12813 c10ab96dcf41
child 20455 f6f9a0c2796b
permissions -rw-r--r--
8000406: change files using @GenerateNativeHeader to use @Native Summary: Use @Native annotation to mark constants interested by native codes Reviewed-by: alanb, anthony, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
     2
 * Copyright (c) 1996, 2013, 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;
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    31
import java.lang.annotation.Native;
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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
public class ComponentEvent extends AWTEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * The first number in the range of ids used for component events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public static final int COMPONENT_FIRST             = 100;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * The last number in the range of ids used for component events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int COMPONENT_LAST              = 103;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * This event indicates that the component's position changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    83
    @Native public static final int COMPONENT_MOVED     = COMPONENT_FIRST;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * This event indicates that the component's size changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    88
    @Native public static final int COMPONENT_RESIZED   = 1 + COMPONENT_FIRST;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * This event indicates that the component was made visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    93
    @Native public static final int COMPONENT_SHOWN     = 2 + COMPONENT_FIRST;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * This event indicates that the component was rendered invisible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
16734
da1901d79073 8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents: 12813
diff changeset
    98
    @Native public static final int COMPONENT_HIDDEN    = 3 + COMPONENT_FIRST;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private static final long serialVersionUID = 8101406823902992965L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Constructs a <code>ComponentEvent</code> object.
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   107
     * <p> This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   111
     * @param source The <code>Component</code> that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   112
     * @param id     An integer indicating the type of event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   113
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   114
     *                     the class description for {@link ComponentEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   116
     * @see #getComponent()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   117
     * @see #getID()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public ComponentEvent(Component source, int id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Returns the originator of the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @return the <code>Component</code> object that originated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * the event, or <code>null</code> if the object is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public Component getComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        return (source instanceof Component) ? (Component)source : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Returns a parameter string identifying this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @return a string identifying the event and its attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        Rectangle b = (source !=null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                       ? ((Component)source).getBounds()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                       : null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
          case COMPONENT_SHOWN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
              typeStr = "COMPONENT_SHOWN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
          case COMPONENT_HIDDEN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
              typeStr = "COMPONENT_HIDDEN";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
          case COMPONENT_MOVED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
              typeStr = "COMPONENT_MOVED ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                         b.x+","+b.y+" "+b.width+"x"+b.height+")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
          case COMPONENT_RESIZED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
              typeStr = "COMPONENT_RESIZED ("+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                         b.x+","+b.y+" "+b.width+"x"+b.height+")";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
              typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
}