1 /*
2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package javax.swing;
27 
28 import javax.swing.event.*;
29 
30 
31 /**
32  * Defines the data model used by components like <code>Slider</code>s
33  * and <code>ProgressBar</code>s.
34  * Defines four interrelated integer properties: minimum, maximum, extent
35  * and value.  These four integers define two nested ranges like this:
36  * <pre>
37  * minimum &lt;= value &lt;= value+extent &lt;= maximum
38  * </pre>
39  * The outer range is <code>minimum,maximum</code> and the inner
40  * range is <code>value,value+extent</code>.  The inner range
41  * must lie within the outer one, i.e. <code>value</code> must be
42  * less than or equal to <code>maximum</code> and <code>value+extent</code>
43  * must greater than or equal to <code>minimum</code>, and <code>maximum</code>
44  * must be greater than or equal to <code>minimum</code>.
45  * There are a few features of this model that one might find a little
46  * surprising.  These quirks exist for the convenience of the
47  * Swing BoundedRangeModel clients, such as <code>Slider</code> and
48  * <code>ScrollBar</code>.
49  * <ul>
50  * <li>
51  *   The minimum and maximum set methods "correct" the other
52  *   three properties to accommodate their new value argument.  For
53  *   example setting the model's minimum may change its maximum, value,
54  *   and extent properties (in that order), to maintain the constraints
55  *   specified above.
56  *
57  * <li>
58  *   The value and extent set methods "correct" their argument to
59  *   fit within the limits defined by the other three properties.
60  *   For example if <code>value == maximum</code>, <code>setExtent(10)</code>
61  *   would change the extent (back) to zero.
62  *
63  * <li>
64  *   The four BoundedRangeModel values are defined as Java Beans properties
65  *   however Swing ChangeEvents are used to notify clients of changes rather
66  *   than PropertyChangeEvents. This was done to keep the overhead of monitoring
67  *   a BoundedRangeModel low. Changes are often reported at MouseDragged rates.
68  * </ul>
69  *
70  * <p>
71  *
72  * For an example of specifying custom bounded range models used by sliders,
73  * see <a
74  href="http://www.oracle.com/technetwork/java/architecture-142923.html#separable">Separable model architecture</a>
75  * in <em>A Swing Architecture Overview.</em>
76  *
77  * @author Hans Muller
78  * @see DefaultBoundedRangeModel
79  * @since 1.2
80  */
81 public interface BoundedRangeModel
82 {
83     /**
84      * Returns the minimum acceptable value.
85      *
86      * @return the value of the minimum property
87      * @see #setMinimum
88      */
getMinimum()89     int getMinimum();
90 
91 
92     /**
93      * Sets the model's minimum to <I>newMinimum</I>.   The
94      * other three properties may be changed as well, to ensure
95      * that:
96      * <pre>
97      * minimum &lt;= value &lt;= value+extent &lt;= maximum
98      * </pre>
99      * <p>
100      * Notifies any listeners if the model changes.
101      *
102      * @param newMinimum the model's new minimum
103      * @see #getMinimum
104      * @see #addChangeListener
105      */
setMinimum(int newMinimum)106     void setMinimum(int newMinimum);
107 
108 
109     /**
110      * Returns the model's maximum.  Note that the upper
111      * limit on the model's value is (maximum - extent).
112      *
113      * @return the value of the maximum property.
114      * @see #setMaximum
115      * @see #setExtent
116      */
getMaximum()117     int getMaximum();
118 
119 
120     /**
121      * Sets the model's maximum to <I>newMaximum</I>. The other
122      * three properties may be changed as well, to ensure that
123      * <pre>
124      * minimum &lt;= value &lt;= value+extent &lt;= maximum
125      * </pre>
126      * <p>
127      * Notifies any listeners if the model changes.
128      *
129      * @param newMaximum the model's new maximum
130      * @see #getMaximum
131      * @see #addChangeListener
132      */
setMaximum(int newMaximum)133     void setMaximum(int newMaximum);
134 
135 
136     /**
137      * Returns the model's current value.  Note that the upper
138      * limit on the model's value is <code>maximum - extent</code>
139      * and the lower limit is <code>minimum</code>.
140      *
141      * @return  the model's value
142      * @see     #setValue
143      */
getValue()144     int getValue();
145 
146 
147     /**
148      * Sets the model's current value to <code>newValue</code> if <code>newValue</code>
149      * satisfies the model's constraints. Those constraints are:
150      * <pre>
151      * minimum &lt;= value &lt;= value+extent &lt;= maximum
152      * </pre>
153      * Otherwise, if <code>newValue</code> is less than <code>minimum</code>
154      * it's set to <code>minimum</code>, if its greater than
155      * <code>maximum</code> then it's set to <code>maximum</code>, and
156      * if it's greater than <code>value+extent</code> then it's set to
157      * <code>value+extent</code>.
158      * <p>
159      * When a BoundedRange model is used with a scrollbar the value
160      * specifies the origin of the scrollbar knob (aka the "thumb" or
161      * "elevator").  The value usually represents the origin of the
162      * visible part of the object being scrolled.
163      * <p>
164      * Notifies any listeners if the model changes.
165      *
166      * @param newValue the model's new value
167      * @see #getValue
168      */
setValue(int newValue)169     void setValue(int newValue);
170 
171 
172     /**
173      * This attribute indicates that any upcoming changes to the value
174      * of the model should be considered a single event. This attribute
175      * will be set to true at the start of a series of changes to the value,
176      * and will be set to false when the value has finished changing.  Normally
177      * this allows a listener to only take action when the final value change in
178      * committed, instead of having to do updates for all intermediate values.
179      * <p>
180      * Sliders and scrollbars use this property when a drag is underway.
181      *
182      * @param b true if the upcoming changes to the value property are part of a series
183      */
setValueIsAdjusting(boolean b)184     void setValueIsAdjusting(boolean b);
185 
186 
187     /**
188      * Returns true if the current changes to the value property are part
189      * of a series of changes.
190      *
191      * @return the valueIsAdjustingProperty.
192      * @see #setValueIsAdjusting
193      */
getValueIsAdjusting()194     boolean getValueIsAdjusting();
195 
196 
197     /**
198      * Returns the model's extent, the length of the inner range that
199      * begins at the model's value.
200      *
201      * @return  the value of the model's extent property
202      * @see     #setExtent
203      * @see     #setValue
204      */
getExtent()205     int getExtent();
206 
207 
208     /**
209      * Sets the model's extent.  The <I>newExtent</I> is forced to
210      * be greater than or equal to zero and less than or equal to
211      * maximum - value.
212      * <p>
213      * When a BoundedRange model is used with a scrollbar the extent
214      * defines the length of the scrollbar knob (aka the "thumb" or
215      * "elevator").  The extent usually represents how much of the
216      * object being scrolled is visible. When used with a slider,
217      * the extent determines how much the value can "jump", for
218      * example when the user presses PgUp or PgDn.
219      * <p>
220      * Notifies any listeners if the model changes.
221      *
222      * @param  newExtent the model's new extent
223      * @see #getExtent
224      * @see #setValue
225      */
setExtent(int newExtent)226     void setExtent(int newExtent);
227 
228 
229 
230     /**
231      * This method sets all of the model's data with a single method call.
232      * The method results in a single change event being generated. This is
233      * convenient when you need to adjust all the model data simultaneously and
234      * do not want individual change events to occur.
235      *
236      * @param value  an int giving the current value
237      * @param extent an int giving the amount by which the value can "jump"
238      * @param min    an int giving the minimum value
239      * @param max    an int giving the maximum value
240      * @param adjusting a boolean, true if a series of changes are in
241      *                    progress
242      *
243      * @see #setValue
244      * @see #setExtent
245      * @see #setMinimum
246      * @see #setMaximum
247      * @see #setValueIsAdjusting
248      */
setRangeProperties(int value, int extent, int min, int max, boolean adjusting)249     void setRangeProperties(int value, int extent, int min, int max, boolean adjusting);
250 
251 
252     /**
253      * Adds a ChangeListener to the model's listener list.
254      *
255      * @param x the ChangeListener to add
256      * @see #removeChangeListener
257      */
addChangeListener(ChangeListener x)258     void addChangeListener(ChangeListener x);
259 
260 
261     /**
262      * Removes a ChangeListener from the model's listener list.
263      *
264      * @param x the ChangeListener to remove
265      * @see #addChangeListener
266      */
removeChangeListener(ChangeListener x)267     void removeChangeListener(ChangeListener x);
268 
269 }
270