jdk/src/share/classes/java/awt/event/ActionEvent.java
author erikj
Thu, 07 Jun 2012 18:05:09 -0700
changeset 12813 c10ab96dcf41
parent 7668 d4a77089c587
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
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6640
diff changeset
     2
 * Copyright (c) 1996, 2010, 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: 440
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: 440
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: 440
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 440
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.Event;
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 7668
diff changeset
    30
import javax.tools.annotation.GenerateNativeHeader;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A semantic event which indicates that a component-defined action occurred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This high-level event is generated by a component (such as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>Button</code>) when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * the component-specific action occurs (such as being pressed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The event is passed to every <code>ActionListener</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * that registered to receive such events using the component's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <code>addActionListener</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <b>Note:</b> To invoke an <code>ActionEvent</code> on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <code>Button</code> using the keyboard, use the Space bar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * The object that implements the <code>ActionListener</code> interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * gets this <code>ActionEvent</code> when the event occurs. The listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * is therefore spared the details of processing individual mouse movements
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * and mouse clicks, and can instead process a "meaningful" (semantic)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * event like "button pressed".
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    49
 * <p>
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    50
 * An unspecified behavior will be caused if the {@code id} parameter
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    51
 * of any particular {@code ActionEvent} instance is not
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
    52
 * in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @see ActionListener
6640
5e889a82c906 6694729: obsolete link in ActionEvent javadoc
dav
parents: 5506
diff changeset
    55
 * @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @author Carl Quinn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * @since 1.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 */
12813
c10ab96dcf41 7170969: Add @GenerateNativeHeader to classes whose fields need to be exported for JNI
erikj
parents: 7668
diff changeset
    60
/* 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: 7668
diff changeset
    61
@GenerateNativeHeader
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
public class ActionEvent extends AWTEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * The shift modifier. An indicator that the shift key was held
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * down during the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public static final int SHIFT_MASK          = Event.SHIFT_MASK;
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 control modifier. An indicator that the control key was held
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * down during the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static final int CTRL_MASK           = Event.CTRL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * The meta modifier. An indicator that the meta key was held
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * down during the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public static final int META_MASK           = Event.META_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * The alt modifier. An indicator that the alt key was held
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * down during the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final int ALT_MASK            = Event.ALT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * The first number in the range of ids used for action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static final int ACTION_FIRST                = 1001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * The last number in the range of ids used for action events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public static final int ACTION_LAST                 = 1001;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * This event id indicates that a meaningful action occured.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static final int ACTION_PERFORMED    = ACTION_FIRST; //Event.ACTION_EVENT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The nonlocalized string that gives more details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * of what actually caused the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * This information is very specific to the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * that fired it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #getActionCommand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    String actionCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Timestamp of when this event occurred. Because an ActionEvent is a high-
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * level, semantic event, the timestamp is typically the same as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * underlying InputEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @see #getWhen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    long when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * This represents the key modifier that was selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * and is used to determine the state of the selected key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * If no modifier has been selected it will default to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * @see #getModifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    int modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * JDK 1.1 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static final long serialVersionUID = -7671078796273832149L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Constructs an <code>ActionEvent</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <p>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   144
     * This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * A <code>null</code> <code>command</code> string is legal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * but not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   150
     * @param source  The object that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   151
     * @param id      An integer that identifies the event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   152
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   153
     *                     the class description for {@link ActionEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   154
     * @param command A string that may specify a command (possibly one
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *                of several) associated with the event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   157
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   158
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   159
     * @see #getActionCommand()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    public ActionEvent(Object source, int id, String command) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        this(source, id, command, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Constructs an <code>ActionEvent</code> object with modifier keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <p>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   168
     * This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * A <code>null</code> <code>command</code> string is legal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * but not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   174
     * @param source  The object that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   175
     * @param id      An integer that identifies the event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   176
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   177
     *                     the class description for {@link ActionEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   178
     * @param command A string that may specify a command (possibly one
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   179
     *                of several) associated with the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   180
     * @param modifiers The modifier keys down during event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   181
     *                  (shift, ctrl, alt, meta).
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   182
     *                  Passing negative parameter is not recommended.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   183
     *                  Zero value means that no modifiers were passed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   185
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   186
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   187
     * @see #getActionCommand()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   188
     * @see #getModifiers()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public ActionEvent(Object source, int id, String command, int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        this(source, id, command, 0, modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Constructs an <code>ActionEvent</code> object with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * modifier keys and timestamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * <p>
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   198
     * This method throws an
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <code>IllegalArgumentException</code> if <code>source</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * A <code>null</code> <code>command</code> string is legal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * but not recommended.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   204
     * @param source    The object that originated the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   205
     * @param id      An integer that identifies the event.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   206
     *                     For information on allowable values, see
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   207
     *                     the class description for {@link ActionEvent}
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   208
     * @param command A string that may specify a command (possibly one
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   209
     *                of several) associated with the event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   210
     * @param modifiers The modifier keys down during event
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   211
     *                  (shift, ctrl, alt, meta).
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   212
     *                  Passing negative parameter is not recommended.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   213
     *                  Zero value means that no modifiers were passed
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   214
     * @param when   A long that gives the time the event occurred.
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   215
     *               Passing negative or zero value
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   216
     *               is not recommended
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @throws IllegalArgumentException if <code>source</code> is null
440
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   218
     * @see #getSource()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   219
     * @see #getID()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   220
     * @see #getActionCommand()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   221
     * @see #getModifiers()
a3dac373f62d 6520716: event classes lack info about parameters
dav
parents: 2
diff changeset
   222
     * @see #getWhen()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public ActionEvent(Object source, int id, String command, long when,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                       int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        super(source, id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        this.actionCommand = command;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        this.when = when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        this.modifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Returns the command string associated with this action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * This string allows a "modal" component to specify one of several
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * commands, depending on its state. For example, a single button might
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * toggle between "show details" and "hide details". The source object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * and the event would be the same in each case, but the command string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * would identify the intended action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Note that if a <code>null</code> command string was passed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * to the constructor for this <code>ActionEvent</code>, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * this method returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * @return the string identifying the command for this event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public String getActionCommand() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        return actionCommand;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Returns the timestamp of when this event occurred. Because an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * ActionEvent is a high-level, semantic event, the timestamp is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * the same as an underlying InputEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @return this event's timestamp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public long getWhen() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        return when;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Returns the modifier keys held down during this action event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @return the bitwise-or of the modifier constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public int getModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Returns a parameter string identifying this action event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * This method is useful for event-logging and for debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return a string identifying the event and its associated command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        String typeStr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        switch(id) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
          case ACTION_PERFORMED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
              typeStr = "ACTION_PERFORMED";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
              break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
              typeStr = "unknown type";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return typeStr + ",cmd="+actionCommand+",when="+when+",modifiers="+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            KeyEvent.getKeyModifiersText(modifiers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
}