KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > event > AdjustmentEvent


1 /*
2  * @(#)AdjustmentEvent.java 1.27 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt.event;
9
10 import java.awt.Adjustable JavaDoc;
11 import java.awt.AWTEvent JavaDoc;
12 import java.awt.Event JavaDoc;
13
14 /**
15  * The adjustment event emitted by Adjustable objects.
16  * @see java.awt.Adjustable
17  * @see AdjustmentListener
18  *
19  * @author Amy Fowler
20  * @version 1.27 12/19/03
21  * @since 1.1
22  */

23 public class AdjustmentEvent extends AWTEvent JavaDoc {
24
25     /**
26      * Marks the first integer id for the range of adjustment event ids.
27      */

28     public static final int ADJUSTMENT_FIRST = 601;
29
30     /**
31      * Marks the last integer id for the range of adjustment event ids.
32      */

33     public static final int ADJUSTMENT_LAST = 601;
34
35     /**
36      * The adjustment value changed event.
37      */

38     public static final int ADJUSTMENT_VALUE_CHANGED = ADJUSTMENT_FIRST; //Event.SCROLL_LINE_UP
39

40     /**
41      * The unit increment adjustment type.
42      */

43     public static final int UNIT_INCREMENT = 1;
44
45     /**
46      * The unit decrement adjustment type.
47      */

48     public static final int UNIT_DECREMENT = 2;
49
50     /**
51      * The block decrement adjustment type.
52      */

53     public static final int BLOCK_DECREMENT = 3;
54
55     /**
56      * The block increment adjustment type.
57      */

58     public static final int BLOCK_INCREMENT = 4;
59
60     /**
61      * The absolute tracking adjustment type.
62      */

63     public static final int TRACK = 5;
64
65     /**
66      * The adjustable object that fired the event.
67      *
68      * @serial
69      * @see #getAdjustable
70      */

71     Adjustable JavaDoc adjustable;
72
73     /**
74      * <code>value</code> will contain the new value of the
75      * adjustable object. This value will always be in a
76      * range associated adjustable object.
77      *
78      * @serial
79      * @see #getValue
80      */

81     int value;
82
83     /**
84      * The <code>adjustmentType</code> describes how the adjustable
85      * object value has changed.
86      * This value can be increased/decreased by a block or unit amount
87      * where the block is associated with page increments/decrements,
88      * and a unit is associated with line increments/decrements.
89      *
90      * @serial
91      * @see #getAdjustmentType
92      */

93     int adjustmentType;
94
95
96     /**
97      * The <code>isAdjusting</code> is true if the event is one
98      * of the series of multiple adjustment events.
99      *
100      * @since 1.4
101      * @serial
102      * @see #getValueIsAdjusting
103      */

104     boolean isAdjusting;
105
106
107     /*
108      * JDK 1.1 serialVersionUID
109      */

110      private static final long serialVersionUID = 5700290645205279921L;
111
112
113     /**
114      * Constructs an <code>AdjustmentEvent</code> object with the
115      * specified <code>Adjustable</code> source, event type,
116      * adjustment type, and value.
117      * <p>Note that passing in an invalid <code>id</code> results in
118      * unspecified behavior. This method throws an
119      * <code>IllegalArgumentException</code> if <code>source</code>
120      * is <code>null</code>.
121      *
122      * @param source the <code>Adjustable</code> object where the
123      * event originated
124      * @param id the event type
125      * @param type the adjustment type
126      * @param value the current value of the adjustment
127      * @throws IllegalArgumentException if <code>source</code> is null
128      */

129     public AdjustmentEvent(Adjustable JavaDoc source, int id, int type, int value) {
130     this(source, id, type, value, false);
131     }
132
133     /**
134      * Constructs an <code>AdjustmentEvent</code> object with the
135      * specified Adjustable source, event type, adjustment type, and value.
136      * <p>Note that passing in an invalid <code>id</code> results in
137      * unspecified behavior. This method throws an
138      * <code>IllegalArgumentException</code> if <code>source</code>
139      * is <code>null</code>.
140
141      *
142      * @param source the <code>Adjustable</code> object where the
143      * event originated
144      * @param id the event type
145      * @param type the adjustment type
146      * @param value the current value of the adjustment
147      * @param isAdjusting <code>true</code> if the event is one
148      * of a series of multiple adjusting events,
149      * otherwise <code>false</code>
150      * @throws IllegalArgumentException if <code>source</code> is null
151      */

152     public AdjustmentEvent(Adjustable JavaDoc source, int id, int type, int value, boolean isAdjusting) {
153         super(source, id);
154     adjustable = source;
155         this.adjustmentType = type;
156     this.value = value;
157     this.isAdjusting = isAdjusting;
158     }
159
160     /**
161      * Returns the <code>Adjustable</code> object where this event originated.
162      *
163      * @return the <code>Adjustable</code> object where this event originated
164      */

165     public Adjustable JavaDoc getAdjustable() {
166         return adjustable;
167     }
168
169     /**
170      * Returns the current value in the adjustment event.
171      *
172      * @return the current value in the adjustment event
173      */

174     public int getValue() {
175         return value;
176     }
177
178     /**
179      * Returns the type of adjustment which caused the value changed
180      * event. It will have one of the following values:
181      * <ul>
182      * <li>{@link #UNIT_INCREMENT}
183      * <li>{@link #UNIT_DECREMENT}
184      * <li>{@link #BLOCK_INCREMENT}
185      * <li>{@link #BLOCK_DECREMENT}
186      * <li>{@link #TRACK}
187      * </ul>
188      * @return one of the adjustment values listed above
189      */

190     public int getAdjustmentType() {
191         return adjustmentType;
192     }
193
194     /**
195      * Returns <code>true</code> if this is one of multiple
196      * adjustment events.
197      *
198      * @return <code>true</code> if this is one of multiple
199      * adjustment events, otherwise returns <code>false</code>
200      */

201     public boolean getValueIsAdjusting() {
202     return isAdjusting;
203     }
204
205     public String JavaDoc paramString() {
206         String JavaDoc typeStr;
207         switch(id) {
208           case ADJUSTMENT_VALUE_CHANGED:
209               typeStr = "ADJUSTMENT_VALUE_CHANGED";
210               break;
211           default:
212               typeStr = "unknown type";
213         }
214         String JavaDoc adjTypeStr;
215         switch(adjustmentType) {
216           case UNIT_INCREMENT:
217               adjTypeStr = "UNIT_INCREMENT";
218               break;
219           case UNIT_DECREMENT:
220               adjTypeStr = "UNIT_DECREMENT";
221               break;
222           case BLOCK_INCREMENT:
223               adjTypeStr = "BLOCK_INCREMENT";
224               break;
225           case BLOCK_DECREMENT:
226               adjTypeStr = "BLOCK_DECREMENT";
227               break;
228           case TRACK:
229               adjTypeStr = "TRACK";
230               break;
231           default:
232               adjTypeStr = "unknown type";
233         }
234         return typeStr
235         + ",adjType="+adjTypeStr
236         + ",value="+value
237         + ",isAdjusting="+isAdjusting;
238     }
239 }
240
Popular Tags