Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/java/awt/event/ItemEvent.java
+++ new/src/share/classes/java/awt/event/ItemEvent.java
1 1 /*
2 2 * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Oracle designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Oracle in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 22 * or visit www.oracle.com if you need additional information or have any
23 23 * questions.
24 24 */
25 25
26 26 package java.awt.event;
27 27
28 28 import java.awt.AWTEvent;
29 29 import java.awt.ItemSelectable;
30 30
31 31 /**
32 32 * A semantic event which indicates that an item was selected or deselected.
33 33 * This high-level event is generated by an ItemSelectable object (such as a
34 34 * List) when an item is selected or deselected by the user.
35 35 * The event is passed to every <code>ItemListener</code> object which
36 36 * registered to receive such events using the component's
37 37 * <code>addItemListener</code> method.
38 38 * <P>
39 39 * The object that implements the <code>ItemListener</code> interface gets
40 40 * this <code>ItemEvent</code> when the event occurs. The listener is
41 41 * spared the details of processing individual mouse movements and mouse
42 42 * clicks, and can instead process a "meaningful" (semantic) event like
43 43 * "item selected" or "item deselected".
44 44 * <p>
45 45 * An unspecified behavior will be caused if the {@code id} parameter
46 46 * of any particular {@code ItemEvent} instance is not
47 47 * in the range from {@code ITEM_FIRST} to {@code ITEM_LAST}.
48 48 * <p>
49 49 * The {@code stateChange} of any {@code ItemEvent} instance takes one of the following
50 50 * values:
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
51 51 * <ul>
52 52 * <li> {@code ItemEvent.SELECTED}
53 53 * <li> {@code ItemEvent.DESELECTED}
54 54 * </ul>
55 55 * Assigning the value different from listed above will cause an unspecified behavior.
56 56 *
57 57 * @author Carl Quinn
58 58 *
59 59 * @see java.awt.ItemSelectable
60 60 * @see ItemListener
61 - * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/itemlistener.html">Tutorial: Writing an Item Listener</a>
61 + * @see <a href="https://docs.oracle.com/javase/tutorial/uiswing/events/itemlistener.html">Tutorial: Writing an Item Listener</a>
62 62 *
63 63 * @since 1.1
64 64 */
65 65 public class ItemEvent extends AWTEvent {
66 66
67 67 /**
68 68 * The first number in the range of ids used for item events.
69 69 */
70 70 public static final int ITEM_FIRST = 701;
71 71
72 72 /**
73 73 * The last number in the range of ids used for item events.
74 74 */
75 75 public static final int ITEM_LAST = 701;
76 76
77 77 /**
78 78 * This event id indicates that an item's state changed.
79 79 */
80 80 public static final int ITEM_STATE_CHANGED = ITEM_FIRST; //Event.LIST_SELECT
81 81
82 82 /**
83 83 * This state-change value indicates that an item was selected.
84 84 */
85 85 public static final int SELECTED = 1;
86 86
87 87 /**
88 88 * This state-change-value indicates that a selected item was deselected.
89 89 */
90 90 public static final int DESELECTED = 2;
91 91
92 92 /**
93 93 * The item whose selection state has changed.
94 94 *
95 95 * @serial
96 96 * @see #getItem()
97 97 */
98 98 Object item;
99 99
100 100 /**
101 101 * <code>stateChange</code> indicates whether the <code>item</code>
102 102 * was selected or deselected.
103 103 *
104 104 * @serial
105 105 * @see #getStateChange()
106 106 */
107 107 int stateChange;
108 108
109 109 /*
110 110 * JDK 1.1 serialVersionUID
111 111 */
112 112 private static final long serialVersionUID = -608708132447206933L;
113 113
114 114 /**
115 115 * Constructs an <code>ItemEvent</code> object.
116 116 * <p> This method throws an
117 117 * <code>IllegalArgumentException</code> if <code>source</code>
118 118 * is <code>null</code>.
119 119 *
120 120 * @param source The <code>ItemSelectable</code> object
121 121 * that originated the event
122 122 * @param id The integer that identifies the event type.
123 123 * For information on allowable values, see
124 124 * the class description for {@link ItemEvent}
125 125 * @param item An object -- the item affected by the event
126 126 * @param stateChange An integer that indicates whether the item was
127 127 * selected or deselected.
128 128 * For information on allowable values, see
129 129 * the class description for {@link ItemEvent}
130 130 * @throws IllegalArgumentException if <code>source</code> is null
131 131 * @see #getItemSelectable()
132 132 * @see #getID()
133 133 * @see #getStateChange()
134 134 */
135 135 public ItemEvent(ItemSelectable source, int id, Object item, int stateChange) {
136 136 super(source, id);
137 137 this.item = item;
138 138 this.stateChange = stateChange;
139 139 }
140 140
141 141 /**
142 142 * Returns the originator of the event.
143 143 *
144 144 * @return the ItemSelectable object that originated the event.
145 145 */
146 146 public ItemSelectable getItemSelectable() {
147 147 return (ItemSelectable)source;
148 148 }
149 149
150 150 /**
151 151 * Returns the item affected by the event.
152 152 *
153 153 * @return the item (object) that was affected by the event
154 154 */
155 155 public Object getItem() {
156 156 return item;
157 157 }
158 158
159 159 /**
160 160 * Returns the type of state change (selected or deselected).
161 161 *
162 162 * @return an integer that indicates whether the item was selected
163 163 * or deselected
164 164 *
165 165 * @see #SELECTED
166 166 * @see #DESELECTED
167 167 */
168 168 public int getStateChange() {
169 169 return stateChange;
170 170 }
171 171
172 172 /**
173 173 * Returns a parameter string identifying this item event.
174 174 * This method is useful for event-logging and for debugging.
175 175 *
176 176 * @return a string identifying the event and its attributes
177 177 */
178 178 public String paramString() {
179 179 String typeStr;
180 180 switch(id) {
181 181 case ITEM_STATE_CHANGED:
182 182 typeStr = "ITEM_STATE_CHANGED";
183 183 break;
184 184 default:
185 185 typeStr = "unknown type";
186 186 }
187 187
188 188 String stateStr;
189 189 switch(stateChange) {
190 190 case SELECTED:
191 191 stateStr = "SELECTED";
192 192 break;
193 193 case DESELECTED:
194 194 stateStr = "DESELECTED";
195 195 break;
196 196 default:
197 197 stateStr = "unknown type";
198 198 }
199 199 return typeStr + ",item="+item + ",stateChange="+stateStr;
200 200 }
201 201
202 202 }
↓ open down ↓ |
131 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX