Menu

Spark Range

SourceForge Editorial Staff

Spark Range - Functional and Design Specification


Glossary


scale - the scale of a Range is the set of allowed numbers that the value property can take on. The allowed numbers are increments of the snapInterval starting from minimum, but also includes the maximum. For example, a Range with:

minimum = -1
maximum = 10
snapInterval = 3

would have a scale of [-1, 2, 5, 8, 10].

Summary and Background


The Range base class provides basic functionality for a value constrained by a maximum and minimum as well as restricting the value to a certain increment. Range inherits from SkinnableComponent and subclasses include TrackBase and Spinner.

This class allows us to unify ideas of a scale and stepping across subclasses.

Usage Scenarios


Detailed Description


Properties

value - The current value. The default is 0.

minimum, maximum - The minimum and maximum values that constrain value. The minimum may not be > maximum nor can the maximum be < minimum, but they can be equal. The defaults of minimum and maximum are 0 and 100.

snapInterval - If greater than 0, snapInterval constrains the value of the Range to be increments of snapInterval starting from the minimum, but less than the maximum. If snapInterval is 0, then the value can be any number between minimum and maximum. Also, the value may always be set to the maximum. The default of snapInterval is 1.

stepSize - stepSize is the amount that the value changes when changeValueByStep() is called. It must be a multiple of snapInterval unless snapInterval is 0. If the stepSize is not a multiple of snapInterval, it is rounded to the nearest multiple >= snapInterval. The default of stepSize is 1. Also, if stepSize is explicitly set but snapInterval is not, snapInterval will default to stepSize until snapInterval is explicitly set.

Events

valueCommit - The "valueCommit" event is dispatched when the value changes.

Public Methods

changeValueByStep() - The changeValueByStep() method will step the value up or down by stepSize depending on the parameter given.

Protected Methods

nearestValidValue() - Rounds the given value to the closest increment of interval starting from the minimum, but less than or equal to the maximum. If interval is 0, then the value is only constrained by the maximum and minimum.

setValue() - Sets the backing store for value and dispatches a valueCommit event.

API Description


package spark.components.supportClasses
{

import flash.events.Event;

import spark.components.supportClasses.SkinnableComponent

import mx.events.FlexEvent;

/**
 *  The Range class holds a value and an allowed range for that 
 *  value, defined by <code>minimum</code> and <code>maximum</code> properties. 
 *  The <code>value</code> property 
 *  is always constrained to be between the current <code>minimum</code> and
 *  <code>maximum</code>, and the <code>minimum</code>,
 *  and <code>maximum</code> are always constrained
 *  to be in the proper numerical order, such that
 *  <code>(minimum &lt;= value &lt;= maximum)</code> is <code>true</code>. 
 *  If the value of the <code>snapInterval</code> property is not 0, 
 *  then the <code>value</code> property is also constrained to be a multiple of 
 *  <code>snapInterval</code>.
 * 
 *  <p>Range is a base class for various controls that require range
 *  functionality, including TrackBase and Spinner.</p>
 * 
 *  @see spark.components.supportClasses.TrackBase
 *  @see spark.components.Spinner
 */  
public class Range extends SkinnableComponent
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Constructor
    //
    //--------------------------------------------------------------------------

    /**
     *  Constructor. 
     */
    public function Range():void;

    //--------------------------------------------------------------------------
    //
    //  Properties
    //
    //--------------------------------------------------------------------------

    //---------------------------------
    // maximum
    //---------------------------------

    /**
     *  The maximum valid <code>value</code>.
     * 
     *  <p>Changes to the value property are constrained
     *  by <code>commitProperties()</code> to be less than or equal to
     *  maximum with the <code>nearestValidValue()</code> method.</p> 
     *
     *  @default 100
     */
    public function get maximum():Number;
    public function set maximum(value:Number):void;

    //---------------------------------
    // minimum
    //---------------------------------

    /**
     *  The minimum valid <code>value</code>.
     * 
     *  <p>Changes to the value property are constrained
     *  by <code>commitProperties()</code> to be greater than or equal to
     *  minimum with the <code>nearestValidValue()</code> method.</p> 
     *
     *  @default 0
     */
    public function get minimum():Number;
    public function set minimum(value:Number):void;

    //---------------------------------
    // stepSize
    //---------------------------------

    /**
     *  The amount that the <code>value</code> property 
     *  changes when the <code>changeValueByStep()</code> method is called. It must
     *  be a multiple of <code>snapInterval</code>, unless 
     *  <code>snapInterval</code> is 0. 
     *  If <code>stepSize</code>
     *  is not a multiple, it is rounded to the nearest 
     *  multiple that is greater than or equal to <code>snapInterval</code>.
     *
     *  @default 1
     */
    public function get stepSize():Number;
    public function set stepSize(value:Number):void;

    //---------------------------------
    // value
    //---------------------------------

    <a href="Bindable%28event%3D%26quot%3BvalueCommit%26quot%3B%29">Bindable(event="valueCommit")</a>

    /**
     *  The current value for this range.
     *  
     *  <p>Changes to the value property are constrained
     *  by <code>commitProperties()</code> to be greater than or equal to
     *  the <code>minimum</code> property, less than or equal to the <code>maximum</code> property, and a
     *  multiple of <code>snapInterval</code> with the <code>nearestValidValue()</code>
     *  method.</p> 
     * 
     *  @default 0
     */
    public function get value():Number;
    public function set value(newValue:Number):void;

    //---------------------------------
    // snapInterval
    //---------------------------------

    /**
     *  If nonzero, valid values are the sum of the minimum with integer multiples
     *  of this property and less than or equal to the maximum.
     *  
     *  <p>If the value of this property is zero, then valid values are only constrained
     *  to be between minimum and maximum inclusive.</p>
     * 
     *  <p>This property also constrains valid values for the <code>stepSize</code> property when set.
     *  If this property is not explicitly set and <code>stepSize</code> is set, 
     *  then <code>snapInterval</code> defaults to <code>stepSize</code>.</p>
     *  
     *  @default 1
     */
    public function get snapInterval():Number;
    public function set snapInterval(value:Number):void;

    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------

    /**
     *  Returns the sum of the minimum with an integer multiple of <code>interval</code> that's 
     *  closest to <code>value</code>, unless <code>value</code> is closer to the maximum limit,
     *  in which case the maximum is returned.
     * 
     *  <p>If <code>interval</code> is equal to 0, the value is clipped to the minimum and maximum 
     *  limits.</p>
     * 
     *  <p>The valid values for a range are defined by the sum of the <code>minimum</code> property
     *  with multiples of the <code>interval</code> and also defined to be less than or equal to the
     *  <code>maximum</code> property.
     * 
     *  The maximum need not be a multiple of <code>snapInterval</code>.</p>
     * 
     *  <p>For example, if <code>minimum</code> is equal to 1, <code>maximum</code> is equal to 6,
     *  and <code>snapInterval</code> is equal to 2, the valid
     *  values for the Range are 1, 3, 5, 6.
     * 
     *  Similarly, if <code>minimum</code> is equal to 2, <code>maximum</code> is equal to 9,
     *  and <code>snapInterval</code> is equal to 1.5, the valid
     *  values for the Range are 2, 3.5, 5, 6.5, 8, and 9.</p>
     * 
     *  @param value The input value.
     *  @param interval The value of snapInterval or an integer multiple of snapInterval.
     *  @return The valid value that's closest to the input.
     */
    protected function nearestValidValue(value:Number, interval:Number):Number;

    /**
     *  Sets the backing store for the <code>value</code> property and 
     *  dispatches a <code>valueCommit</code> event if the property changes.  
     * 
     *  <p>All updates to the <code>value</code> property cause a call to this method.</p>
     * 
     *  <p>This method assumes that the caller has already used the <code>nearestValidValue()</code> method
     *  to constrain the value parameter</p>
     * 
     *  @param value The new value of the <code>value</code> property.
     */
    protected function setValue(value:Number):void;

    /**
     *  Increases or decreases <code>value</code> by <code>stepSize</code>.
     *
     *  @param increase If true, adds <code>stepSize</code> to <code>value</code>, otherwise, subtracts it.
     */
    public function changeValueByStep(increase:Boolean = true):void;
}

}

B Features


Additional Implementation Details


none

Prototype Work


Compiler Work


none

Web Tier Compiler Impact


none

Flex Feature Dependencies


Backwards Compatibility


Syntax changes

None - New Class

Behavior

None

Warnings/Deprecation

None

Accessibility


Support Halo equivalent.

Performance


none.

Globalization


none

Localization


Compiler Features

none.

Documentation


Yes.

QA


Yes.



Related

Wiki: Flex 4
Wiki: Spark NumericStepper
Wiki: Spark ScrollBar
Wiki: Spark Slider
Wiki: Spark Spinner
Wiki: Spark TrackBase

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.