0N/A/*
2362N/A * Copyright (c) 1996, 2008, 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.ItemSelectable;
0N/A
0N/A/**
0N/A * A semantic event which indicates that an item was selected or deselected.
0N/A * This high-level event is generated by an ItemSelectable object (such as a
0N/A * List) when an item is selected or deselected by the user.
0N/A * The event is passed to every <code>ItemListener</code> object which
0N/A * registered to receive such events using the component's
0N/A * <code>addItemListener</code> method.
0N/A * <P>
0N/A * The object that implements the <code>ItemListener</code> interface gets
0N/A * this <code>ItemEvent</code> when the event occurs. The listener is
0N/A * spared the details of processing individual mouse movements and mouse
0N/A * clicks, and can instead process a "meaningful" (semantic) event like
0N/A * "item selected" or "item deselected".
217N/A * <p>
217N/A * An unspecified behavior will be caused if the {@code id} parameter
217N/A * of any particular {@code ItemEvent} instance is not
217N/A * in the range from {@code ITEM_FIRST} to {@code ITEM_LAST}.
217N/A * <p>
217N/A * The {@code stateChange} of any {@code ItemEvent} instance takes one of the following
217N/A * values:
217N/A * <ul>
217N/A * <li> {@code ItemEvent.SELECTED}
217N/A * <li> {@code ItemEvent.DESELECTED}
217N/A * </ul>
217N/A * Assigning the value different from listed above will cause an unspecified behavior.
0N/A *
0N/A * @author Carl Quinn
0N/A *
0N/A * @see java.awt.ItemSelectable
0N/A * @see ItemListener
0N/A * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/itemlistener.html">Tutorial: Writing an Item Listener</a>
0N/A *
0N/A * @since 1.1
0N/A */
0N/Apublic class ItemEvent extends AWTEvent {
0N/A
0N/A /**
0N/A * The first number in the range of ids used for item events.
0N/A */
0N/A public static final int ITEM_FIRST = 701;
0N/A
0N/A /**
0N/A * The last number in the range of ids used for item events.
0N/A */
0N/A public static final int ITEM_LAST = 701;
0N/A
0N/A /**
0N/A * This event id indicates that an item's state changed.
0N/A */
0N/A public static final int ITEM_STATE_CHANGED = ITEM_FIRST; //Event.LIST_SELECT
0N/A
0N/A /**
0N/A * This state-change value indicates that an item was selected.
0N/A */
0N/A public static final int SELECTED = 1;
0N/A
0N/A /**
0N/A * This state-change-value indicates that a selected item was deselected.
0N/A */
0N/A public static final int DESELECTED = 2;
0N/A
0N/A /**
0N/A * The item whose selection state has changed.
0N/A *
0N/A * @serial
0N/A * @see #getItem()
0N/A */
0N/A Object item;
0N/A
0N/A /**
0N/A * <code>stateChange</code> indicates whether the <code>item</code>
0N/A * was selected or deselected.
0N/A *
0N/A * @serial
0N/A * @see #getStateChange()
0N/A */
0N/A int stateChange;
0N/A
0N/A /*
0N/A * JDK 1.1 serialVersionUID
0N/A */
0N/A private static final long serialVersionUID = -608708132447206933L;
0N/A
0N/A /**
0N/A * Constructs an <code>ItemEvent</code> object.
217N/A * <p> This method throws an
0N/A * <code>IllegalArgumentException</code> if <code>source</code>
0N/A * is <code>null</code>.
0N/A *
217N/A * @param source The <code>ItemSelectable</code> object
0N/A * that originated the event
217N/A * @param id The integer that identifies the event type.
217N/A * For information on allowable values, see
217N/A * the class description for {@link ItemEvent}
217N/A * @param item An object -- the item affected by the event
217N/A * @param stateChange An integer that indicates whether the item was
217N/A * selected or deselected.
217N/A * For information on allowable values, see
217N/A * the class description for {@link ItemEvent}
0N/A * @throws IllegalArgumentException if <code>source</code> is null
217N/A * @see #getItemSelectable()
217N/A * @see #getID()
217N/A * @see #getStateChange()
0N/A */
0N/A public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) {
0N/A super(source, id);
0N/A this.item = item;
0N/A this.stateChange = stateChange;
0N/A }
0N/A
0N/A /**
0N/A * Returns the originator of the event.
0N/A *
0N/A * @return the ItemSelectable object that originated the event.
0N/A */
0N/A public ItemSelectable getItemSelectable() {
0N/A return (ItemSelectable)source;
0N/A }
0N/A
0N/A /**
0N/A * Returns the item affected by the event.
0N/A *
0N/A * @return the item (object) that was affected by the event
0N/A */
0N/A public Object getItem() {
0N/A return item;
0N/A }
0N/A
0N/A /**
0N/A * Returns the type of state change (selected or deselected).
0N/A *
0N/A * @return an integer that indicates whether the item was selected
0N/A * or deselected
0N/A *
0N/A * @see #SELECTED
0N/A * @see #DESELECTED
0N/A */
0N/A public int getStateChange() {
0N/A return stateChange;
0N/A }
0N/A
0N/A /**
0N/A * Returns a parameter string identifying this item 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 attributes
0N/A */
0N/A public String paramString() {
0N/A String typeStr;
0N/A switch(id) {
0N/A case ITEM_STATE_CHANGED:
0N/A typeStr = "ITEM_STATE_CHANGED";
0N/A break;
0N/A default:
0N/A typeStr = "unknown type";
0N/A }
0N/A
0N/A String stateStr;
0N/A switch(stateChange) {
0N/A case SELECTED:
0N/A stateStr = "SELECTED";
0N/A break;
0N/A case DESELECTED:
0N/A stateStr = "DESELECTED";
0N/A break;
0N/A default:
0N/A stateStr = "unknown type";
0N/A }
0N/A return typeStr + ",item="+item + ",stateChange="+stateStr;
0N/A }
0N/A
0N/A}