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 / ItemEvent.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  4.6 KB  |  156 lines

  1. /*
  2.  * @(#)ItemEvent.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.Component;
  18. import java.awt.AWTEvent;
  19. import java.awt.Event;
  20. import java.awt.ItemSelectable;
  21.  
  22. /**
  23.  * A semantic event which indicates that an item was selected or deselected.
  24.  * This high-level event is generated by an ItemSelectable object (such as a 
  25.  * List) when an item is selected or de-selected. The event is passed to
  26.  * every <code>ItemListener</code> object which registered to receive such
  27.  * events using the component's <code>addItemListener</code> method. 
  28.  * <P>
  29.  * The object that implements the <code>ItemListener</code> interface gets
  30.  * this <code>ItemEvent</code> when the event occurs. The listener is
  31.  * spared the details of processing individual mouse movements and mouse
  32.  * clicks, and can instead process a "meaningful" (semantic) event like
  33.  * "item selected" or "item deselected". 
  34.  *
  35.  * @see java.awt.ItemSelectable
  36.  * @see ItemListener
  37.  * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/itemlistener.html">Tutorial: Writing an Item Listener</a>
  38.  * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
  39.  *
  40.  * @version 1.16 03/18/98
  41.  * @author Carl Quinn
  42.  */
  43. public class ItemEvent extends AWTEvent {
  44.  
  45.     /**
  46.      * The first number in the range of ids used for item events.
  47.      */
  48.     public static final int ITEM_FIRST        = 701;
  49.  
  50.     /**
  51.      * The last number in the range of ids used for item events.
  52.      */
  53.     public static final int ITEM_LAST        = 701;
  54.  
  55.     /** 
  56.      * This event id indicates that an item's state changed.
  57.      */
  58.     public static final int ITEM_STATE_CHANGED    = ITEM_FIRST; //Event.LIST_SELECT 
  59.  
  60.     /**
  61.      * This state-change value indicates that an item was selected.
  62.      */
  63.     public static final int SELECTED = 1;
  64.  
  65.     /** 
  66.      * This state-change-value indicates that a selected item was un-selected.
  67.      */
  68.     public static final int DESELECTED    = 2;
  69.  
  70.     Object item;
  71.     int stateChange;
  72.  
  73.     /*
  74.      * JDK 1.1 serialVersionUID 
  75.      */
  76.     private static final long serialVersionUID = -608708132447206933L;
  77.  
  78.     /**
  79.      * Constructs an ItemEvent object.
  80.      *
  81.      * @param source the ItemSelectable object that originated the event
  82.      * @param id     an integer that identifies the event type
  83.      * @param item   an object -- the item affected by the event
  84.      * @param stateChange 
  85.      *               an integer that indicates whether the item was
  86.      *               selected or deselected
  87.      */
  88.     public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) {
  89.         super(source, id);
  90.     this.item = item;
  91.         this.stateChange = stateChange;
  92.     }
  93.  
  94.     /**
  95.      * Returns the originator of the event.
  96.      *
  97.      * @return the ItemSelectable object that originated the event.
  98.      */
  99.     public ItemSelectable getItemSelectable() {
  100.         return (ItemSelectable)source;
  101.     }
  102.  
  103.    /**
  104.     * Returns the item affected by the event.
  105.     *
  106.     * @return the item (object) that was affected by the event
  107.     */
  108.     public Object getItem() {
  109.         return item;
  110.     }
  111.  
  112.    /**
  113.     * Returns the type of state change (selected or deselected).
  114.     *
  115.     * @return an integer that indicates whether the item was selected
  116.     *         or deselected
  117.     *
  118.     * @see #SELECTED
  119.     * @see #DESELECTED
  120.     */
  121.     public int getStateChange() {
  122.         return stateChange;
  123.     }
  124.  
  125.     /**
  126.      * Returns a parameter string identifying this item event.
  127.      * This method is useful for event-logging and for debugging.
  128.      *
  129.      * @return a string identifying the event and its attributes
  130.      */
  131.     public String paramString() {
  132.         String typeStr;
  133.         switch(id) {
  134.           case ITEM_STATE_CHANGED:
  135.               typeStr = "ITEM_STATE_CHANGED";
  136.               break;
  137.           default:
  138.               typeStr = "unknown type";
  139.         }
  140.  
  141.         String stateStr;
  142.         switch(stateChange) {
  143.           case SELECTED:
  144.               stateStr = "SELECTED";
  145.               break;
  146.           case DESELECTED:
  147.               stateStr = "DESELECTED";
  148.               break;
  149.           default:
  150.               stateStr = "unknown type";
  151.         }
  152.         return typeStr + ",item="+item + ",stateChange="+stateStr;
  153.     }
  154.  
  155. }
  156.