|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JSlider net.sourceforge.webcompmath.awt.VariableJSlider
public class VariableJSlider
A VariableJSlider is a slider (implemented as a JSlider) whose position represents the value of an associated variable. The range of values represented by the slider is given by a pair of Value objects. They can be specified in the constructor or later with the setMin and setMax methods. A VariableJSlider has an associated variable that represents the value of the slider. Note that the value of the variable can change only when the setInput() or checkInput() method is called. If you want the value of the variable to track the position of the slider as it is is manipulated by the user, add the slider to a Controller and set the Controller as the Slider's "onUserAction" property. This allows other objects that depend on the values of the slider to be recomputed by the controller when the value changes, as long as they are also registered with the Controller.
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 VariableJSlider never throws WCMErrors. If an error occurs when min or max is evaluated, the value of the variable associated with this VariableJSlider 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.)
You can also display value labels for the slider by using
setPaintLabels(true)
. This labels the two ends and the middle
of the slider. If you want more labels or you want tick marks, you will need
to dig into using the JSlider methods directly.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JSlider |
---|
javax.swing.JSlider.AccessibleJSlider |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
java.awt.Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary | |
---|---|
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 slider (Unless integerValued is true.) |
protected Value |
intervalsValue
The number of possible values of the slider, represented as a Value. |
protected Value |
max
The max value. |
protected double |
maxVal
The value found for 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 value found for min 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 slider the last time getVal() or setVal() was called. |
protected long |
serialNumber
This increases every time the value of the variable changes. |
protected net.sourceforge.webcompmath.awt.VariableJSlider.VS |
variable
The variable associated with this VariableJSlider. |
Fields inherited from class javax.swing.JSlider |
---|
changeEvent, changeListener, majorTickSpacing, minorTickSpacing, orientation, sliderModel, snapToTicks |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface javax.swing.SwingConstants |
---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
VariableJSlider()
Create a horizontal variable slider with no name and with a default value range of -5 to 5. |
|
VariableJSlider(java.lang.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). |
|
VariableJSlider(java.lang.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). |
|
VariableJSlider(Value min,
Value max)
Create a horizontal variable slider with no name and with the specified range of values. |
Method Summary | |
---|---|
void |
addTo(Parser p)
A convenience method that registers this VariableJSlider's variable with p (but only if both p and the name of the variable are non-null). |
void |
adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)
Overridden to call onUserAction.compute() if onUserAction is non-null. |
void |
checkInput()
From the InputObject interface. |
boolean |
getIntegerValued()
Return a boolean which is true if the VariableJSlider restricts ranges of values to integers, false otherwise. |
int |
getIntervals()
Get the number of discrete slider steps |
Value |
getIntervalsValue()
Get the number of slider steps as a Value object. |
Value |
getMax()
Get the Value object that gives the value of the variable when the slider is at the right (or top) of the slider. |
Value |
getMin()
Get the Value object that gives the value of the variable when the slider is at the left (or bottom) of the slider. |
Controller |
getOnUserAction()
Return the Controller, if any, that is notified when the user adjusts the position of the scroll bar. |
java.awt.Dimension |
getPreferredSize()
Modify getPreferredSize to return a width of 200, if the slider 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 VariableJSlider. |
Variable |
getVariable()
Return the variable associated with this VariableJSlider. |
void |
notifyControllerOnChange(Controller c)
Method required by InputObject interface; in this class, it simply calls setOnUserAction(c). |
void |
setIntegerValued(boolean b)
If set to true, restrict the values of the variable associated with this slider to be integers. |
void |
setIntervals(int intervals)
Set the number of discrete slider steps |
void |
setIntervalsValue(Value v)
Set the number of slider steps as a Value object. |
void |
setMax(Value v)
Set the value that the variable has when the slider is at the right (or top) of the slider. |
void |
setMin(Value v)
Set the value that the variable has when the slider is at the left (or bottom) of the slider. |
void |
setName(java.lang.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. |
Methods inherited from class javax.swing.JSlider |
---|
addChangeListener, createChangeListener, createStandardLabels, createStandardLabels, fireStateChanged, getAccessibleContext, getChangeListeners, getExtent, getInverted, getLabelTable, getMajorTickSpacing, getMaximum, getMinimum, getMinorTickSpacing, getModel, getOrientation, getPaintLabels, getPaintTicks, getPaintTrack, getSnapToTicks, getUI, getUIClassID, getValue, getValueIsAdjusting, paramString, removeChangeListener, setExtent, setFont, setInverted, setLabelTable, setMajorTickSpacing, setMaximum, setMinimum, setMinorTickSpacing, setModel, setOrientation, setPaintLabels, setPaintTicks, setPaintTrack, setSnapToTicks, setUI, setValue, setValueIsAdjusting, updateLabelUIs, updateUI |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
---|
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected net.sourceforge.webcompmath.awt.VariableJSlider.VS variable
protected Value min
protected Value max
protected boolean integerValued
protected int intervals
protected Value intervalsValue
protected long serialNumber
protected boolean needsValueCheck
protected int oldPosition
protected double minVal
protected double maxVal
Constructor Detail |
---|
public VariableJSlider()
public VariableJSlider(Value min, Value max)
min
- min value for rangemax
- max value for rangepublic VariableJSlider(java.lang.String name, Value min, Value max, Parser p)
name
- name of slidermin
- min value for rangemax
- max value for rangep
- parser to usepublic VariableJSlider(java.lang.String name, Value min, Value max, Parser p, int intervals, int orientation)
name
- name for this VariableJSlider.min
- minimum value for slider.max
- maximum value for slider.p
- register VariableJSlider with this Parser.intervals
- discrete positions on slider.orientation
- slider.HORIZONTAL or slider.VERTICAL.Method Detail |
---|
public void setName(java.lang.String name)
setName
in class java.awt.Component
name
- name of the variablepublic void addTo(Parser p)
p
- parser to usepublic Variable getVariable()
public void setIntegerValued(boolean b)
b
- true or falsepublic boolean getIntegerValued()
public void setMin(Value v)
v
- value to setpublic void setMax(Value v)
v
- value to setpublic Value getMin()
public Value getMax()
public void setOnUserAction(Controller c)
c
- the controller to usepublic void notifyControllerOnChange(Controller c)
notifyControllerOnChange
in interface InputObject
c
- controller to notifypublic Controller getOnUserAction()
public long getSerialNumber()
getSerialNumber
in interface Tieable
public void sync(Tie tie, Tieable newest)
sync
in interface Tieable
tie
- the tie that connects the objectsnewest
- the object to synch withpublic double getVal()
getVal
in interface Value
public void setVal(double x)
x
- the value to setpublic void checkInput()
checkInput
in interface InputObject
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JComponent
public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt)
adjustmentValueChanged
in interface java.awt.event.AdjustmentListener
evt
- the event created when user adjusts the sliderpublic int getIntervals()
public void setIntervals(int intervals)
intervals
- the intervals to setpublic Value getIntervalsValue()
public void setIntervalsValue(Value v)
v
- the Value for the number of steps
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |