blob: b928899b2ecd9e2373a2663ef6e49182af9c0d49 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 1996-2007 Sun Microsystems, Inc. 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. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package java.awt.event;
27
28import java.awt.Adjustable;
29import java.awt.AWTEvent;
30
31/**
32 * The adjustment event emitted by Adjustable objects.
33 * @see java.awt.Adjustable
34 * @see AdjustmentListener
35 *
36 * @author Amy Fowler
37 * @since 1.1
38 */
39public class AdjustmentEvent extends AWTEvent {
40
41 /**
42 * Marks the first integer id for the range of adjustment event ids.
43 */
44 public static final int ADJUSTMENT_FIRST = 601;
45
46 /**
47 * Marks the last integer id for the range of adjustment event ids.
48 */
49 public static final int ADJUSTMENT_LAST = 601;
50
51 /**
52 * The adjustment value changed event.
53 */
54 public static final int ADJUSTMENT_VALUE_CHANGED = ADJUSTMENT_FIRST; //Event.SCROLL_LINE_UP
55
56 /**
57 * The unit increment adjustment type.
58 */
59 public static final int UNIT_INCREMENT = 1;
60
61 /**
62 * The unit decrement adjustment type.
63 */
64 public static final int UNIT_DECREMENT = 2;
65
66 /**
67 * The block decrement adjustment type.
68 */
69 public static final int BLOCK_DECREMENT = 3;
70
71 /**
72 * The block increment adjustment type.
73 */
74 public static final int BLOCK_INCREMENT = 4;
75
76 /**
77 * The absolute tracking adjustment type.
78 */
79 public static final int TRACK = 5;
80
81 /**
82 * The adjustable object that fired the event.
83 *
84 * @serial
85 * @see #getAdjustable
86 */
87 Adjustable adjustable;
88
89 /**
90 * <code>value</code> will contain the new value of the
91 * adjustable object. This value will always be in a
92 * range associated adjustable object.
93 *
94 * @serial
95 * @see #getValue
96 */
97 int value;
98
99 /**
100 * The <code>adjustmentType</code> describes how the adjustable
101 * object value has changed.
102 * This value can be increased/decreased by a block or unit amount
103 * where the block is associated with page increments/decrements,
104 * and a unit is associated with line increments/decrements.
105 *
106 * @serial
107 * @see #getAdjustmentType
108 */
109 int adjustmentType;
110
111
112 /**
113 * The <code>isAdjusting</code> is true if the event is one
114 * of the series of multiple adjustment events.
115 *
116 * @since 1.4
117 * @serial
118 * @see #getValueIsAdjusting
119 */
120 boolean isAdjusting;
121
122
123 /*
124 * JDK 1.1 serialVersionUID
125 */
126 private static final long serialVersionUID = 5700290645205279921L;
127
128
129 /**
130 * Constructs an <code>AdjustmentEvent</code> object with the
131 * specified <code>Adjustable</code> source, event type,
132 * adjustment type, and value.
133 * <p>Note that passing in an invalid <code>id</code> results in
134 * unspecified behavior. This method throws an
135 * <code>IllegalArgumentException</code> if <code>source</code>
136 * is <code>null</code>.
137 *
138 * @param source the <code>Adjustable</code> object where the
139 * event originated
140 * @param id the event type
141 * @param type the adjustment type
142 * @param value the current value of the adjustment
143 * @throws IllegalArgumentException if <code>source</code> is null
144 */
145 public AdjustmentEvent(Adjustable source, int id, int type, int value) {
146 this(source, id, type, value, false);
147 }
148
149 /**
150 * Constructs an <code>AdjustmentEvent</code> object with the
151 * specified Adjustable source, event type, adjustment type, and value.
152 * <p>Note that passing in an invalid <code>id</code> results in
153 * unspecified behavior. This method throws an
154 * <code>IllegalArgumentException</code> if <code>source</code>
155 * is <code>null</code>.
156
157 *
158 * @param source the <code>Adjustable</code> object where the
159 * event originated
160 * @param id the event type
161 * @param type the adjustment type
162 * @param value the current value of the adjustment
163 * @param isAdjusting <code>true</code> if the event is one
164 * of a series of multiple adjusting events,
165 * otherwise <code>false</code>
166 * @throws IllegalArgumentException if <code>source</code> is null
167 * @since 1.4
168 */
169 public AdjustmentEvent(Adjustable source, int id, int type, int value, boolean isAdjusting) {
170 super(source, id);
171 adjustable = source;
172 this.adjustmentType = type;
173 this.value = value;
174 this.isAdjusting = isAdjusting;
175 }
176
177 /**
178 * Returns the <code>Adjustable</code> object where this event originated.
179 *
180 * @return the <code>Adjustable</code> object where this event originated
181 */
182 public Adjustable getAdjustable() {
183 return adjustable;
184 }
185
186 /**
187 * Returns the current value in the adjustment event.
188 *
189 * @return the current value in the adjustment event
190 */
191 public int getValue() {
192 return value;
193 }
194
195 /**
196 * Returns the type of adjustment which caused the value changed
197 * event. It will have one of the following values:
198 * <ul>
199 * <li>{@link #UNIT_INCREMENT}
200 * <li>{@link #UNIT_DECREMENT}
201 * <li>{@link #BLOCK_INCREMENT}
202 * <li>{@link #BLOCK_DECREMENT}
203 * <li>{@link #TRACK}
204 * </ul>
205 * @return one of the adjustment values listed above
206 */
207 public int getAdjustmentType() {
208 return adjustmentType;
209 }
210
211 /**
212 * Returns <code>true</code> if this is one of multiple
213 * adjustment events.
214 *
215 * @return <code>true</code> if this is one of multiple
216 * adjustment events, otherwise returns <code>false</code>
217 * @since 1.4
218 */
219 public boolean getValueIsAdjusting() {
220 return isAdjusting;
221 }
222
223 public String paramString() {
224 String typeStr;
225 switch(id) {
226 case ADJUSTMENT_VALUE_CHANGED:
227 typeStr = "ADJUSTMENT_VALUE_CHANGED";
228 break;
229 default:
230 typeStr = "unknown type";
231 }
232 String adjTypeStr;
233 switch(adjustmentType) {
234 case UNIT_INCREMENT:
235 adjTypeStr = "UNIT_INCREMENT";
236 break;
237 case UNIT_DECREMENT:
238 adjTypeStr = "UNIT_DECREMENT";
239 break;
240 case BLOCK_INCREMENT:
241 adjTypeStr = "BLOCK_INCREMENT";
242 break;
243 case BLOCK_DECREMENT:
244 adjTypeStr = "BLOCK_DECREMENT";
245 break;
246 case TRACK:
247 adjTypeStr = "TRACK";
248 break;
249 default:
250 adjTypeStr = "unknown type";
251 }
252 return typeStr
253 + ",adjType="+adjTypeStr
254 + ",value="+value
255 + ",isAdjusting="+isAdjusting;
256 }
257}