0N/A/*
3261N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.event;
0N/A
0N/Aimport java.awt.AWTEvent;
0N/Aimport java.awt.Event;
0N/A
0N/A/**
0N/A * A semantic event which indicates that a component-defined action occurred.
0N/A * This high-level event is generated by a component (such as a
0N/A * <code>Button</code>) when
0N/A * the component-specific action occurs (such as being pressed).
0N/A * The event is passed to every <code>ActionListener</code> object
0N/A * that registered to receive such events using the component's
0N/A * <code>addActionListener</code> method.
0N/A * <p>
0N/A * <b>Note:</b> To invoke an <code>ActionEvent</code> on a
0N/A * <code>Button</code> using the keyboard, use the Space bar.
0N/A * <P>
0N/A * The object that implements the <code>ActionListener</code> interface
0N/A * gets this <code>ActionEvent</code> when the event occurs. The listener
0N/A * is therefore spared the details of processing individual mouse movements
0N/A * and mouse clicks, and can instead process a "meaningful" (semantic)
0N/A * event like "button pressed".
217N/A * <p>
217N/A * An unspecified behavior will be caused if the {@code id} parameter
217N/A * of any particular {@code ActionEvent} instance is not
217N/A * in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}.
0N/A *
0N/A * @see ActionListener
2771N/A * @see <a href="http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a>
0N/A *
0N/A * @author Carl Quinn
0N/A * @since 1.1
0N/A */
0N/Apublic class ActionEvent extends AWTEvent {
0N/A
0N/A /**
0N/A * The shift modifier. An indicator that the shift key was held
0N/A * down during the event.
0N/A */
0N/A public static final int SHIFT_MASK = Event.SHIFT_MASK;
0N/A
0N/A /**
0N/A * The control modifier. An indicator that the control key was held
0N/A * down during the event.
0N/A */
0N/A public static final int CTRL_MASK = Event.CTRL_MASK;
0N/A
0N/A /**
0N/A * The meta modifier. An indicator that the meta key was held
0N/A * down during the event.
0N/A */
0N/A public static final int META_MASK = Event.META_MASK;
0N/A
0N/A /**
0N/A * The alt modifier. An indicator that the alt key was held
0N/A * down during the event.
0N/A */
0N/A public static final int ALT_MASK = Event.ALT_MASK;
0N/A
0N/A
0N/A /**
0N/A * The first number in the range of ids used for action events.
0N/A */
0N/A public static final int ACTION_FIRST = 1001;
0N/A
0N/A /**
0N/A * The last number in the range of ids used for action events.
0N/A */
0N/A public static final int ACTION_LAST = 1001;
0N/A
0N/A /**
0N/A * This event id indicates that a meaningful action occured.
0N/A */
0N/A public static final int ACTION_PERFORMED = ACTION_FIRST; //Event.ACTION_EVENT
0N/A
0N/A /**
0N/A * The nonlocalized string that gives more details
0N/A * of what actually caused the event.
0N/A * This information is very specific to the component
0N/A * that fired it.
0N/A
0N/A * @serial
0N/A * @see #getActionCommand
0N/A */
0N/A String actionCommand;
0N/A
0N/A /**
0N/A * Timestamp of when this event occurred. Because an ActionEvent is a high-
0N/A * level, semantic event, the timestamp is typically the same as an
0N/A * underlying InputEvent.
0N/A *
0N/A * @serial
0N/A * @see #getWhen
0N/A */
0N/A long when;
0N/A
0N/A /**
0N/A * This represents the key modifier that was selected,
0N/A * and is used to determine the state of the selected key.
0N/A * If no modifier has been selected it will default to
0N/A * zero.
0N/A *
0N/A * @serial
0N/A * @see #getModifiers
0N/A */
0N/A int modifiers;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -7671078796273832149L;
0N/A
0N/A /**
0N/A * Constructs an <code>ActionEvent</code> object.
0N/A * <p>
217N/A * This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A * A <code>null</code> <code>command</code> string is legal,
0N/A * but not recommended.
0N/A *
217N/A * @param source The object that originated the event
217N/A * @param id An integer that identifies the event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link ActionEvent}
217N/A * @param command A string that may specify a command (possibly one
0N/A * of several) associated with the event
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getActionCommand()
0N/A */
0N/A public ActionEvent(Object source, int id, String command) {
0N/A this(source, id, command, 0);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <code>ActionEvent</code> object with modifier keys.
0N/A * <p>
217N/A * This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A * A <code>null</code> <code>command</code> string is legal,
0N/A * but not recommended.
0N/A *
217N/A * @param source The object that originated the event
217N/A * @param id An integer that identifies the event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link ActionEvent}
217N/A * @param command A string that may specify a command (possibly one
217N/A * of several) associated with the event
217N/A * @param modifiers The modifier keys down during event
217N/A * (shift, ctrl, alt, meta).
217N/A * Passing negative parameter is not recommended.
217N/A * Zero value means that no modifiers were passed
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getActionCommand()
217N/A * @see #getModifiers()
0N/A */
0N/A public ActionEvent(Object source, int id, String command, int modifiers) {
0N/A this(source, id, command, 0, modifiers);
0N/A }
0N/A
0N/A /**
0N/A * Constructs an <code>ActionEvent</code> object with the specified
0N/A * modifier keys and timestamp.
0N/A * <p>
217N/A * This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A * A <code>null</code> <code>command</code> string is legal,
0N/A * but not recommended.
0N/A *
217N/A * @param source The object that originated the event
217N/A * @param id An integer that identifies the event.
217N/A * For information on allowable values, see
217N/A * the class description for {@link ActionEvent}
217N/A * @param command A string that may specify a command (possibly one
217N/A * of several) associated with the event
217N/A * @param modifiers The modifier keys down during event
217N/A * (shift, ctrl, alt, meta).
217N/A * Passing negative parameter is not recommended.
217N/A * Zero value means that no modifiers were passed
217N/A * @param when A long that gives the time the event occurred.
217N/A * Passing negative or zero value
217N/A * is not recommended
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getSource()
217N/A * @see #getID()
217N/A * @see #getActionCommand()
217N/A * @see #getModifiers()
217N/A * @see #getWhen()
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public ActionEvent(Object source, int id, String command, long when,
0N/A int modifiers) {
0N/A super(source, id);
0N/A this.actionCommand = command;
0N/A this.when = when;
0N/A this.modifiers = modifiers;
0N/A }
0N/A
0N/A /**
0N/A * Returns the command string associated with this action.
0N/A * This string allows a "modal" component to specify one of several
0N/A * commands, depending on its state. For example, a single button might
0N/A * toggle between "show details" and "hide details". The source object
0N/A * and the event would be the same in each case, but the command string
0N/A * would identify the intended action.
0N/A * <p>
0N/A * Note that if a <code>null</code> command string was passed
0N/A * to the constructor for this <code>ActionEvent</code>, this
0N/A * this method returns <code>null</code>.
0N/A *
0N/A * @return the string identifying the command for this event
0N/A */
0N/A public String getActionCommand() {
0N/A return actionCommand;
0N/A }
0N/A
0N/A /**
0N/A * Returns the timestamp of when this event occurred. Because an
0N/A * ActionEvent is a high-level, semantic event, the timestamp is typically
0N/A * the same as an underlying InputEvent.
0N/A *
0N/A * @return this event's timestamp
0N/A * @since 1.4
0N/A */
0N/A public long getWhen() {
0N/A return when;
0N/A }
0N/A
0N/A /**
0N/A * Returns the modifier keys held down during this action event.
0N/A *
0N/A * @return the bitwise-or of the modifier constants
0N/A */
0N/A public int getModifiers() {
0N/A return modifiers;
0N/A }
0N/A
0N/A /**
0N/A * Returns a parameter string identifying this action event.
0N/A * This method is useful for event-logging and for debugging.
0N/A *
0N/A * @return a string identifying the event and its associated command
0N/A */
0N/A public String paramString() {
0N/A String typeStr;
0N/A switch(id) {
0N/A case ACTION_PERFORMED:
0N/A typeStr = "ACTION_PERFORMED";
0N/A break;
0N/A default:
0N/A typeStr = "unknown type";
0N/A }
0N/A return typeStr + ",cmd="+actionCommand+",when="+when+",modifiers="+
0N/A KeyEvent.getKeyModifiersText(modifiers);
0N/A }
0N/A}