1. /*
  2. * @(#)BoundedRangeModel.java 1.20 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing;
  8. import javax.swing.event.*;
  9. /**
  10. * Defines the data model used by components like Sliders and ProgressBars.
  11. * Defines four interrelated integer properties: minimum, maximum, extent
  12. * and value. These four integers define two nested ranges like this:
  13. * <pre>
  14. * minimum <= value <= value+extent <= maximum
  15. * </pre>
  16. * The outer range is <code>minimum,maximum</code> and the inner
  17. * range is <code>value,value+extent</code>. The inner range
  18. * must lie within the outer one, i.e. <code>value</code> must be
  19. * less than or equal to <code>maximum</code> and <code>value+extent</code>
  20. * must greater than or equal to <code>minimum</code>, and <code>maximum</code>
  21. * must be greater than or equal to <code>minimum</code>.
  22. * There are a few features of this model that one might find a little
  23. * surprising. These quirks exist for the convenience of the
  24. * Swing BoundedRangeModel clients like like Slider and ScrollBar.
  25. * <ul>
  26. * <li>
  27. * The minimum and maximum set methods "correct" the other
  28. * three properties to acommodate their new value argument. For
  29. * example setting the model's minimum may change its maximum, value,
  30. * and extent properties (in that order), to maintain the constraints
  31. * specified above.
  32. *
  33. * <li>
  34. * The value and extent set methods "correct" their argument to
  35. * fit within the limits defined by the other three properties.
  36. * For example if <code>value == maximum</code>, <code>setExtent(10)</code>
  37. * would change the extent (back) to zero.
  38. *
  39. * <li>
  40. * The four BoundedRangeModel values are defined as Java Beans properties
  41. * however Swing ChangeEvents are used to notify clients of changes rather
  42. * than PropertyChangeEvents. This was done to keep the overhead of monitoring
  43. * a BoundedRangeModel low. Changes are often reported at MouseDragged rates.
  44. * </ul>
  45. *
  46. * @version 1.20 11/29/01
  47. * @author Hans Muller
  48. * @see DefaultBoundedRangeModel
  49. */
  50. public interface BoundedRangeModel
  51. {
  52. /**
  53. * Returns the minimum acceptable value.
  54. *
  55. * @return the value of the minimum property
  56. * @see #setMinimum
  57. */
  58. int getMinimum();
  59. /**
  60. * Sets the model's minimum to <I>newMinimum</I>. The
  61. * other three properties may be changed as well, to ensure
  62. * that:
  63. * <pre>
  64. * minimum <= value <= value+extent <= maximum
  65. * </pre>
  66. * <p>
  67. * Notifies any listeners if the model changes.
  68. *
  69. * @param newMinimum the model's new minimum
  70. * @see #getMinimum
  71. * @see #addChangeListener
  72. */
  73. void setMinimum(int newMinimum);
  74. /**
  75. * Returns the model's maximum. Note that the upper
  76. * limit on the model's value is (maximum - extent).
  77. *
  78. * @return the value of the maximum property.
  79. * @see #setMaximum
  80. * @see #setExtent
  81. */
  82. int getMaximum();
  83. /**
  84. * Sets the model's maximum to <I>newMaximum</I>. The other
  85. * three properties may be changed as well, to ensure that
  86. * <pre>
  87. * minimum <= value <= value+extent <= maximum
  88. * </pre>
  89. * <p>
  90. * Notifies any listeners if the model changes.
  91. *
  92. * @param newMaximum the model's new maximum
  93. * @see #getMaximum
  94. * @see #addChangeListener
  95. */
  96. void setMaximum(int newMaximum);
  97. /**
  98. * Returns the model's current value. Note that the upper
  99. * limit on the model's value is <code>maximum - extent</code>
  100. * and the lower limit is <code>minimum</code>.
  101. *
  102. * @return the model's value
  103. * @see #setValue
  104. */
  105. int getValue();
  106. /**
  107. * Sets the model's current value to <code>newValue</code> if <code>newValue</code>
  108. * satisfies the model's constraints. Those constraints are:
  109. * <pre>
  110. * minimum <= value <= value+extent <= maximum
  111. * </pre>
  112. * Otherwise, if <code>newValue</code> is less than <code>minimum</code>
  113. * it's set to <code>minimum</code>, if its greater than
  114. * <code>maximum</code> then it's set to <code>maximum</code>, and
  115. * if it's greater than <code>value+extent</code> then it's set to
  116. * <code>value+extent</code>.
  117. * <p>
  118. * When a BoundedRange model is used with a scrollbar the value
  119. * specifies the origin of the scrollbar knob (aka the "thumb" or
  120. * "elevator"). The value usually represents the origin of the
  121. * visible part of the object being scrolled.
  122. * <p>
  123. * Notifies any listeners if the model changes.
  124. *
  125. * @param newValue the model's new value
  126. * @see #getValue
  127. */
  128. void setValue(int newValue);
  129. /**
  130. * This attribute indicates that any upcoming changes to the value
  131. * of the model should be considered a single event. This attribute
  132. * will be set to true at the start of a series of changes to the value,
  133. * and will be set to false when the value has finished changing. Normally
  134. * this allows a listener to only take action when the final value change in
  135. * committed, instead of having to do updates for all intermediate values.
  136. * <p>
  137. * Sliders and scrollbars use this property when a drag is underway.
  138. *
  139. * @param b true if the upcoming changes to the value property are part of a series
  140. */
  141. void setValueIsAdjusting(boolean b);
  142. /**
  143. * Returns true if the current changes to the value property are part
  144. * of a series of changes.
  145. *
  146. * @return the valueIsAdjustingProperty.
  147. * @see #setValueIsAdjusting
  148. */
  149. boolean getValueIsAdjusting();
  150. /**
  151. * Returns the model's extent, the length of the inner range that
  152. * begins at the model's value.
  153. *
  154. * @return the value of the model's extent property
  155. * @see #setExtent
  156. * @see #setValue
  157. */
  158. int getExtent();
  159. /**
  160. * Sets the model's extent. The <I>newExtent</I> is forced to
  161. * be greater than or equal to zero and less than or equal to
  162. * maximum - value.
  163. * <p>
  164. * When a BoundedRange model is used with a scrollbar the extent
  165. * defines the length of the scrollbar knob (aka the "thumb" or
  166. * "elevator"). The extent usually represents how much of the
  167. * object being scrolled is visible. When used with a slider,
  168. * the extent determines how much the value can "jump", for
  169. * example when the user presses PgUp or PgDn.
  170. * <p>
  171. * Notifies any listeners if the model changes.
  172. *
  173. * @param newExtent the model's new extent
  174. * @see #getExtent
  175. * @see #setValue
  176. */
  177. void setExtent(int newExtent);
  178. /**
  179. * This method sets all of the model's data with a single method call.
  180. * The method results in a single change event being generated. This is
  181. * convenient when you need to adjust all the model data simulaneously and
  182. * do not want individual change events to occur.
  183. *
  184. * @param value an int giving the current value
  185. * @param extent an int giving the amount by which the value can "jump"
  186. * @param min an int giving the minimum value
  187. * @param max an int giving the maximum value
  188. * @param isAdjusting a boolean, true if a series of changes are in
  189. * progress
  190. *
  191. * @see #setValue
  192. * @see #setExtent
  193. * @see #setMinimum
  194. * @see #setMaximum
  195. * @see #setValueIsAdjusting
  196. */
  197. void setRangeProperties(int value, int extent, int min, int max, boolean adjusting);
  198. /**
  199. * Adds a ChangeListener to the model's listener list.
  200. *
  201. * @param x the ChangeListener to add
  202. * @see #removeChangeListener
  203. */
  204. void addChangeListener(ChangeListener x);
  205. /**
  206. * Removes a ChangeListener from the model's listener list.
  207. *
  208. * @param x the ChangeListener to remove
  209. * @see #addChangeListener
  210. */
  211. void removeChangeListener(ChangeListener x);
  212. }