FileDocCategorySizeDatePackage
ConverterRangeModel.javaAPI DocExample5720Tue Dec 12 18:59:14 GMT 2000None

ConverterRangeModel

public class ConverterRangeModel extends Object implements BoundedRangeModel
Based on the source code for DefaultBoundedRangeModel, this class stores its value as a double, rather than an int. The minimum value and extent are always 0.

Fields Summary
protected ChangeEvent
changeEvent
protected EventListenerList
listenerList
protected int
maximum
protected int
minimum
protected int
extent
protected double
value
protected double
multiplier
protected boolean
isAdjusting
static final boolean
DEBUG
Constructors Summary
public ConverterRangeModel()


      
    
Methods Summary
public voidaddChangeListener(javax.swing.event.ChangeListener l)

        listenerList.add(ChangeListener.class, l);
    
protected voidfireStateChanged()

        Object[] listeners = listenerList.getListenerList();
        for (int i = listeners.length - 2; i >= 0; i -=2 ) {
            if (listeners[i] == ChangeListener.class) {
                if (changeEvent == null) {
                    changeEvent = new ChangeEvent(this);
                }
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
            }
        }
    
public doublegetDoubleValue()

        if (DEBUG) {
            System.out.println("In ConverterRangeModel getDoubleValue");
        }
        return value;
    
public intgetExtent()

        return (int)extent;
    
public intgetMaximum()

        if (DEBUG) {
            System.out.println("In ConverterRangeModel getMaximum");
        }
        return maximum;
    
public intgetMinimum()

        return (int)minimum;
    
public doublegetMultiplier()

        if (DEBUG) {
            System.out.println("In ConverterRangeModel getMultiplier");
        }
        return multiplier;
    
public intgetValue()

        if (DEBUG) {
            System.out.println("In ConverterRangeModel getValue");
        }
        return (int)getDoubleValue();
    
public booleangetValueIsAdjusting()

        return isAdjusting;
    
public voidremoveChangeListener(javax.swing.event.ChangeListener l)

        listenerList.remove(ChangeListener.class, l);
    
public voidsetDoubleValue(double newValue)

        if (DEBUG) {
            System.out.println("In ConverterRangeModel setDoubleValue");
        }
        setRangeProperties(newValue, extent, minimum, maximum, isAdjusting);
    
public voidsetExtent(int newExtent)

        //Do nothing.
    
public voidsetMaximum(int newMaximum)

        if (DEBUG) {
            System.out.println("In ConverterRangeModel setMaximum");
        }
        setRangeProperties(value, extent, minimum, newMaximum, isAdjusting);
    
public voidsetMinimum(int newMinimum)

        System.out.println("In ConverterRangeModel setMinimum");
        //Do nothing.
    
public voidsetMultiplier(double multiplier)

        if (DEBUG) {
            System.out.println("In ConverterRangeModel setMultiplier");
        }
        this.multiplier = multiplier;
        fireStateChanged();
    
public voidsetRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean newAdjusting)

        System.out.println("In ConverterRangeModel setRangeProperties");
        setRangeProperties((double)newValue,
                           newExtent,
                           newMin,
                           newMax,
                           newAdjusting);
    
public voidsetRangeProperties(double newValue, int unusedExtent, int unusedMin, int newMax, boolean newAdjusting)

        if (DEBUG) {
            System.out.println("setRangeProperties(): "
                                + "newValue = " + newValue
                                + "; newMax = " + newMax);
        }
        if (newMax <= minimum) {
            newMax = minimum + 1;
            if (DEBUG) {
                System.out.println("maximum raised by 1 to " + newMax);
            }
        }
        if (Math.round(newValue) > newMax) { //allow some rounding error
            newValue = newMax;
            if (DEBUG) {
                System.out.println("value lowered to " + newMax);
            }
        }

        boolean changeOccurred = false;
        if (newValue != value) {
            if (DEBUG) {
                System.out.println("value set to " + newValue);
            }
            value = newValue;
            changeOccurred = true;
        }
        if (newMax != maximum) {
            if (DEBUG) {
                System.out.println("maximum set to " + newMax);
            }
            maximum = newMax;
            changeOccurred = true;
        }
        if (newAdjusting != isAdjusting) {
            maximum = newMax;
            isAdjusting = newAdjusting;
            changeOccurred = true;
        }

        if (changeOccurred) {
            fireStateChanged();
        }
    
public voidsetValue(int newValue)

        if (DEBUG) {
            System.out.println("In ConverterRangeModel setValue");
        }
        setDoubleValue((double)newValue);
    
public voidsetValueIsAdjusting(boolean b)

        setRangeProperties(value, extent, minimum, maximum, b);