home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / ItemEvent.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  136 lines

  1. /*
  2.  * @(#)ItemEvent.java    1.13 97/02/13
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.awt.event;
  24.  
  25. import java.awt.Component;
  26. import java.awt.AWTEvent;
  27. import java.awt.Event;
  28. import java.awt.ItemSelectable;
  29.  
  30. /**
  31.  * The item event emitted by ItemSelectable objects.
  32.  * This event is generated when an item is selected or de-selected.
  33.  * @see java.awt.ItemSelectable
  34.  * @see ItemListener
  35.  *
  36.  * @version 1.13 02/13/97
  37.  * @author Carl Quinn
  38.  */
  39. public class ItemEvent extends AWTEvent {
  40.  
  41.     /**
  42.      * Marks the first integer id for the range of item event ids.
  43.      */
  44.     public static final int ITEM_FIRST        = 701;
  45.  
  46.     /**
  47.      * Marks the last integer id for the range of item event ids.
  48.      */
  49.     public static final int ITEM_LAST        = 701;
  50.  
  51.     /** 
  52.      * The item state changed event type.
  53.      */
  54.     public static final int ITEM_STATE_CHANGED    = ITEM_FIRST; //Event.LIST_SELECT 
  55.  
  56.     /**
  57.      * The item selected state change type.
  58.      */
  59.     public static final int SELECTED = 1;
  60.  
  61.     /** 
  62.      * The item de-selected state change type.
  63.      */
  64.     public static final int DESELECTED    = 2;
  65.  
  66.     Object item;
  67.     int stateChange;
  68.  
  69.     /*
  70.      * JDK 1.1 serialVersionUID 
  71.      */
  72.     private static final long serialVersionUID = -608708132447206933L;
  73.  
  74.     /**
  75.      * Constructs a ItemSelectEvent object with the specified ItemSelectable source,
  76.      * type, item, and item select state.
  77.      * @param source the ItemSelectable object where the event originated
  78.      * @id the event type
  79.      * @item the item where the event occurred
  80.      * @stateChange the state change type which caused the event
  81.      */
  82.     public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) {
  83.         super(source, id);
  84.     this.item = item;
  85.         this.stateChange = stateChange;
  86.     }
  87.  
  88.     /**
  89.      * Returns the ItemSelectable object where this event originated.
  90.      */
  91.     public ItemSelectable getItemSelectable() {
  92.         return (ItemSelectable)source;
  93.     }
  94.  
  95.    /**
  96.     * Returns the item where the event occurred.
  97.     */
  98.     public Object getItem() {
  99.         return item;
  100.     }
  101.  
  102.    /**
  103.     * Returns the state change type which generated the event.
  104.     * @see #SELECTED
  105.     * @see #DESELECTED
  106.     */
  107.     public int getStateChange() {
  108.         return stateChange;
  109.     }
  110.  
  111.     public String paramString() {
  112.         String typeStr;
  113.         switch(id) {
  114.           case ITEM_STATE_CHANGED:
  115.               typeStr = "ITEM_STATE_CHANGED";
  116.               break;
  117.           default:
  118.               typeStr = "unknown type";
  119.         }
  120.  
  121.         String stateStr;
  122.         switch(stateChange) {
  123.           case SELECTED:
  124.               stateStr = "SELECTED";
  125.               break;
  126.           case DESELECTED:
  127.               stateStr = "DESELECTED";
  128.               break;
  129.           default:
  130.               stateStr = "unknown type";
  131.         }
  132.         return typeStr + ",item="+item + ",stateChange="+stateStr;
  133.     }
  134.  
  135. }
  136.