Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/swing/BoundedRangeModel.java
38829 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*/79public interface BoundedRangeModel80{81/**82* Returns the minimum acceptable value.83*84* @return the value of the minimum property85* @see #setMinimum86*/87int getMinimum();888990/**91* Sets the model's minimum to <I>newMinimum</I>. The92* other three properties may be changed as well, to ensure93* that:94* <pre>95* minimum <= value <= value+extent <= maximum96* </pre>97* <p>98* Notifies any listeners if the model changes.99*100* @param newMinimum the model's new minimum101* @see #getMinimum102* @see #addChangeListener103*/104void setMinimum(int newMinimum);105106107/**108* Returns the model's maximum. Note that the upper109* limit on the model's value is (maximum - extent).110*111* @return the value of the maximum property.112* @see #setMaximum113* @see #setExtent114*/115int getMaximum();116117118/**119* Sets the model's maximum to <I>newMaximum</I>. The other120* three properties may be changed as well, to ensure that121* <pre>122* minimum <= value <= value+extent <= maximum123* </pre>124* <p>125* Notifies any listeners if the model changes.126*127* @param newMaximum the model's new maximum128* @see #getMaximum129* @see #addChangeListener130*/131void setMaximum(int newMaximum);132133134/**135* Returns the model's current value. Note that the upper136* limit on the model's value is <code>maximum - extent</code>137* and the lower limit is <code>minimum</code>.138*139* @return the model's value140* @see #setValue141*/142int getValue();143144145/**146* Sets the model's current value to <code>newValue</code> if <code>newValue</code>147* satisfies the model's constraints. Those constraints are:148* <pre>149* minimum <= value <= value+extent <= maximum150* </pre>151* Otherwise, if <code>newValue</code> is less than <code>minimum</code>152* it's set to <code>minimum</code>, if its greater than153* <code>maximum</code> then it's set to <code>maximum</code>, and154* if it's greater than <code>value+extent</code> then it's set to155* <code>value+extent</code>.156* <p>157* When a BoundedRange model is used with a scrollbar the value158* specifies the origin of the scrollbar knob (aka the "thumb" or159* "elevator"). The value usually represents the origin of the160* visible part of the object being scrolled.161* <p>162* Notifies any listeners if the model changes.163*164* @param newValue the model's new value165* @see #getValue166*/167void setValue(int newValue);168169170/**171* This attribute indicates that any upcoming changes to the value172* of the model should be considered a single event. This attribute173* will be set to true at the start of a series of changes to the value,174* and will be set to false when the value has finished changing. Normally175* this allows a listener to only take action when the final value change in176* committed, instead of having to do updates for all intermediate values.177* <p>178* Sliders and scrollbars use this property when a drag is underway.179*180* @param b true if the upcoming changes to the value property are part of a series181*/182void setValueIsAdjusting(boolean b);183184185/**186* Returns true if the current changes to the value property are part187* of a series of changes.188*189* @return the valueIsAdjustingProperty.190* @see #setValueIsAdjusting191*/192boolean getValueIsAdjusting();193194195/**196* Returns the model's extent, the length of the inner range that197* begins at the model's value.198*199* @return the value of the model's extent property200* @see #setExtent201* @see #setValue202*/203int getExtent();204205206/**207* Sets the model's extent. The <I>newExtent</I> is forced to208* be greater than or equal to zero and less than or equal to209* maximum - value.210* <p>211* When a BoundedRange model is used with a scrollbar the extent212* defines the length of the scrollbar knob (aka the "thumb" or213* "elevator"). The extent usually represents how much of the214* object being scrolled is visible. When used with a slider,215* the extent determines how much the value can "jump", for216* example when the user presses PgUp or PgDn.217* <p>218* Notifies any listeners if the model changes.219*220* @param newExtent the model's new extent221* @see #getExtent222* @see #setValue223*/224void setExtent(int newExtent);225226227228/**229* This method sets all of the model's data with a single method call.230* The method results in a single change event being generated. This is231* convenient when you need to adjust all the model data simultaneously and232* do not want individual change events to occur.233*234* @param value an int giving the current value235* @param extent an int giving the amount by which the value can "jump"236* @param min an int giving the minimum value237* @param max an int giving the maximum value238* @param adjusting a boolean, true if a series of changes are in239* progress240*241* @see #setValue242* @see #setExtent243* @see #setMinimum244* @see #setMaximum245* @see #setValueIsAdjusting246*/247void setRangeProperties(int value, int extent, int min, int max, boolean adjusting);248249250/**251* Adds a ChangeListener to the model's listener list.252*253* @param x the ChangeListener to add254* @see #removeChangeListener255*/256void addChangeListener(ChangeListener x);257258259/**260* Removes a ChangeListener from the model's listener list.261*262* @param x the ChangeListener to remove263* @see #addChangeListener264*/265void removeChangeListener(ChangeListener x);266267}268269270