home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / event / ActionEvent.java next >
Encoding:
Java Source  |  1998-03-20  |  5.2 KB  |  160 lines

  1. /*
  2.  * @(#)ActionEvent.java    1.16 98/03/18
  3.  *
  4.  * Copyright 1996, 1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.event;
  16.  
  17. import java.awt.AWTEvent;
  18. import java.awt.Event;
  19.  
  20. /**
  21.  * A semantic event which indicates that a component-defined action occured.
  22.  * This high-level event is generated by a component (such as a Button) when
  23.  * the component-specific action occurs (such as being pressed).
  24.  * The event is passed to every every <code>ActionListener</code> object
  25.  * that registered to receive such events using the component's
  26.  * <code>addActionListener</code> method.
  27.  * <P>
  28.  * The object that implements the <code>ActionListener</code> interface
  29.  * gets this <code>ActionEvent</code> when the event occurs. The listener
  30.  * is therefore spared the details of processing individual mouse movements
  31.  * and mouse clicks, and can instead process a "meaningful" (semantic)
  32.  * event like "button pressed".
  33.  *  
  34.  * @see ActionListener
  35.  * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/eventmodel.html">Tutorial: Java 1.1 Event Model</a>
  36.  * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
  37.  *
  38.  * @version 1.16 03/18/98
  39.  * @author Carl Quinn
  40.  */
  41. public class ActionEvent extends AWTEvent {
  42.  
  43.     /**
  44.      * The shift modifier. An indicator that the shift key was held
  45.      * down during the event.
  46.      */
  47.     public static final int SHIFT_MASK        = Event.SHIFT_MASK;
  48.  
  49.     /**
  50.      * The control modifier. An indicator that the control key was held
  51.      * down during the event.
  52.      */
  53.     public static final int CTRL_MASK        = Event.CTRL_MASK;
  54.  
  55.     /** 
  56.      * The meta modifier. An indicator that the meta key was held
  57.      * down during the event.
  58.      */
  59.     public static final int META_MASK        = Event.META_MASK;
  60.  
  61.     /** 
  62.      * The alt modifier. An indicator that the alt key was held
  63.      * down during the event.
  64.      */
  65.     public static final int ALT_MASK        = Event.ALT_MASK;
  66.  
  67.  
  68.     /**
  69.      * The first number in the range of ids used for action events.
  70.      */
  71.     public static final int ACTION_FIRST        = 1001;
  72.  
  73.     /**
  74.      * The last number in the range of ids used for action events.
  75.      */
  76.     public static final int ACTION_LAST                = 1001;
  77.  
  78.     /**
  79.      * This event id indicates that a meaningful action occured.
  80.      */
  81.     public static final int ACTION_PERFORMED    = ACTION_FIRST; //Event.ACTION_EVENT
  82.  
  83.     String actionCommand;
  84.     int modifiers;
  85.  
  86.     /*
  87.      * JDK 1.1 serialVersionUID 
  88.      */
  89.     private static final long serialVersionUID = -7671078796273832149L;
  90.  
  91.     /**
  92.      * Constructs an <code>ActionEvent</code> object.
  93.      *
  94.      * @param source  the object that originated the event
  95.      * @param id      an integer that identifies the event
  96.      * @param command a string that may specify a command (possibly one 
  97.      *                of several) associated with the event
  98.      */
  99.     public ActionEvent(Object source, int id, String command) {
  100.         this(source, id, command, 0);
  101.     }
  102.  
  103.     /**
  104.      * Constructs an <code>ActionEvent</code> object with modifier keys.
  105.      *
  106.      * @param source    the object that originated the event
  107.      * @param id        an integer that identifies the event
  108.      * @param command   a string that may specify a command (possibly one 
  109.      *                  of several) associated with the event
  110.      * @param modifiers the modifier keys held down during this action
  111.      */
  112.     public ActionEvent(Object source, int id, String command, int modifiers) {
  113.         super(source, id);
  114.         this.actionCommand = command;
  115.         this.modifiers = modifiers;
  116.     }
  117.  
  118.     /**
  119.      * Returns the command string associated with this action.
  120.      * This string allows a "modal" component to specify one of several 
  121.      * commands, depending on its state. For example, a single button might
  122.      * toggle between "show details" and "hide details". The source object
  123.      * and the event would be the same in each case, but the command string
  124.      * would identify the intended action.
  125.      *
  126.      *@return the string identifying the command for this event
  127.      */
  128.     public String getActionCommand() {
  129.         return actionCommand;
  130.     }
  131.  
  132.     /**
  133.      * Returns the modifier keys held down during this action event.
  134.      * 
  135.      * @return the integer sum of the modifier constants
  136.      */
  137.     public int getModifiers() {
  138.         return modifiers;
  139.     }
  140.  
  141.     /**
  142.      * Returns a parameter string identifying this action event.
  143.      * This method is useful for event-logging and for debugging.
  144.      * 
  145.      * @return a string identifying the event and its associated command 
  146.      */
  147.     public String paramString() {
  148.         String typeStr;
  149.         switch(id) {
  150.           case ACTION_PERFORMED:
  151.               typeStr = "ACTION_PERFORMED";
  152.               break;
  153.           default:
  154.               typeStr = "unknown type";
  155.         }
  156.         return typeStr + ",cmd="+actionCommand;
  157.     }
  158.  
  159. }
  160.