Home | History | Annotate | Download | only in event
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 /**
     18  * @author Michael Danilov
     19  * @version $Revision$
     20  */
     21 package java.awt.event;
     22 
     23 import java.awt.AWTEvent;
     24 import java.awt.ItemSelectable;
     25 
     26 /**
     27  * This class is not supported in Android 1.0. It is merely provided to maintain
     28  * interface compatibility with desktop Java implementations.
     29  *
     30  * @since Android 1.0
     31  */
     32 public class ItemEvent extends AWTEvent {
     33 
     34     private static final long serialVersionUID = -608708132447206933L;
     35 
     36     public static final int ITEM_FIRST = 701;
     37 
     38     public static final int ITEM_LAST = 701;
     39 
     40     public static final int ITEM_STATE_CHANGED = 701;
     41 
     42     public static final int SELECTED = 1;
     43 
     44     public static final int DESELECTED = 2;
     45 
     46     private Object item;
     47     private int stateChange;
     48 
     49     public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) {
     50         super(source, id);
     51 
     52         this.item = item;
     53         this.stateChange = stateChange;
     54     }
     55 
     56     public Object getItem() {
     57         return item;
     58     }
     59 
     60     public int getStateChange() {
     61         return stateChange;
     62     }
     63 
     64     public ItemSelectable getItemSelectable() {
     65         return (ItemSelectable) source;
     66     }
     67 
     68     @Override
     69     public String paramString() {
     70         /* The format is based on 1.5 release behavior
     71          * which can be revealed by the following code:
     72          *
     73          * Checkbox c = new Checkbox("Checkbox", true);
     74          * ItemEvent e = new ItemEvent(c, ItemEvent.ITEM_STATE_CHANGED,
     75          *                             c, ItemEvent.SELECTED);
     76          * System.out.println(e);
     77          */
     78 
     79         String stateString = null;
     80 
     81         switch (stateChange) {
     82         case SELECTED:
     83             stateString = "SELECTED"; //$NON-NLS-1$
     84             break;
     85         case DESELECTED:
     86             stateString = "DESELECTED"; //$NON-NLS-1$
     87             break;
     88         default:
     89             stateString = "unknown type"; //$NON-NLS-1$
     90         }
     91 
     92         return ((id == ITEM_STATE_CHANGED ? "ITEM_STATE_CHANGED" : "unknown type") + //$NON-NLS-1$ //$NON-NLS-2$
     93                 ",item=" + item + ",stateChange=" + stateString); //$NON-NLS-1$ //$NON-NLS-2$
     94     }
     95 
     96 }
     97