Path: blob/master/src/java.desktop/share/classes/javax/swing/BoundedRangeModel.java
41153 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.swing;2627import javax.swing.event.*;282930/**31* Defines the data model used by components like <code>Slider</code>s32* and <code>ProgressBar</code>s.33* Defines four interrelated integer properties: minimum, maximum, extent34* and value. These four integers define two nested ranges like this:35* <pre>36* minimum <= value <= value+extent <= maximum37* </pre>38* The outer range is <code>minimum,maximum</code> and the inner39* range is <code>value,value+extent</code>. The inner range40* must lie within the outer one, i.e. <code>value</code> must be41* less than or equal to <code>maximum</code> and <code>value+extent</code>42* must greater than or equal to <code>minimum</code>, and <code>maximum</code>43* must be greater than or equal to <code>minimum</code>.44* There are a few features of this model that one might find a little45* surprising. These quirks exist for the convenience of the46* Swing BoundedRangeModel clients, such as <code>Slider</code> and47* <code>ScrollBar</code>.48* <ul>49* <li>50* The minimum and maximum set methods "correct" the other51* three properties to accommodate their new value argument. For52* example setting the model's minimum may change its maximum, value,53* and extent properties (in that order), to maintain the constraints54* specified above.55*56* <li>57* The value and extent set methods "correct" their argument to58* fit within the limits defined by the other three properties.59* For example if <code>value == maximum</code>, <code>setExtent(10)</code>60* would change the extent (back) to zero.61*62* <li>63* The four BoundedRangeModel values are defined as Java Beans properties64* however Swing ChangeEvents are used to notify clients of changes rather65* than PropertyChangeEvents. This was done to keep the overhead of monitoring66* a BoundedRangeModel low. Changes are often reported at MouseDragged rates.67* </ul>68*69* <p>70*71* For an example of specifying custom bounded range models used by sliders,72* see <a73href="http://www.oracle.com/technetwork/java/architecture-142923.html#separable">Separable model architecture</a>74* in <em>A Swing Architecture Overview.</em>75*76* @author Hans Muller77* @see DefaultBoundedRangeModel78* @since 1.279*/80public interface BoundedRangeModel81{82/**83* Returns the minimum acceptable value.84*85* @return the value of the minimum property86* @see #setMinimum87*/88int getMinimum();899091/**92* Sets the model's minimum to <I>newMinimum</I>. The93* other three properties may be changed as well, to ensure94* that:95* <pre>96* minimum <= value <= value+extent <= maximum97* </pre>98* <p>99* Notifies any listeners if the model changes.100*101* @param newMinimum the model's new minimum102* @see #getMinimum103* @see #addChangeListener104*/105void setMinimum(int newMinimum);106107108/**109* Returns the model's maximum. Note that the upper110* limit on the model's value is (maximum - extent).111*112* @return the value of the maximum property.113* @see #setMaximum114* @see #setExtent115*/116int getMaximum();117118119/**120* Sets the model's maximum to <I>newMaximum</I>. The other121* three properties may be changed as well, to ensure that122* <pre>123* minimum <= value <= value+extent <= maximum124* </pre>125* <p>126* Notifies any listeners if the model changes.127*128* @param newMaximum the model's new maximum129* @see #getMaximum130* @see #addChangeListener131*/132void setMaximum(int newMaximum);133134135/**136* Returns the model's current value. Note that the upper137* limit on the model's value is <code>maximum - extent</code>138* and the lower limit is <code>minimum</code>.139*140* @return the model's value141* @see #setValue142*/143int getValue();144145146/**147* Sets the model's current value to <code>newValue</code> if <code>newValue</code>148* satisfies the model's constraints. Those constraints are:149* <pre>150* minimum <= value <= value+extent <= maximum151* </pre>152* Otherwise, if <code>newValue</code> is less than <code>minimum</code>153* it's set to <code>minimum</code>, if its greater than154* <code>maximum</code> then it's set to <code>maximum</code>, and155* if it's greater than <code>value+extent</code> then it's set to156* <code>value+extent</code>.157* <p>158* When a BoundedRange model is used with a scrollbar the value159* specifies the origin of the scrollbar knob (aka the "thumb" or160* "elevator"). The value usually represents the origin of the161* visible part of the object being scrolled.162* <p>163* Notifies any listeners if the model changes.164*165* @param newValue the model's new value166* @see #getValue167*/168void setValue(int newValue);169170171/**172* This attribute indicates that any upcoming changes to the value173* of the model should be considered a single event. This attribute174* will be set to true at the start of a series of changes to the value,175* and will be set to false when the value has finished changing. Normally176* this allows a listener to only take action when the final value change in177* committed, instead of having to do updates for all intermediate values.178* <p>179* Sliders and scrollbars use this property when a drag is underway.180*181* @param b true if the upcoming changes to the value property are part of a series182*/183void setValueIsAdjusting(boolean b);184185186/**187* Returns true if the current changes to the value property are part188* of a series of changes.189*190* @return the valueIsAdjustingProperty.191* @see #setValueIsAdjusting192*/193boolean getValueIsAdjusting();194195196/**197* Returns the model's extent, the length of the inner range that198* begins at the model's value.199*200* @return the value of the model's extent property201* @see #setExtent202* @see #setValue203*/204int getExtent();205206207/**208* Sets the model's extent. The <I>newExtent</I> is forced to209* be greater than or equal to zero and less than or equal to210* maximum - value.211* <p>212* When a BoundedRange model is used with a scrollbar the extent213* defines the length of the scrollbar knob (aka the "thumb" or214* "elevator"). The extent usually represents how much of the215* object being scrolled is visible. When used with a slider,216* the extent determines how much the value can "jump", for217* example when the user presses PgUp or PgDn.218* <p>219* Notifies any listeners if the model changes.220*221* @param newExtent the model's new extent222* @see #getExtent223* @see #setValue224*/225void setExtent(int newExtent);226227228229/**230* This method sets all of the model's data with a single method call.231* The method results in a single change event being generated. This is232* convenient when you need to adjust all the model data simultaneously and233* do not want individual change events to occur.234*235* @param value an int giving the current value236* @param extent an int giving the amount by which the value can "jump"237* @param min an int giving the minimum value238* @param max an int giving the maximum value239* @param adjusting a boolean, true if a series of changes are in240* progress241*242* @see #setValue243* @see #setExtent244* @see #setMinimum245* @see #setMaximum246* @see #setValueIsAdjusting247*/248void setRangeProperties(int value, int extent, int min, int max, boolean adjusting);249250251/**252* Adds a ChangeListener to the model's listener list.253*254* @param x the ChangeListener to add255* @see #removeChangeListener256*/257void addChangeListener(ChangeListener x);258259260/**261* Removes a ChangeListener from the model's listener list.262*263* @param x the ChangeListener to remove264* @see #addChangeListener265*/266void removeChangeListener(ChangeListener x);267268}269270271