1. /*
  2. * @(#)AdjustmentEvent.java 1.25 03/01/23
  3. *
  4. * Copyright 2003 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.25 01/23/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.
  99. *
  100. * @param source the <code>Adjustable</code> object where the
  101. * event originated
  102. * @param id the event type
  103. * @param type the adjustment type
  104. * @param value the current value of the adjustment
  105. */
  106. public AdjustmentEvent(Adjustable source, int id, int type, int value) {
  107. this(source, id, type, value, false);
  108. }
  109. /**
  110. * Constructs an <code>AdjustmentEvent</code> object with the
  111. * specified Adjustable source, event type, adjustment type, and value.
  112. * <p>Note that passing in an invalid <code>id</code> results in
  113. * unspecified behavior.
  114. *
  115. * @param source the <code>Adjustable</code> object where the
  116. * event originated
  117. * @param id the event type
  118. * @param type the adjustment type
  119. * @param value the current value of the adjustment
  120. * @param isAdjusting <code>true</code> if the event is one
  121. * of a series of multiple adjusting events,
  122. * otherwise <code>false</code>
  123. */
  124. public AdjustmentEvent(Adjustable source, int id, int type, int value, boolean isAdjusting) {
  125. super(source, id);
  126. adjustable = source;
  127. this.adjustmentType = type;
  128. this.value = value;
  129. this.isAdjusting = isAdjusting;
  130. }
  131. /**
  132. * Returns the <code>Adjustable</code> object where this event originated.
  133. *
  134. * @return the <code>Adjustable</code> object where this event originated
  135. */
  136. public Adjustable getAdjustable() {
  137. return adjustable;
  138. }
  139. /**
  140. * Returns the current value in the adjustment event.
  141. *
  142. * @return the current value in the adjustment event
  143. */
  144. public int getValue() {
  145. return value;
  146. }
  147. /**
  148. * Returns the type of adjustment which caused the value changed
  149. * event. It will have one of the following values:
  150. * <ul>
  151. * <li>{@link #UNIT_INCREMENT}
  152. * <li>{@link #UNIT_DECREMENT}
  153. * <li>{@link #BLOCK_INCREMENT}
  154. * <li>{@link #BLOCK_DECREMENT}
  155. * <li>{@link #TRACK}
  156. * </ul>
  157. * @return one of the adjustment values listed above
  158. */
  159. public int getAdjustmentType() {
  160. return adjustmentType;
  161. }
  162. /**
  163. * Returns <code>true</code> if this is one of multiple
  164. * adjustment events.
  165. *
  166. * @return <code>true</code> if this is one of multiple
  167. * adjustment events, otherwise returns <code>false</code>
  168. */
  169. public boolean getValueIsAdjusting() {
  170. return isAdjusting;
  171. }
  172. public String paramString() {
  173. String typeStr;
  174. switch(id) {
  175. case ADJUSTMENT_VALUE_CHANGED:
  176. typeStr = "ADJUSTMENT_VALUE_CHANGED";
  177. break;
  178. default:
  179. typeStr = "unknown type";
  180. }
  181. String adjTypeStr;
  182. switch(adjustmentType) {
  183. case UNIT_INCREMENT:
  184. adjTypeStr = "UNIT_INCREMENT";
  185. break;
  186. case UNIT_DECREMENT:
  187. adjTypeStr = "UNIT_DECREMENT";
  188. break;
  189. case BLOCK_INCREMENT:
  190. adjTypeStr = "BLOCK_INCREMENT";
  191. break;
  192. case BLOCK_DECREMENT:
  193. adjTypeStr = "BLOCK_DECREMENT";
  194. break;
  195. case TRACK:
  196. adjTypeStr = "TRACK";
  197. break;
  198. default:
  199. adjTypeStr = "unknown type";
  200. }
  201. return typeStr
  202. + ",adjType="+adjTypeStr
  203. + ",value="+value
  204. + ",isAdjusting="+isAdjusting;
  205. }
  206. }