1 /* 2 * Copyright (c) 1996, 2013, 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 import java.lang.annotation.Native; 31 32 33 /** 34 * The adjustment event emitted by Adjustable objects like 35 * {@link java.awt.Scrollbar} and {@link java.awt.ScrollPane}. 36 * When the user changes the value of the scrolling component, 37 * it receives an instance of {@code AdjustmentEvent}. 38 * <p> 39 * An unspecified behavior will be caused if the {@code id} parameter 40 * of any particular {@code AdjustmentEvent} instance is not 41 * in the range from {@code ADJUSTMENT_FIRST} to {@code ADJUSTMENT_LAST}. 42 * <p> 43 * The {@code type} of any {@code AdjustmentEvent} instance takes one of the following 44 * values: 45 * <ul> 46 * <li> {@code UNIT_INCREMENT} 47 * <li> {@code UNIT_DECREMENT} 48 * <li> {@code BLOCK_INCREMENT} 49 * <li> {@code BLOCK_DECREMENT} 50 * <li> {@code TRACK} 51 * </ul> 52 * Assigning the value different from listed above will cause an unspecified behavior. 53 * @see java.awt.Adjustable 54 * @see AdjustmentListener 55 * 56 * @author Amy Fowler 57 * @since 1.1 58 */ 59 public class AdjustmentEvent extends AWTEvent { 60 61 /** 62 * Marks the first integer id for the range of adjustment event ids. 63 */ 64 public static final int ADJUSTMENT_FIRST = 601; 65 66 /** 67 * Marks the last integer id for the range of adjustment event ids. 68 */ 69 public static final int ADJUSTMENT_LAST = 601; 70 71 /** 72 * The adjustment value changed event. 73 */ 74 public static final int ADJUSTMENT_VALUE_CHANGED = ADJUSTMENT_FIRST; //Event.SCROLL_LINE_UP 75 76 /** 77 * The unit increment adjustment type. 78 */ 79 @Native public static final int UNIT_INCREMENT = 1; 80 81 /** 82 * The unit decrement adjustment type. 83 */ 84 @Native public static final int UNIT_DECREMENT = 2; 85 86 /** 87 * The block decrement adjustment type. 88 */ 89 @Native public static final int BLOCK_DECREMENT = 3; 90 91 /** 92 * The block increment adjustment type. 93 */ 94 @Native public static final int BLOCK_INCREMENT = 4; 95 96 /** 97 * The absolute tracking adjustment type. 98 */ 99 @Native public static final int TRACK = 5; 100 101 /** 102 * The adjustable object that fired the event. 103 * 104 * @serial 105 * @see #getAdjustable 106 */ 107 @SuppressWarnings("serial") // Not statically typed as Serializable 108 Adjustable adjustable; 109 110 /** 111 * {@code value} will contain the new value of the 112 * adjustable object. This value will always be in a 113 * range associated adjustable object. 114 * 115 * @serial 116 * @see #getValue 117 */ 118 int value; 119 120 /** 121 * The {@code adjustmentType} describes how the adjustable 122 * object value has changed. 123 * This value can be increased/decreased by a block or unit amount 124 * where the block is associated with page increments/decrements, 125 * and a unit is associated with line increments/decrements. 126 * 127 * @serial 128 * @see #getAdjustmentType 129 */ 130 int adjustmentType; 131 132 133 /** 134 * The {@code isAdjusting} is true if the event is one 135 * of the series of multiple adjustment events. 136 * 137 * @since 1.4 138 * @serial 139 * @see #getValueIsAdjusting 140 */ 141 boolean isAdjusting; 142 143 144 /* 145 * JDK 1.1 serialVersionUID 146 */ 147 private static final long serialVersionUID = 5700290645205279921L; 148 149 150 /** 151 * Constructs an {@code AdjustmentEvent} object with the 152 * specified {@code Adjustable} source, event type, 153 * adjustment type, and value. 154 * <p> This method throws an 155 * {@code IllegalArgumentException} if {@code source} 156 * is {@code null}. 157 * 158 * @param source The {@code Adjustable} object where the 159 * event originated 160 * @param id An integer indicating the type of event. 161 * For information on allowable values, see 162 * the class description for {@link AdjustmentEvent} 163 * @param type An integer indicating the adjustment type. 164 * For information on allowable values, see 165 * the class description for {@link AdjustmentEvent} 166 * @param value The current value of the adjustment 167 * @throws IllegalArgumentException if {@code source} is null 168 * @see #getSource() 169 * @see #getID() 170 * @see #getAdjustmentType() 171 * @see #getValue() 172 */ 173 public AdjustmentEvent(Adjustable source, int id, int type, int value) { 174 this(source, id, type, value, false); 175 } 176 177 /** 178 * Constructs an {@code AdjustmentEvent} object with the 179 * specified Adjustable source, event type, adjustment type, and value. 180 * <p> This method throws an 181 * {@code IllegalArgumentException} if {@code source} 182 * is {@code null}. 183 * 184 * @param source The {@code Adjustable} object where the 185 * event originated 186 * @param id An integer indicating the type of event. 187 * For information on allowable values, see 188 * the class description for {@link AdjustmentEvent} 189 * @param type An integer indicating the adjustment type. 190 * For information on allowable values, see 191 * the class description for {@link AdjustmentEvent} 192 * @param value The current value of the adjustment 193 * @param isAdjusting A boolean that equals {@code true} if the event is one 194 * of a series of multiple adjusting events, 195 * otherwise {@code false} 196 * @throws IllegalArgumentException if {@code source} is null 197 * @since 1.4 198 * @see #getSource() 199 * @see #getID() 200 * @see #getAdjustmentType() 201 * @see #getValue() 202 * @see #getValueIsAdjusting() 203 */ 204 public AdjustmentEvent(Adjustable source, int id, int type, int value, boolean isAdjusting) { 205 super(source, id); 206 adjustable = source; 207 this.adjustmentType = type; 208 this.value = value; 209 this.isAdjusting = isAdjusting; 210 } 211 212 /** 213 * Returns the {@code Adjustable} object where this event originated. 214 * 215 * @return the {@code Adjustable} object where this event originated 216 */ 217 public Adjustable getAdjustable() { 218 return adjustable; 219 } 220 221 /** 222 * Returns the current value in the adjustment event. 223 * 224 * @return the current value in the adjustment event 225 */ 226 public int getValue() { 227 return value; 228 } 229 230 /** 231 * Returns the type of adjustment which caused the value changed 232 * event. It will have one of the following values: 233 * <ul> 234 * <li>{@link #UNIT_INCREMENT} 235 * <li>{@link #UNIT_DECREMENT} 236 * <li>{@link #BLOCK_INCREMENT} 237 * <li>{@link #BLOCK_DECREMENT} 238 * <li>{@link #TRACK} 239 * </ul> 240 * @return one of the adjustment values listed above 241 */ 242 public int getAdjustmentType() { 243 return adjustmentType; 244 } 245 246 /** 247 * Returns {@code true} if this is one of multiple 248 * adjustment events. 249 * 250 * @return {@code true} if this is one of multiple 251 * adjustment events, otherwise returns {@code false} 252 * @since 1.4 253 */ 254 public boolean getValueIsAdjusting() { 255 return isAdjusting; 256 } 257 258 public String paramString() { 259 String typeStr; 260 switch(id) { 261 case ADJUSTMENT_VALUE_CHANGED: 262 typeStr = "ADJUSTMENT_VALUE_CHANGED"; 263 break; 264 default: 265 typeStr = "unknown type"; 266 } 267 String adjTypeStr; 268 switch(adjustmentType) { 269 case UNIT_INCREMENT: 270 adjTypeStr = "UNIT_INCREMENT"; 271 break; 272 case UNIT_DECREMENT: 273 adjTypeStr = "UNIT_DECREMENT"; 274 break; 275 case BLOCK_INCREMENT: 276 adjTypeStr = "BLOCK_INCREMENT"; 277 break; 278 case BLOCK_DECREMENT: 279 adjTypeStr = "BLOCK_DECREMENT"; 280 break; 281 case TRACK: 282 adjTypeStr = "TRACK"; 283 break; 284 default: 285 adjTypeStr = "unknown type"; 286 } 287 return typeStr 288 + ",adjType="+adjTypeStr 289 + ",value="+value 290 + ",isAdjusting="+isAdjusting; 291 } 292 }