1. /*
  2. * @(#)BoundedRangeModel.java 1.26 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 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 accommodate 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. * <p>
  47. *
  48. * For an example of specifying custom bounded range models used by sliders,
  49. * see <a
  50. href="http://java.sun.com/docs/books/tutorial/uiswing/overview/anatomy.html">The Anatomy of a Swing-Based Program</a>
  51. * in <em>The Java Tutorial.</em>
  52. *
  53. * @version 1.26 01/23/03
  54. * @author Hans Muller
  55. * @see DefaultBoundedRangeModel
  56. */
  57. public interface BoundedRangeModel
  58. {
  59. /**
  60. * Returns the minimum acceptable value.
  61. *
  62. * @return the value of the minimum property
  63. * @see #setMinimum
  64. */
  65. int getMinimum();
  66. /**
  67. * Sets the model's minimum to <I>newMinimum</I>. The
  68. * other three properties may be changed as well, to ensure
  69. * that:
  70. * <pre>
  71. * minimum <= value <= value+extent <= maximum
  72. * </pre>
  73. * <p>
  74. * Notifies any listeners if the model changes.
  75. *
  76. * @param newMinimum the model's new minimum
  77. * @see #getMinimum
  78. * @see #addChangeListener
  79. */
  80. void setMinimum(int newMinimum);
  81. /**
  82. * Returns the model's maximum. Note that the upper
  83. * limit on the model's value is (maximum - extent).
  84. *
  85. * @return the value of the maximum property.
  86. * @see #setMaximum
  87. * @see #setExtent
  88. */
  89. int getMaximum();
  90. /**
  91. * Sets the model's maximum to <I>newMaximum</I>. The other
  92. * three properties may be changed as well, to ensure that
  93. * <pre>
  94. * minimum <= value <= value+extent <= maximum
  95. * </pre>
  96. * <p>
  97. * Notifies any listeners if the model changes.
  98. *
  99. * @param newMaximum the model's new maximum
  100. * @see #getMaximum
  101. * @see #addChangeListener
  102. */
  103. void setMaximum(int newMaximum);
  104. /**
  105. * Returns the model's current value. Note that the upper
  106. * limit on the model's value is <code>maximum - extent</code>
  107. * and the lower limit is <code>minimum</code>.
  108. *
  109. * @return the model's value
  110. * @see #setValue
  111. */
  112. int getValue();
  113. /**
  114. * Sets the model's current value to <code>newValue</code> if <code>newValue</code>
  115. * satisfies the model's constraints. Those constraints are:
  116. * <pre>
  117. * minimum <= value <= value+extent <= maximum
  118. * </pre>
  119. * Otherwise, if <code>newValue</code> is less than <code>minimum</code>
  120. * it's set to <code>minimum</code>, if its greater than
  121. * <code>maximum</code> then it's set to <code>maximum</code>, and
  122. * if it's greater than <code>value+extent</code> then it's set to
  123. * <code>value+extent</code>.
  124. * <p>
  125. * When a BoundedRange model is used with a scrollbar the value
  126. * specifies the origin of the scrollbar knob (aka the "thumb" or
  127. * "elevator"). The value usually represents the origin of the
  128. * visible part of the object being scrolled.
  129. * <p>
  130. * Notifies any listeners if the model changes.
  131. *
  132. * @param newValue the model's new value
  133. * @see #getValue
  134. */
  135. void setValue(int newValue);
  136. /**
  137. * This attribute indicates that any upcoming changes to the value
  138. * of the model should be considered a single event. This attribute
  139. * will be set to true at the start of a series of changes to the value,
  140. * and will be set to false when the value has finished changing. Normally
  141. * this allows a listener to only take action when the final value change in
  142. * committed, instead of having to do updates for all intermediate values.
  143. * <p>
  144. * Sliders and scrollbars use this property when a drag is underway.
  145. *
  146. * @param b true if the upcoming changes to the value property are part of a series
  147. */
  148. void setValueIsAdjusting(boolean b);
  149. /**
  150. * Returns true if the current changes to the value property are part
  151. * of a series of changes.
  152. *
  153. * @return the valueIsAdjustingProperty.
  154. * @see #setValueIsAdjusting
  155. */
  156. boolean getValueIsAdjusting();
  157. /**
  158. * Returns the model's extent, the length of the inner range that
  159. * begins at the model's value.
  160. *
  161. * @return the value of the model's extent property
  162. * @see #setExtent
  163. * @see #setValue
  164. */
  165. int getExtent();
  166. /**
  167. * Sets the model's extent. The <I>newExtent</I> is forced to
  168. * be greater than or equal to zero and less than or equal to
  169. * maximum - value.
  170. * <p>
  171. * When a BoundedRange model is used with a scrollbar the extent
  172. * defines the length of the scrollbar knob (aka the "thumb" or
  173. * "elevator"). The extent usually represents how much of the
  174. * object being scrolled is visible. When used with a slider,
  175. * the extent determines how much the value can "jump", for
  176. * example when the user presses PgUp or PgDn.
  177. * <p>
  178. * Notifies any listeners if the model changes.
  179. *
  180. * @param newExtent the model's new extent
  181. * @see #getExtent
  182. * @see #setValue
  183. */
  184. void setExtent(int newExtent);
  185. /**
  186. * This method sets all of the model's data with a single method call.
  187. * The method results in a single change event being generated. This is
  188. * convenient when you need to adjust all the model data simultaneously and
  189. * do not want individual change events to occur.
  190. *
  191. * @param value an int giving the current value
  192. * @param extent an int giving the amount by which the value can "jump"
  193. * @param min an int giving the minimum value
  194. * @param max an int giving the maximum value
  195. * @param adjusting a boolean, true if a series of changes are in
  196. * progress
  197. *
  198. * @see #setValue
  199. * @see #setExtent
  200. * @see #setMinimum
  201. * @see #setMaximum
  202. * @see #setValueIsAdjusting
  203. */
  204. void setRangeProperties(int value, int extent, int min, int max, boolean adjusting);
  205. /**
  206. * Adds a ChangeListener to the model's listener list.
  207. *
  208. * @param x the ChangeListener to add
  209. * @see #removeChangeListener
  210. */
  211. void addChangeListener(ChangeListener x);
  212. /**
  213. * Removes a ChangeListener from the model's listener list.
  214. *
  215. * @param x the ChangeListener to remove
  216. * @see #addChangeListener
  217. */
  218. void removeChangeListener(ChangeListener x);
  219. }