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. package java.awt.event;
  8. import java.awt.Adjustable;
  9. import java.awt.AWTEvent;
  10. import java.awt.Event;
  11. /**
  12. * The adjustment event emitted by Adjustable objects.
  13. * @see java.awt.Adjustable
  14. * @see AdjustmentListener
  15. *
  16. * @author Amy Fowler
  17. * @version 1.27 12/19/03
  18. * @since 1.1
  19. */
  20. public class AdjustmentEvent extends AWTEvent {
  21. /**
  22. * Marks the first integer id for the range of adjustment event ids.
  23. */
  24. public static final int ADJUSTMENT_FIRST = 601;
  25. /**
  26. * Marks the last integer id for the range of adjustment event ids.
  27. */
  28. public static final int ADJUSTMENT_LAST = 601;
  29. /**
  30. * The adjustment value changed event.
  31. */
  32. public static final int ADJUSTMENT_VALUE_CHANGED = ADJUSTMENT_FIRST; //Event.SCROLL_LINE_UP
  33. /**
  34. * The unit increment adjustment type.
  35. */
  36. public static final int UNIT_INCREMENT = 1;
  37. /**
  38. * The unit decrement adjustment type.
  39. */
  40. public static final int UNIT_DECREMENT = 2;
  41. /**
  42. * The block decrement adjustment type.
  43. */
  44. public static final int BLOCK_DECREMENT = 3;
  45. /**
  46. * The block increment adjustment type.
  47. */
  48. public static final int BLOCK_INCREMENT = 4;
  49. /**
  50. * The absolute tracking adjustment type.
  51. */
  52. public static final int TRACK = 5;
  53. /**
  54. * The adjustable object that fired the event.
  55. *
  56. * @serial
  57. * @see #getAdjustable
  58. */
  59. Adjustable adjustable;
  60. /**
  61. * <code>value</code> will contain the new value of the
  62. * adjustable object. This value will always be in a
  63. * range associated adjustable object.
  64. *
  65. * @serial
  66. * @see #getValue
  67. */
  68. int value;
  69. /**
  70. * The <code>adjustmentType</code> describes how the adjustable
  71. * object value has changed.
  72. * This value can be increased/decreased by a block or unit amount
  73. * where the block is associated with page increments/decrements,
  74. * and a unit is associated with line increments/decrements.
  75. *
  76. * @serial
  77. * @see #getAdjustmentType
  78. */
  79. int adjustmentType;
  80. /**
  81. * The <code>isAdjusting</code> is true if the event is one
  82. * of the series of multiple adjustment events.
  83. *
  84. * @since 1.4
  85. * @serial
  86. * @see #getValueIsAdjusting
  87. */
  88. boolean isAdjusting;
  89. /*
  90. * JDK 1.1 serialVersionUID
  91. */
  92. private static final long serialVersionUID = 5700290645205279921L;
  93. /**
  94. * Constructs an <code>AdjustmentEvent</code> object with the
  95. * specified <code>Adjustable</code> source, event type,
  96. * adjustment type, and value.
  97. * <p>Note that passing in an invalid <code>id</code> results in
  98. * unspecified behavior. This method throws an
  99. * <code>IllegalArgumentException</code> if <code>source</code>
  100. * is <code>null</code>.
  101. *
  102. * @param source the <code>Adjustable</code> object where the
  103. * event originated
  104. * @param id the event type
  105. * @param type the adjustment type
  106. * @param value the current value of the adjustment
  107. * @throws IllegalArgumentException if <code>source</code> is null
  108. */
  109. public AdjustmentEvent(Adjustable source, int id, int type, int value) {
  110. this(source, id, type, value, false);
  111. }
  112. /**
  113. * Constructs an <code>AdjustmentEvent</code> object with the
  114. * specified Adjustable source, event type, adjustment type, and value.
  115. * <p>Note that passing in an invalid <code>id</code> results in
  116. * unspecified behavior. This method throws an
  117. * <code>IllegalArgumentException</code> if <code>source</code>
  118. * is <code>null</code>.
  119. *
  120. * @param source the <code>Adjustable</code> object where the
  121. * event originated
  122. * @param id the event type
  123. * @param type the adjustment type
  124. * @param value the current value of the adjustment
  125. * @param isAdjusting <code>true</code> if the event is one
  126. * of a series of multiple adjusting events,
  127. * otherwise <code>false</code>
  128. * @throws IllegalArgumentException if <code>source</code> is null
  129. */
  130. public AdjustmentEvent(Adjustable source, int id, int type, int value, boolean isAdjusting) {
  131. super(source, id);
  132. adjustable = source;
  133. this.adjustmentType = type;
  134. this.value = value;
  135. this.isAdjusting = isAdjusting;
  136. }
  137. /**
  138. * Returns the <code>Adjustable</code> object where this event originated.
  139. *
  140. * @return the <code>Adjustable</code> object where this event originated
  141. */
  142. public Adjustable getAdjustable() {
  143. return adjustable;
  144. }
  145. /**
  146. * Returns the current value in the adjustment event.
  147. *
  148. * @return the current value in the adjustment event
  149. */
  150. public int getValue() {
  151. return value;
  152. }
  153. /**
  154. * Returns the type of adjustment which caused the value changed
  155. * event. It will have one of the following values:
  156. * <ul>
  157. * <li>{@link #UNIT_INCREMENT}
  158. * <li>{@link #UNIT_DECREMENT}
  159. * <li>{@link #BLOCK_INCREMENT}
  160. * <li>{@link #BLOCK_DECREMENT}
  161. * <li>{@link #TRACK}
  162. * </ul>
  163. * @return one of the adjustment values listed above
  164. */
  165. public int getAdjustmentType() {
  166. return adjustmentType;
  167. }
  168. /**
  169. * Returns <code>true</code> if this is one of multiple
  170. * adjustment events.
  171. *
  172. * @return <code>true</code> if this is one of multiple
  173. * adjustment events, otherwise returns <code>false</code>
  174. */
  175. public boolean getValueIsAdjusting() {
  176. return isAdjusting;
  177. }
  178. public String paramString() {
  179. String typeStr;
  180. switch(id) {
  181. case ADJUSTMENT_VALUE_CHANGED:
  182. typeStr = "ADJUSTMENT_VALUE_CHANGED";
  183. break;
  184. default:
  185. typeStr = "unknown type";
  186. }
  187. String adjTypeStr;
  188. switch(adjustmentType) {
  189. case UNIT_INCREMENT:
  190. adjTypeStr = "UNIT_INCREMENT";
  191. break;
  192. case UNIT_DECREMENT:
  193. adjTypeStr = "UNIT_DECREMENT";
  194. break;
  195. case BLOCK_INCREMENT:
  196. adjTypeStr = "BLOCK_INCREMENT";
  197. break;
  198. case BLOCK_DECREMENT:
  199. adjTypeStr = "BLOCK_DECREMENT";
  200. break;
  201. case TRACK:
  202. adjTypeStr = "TRACK";
  203. break;
  204. default:
  205. adjTypeStr = "unknown type";
  206. }
  207. return typeStr
  208. + ",adjType="+adjTypeStr
  209. + ",value="+value
  210. + ",isAdjusting="+isAdjusting;
  211. }
  212. }