Class VariableSlider
- All Implemented Interfaces:
InputObject
,Tieable
,Value
,Adjustable
,ImageObserver
,MenuContainer
,Serializable
,Accessible
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.)
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.awt.Scrollbar
Scrollbar.AccessibleAWTScrollBar
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
If this is true, then the value of the variable associated with this slider is an integer.protected int
The number of possible value of the scrollbar (Unless integerValued is true.)protected Value
The Values that specify the range of values represented by the slider.protected double
The values found for min and max the last time checkInput() was called.protected Value
The Values that specify the range of values represented by the slider.protected double
The values found for min and max the last time checkInput() was called.protected boolean
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
This is the position of the scrollbar the last time getVal() or setVal() was called.protected long
This increases every time the value of the variable changes.protected edu.hws.jcm.awt.VariableSlider.VS
The variable associated with this VariableSlider.Fields inherited from class java.awt.Scrollbar
HORIZONTAL, VERTICAL
Fields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.Adjustable
NO_ORIENTATION
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a horizontal variable slider with no name and with a default value range of -5 to 5.VariableSlider
(Value min, Value max) Create a horizontal variable slider with no name and with the specified range of values.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). -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
From the InputObject interface.boolean
Return a boolean which is true if the VariableSlider restricts ranges of values to integers, false otherwise.getMax()
Get the Value object that gives the value of the variable when the slider is at the right (or top) of the scrollbar.getMin()
Get the Value object that gives the value of the variable when the slider is at the left (or bottom) of the scrollbar.Return the Controller, if any, that is notified when the user adjusts the position of the scroll bar.Modify getPreferredSize to return a width of 200, if the scrollbar is horzontal, or a height of 200, if it is vertical.long
Return this object's serial number, which is increased every time the value changes.double
getVal()
Get the value of this VariableSlider.Return the variable associated with this VariableSlider.void
Method required by InputObject interface; in this class, it simply calls setOnUserAction(c).void
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
Set the value that the variable has when the slider is at the right (or top) of the scrollbar.void
Set the value that the variable has when the slider is at the left (or bottom) of the scrollbar.void
Set the name of the associated variable.void
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
Change the value and serial number of this object to match those of newest.Methods inherited from class java.awt.Scrollbar
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
Methods inherited from class java.awt.Component
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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
-
Field Details
-
variable
protected edu.hws.jcm.awt.VariableSlider.VS variableThe variable associated with this VariableSlider. VS is a nested private class, defined below. -
min
The Values that specify the range of values represented by the slider. min does not have to be less than max. -
max
The Values that specify the range of values represented by the slider. min does not have to be less than max. -
integerValued
protected boolean integerValuedIf this is true, then the value of the variable associated with this slider is an integer. Furthermore, the number of intervals on the slider is set to be the same as the range of possible values (unless this range is too big). -
intervals
protected int intervalsThe number of possible value of the scrollbar (Unless integerValued is true.) -
serialNumber
protected long serialNumberThis increases every time the value of the variable changes. -
needsValueCheck
protected boolean needsValueCheckThis 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. -
oldPosition
protected int oldPositionThis is the position of the scrollbar the last time getVal() or setVal() was called. It is used to check whether the user has repositioned the slider. -
minVal
protected double minValThe values found for min and max the last time checkInput() was called. -
maxVal
protected double maxValThe values found for min and max the last time checkInput() was called.
-
-
Constructor Details
-
VariableSlider
public VariableSlider()Create a horizontal variable slider with no name and with a default value range of -5 to 5. -
VariableSlider
Create a horizontal variable slider with no name and with the specified range of values. If min is null, a default value -5 is used. If max is null, a default value 5 is used. -
VariableSlider
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). If min is null, a default value -5 is used. If max is null, a default value 5 is used. -
VariableSlider
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). The "intervals" parameter specifes how many different positions there are on the slider. (The value of the scrollbar ranges from 0 to intervals.) If intervals is invalid input: '<'= 0, it will be set to 1000. If it is between 1 and 9, it will be set to 10. The orientation must be either Scrollbar.HORIZONTAL or Scrollbar.VERTICAL. It specifies whether this is a horizontal or vertical scrollbar. If min is null, a default value -5 is used. If max is null, a default value 5 is used.- Parameters:
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.
-
-
Method Details
-
setName
Set the name of the associated variable. You shouldn't do this if it has been added to a parser. If name is non-null, then the name of this Component is also set to the specified name. -
addTo
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). -
getVariable
Return the variable associated with this VariableSlider. -
setIntegerValued
public void setIntegerValued(boolean b) If set to true, restrict the values of the variable associated with this slider to be integers. Furthermore, the number of intervals on the scrollbar will be set to be the same as the size of the range from min to max (unless this range is too big). The setVal() method can still set the value of the variable to be a non-integer. -
getIntegerValued
public boolean getIntegerValued()Return a boolean which is true if the VariableSlider restricts ranges of values to integers, false otherwise. -
setMin
Set the value that the variable has when the slider is at the left (or bottom) of the scrollbar. If v is null, -5 is used as the default value. -
setMax
Set the value that the variable has when the slider is at the right (or top) of the scrollbar. If v is null, 5 is used as the default 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. The Value is always non-null. -
getMax
Get the Value object that gives the value of the variable when the slider is at the right (or top) of the scrollbar. The Value is always non-null. -
setOnUserAction
If the Controller, c, is non-null, then its compute method will be called whenever the user adjusts the position of the scroll bar. -
notifyControllerOnChange
Method required by InputObject interface; in this class, it simply calls setOnUserAction(c). This is meant to be called by JCMPanel.gatherInputs().- Specified by:
notifyControllerOnChange
in interfaceInputObject
-
getOnUserAction
Return the Controller, if any, that is notified when the user adjusts the position of the scroll bar. -
getSerialNumber
public long getSerialNumber()Return this object's serial number, which is increased every time the value changes.- Specified by:
getSerialNumber
in interfaceTieable
-
sync
Change the value and serial number of this object to match those of newest. See the Tie class for more information. This is not meant to be called directly -
getVal
public double getVal()Get the value of this VariableSlider. (If needsValueCheck is true, then the value is recomputed. Otherwise, the current value is returned.) -
setVal
public void setVal(double x) Set the value of the variable to x. If possible, set the value on the scroll bar to match. -
checkInput
public void checkInput()From the InputObject interface. This will force the slider to recompute its max and min values, and possibly clamp its value between these two extremes) the next time the value or serial number is checked. This is ordinarily called by a Controller.- Specified by:
checkInput
in interfaceInputObject
-
getPreferredSize
Modify getPreferredSize to return a width of 200, if the scrollbar is horzontal, or a height of 200, if it is vertical. This is not meant to be called directly.- Overrides:
getPreferredSize
in classComponent
-
processAdjustmentEvent
Overridden to call onUserAction.compute() if onUserAction is non-null. This is not meant to be called directly.- Overrides:
processAdjustmentEvent
in classScrollbar
-