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