1 /*
2 * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.awt.event;
27
28 import java.awt.Adjustable;
29 import java.awt.AWTEvent;
30
31 /**
32 * The adjustment event emitted by Adjustable objects like
33 * {@link java.awt.Scrollbar} and {@link java.awt.ScrollPane}.
34 * When the user changes the value of the scrolling component,
35 * it receives an instance of {@code AdjustmentEvent}.
36 * <p>
37 * An unspecified behavior will be caused if the {@code id} parameter
38 * of any particular {@code AdjustmentEvent} instance is not
39 * in the range from {@code ADJUSTMENT_FIRST} to {@code ADJUSTMENT_LAST}.
40 * <p>
41 * The {@code type} of any {@code AdjustmentEvent} instance takes one of the following
42 * values:
43 * <ul>
44 * <li> {@code UNIT_INCREMENT}
45 * <li> {@code UNIT_DECREMENT}
46 * <li> {@code BLOCK_INCREMENT}
47 * <li> {@code BLOCK_DECREMENT}
48 * <li> {@code TRACK}
49 * </ul>
50 * Assigning the value different from listed above will cause an unspecified behavior.
51 * @see java.awt.Adjustable
52 * @see AdjustmentListener
53 *
54 * @author Amy Fowler
55 * @since 1.1
56 */
57 public class AdjustmentEvent extends AWTEvent {
58
59 /**
60 * Marks the first integer id for the range of adjustment event ids.
61 */
62 public static final int ADJUSTMENT_FIRST = 601;
63
64 /**
65 * Marks the last integer id for the range of adjustment event ids.
66 */
67 public static final int ADJUSTMENT_LAST = 601;
68
69 /**
70 * The adjustment value changed event.
71 */
72 public static final int ADJUSTMENT_VALUE_CHANGED = ADJUSTMENT_FIRST; //Event.SCROLL_LINE_UP
73
74 /**
75 * The unit increment adjustment type.
76 */
77 public static final int UNIT_INCREMENT = 1;
78
79 /**
80 * The unit decrement adjustment type.
81 */
82 public static final int UNIT_DECREMENT = 2;
83
84 /**
85 * The block decrement adjustment type.
86 */
87 public static final int BLOCK_DECREMENT = 3;
88
89 /**
90 * The block increment adjustment type.
91 */
92 public static final int BLOCK_INCREMENT = 4;
93
94 /**
95 * The absolute tracking adjustment type.
96 */
97 public static final int TRACK = 5;
98
99 /**
100 * The adjustable object that fired the event.
101 *
102 * @serial
103 * @see #getAdjustable
104 */
105 Adjustable adjustable;
106
107 /**
108 * <code>value</code> will contain the new value of the
109 * adjustable object. This value will always be in a
110 * range associated adjustable object.
111 *
112 * @serial
113 * @see #getValue
114 */
115 int value;
116
117 /**
118 * The <code>adjustmentType</code> describes how the adjustable
119 * object value has changed.
120 * This value can be increased/decreased by a block or unit amount
121 * where the block is associated with page increments/decrements,
122 * and a unit is associated with line increments/decrements.
123 *
124 * @serial
125 * @see #getAdjustmentType
126 */
127 int adjustmentType;
128
129
130 /**
131 * The <code>isAdjusting</code> is true if the event is one
132 * of the series of multiple adjustment events.
133 *
134 * @since 1.4
135 * @serial
136 * @see #getValueIsAdjusting
137 */
138 boolean isAdjusting;
139
140
141 /*
142 * JDK 1.1 serialVersionUID
143 */
144 private static final long serialVersionUID = 5700290645205279921L;
145
146
147 /**
148 * Constructs an <code>AdjustmentEvent</code> object with the
149 * specified <code>Adjustable</code> source, event type,
150 * adjustment type, and value.
151 * <p> This method throws an
152 * <code>IllegalArgumentException</code> if <code>source</code>
153 * is <code>null</code>.
154 *
155 * @param source The <code>Adjustable</code> object where the
156 * event originated
157 * @param id An integer indicating the type of event.
158 * For information on allowable values, see
159 * the class description for {@link AdjustmentEvent}
160 * @param type An integer indicating the adjustment type.
161 * For information on allowable values, see
162 * the class description for {@link AdjustmentEvent}
163 * @param value The current value of the adjustment
164 * @throws IllegalArgumentException if <code>source</code> is null
165 * @see #getSource()
166 * @see #getID()
167 * @see #getAdjustmentType()
168 * @see #getValue()
169 */
170 public AdjustmentEvent(Adjustable source, int id, int type, int value) {
171 this(source, id, type, value, false);
172 }
173
174 /**
175 * Constructs an <code>AdjustmentEvent</code> object with the
176 * specified Adjustable source, event type, adjustment type, and value.
177 * <p> This method throws an
178 * <code>IllegalArgumentException</code> if <code>source</code>
179 * is <code>null</code>.
180 *
181 * @param source The <code>Adjustable</code> object where the
182 * event originated
183 * @param id An integer indicating the type of event.
184 * For information on allowable values, see
185 * the class description for {@link AdjustmentEvent}
186 * @param type An integer indicating the adjustment type.
187 * For information on allowable values, see
188 * the class description for {@link AdjustmentEvent}
189 * @param value The current value of the adjustment
190 * @param isAdjusting A boolean that equals <code>true</code> if the event is one
191 * of a series of multiple adjusting events,
192 * otherwise <code>false</code>
193 * @throws IllegalArgumentException if <code>source</code> is null
194 * @since 1.4
195 * @see #getSource()
196 * @see #getID()
197 * @see #getAdjustmentType()
198 * @see #getValue()
199 * @see #getValueIsAdjusting()
200 */
201 public AdjustmentEvent(Adjustable source, int id, int type, int value, boolean isAdjusting) {
202 super(source, id);
203 adjustable = source;
204 this.adjustmentType = type;
205 this.value = value;
206 this.isAdjusting = isAdjusting;
207 }
208
209 /**
210 * Returns the <code>Adjustable</code> object where this event originated.
211 *
212 * @return the <code>Adjustable</code> object where this event originated
213 */
214 public Adjustable getAdjustable() {
215 return adjustable;
216 }
217
218 /**
219 * Returns the current value in the adjustment event.
220 *
221 * @return the current value in the adjustment event
222 */
223 public int getValue() {
224 return value;
225 }
226
227 /**
228 * Returns the type of adjustment which caused the value changed
229 * event. It will have one of the following values:
230 * <ul>
231 * <li>{@link #UNIT_INCREMENT}
232 * <li>{@link #UNIT_DECREMENT}
233 * <li>{@link #BLOCK_INCREMENT}
234 * <li>{@link #BLOCK_DECREMENT}
235 * <li>{@link #TRACK}
236 * </ul>
237 * @return one of the adjustment values listed above
238 */
239 public int getAdjustmentType() {
240 return adjustmentType;
241 }
242
243 /**
244 * Returns <code>true</code> if this is one of multiple
245 * adjustment events.
246 *
247 * @return <code>true</code> if this is one of multiple
248 * adjustment events, otherwise returns <code>false</code>
249 * @since 1.4
250 */
251 public boolean getValueIsAdjusting() {
252 return isAdjusting;
253 }
254
255 public String paramString() {
256 String typeStr;
257 switch(id) {
258 case ADJUSTMENT_VALUE_CHANGED:
259 typeStr = "ADJUSTMENT_VALUE_CHANGED";
260 break;
261 default:
262 typeStr = "unknown type";
263 }
264 String adjTypeStr;
265 switch(adjustmentType) {
266 case UNIT_INCREMENT:
267 adjTypeStr = "UNIT_INCREMENT";
268 break;
269 case UNIT_DECREMENT:
270 adjTypeStr = "UNIT_DECREMENT";
271 break;
272 case BLOCK_INCREMENT:
273 adjTypeStr = "BLOCK_INCREMENT";
274 break;
275 case BLOCK_DECREMENT:
276 adjTypeStr = "BLOCK_DECREMENT";
277 break;
278 case TRACK:
279 adjTypeStr = "TRACK";
280 break;
281 default:
282 adjTypeStr = "unknown type";
283 }
284 return typeStr
285 + ",adjType="+adjTypeStr
286 + ",value="+value
287 + ",isAdjusting="+isAdjusting;
288 }
289 }