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