java.awt.event

Class ItemEvent

Implemented Interfaces:
Serializable

public class ItemEvent
extends AWTEvent

A semantic event which indicates that an item was selected or deselected. This high-level event is generated by an ItemSelectable object (such as a List) when an item is selected or deselected by the user. The event is passed to every ItemListener object which registered to receive such events using the component's addItemListener method.

The object that implements the ItemListener interface gets this ItemEvent when the event occurs. The listener is spared the details of processing individual mouse movements and mouse clicks, and can instead process a "meaningful" (semantic) event like "item selected" or "item deselected".

Since:
1.1
See Also:
ItemSelectable, ItemListener, Tutorial: Writing an Item Listener, Reference: The Java Class Libraries (update file), Serialized Form

Field Summary

static int
DESELECTED
This state-change-value indicates that a selected item was deselected.
static int
ITEM_FIRST
The first number in the range of ids used for item events.
static int
ITEM_LAST
The last number in the range of ids used for item events.
static int
ITEM_STATE_CHANGED
This event id indicates that an item's state changed.
static int
SELECTED
This state-change value indicates that an item was selected.

Fields inherited from class java.awt.AWTEvent

ACTION_EVENT_MASK, ADJUSTMENT_EVENT_MASK, COMPONENT_EVENT_MASK, CONTAINER_EVENT_MASK, FOCUS_EVENT_MASK, HIERARCHY_BOUNDS_EVENT_MASK, HIERARCHY_EVENT_MASK, INPUT_METHOD_EVENT_MASK, INVOCATION_EVENT_MASK, ITEM_EVENT_MASK, KEY_EVENT_MASK, MOUSE_EVENT_MASK, MOUSE_MOTION_EVENT_MASK, MOUSE_WHEEL_EVENT_MASK, PAINT_EVENT_MASK, RESERVED_ID_MAX, TEXT_EVENT_MASK, WINDOW_EVENT_MASK, WINDOW_FOCUS_EVENT_MASK, WINDOW_STATE_EVENT_MASK, consumed, id

Fields inherited from class java.util.EventObject

source

Constructor Summary

ItemEvent(ItemSelectable source, int id, Object item, int stateChange)
Constructs an ItemEvent object.

Method Summary

Object
getItem()
Returns the item affected by the event.
ItemSelectable
getItemSelectable()
Returns the originator of the event.
int
getStateChange()
Returns the type of state change (selected or deselected).
String
paramString()
Returns a parameter string identifying this item event.

Methods inherited from class java.awt.AWTEvent

consume, getID, isConsumed, paramString, setSource, toString

Methods inherited from class java.util.EventObject

getSource, toString

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

DESELECTED

public static final int DESELECTED
This state-change-value indicates that a selected item was deselected.
Field Value:
2
Usages and Demos :

View More Examples of ItemEvent.DESELECTED
   1: 
   2:         case ItemEvent.DESELECTED:
   3:           APar.get("YX", "Clock").setStatus(false);
   4:           break;
   5:         }

View Full Code Here
   1:         break;
   2:     case ItemEvent.DESELECTED:
   3:         setState(false);
   4:         break;
   5:     default:

View Full Code Here
   1: 
   2:         case ItemEvent.DESELECTED:
   3:           fishEyeInteraction.getParameter("FishEye").setStatus(false);
   4:           break;
   5:         }

View Full Code Here
   1:     public boolean isLastStateChangeDeselected() {
   2:         return lastStateChange() == ItemEvent.DESELECTED;
   3:     }
   4: 
   5:     

View Full Code Here
   1: 
   2:     int sel = checked ? ItemEvent.SELECTED : ItemEvent.DESELECTED;
   3:     ItemEvent e = new ItemEvent((Checkbox)owner, 
   4:                 ItemEvent.ITEM_STATE_CHANGED, 
   5:                 ((Checkbox)owner).getLabel(),

View Full Code Here

ITEM_FIRST

public static final int ITEM_FIRST
The first number in the range of ids used for item events.
Field Value:
701

ITEM_LAST

public static final int ITEM_LAST
The last number in the range of ids used for item events.
Field Value:
701

ITEM_STATE_CHANGED

public static final int ITEM_STATE_CHANGED
This event id indicates that an item's state changed.
Field Value:
701
Usages and Demos :

View More Examples of ItemEvent.ITEM_STATE_CHANGED
   1:             fireItemStateChanged(new ItemEvent(this,
   2:                     ItemEvent.ITEM_STATE_CHANGED, this,
   3:                     this.isSelected() ? ItemEvent.SELECTED
   4:                             : ItemEvent.DESELECTED));

View Full Code Here
   1:     ItemEvent e = new ItemEvent((Choice)owner, 
   2:                 ItemEvent.ITEM_STATE_CHANGED, 
   3:                 ((Choice)owner).getItem(index), 
   4:                 ItemEvent.SELECTED);
   5:     QtToolkit.eventQueue.postEvent(e);

View Full Code Here
   1:     ItemEvent e = new ItemEvent((Checkbox)owner, 
   2:                 ItemEvent.ITEM_STATE_CHANGED, 
   3:                 ((Checkbox)owner).getLabel(),
   4:                 sel);
   5:     QtToolkit.eventQueue.postEvent(e);

View Full Code Here
   1:       ItemEvent e = new ItemEvent((List)owner, 
   2:                       ItemEvent.ITEM_STATE_CHANGED, 
   3:                       ""+index,
   4:                       ItemEvent.SELECTED);
   5:       QtToolkit.eventQueue.postEvent(e);

View Full Code Here
   1:          ItemListener[] o = getItemListeners();
   2:          ItemEvent evt = new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED,
   3:                this, selected ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
   4:          for (int i = 0; i < o.length;i++)
   5:          {

View Full Code Here

SELECTED

public static final int SELECTED
This state-change value indicates that an item was selected.
Field Value:
1
Usages and Demos :

View More Examples of ItemEvent.SELECTED
   1:         switch(e.getStateChange()) {
   2:         case ItemEvent.SELECTED:
   3:           APar.get("YX", "Clock").setStatus(true);
   4:           break;

View Full Code Here
   1:     switch (e.getStateChange()) {
   2:     case ItemEvent.SELECTED:
   3:         setState(true);
   4:         break;
   5:     case ItemEvent.DESELECTED:

View Full Code Here
   1:         switch(e.getStateChange()) {
   2:         case ItemEvent.SELECTED:
   3:           fishEyeInteraction.getParameter("FishEye").setStatus(true);
   4:           break;

View Full Code Here
   1:                 ((Choice)owner).getItem(index), 
   2:                 ItemEvent.SELECTED);
   3:     QtToolkit.eventQueue.postEvent(e);
   4:   }

View Full Code Here
   1:             int stateChange = e.getStateChange();
   2:             if((stateChange & ItemEvent.SELECTED) ==
   3:         ...
   4:                                                 ItemEvent.SELECTED){
   5:                 System.out.println("Item "+index+" selected.");
   6:             }
   7:             else if((stateChange & ItemEvent.DESELECTED) ==

View Full Code Here

Constructor Details

ItemEvent

public ItemEvent(ItemSelectable source,
                 int id,
                 Object item,
                 int stateChange)
Constructs an ItemEvent object.

Note that passing in an invalid id results in unspecified behavior. This method throws an IllegalArgumentException if source is null.

Parameters:
source - the ItemSelectable object that originated the event
id - an integer that identifies the event type
item - an object -- the item affected by the event
stateChange - an integer that indicates whether the item was selected or deselected
Throws:
IllegalArgumentException - if source is null
Usages and Demos :

View More Examples of ItemEvent(ItemSelectable source,int id,Object item,int stateChange)
   1:     if((current!=null)&&(itemListener!=null)) {
   2:       itemEvent=new ItemEvent(this, 0, current, ItemEvent.DESELECTED);
   3:       itemListener.itemStateChanged(itemEvent);
   4:         ...
   5:     if(itemListener!=null) {
   6:       itemEvent=new ItemEvent(this, 0, current, ItemEvent.SELECTED);
   7:       itemListener.itemStateChanged(itemEvent);
   8:     }
   9:   }

View Full Code Here
   1:         int status = checked ? ItemEvent.SELECTED : ItemEvent.DESELECTED ;
   2:         ItemEvent ie = new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, path, status) ;
   3:         
   4:         ItemListener[] lsnrs = listenerList.getListeners(ItemListener.class) ;
   5:         for(ItemListener lsnr : lsnrs)

View Full Code Here
   1:     int selectionState = (selected ? ItemEvent.SELECTED : ItemEvent.DESELECTED);
   2:     ItemEvent evt = new ItemEvent(this, ItemEvent.ITEM_STATE_CHANGED, this, selectionState);
   3:     for (Iterator i = itemListeners.iterator(); i.hasNext();) {
   4:       ItemListener l = (ItemListener) i.next();
   5:       l.itemStateChanged(evt);

View Full Code Here

Method Details

getItem

public Object getItem()
Returns the item affected by the event.
Returns:
the item (object) that was affected by the event
Usages and Demos :

View More Examples of getItem()
   1: 
   2:   public void itemStateChanged(ItemEvent event) {
   3:         ...
   4:     JRadioButton radiobutton = (JRadioButton)event.getItem();
   5: 
   6:         ...
   7:     if (event.getStateChange() == ItemEvent.SELECTED) {
   8:       System.out.println(radiobutton.getText() + " selected.");

View Full Code Here
   1:         ItemListener itemListener = new ItemListener() {
   2:           public void itemStateChanged(ItemEvent itemEvent) {
   3:             StringWriter sw = new StringWriter();
   4:         ...
   5:             PrintWriter pw = new PrintWriter(sw);
   6:             int state = itemEvent.getStateChange();
   7:             String stateString = 
   8:         ...
   9:               ((state == ItemEvent.SELECTED) ? "Selected" : "Deselected");
  10:             pw.print("Item: " + itemEvent.getItem());
  11:             pw.print(", State: " + stateString);

View Full Code Here
   1: 
   2: import java.awt.event.ItemEvent;
   3: import java.awt.event.ItemListener;
   4:         ...
   5: 
   6:     public void itemStateChanged(final ItemEvent p_e) {
   7:         ...
   8:         Object src = p_e.getItem();
   9:         if (!(src instanceof Vertex)) {

View Full Code Here
   1: 
   2: import java.awt.event.ItemEvent;
   3: import java.awt.event.ItemListener;
   4:         ...
   5:     
   6:     public void itemStateChanged(ItemEvent evt) {
   7:         addEvent(evt);
   8:         ...
   9:             System.out.println("Source:" + evt.getSource());
  10:             System.out.println("Item: " + evt.getItem());
  11:             System.out.println("State change: " + evt.getStateChange());
  12:         ...
  13:     
  14:     public ItemEvent lastEvent() {

View Full Code Here
   1: 
   2: import java.awt.event.ItemEvent;
   3: import java.awt.event.ItemListener;
   4:         ...
   5: 
   6:     public void itemStateChanged(ItemEvent iEvt) {
   7:         ...
   8:         String item = (String) iEvt.getItem();
   9:         int i;

View Full Code Here

getItemSelectable

public ItemSelectable getItemSelectable()
Returns the originator of the event.
Returns:
the ItemSelectable object that originated the event.
Usages and Demos :

View More Examples of getItemSelectable()
   1:     class VoteItemListener implements ItemListener {
   2:       public void itemStateChanged(ItemEvent ev) {
   3:         ...
   4:         boolean selected = (ev.getStateChange() == ItemEvent.SELECTED);
   5:         ...
   6:         AbstractButton button = (AbstractButton)ev.getItemSelectable();
   7:         System.out.println("ITEM Choice Selected: " + selected +

View Full Code Here
   1: 
   2:     public void itemStateChanged(ItemEvent e)
   3:     {
   4:         ...
   5:     Object source = e.getItemSelectable();
   6:         ...
   7:     boolean selected = e.getStateChange() == ItemEvent.SELECTED;
   8:     if(source == snap) {

View Full Code Here
   1: 
   2:     public void itemStateChanged(ItemEvent e) 
   3:     {
   4:         ...
   5:     Object source  = e.getItemSelectable();
   6:         ...
   7:     boolean selected = e.getStateChange() == ItemEvent.SELECTED;

View Full Code Here
   1: import java.awt.BorderLayout;
   2: import java.awt.event.ItemEvent;
   3: import java.awt.event.ItemListener;
   4:         ...
   5: 
   6:         public void itemStateChanged(ItemEvent e) {
   7:         ...
   8:             Object source = e.getItemSelectable();
   9:             if (source == xzoom) {
  10:         ...
  11:                 if (e.getStateChange() == ItemEvent.DESELECTED) {

View Full Code Here
   1: 
   2:     public void itemStateChanged(ItemEvent ie) {
   3:         ...
   4:         String label = ((JCheckBoxMenuItem) ie.getItemSelectable()).getText();
   5: 
   6:         ...
   7:                 ckb.addItemListener(new ItemListener() {
   8:                     public void itemStateChanged(ItemEvent ie) {
   9:                         JCheckBoxMenuItem ckbox = (JCheckBoxMenuItem) ie
  10:         ...
  11:                                 .getItemSelectable();

View Full Code Here

getStateChange

public int getStateChange()
Returns the type of state change (selected or deselected).
Returns:
an integer that indicates whether the item was selected or deselected
Usages and Demos :

View More Examples of getStateChange()
   1:     class VoteItemListener implements ItemListener {
   2:       public void itemStateChanged(ItemEvent ev) {
   3:         ...
   4:         boolean selected = (ev.getStateChange() == ItemEvent.SELECTED);
   5:         AbstractButton button = (AbstractButton)ev.getItemSelectable();
   6:         System.out.println("ITEM Choice Selected: " + selected +
   7:                            ", Selection: " + button.getActionCommand());

View Full Code Here
   1: 
   2:     public void itemStateChanged(ItemEvent e)
   3:     {
   4:         ...
   5:     Object source = e.getItemSelectable();
   6:     boolean selected = e.getStateChange() == ItemEvent.SELECTED;
   7:     if(source == snap) {
   8:         Beacon.snap = selected;
   9:         if(selected) {

View Full Code Here
   1:     {
   2:         final public void itemStateChanged(ItemEvent e)
   3:         {
   4:         ...
   5:             boolean sel = e.getStateChange()==ItemEvent.SELECTED ; 
   6:             Integer val = new Integer(sel ? ulm : spin.getDefaultValue()) ;
   7:             
   8:             spin.setValue(val) ;

View Full Code Here
   1: 
   2:     public void itemStateChanged(ItemEvent e) 
   3:     {
   4:         ...
   5:     Object source  = e.getItemSelectable();
   6:     boolean selected = e.getStateChange() == ItemEvent.SELECTED;
   7: 
   8:     if(source == override) {
   9:         if (lm != null) {

View Full Code Here
   1: 
   2:   public void itemStateChanged(ItemEvent event) {
   3:         ...
   4:     switch (event.getStateChange()) {
   5:         ...
   6:     case ItemEvent.SELECTED:
   7:         ...
   8:     case ItemEvent.DESELECTED:

View Full Code Here

paramString

public String paramString()
Returns a parameter string identifying this item event. This method is useful for event-logging and for debugging.
Overrides:
paramString in interface AWTEvent
Returns:
a string identifying the event and its attributes