public class VariableSlider extends Scrollbar implements InputObject, Tieable, Value
Some points to note: 1) setVal() can set a value outside the range from min to max, which will persist until the next time checkInput() or setVal() is called again. 2) If the value of min or max changes, the value of this variable will not change EXCEPT that it is clamped to the range between min and max. 3) Min does not have to be less than max. 4) The checkInput() routine only sets the needValueCheck flag to true. (The setVal() and getVal() routines both set this flag to false.) This "lazy evaluation" is used because checkInput() can't compute the new value itself. (The max and min might depend on Values that are themselves about to change when some other object's checkInput() mehtod is called.) 5) getVal() returns the current value, as stored in the variable, UNLESS needValueCheck is true. In that case, it recomputes the value first. getSerialNumber() works similarly. 6) A VariableSlider never throws JCMErrors. If an error occurs when min or max is evaluated, the value of the variable associated with this VariableSlider becomes undefined. (The point is, it doesn't generate any errors of its own. The error would be caused by other InputObjects which should throw their own errors when their checkInput() methods are called.)
Scrollbar.AccessibleAWTScrollBar
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected boolean |
integerValued
If this is true, then the value of the
variable associated with this slider is
an integer.
|
protected int |
intervals
The number of possible value of the scrollbar
(Unless integerValued is true.)
|
protected Value |
max
The Values that specify the range of values represented
by the slider.
|
protected double |
maxVal
The values found for min and max the last time
checkInput() was called.
|
protected Value |
min
The Values that specify the range of values represented
by the slider.
|
protected double |
minVal
The values found for min and max the last time
checkInput() was called.
|
protected boolean |
needsValueCheck
This is set to true when checkInput() is called
to indicate that the min and max values must be
checked the next time getVal() is called.
|
protected int |
oldPosition
This is the position of the scrollbar the last time
getVal() or setVal() was called.
|
protected long |
serialNumber
This increases every time the value of the variable changes.
|
protected edu.hws.jcm.awt.VariableSlider.VS |
variable
The variable associated with this VariableSlider.
|
HORIZONTAL, VERTICAL
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
NO_ORIENTATION
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
VariableSlider()
Create a horizontal variable slider with no name and with a default
value range of -5 to 5.
|
VariableSlider(String name,
Value min,
Value max,
Parser p)
Create a horizontal variable slider with the given name and range of
values, and register it with the given parser (but only if
both name and p are non-null).
|
VariableSlider(String name,
Value min,
Value max,
Parser p,
int intervals,
int orientation)
Create a variable slider with the given name and range of
values, and register it with the given parser (but only if
both name and p are non-null).
|
VariableSlider(Value min,
Value max)
Create a horizontal variable slider with no name and with the
specified range of values.
|
Modifier and Type | Method and Description |
---|---|
void |
addTo(Parser p)
A convenience method that registers this VariableSlider's variable
with p (but only if both p and the name of the variable are non-null).
|
void |
checkInput()
From the InputObject interface.
|
boolean |
getIntegerValued()
Return a boolean which is true if the VariableSlider restricts ranges of values to integers, false otherwise.
|
Value |
getMax()
Get the Value object that gives the value of the variable when the slider is
at the right (or top) of the scrollbar.
|
Value |
getMin()
Get the Value object that gives the value of the variable when the slider is
at the left (or bottom) of the scrollbar.
|
Controller |
getOnUserAction()
Return the Controller, if any, that is notified when the user
adjusts the position of the scroll bar.
|
Dimension |
getPreferredSize()
Modify getPreferredSize to return a width of
200, if the scrollbar is horzontal, or a height
of 200, if it is vertical.
|
long |
getSerialNumber()
Return this object's serial number, which is increased every time the
value changes.
|
double |
getVal()
Get the value of this VariableSlider.
|
Variable |
getVariable()
Return the variable associated with this VariableSlider.
|
void |
notifyControllerOnChange(Controller c)
Method required by InputObject interface; in this class, it simply calls
setOnUserAction(c).
|
void |
processAdjustmentEvent(AdjustmentEvent evt)
Overridden to call onUserAction.compute() if onUserAction is non-null.
|
void |
setIntegerValued(boolean b)
If set to true, restrict the values of the variable associated with this
slider to be integers.
|
void |
setMax(Value v)
Set the value that the variable has when the slider is at the right (or
top) of the scrollbar.
|
void |
setMin(Value v)
Set the value that the variable has when the slider is at the left (or
bottom) of the scrollbar.
|
void |
setName(String name)
Set the name of the associated variable.
|
void |
setOnUserAction(Controller c)
If the Controller, c, is non-null, then its compute method will be called whenever
the user adjusts the position of the scroll bar.
|
void |
setVal(double x)
Set the value of the variable to x.
|
void |
sync(Tie tie,
Tieable newest)
Change the value and serial number of this object to match
those of newest.
|
addAdjustmentListener, addNotify, getAccessibleContext, getAdjustmentListeners, getBlockIncrement, getLineIncrement, getListeners, getMaximum, getMinimum, getOrientation, getPageIncrement, getUnitIncrement, getValue, getValueIsAdjusting, getVisible, getVisibleAmount, paramString, processEvent, removeAdjustmentListener, setBlockIncrement, setLineIncrement, setMaximum, setMinimum, setOrientation, setPageIncrement, setUnitIncrement, setValue, setValueIsAdjusting, setValues, setVisibleAmount
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
protected edu.hws.jcm.awt.VariableSlider.VS variable
protected Value min
protected Value max
protected boolean integerValued
protected int intervals
protected long serialNumber
protected boolean needsValueCheck
protected int oldPosition
protected double minVal
protected double maxVal
public VariableSlider()
public VariableSlider(Value min, Value max)
public VariableSlider(String name, Value min, Value max, Parser p)
public VariableSlider(String name, Value min, Value max, Parser p, int intervals, int orientation)
name
- name for this VariableSlider.min
- minimum value for slider.max
- maximum value for slider.p
- register VariableSlider with this Parser.intervals
- discrete positions on slider.orientation
- Scrollbar.HORIZONTAL or Scrollbar.VERTICAL.public void setName(String name)
public void addTo(Parser p)
public Variable getVariable()
public void setIntegerValued(boolean b)
public boolean getIntegerValued()
public void setMin(Value v)
public void setMax(Value v)
public Value getMin()
public Value getMax()
public void setOnUserAction(Controller c)
public void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
public Controller getOnUserAction()
public long getSerialNumber()
getSerialNumber
in interface Tieable
public void sync(Tie tie, Tieable newest)
public double getVal()
public void setVal(double x)
public void checkInput()
checkInput
in interface InputObject
public Dimension getPreferredSize()
getPreferredSize
in class Component
public void processAdjustmentEvent(AdjustmentEvent evt)
processAdjustmentEvent
in class Scrollbar