001 /*
002 * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025
026 package java.awt.event;
027
028 import java.awt.Adjustable;
029 import java.awt.AWTEvent;
030
031 /**
032 * The adjustment event emitted by Adjustable objects.
033 * @see java.awt.Adjustable
034 * @see AdjustmentListener
035 *
036 * @author Amy Fowler
037 * @version 1.37 06/05/07
038 * @since 1.1
039 */
040 public class AdjustmentEvent extends AWTEvent {
041
042 /**
043 * Marks the first integer id for the range of adjustment event ids.
044 */
045 public static final int ADJUSTMENT_FIRST = 601;
046
047 /**
048 * Marks the last integer id for the range of adjustment event ids.
049 */
050 public static final int ADJUSTMENT_LAST = 601;
051
052 /**
053 * The adjustment value changed event.
054 */
055 public static final int ADJUSTMENT_VALUE_CHANGED = ADJUSTMENT_FIRST; //Event.SCROLL_LINE_UP
056
057 /**
058 * The unit increment adjustment type.
059 */
060 public static final int UNIT_INCREMENT = 1;
061
062 /**
063 * The unit decrement adjustment type.
064 */
065 public static final int UNIT_DECREMENT = 2;
066
067 /**
068 * The block decrement adjustment type.
069 */
070 public static final int BLOCK_DECREMENT = 3;
071
072 /**
073 * The block increment adjustment type.
074 */
075 public static final int BLOCK_INCREMENT = 4;
076
077 /**
078 * The absolute tracking adjustment type.
079 */
080 public static final int TRACK = 5;
081
082 /**
083 * The adjustable object that fired the event.
084 *
085 * @serial
086 * @see #getAdjustable
087 */
088 Adjustable adjustable;
089
090 /**
091 * <code>value</code> will contain the new value of the
092 * adjustable object. This value will always be in a
093 * range associated adjustable object.
094 *
095 * @serial
096 * @see #getValue
097 */
098 int value;
099
100 /**
101 * The <code>adjustmentType</code> describes how the adjustable
102 * object value has changed.
103 * This value can be increased/decreased by a block or unit amount
104 * where the block is associated with page increments/decrements,
105 * and a unit is associated with line increments/decrements.
106 *
107 * @serial
108 * @see #getAdjustmentType
109 */
110 int adjustmentType;
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 * JDK 1.1 serialVersionUID
124 */
125 private static final long serialVersionUID = 5700290645205279921L;
126
127 /**
128 * Constructs an <code>AdjustmentEvent</code> object with the
129 * specified <code>Adjustable</code> source, event type,
130 * adjustment type, and value.
131 * <p>Note that passing in an invalid <code>id</code> results in
132 * unspecified behavior. This method throws an
133 * <code>IllegalArgumentException</code> if <code>source</code>
134 * is <code>null</code>.
135 *
136 * @param source the <code>Adjustable</code> object where the
137 * event originated
138 * @param id the event type
139 * @param type the adjustment type
140 * @param value the current value of the adjustment
141 * @throws IllegalArgumentException if <code>source</code> is null
142 */
143 public AdjustmentEvent(Adjustable source, int id, int type,
144 int value) {
145 this (source, id, type, value, false);
146 }
147
148 /**
149 * Constructs an <code>AdjustmentEvent</code> object with the
150 * specified Adjustable source, event type, adjustment type, and value.
151 * <p>Note that passing in an invalid <code>id</code> results in
152 * unspecified behavior. This method throws an
153 * <code>IllegalArgumentException</code> if <code>source</code>
154 * is <code>null</code>.
155
156 *
157 * @param source the <code>Adjustable</code> object where the
158 * event originated
159 * @param id the event type
160 * @param type the adjustment type
161 * @param value the current value of the adjustment
162 * @param isAdjusting <code>true</code> if the event is one
163 * of a series of multiple adjusting events,
164 * otherwise <code>false</code>
165 * @throws IllegalArgumentException if <code>source</code> is null
166 * @since 1.4
167 */
168 public AdjustmentEvent(Adjustable source, int id, int type,
169 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 + ",adjType=" + adjTypeStr + ",value=" + value
253 + ",isAdjusting=" + isAdjusting;
254 }
255 }
|