|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.swing.visuals.SpinButton
public class SpinButton
SpinButton is a class that creates a component with two opposing arrow buttons
that can be pressed to increment or decrement a value field.
Creating a SpinButton Component
A valid instance is created by instantiating an object of SpinButton from one of the two constructors.
// Default Constructor SpinButton spinButton1 = new SpinButton(); // Sets the initial values SpinButton spinButton2 = new SpinButton( initialValue, minimum, maximum, unitIncrement, blockIncrement, orientation );
Usage
Setting up a Model
The SpinButton component uses a model that implements the com.sas.models.BoundedNumberInterface. A default model of BoundedLong is created and attached in setDefaultValues(). To dettach the model call setModel(null).
Range
The range of the SpinButton can be set using the setMinium(int) and setMaximum(int) methods. The SpinButton value will increment/decrement to the minimum and maximum values, inclusively. A click of the increment or decrement button will change the value by the unitIncrement amount.
Orientation
The SpinButton arrows can be positioned either horizontally or vertically based on the orientation of the SpinButton. If the arrows are oriented horizontally the increment button is the right arrow and the decrement is the left arrow. If the arrows are oriented vertically the increment button is the top arrow and the decrement button is the bottom arrow. The functions of the buttons can be swapped by calling swapButtonFunctions().
Cycle
The SpinButton can be set to allow the value to cycle from minimum to maximum and back to minimum.
Alarm
An Alarm object can be set on the SpinButton to cause the buttons to increment everytime the alarm is fired while a button is held down. The start delay of the alarm allows time for a user to press and release the button without starting the alarm. Once the alarm is started, the interval used to fire the alarm is decremented by 100ms every time the alarm fires, to speed up the firing rate of the alarm, until the interval is less than or equal to 100ms.
Handling Events
The SpinButton sends out java.beans.PropertyChangeEvent events for all of its properties and also sends
out java.awt.event.AdjustmentEvent events when the value is changed.
Notes:
SpinBox
,
BoundedLong
,
BoundedDouble
,
BoundedNumberInterface
,
Serialized FormField Summary | |
---|---|
protected ArrowIcon |
decrementArrow
|
protected javax.swing.JButton |
decrementButton
|
protected com.sas.models.BoundedNumberInterface |
defaultRangeModel
the default range model for the spin button |
protected long |
delay
|
protected ArrowIcon |
incrementArrow
|
protected javax.swing.JButton |
incrementButton
|
static int |
LEFT_RIGHT
int values representing the orientation of the spinButton- LEFT_RIGHT |
protected com.sas.models.BoundedNumberInterface |
spinButtonModel
|
protected long |
startInterval
|
static int |
UP_DOWN
int values representing the orientation of the spinButton- UP_DOWN |
protected Alarm |
valueChangeAlarm
|
Constructor Summary | |
---|---|
SpinButton()
Default constructor. |
|
SpinButton(int value,
int min,
int max,
int unit,
int block,
int orient)
Constructor taking all the neccessary variables needed to create a spinButton. |
Method Summary | |
---|---|
void |
addAdjustmentListener(java.awt.event.AdjustmentListener l)
Add a listener to receive adjustment events when the value of the SpinButton changes. |
protected void |
checkEnabled()
Check if the buttons should be enabled or disabled based on the value and the maximum and the minimum. |
java.awt.Dimension |
computePreferredSize()
Get the preferredSize of the RadioButton. |
void |
fireAlarm(AlarmEvent evt)
Invoked when a AlarmEvent is fired by the alarm. |
Alarm |
getAlarm()
Deprecated. |
int |
getArrowDirection()
Get the direction the arrows are pointing. |
int |
getBlockIncrement()
Get the integer value of the blockIncrement property. |
java.lang.Number |
getBlockIncrementNumber()
Get the blockIncrement number based on the model. |
int |
getButtonGap()
Get the pixel value of the buttonGap property. |
static int |
getDefaultHeight()
Returns the default height in pixels |
static int |
getDefaultWidth()
Returns the default width in pixels |
long |
getDelay()
Get the delay before the alarm begins sending AlarmEvents. |
static com.sas.beans.ExtendedBeanInfo |
getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to
augment the automatically introspected information about a SpinButton. |
int |
getMaximum()
Get the value of the maximum property. |
java.lang.Number |
getMaximumNumber()
Get the maximum bounds number based on the model. |
int |
getMinimum()
Get the value of the minimum property. |
java.lang.Number |
getMinimumNumber()
Get the minimum bounds number based on the model. |
java.awt.Dimension |
getMinimumSize()
Get the preferredSize of the RadioButton. |
com.sas.models.BoundedNumberInterface |
getModel()
Returns the BoundedNumberInterface model that is set on the spinButton. |
java.lang.Number |
getNumberValue()
Get the value number based on the model. |
int |
getOrientation()
Get the value of the orientation property. |
java.awt.Dimension |
getPreferredSize()
Get the preferredSize of the RadioButton. |
java.util.Vector |
getRequiredInterfaces()
Returns the required interfaces Vector for this component. |
long |
getStartInterval()
Get the start interval for the alarm. |
int |
getUnitIncrement()
Get the value of the unitIncrement property. |
java.lang.Number |
getUnitIncrementNumber()
Get the unitIncrement number based on the model. |
int |
getValue()
Get the integer value of the value property. |
int |
getVisibleAmount()
NOT USED, only here to satisfy Adjustable interface and alway returns 0 |
java.lang.Number |
incrementBy(int increment,
int incrementType)
Increment, by unit or block increment amount, the current value by the specified number of increments. |
boolean |
isCycleOn()
Indicates whether the spinButton value is cycled to the opposite bound when the increment exceeds the bounds. |
boolean |
isDecrementEnabled()
Get the enabled state of the button that decrements the value. |
boolean |
isDefaultModelAttached()
Returns true if the default model is being used, false otherwise. |
boolean |
isIncrementEnabled()
Get the enabled state of the button that increments the value. |
void |
keyPressed(java.awt.event.KeyEvent e)
Process the key pressed event on one of the buttons. |
void |
keyReleased(java.awt.event.KeyEvent e)
Process the key being released on one of the buttons. |
void |
keyTyped(java.awt.event.KeyEvent e)
Process any key typed events down on the buttons. |
void |
mouseClicked(java.awt.event.MouseEvent e)
Process any mouse click events down on the buttons. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Process the mouse entering event. |
void |
mouseExited(java.awt.event.MouseEvent e)
Process the mouse exiting event. |
void |
mousePressed(java.awt.event.MouseEvent e)
Process the mouse pressed event on one of the buttons. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Process the mouse being released on one of the buttons. |
void |
paintComponent(java.awt.Graphics g)
Paint the SpinButton. |
protected void |
processAdjustmentEvent(java.awt.event.AdjustmentEvent e)
Process adjustment events. |
protected void |
processEvent(java.awt.AWTEvent e)
Process events. |
void |
propertyChange(java.beans.PropertyChangeEvent event)
Invoked when a bound property is changed. |
void |
refresh(com.sas.ModelInterface model)
Refresh the spinButton based on its model. |
void |
removeAdjustmentListener(java.awt.event.AdjustmentListener l)
Remove the adjustment listener. |
void |
setAlarm(Alarm alarm)
Deprecated. |
void |
setArrowDirection(int d)
Sets the direction the arrows are pointing. |
void |
setBlockIncrement(int block)
Sets the integer value of the blockIncrement property. |
void |
setBlockIncrementNumber(java.lang.Number block)
Sets the blockIncrement number. |
void |
setBounds(int x,
int y,
int width,
int height)
Call super.setBounds() and then repaint the entire component. |
void |
setButtonGap(int gap)
Sets the pixel value of the gap between the arrow buttons. |
void |
setCycleOn(boolean cycle)
Sets the SpinButton to cycle the value to the opposite bound when the bounds are reached. |
void |
setDecrementEnabled(boolean decrEnabled)
Sets the decrement button enabled. |
static void |
setDefaultHeight(int newHeight)
Sets the default height in pixels |
void |
setDefaultValues()
Sets the initial values to the default values. |
static void |
setDefaultWidth(int newWidth)
Sets the default width in pixels |
void |
setDelay(long d)
Sets the delay before the alarm begins sending AlarmEvents. |
void |
setEnabled(boolean enabled)
Sets the SpinButton enabled for user input. |
void |
setIncrementEnabled(boolean incrEnabled)
Sets the increment button enabled. |
void |
setMaximum(int max)
Sets the integer value of the maximum bounds. |
void |
setMaximumNumber(java.lang.Number max)
Sets the maximum bounds number. |
void |
setMinimum(int min)
Sets the integer value of the minimum property. |
void |
setMinimumNumber(java.lang.Number min)
Sets the minimum bounds number. |
void |
setModel(com.sas.models.BoundedNumberInterface model)
Sets the BoundedNUmberInterface model on the spinButton. |
void |
setNumberValue(java.lang.Number newValue)
Sets the number value. |
void |
setOrientation(int orient)
Sets the value of the orientation property, which determines the orientation of the SpinButton arrow buttons. |
void |
setStartInterval(long interval)
Sets the start interval for the alarm in milliseconds. |
void |
setToolTipText(java.lang.String text)
Registers the text to display in a tool tip. |
void |
setUnitIncrement(int unit)
Sets the integer value of the unitIncrement for the SpinButton. |
void |
setUnitIncrementNumber(java.lang.Number unit)
Sets the unitIncrement number. |
void |
setValue(int newValue)
Sets the integer value of the value property. |
void |
setVisibleAmount(int amount)
NOT USED, only here to satisfy Adjustable interface. |
void |
stopAdjusting()
Used to stop any incrementing or decrementing that is occurring on the spinButton. |
int |
swapButtonFunction()
Swaps the increment and decrement buttons, so if the incrementer was the Top or Left button, it is now the Bottom or Right button. |
Field Detail |
---|
protected Alarm valueChangeAlarm
protected long startInterval
protected long delay
protected javax.swing.JButton incrementButton
protected javax.swing.JButton decrementButton
protected ArrowIcon incrementArrow
protected ArrowIcon decrementArrow
protected com.sas.models.BoundedNumberInterface defaultRangeModel
protected com.sas.models.BoundedNumberInterface spinButtonModel
public static final int UP_DOWN
public static final int LEFT_RIGHT
Constructor Detail |
---|
public SpinButton()
public SpinButton(int value, int min, int max, int unit, int block, int orient)
value
- the current value within the rangemin
- the minimum valuemax
- the maximum valueunit
- the unit incrementblock
- the block incrementorient
- the orientation of the SpinButton arrow Buttons.Method Detail |
---|
public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
com.sas.beans.Introspector
to
augment the automatically introspected information about a SpinButton.
public static int getDefaultHeight()
setDefaultHeight(int)
public static int getDefaultWidth()
setDefaultWidth(int)
public static void setDefaultHeight(int newHeight)
newHeight
- - the desired default height in pixelsgetDefaultHeight()
public static void setDefaultWidth(int newWidth)
newWidth
- - the desired default width in pixelssetDefaultWidth(int)
public void setToolTipText(java.lang.String text)
setToolTipText
in class javax.swing.JComponent
text
- the string to display; if the text is null,
the tool tip is turned off for this componentpublic void addAdjustmentListener(java.awt.event.AdjustmentListener l)
addAdjustmentListener
in interface java.awt.Adjustable
l
- the adjustment listenerAdjustable.addAdjustmentListener(java.awt.event.AdjustmentListener)
,
AdjustmentEvent
public void removeAdjustmentListener(java.awt.event.AdjustmentListener l)
removeAdjustmentListener
in interface java.awt.Adjustable
l
- the adjustment listeneraddAdjustmentListener(java.awt.event.AdjustmentListener)
,
AdjustmentEvent
protected void checkEnabled()
public java.awt.Dimension computePreferredSize()
public void fireAlarm(AlarmEvent evt)
fireAlarm
in interface AlarmListener
evt
- the AlarmEvent firedpublic Alarm getAlarm()
setAlarm(com.sas.util.Alarm)
public int getArrowDirection()
setArrowDirection(int)
public final int getBlockIncrement()
getBlockIncrement
in interface java.awt.Adjustable
setBlockIncrement(int)
public int getButtonGap()
buttonGap
property.
The gap in pixel specifies the amount of space between the two
arrow buttons.
setButtonGap(int)
public long getDelay()
setDelay(long)
public final int getMaximum()
getMaximum
in interface java.awt.Adjustable
setMaximum(int)
public final int getMinimum()
getMinimum
in interface java.awt.Adjustable
setMinimum(int)
public int getOrientation()
getOrientation
in interface java.awt.Adjustable
Adjustable
,
setOrientation(int)
public java.util.Vector getRequiredInterfaces()
ViewInterface.getRequiredInterfaces()
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JComponent
public java.awt.Dimension getMinimumSize()
getMinimumSize
in class javax.swing.JComponent
public long getStartInterval()
setStartInterval(long)
public final int getUnitIncrement()
unitIncrement
property. This specifies
how much the value in the spin button will be incremented every time the up or
down arrows are pressed.
This method calls getUnitIncrementNumber() and returns intValue().
getUnitIncrement
in interface java.awt.Adjustable
setUnitIncrement(int)
public final int getValue()
getValue
in interface java.awt.Adjustable
setValue(int)
public int getVisibleAmount()
getVisibleAmount
in interface java.awt.Adjustable
public boolean isCycleOn()
public boolean isDecrementEnabled()
public boolean isIncrementEnabled()
public java.lang.Number incrementBy(int increment, int incrementType)
incrementBy
in interface com.sas.models.IncrementInterface
increment
- The number of incrementType(unit or block) amounts to increment
the current value(can be negative to decrement value).incrementType
- UNIT to increment by the unit amount;
BLOCK to increment by the block amountpublic void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
g
- the graphics contextpublic void stopAdjusting()
protected void processEvent(java.awt.AWTEvent e)
processEvent
in class java.awt.Container
e
- the awt event that has changedprotected void processAdjustmentEvent(java.awt.event.AdjustmentEvent e)
e
- the adjustment event that has changedpublic void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
e
- the mouse clicked eventpublic void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
e
- the mouse entered eventpublic void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
the
- mouse exiting eventpublic void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
e
- the mouse pressed event on one of the buttonspublic void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
the
- mouse released event on one of the buttonspublic void keyTyped(java.awt.event.KeyEvent e)
keyTyped
in interface java.awt.event.KeyListener
e
- the key typed eventpublic void keyPressed(java.awt.event.KeyEvent e)
keyPressed
in interface java.awt.event.KeyListener
e
- the key pressed event on one of the buttonspublic void keyReleased(java.awt.event.KeyEvent e)
keyReleased
in interface java.awt.event.KeyListener
the
- key released event on one of the buttonspublic void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
event
- the property event that has changedpublic boolean isDefaultModelAttached()
isDefaultModelAttached
in interface ViewDefaultModel
ViewDefaultModel
public com.sas.models.BoundedNumberInterface getModel()
public void setModel(com.sas.models.BoundedNumberInterface model)
the
- model to set on the spinButton, null to dettach the modelpublic void refresh(com.sas.ModelInterface model)
model
- the ModelInterface that has changed and need to be refreshedpublic void setArrowDirection(int d)
d
- the UP_DOWN or the LEFT_RIGHT values.getArrowDirection()
public final void setBlockIncrement(int block)
setBlockIncrement
in interface java.awt.Adjustable
blockIncrement
- the new value of the blockIncrement property.getBlockIncrement()
public void setBounds(int x, int y, int width, int height)
setBounds
in class java.awt.Component
ComponentVisualComponent.setBounds(int, int, int, int)
public void setButtonGap(int gap)
gap
- the pixel gap between the arrow buttonsgetButtonGap()
public void setCycleOn(boolean cycle)
cycle
- if the cycle is onpublic void setDecrementEnabled(boolean decrEnabled)
decrEnabled
- if true, the decrement button will be enabled; otherwise
it will be grayed and disabled to user input.public void setDefaultValues()
public void setAlarm(Alarm alarm)
alarm
- the alarm to trigger the value change.getAlarm()
,
AlarmListener
public void setDelay(long d)
d
- the milliseconds to delay firing the alarm.getDelay()
public void setEnabled(boolean enabled)
setEnabled
in class javax.swing.JComponent
enabled
- true to allow user input, false otherwiseComponent.isEnabled()
public void setIncrementEnabled(boolean incrEnabled)
incrEnabled
- if true, the increment button will be enabled; otherwise
it will be grayed and disabled to user input.public final void setMaximum(int max)
setMaximum
in interface java.awt.Adjustable
max
- the new value of the maximum bounds.getMaximum()
public final void setMinimum(int min)
setMinimum
in interface java.awt.Adjustable
min
- the new value of the minimum bounds.getMinimum()
public void setOrientation(int orient)
setOrientation
in conjunction with a swapButtonFunction()
method call can cancel both calls out.
If the setOrientation method is called after the buttons have been swapped
the buttons will be back in their default positions for the respective
orientation that they were set to. Another call to swapButtonFunction()
is required to swap the buttons back to their previous state
before the setOrientation() call.
orientation
- the new value of the orientation property:
either HORIZONTAL or VERTICAL.swapButtonFunction()
,
getOrientation()
public void setStartInterval(long interval)
interval
- the start interval for the alarm.getStartInterval()
public final void setUnitIncrement(int unit)
setUnitIncrement
in interface java.awt.Adjustable
unit
- the amount the value is incremented/decremented when
the SpinButton is triggered.getUnitIncrement()
public final void setValue(int newValue)
setValue
in interface java.awt.Adjustable
newValue
- the new value of the SpinButton.getValue()
public java.lang.Number getUnitIncrementNumber()
getUnitIncrementNumber
in interface com.sas.models.IncrementInterface
setUnitIncrementNumber(java.lang.Number)
public java.lang.Number getBlockIncrementNumber()
getBlockIncrementNumber
in interface com.sas.models.IncrementInterface
setBlockIncrementNumber(java.lang.Number)
public java.lang.Number getMaximumNumber()
setMaximumNumber(java.lang.Number)
public java.lang.Number getMinimumNumber()
setMinimumNumber(java.lang.Number)
public java.lang.Number getNumberValue()
setNumberValue(java.lang.Number)
public void setMaximumNumber(java.lang.Number max)
max
- the new maximum bounds for the SpinButton value.getMaximumNumber()
public void setMinimumNumber(java.lang.Number min)
min
- the new minimum bounds for the SpinButton value.getMinimumNumber()
public void setBlockIncrementNumber(java.lang.Number block)
setBlockIncrementNumber
in interface com.sas.models.IncrementInterface
block
- the new blockIncrement number.getBlockIncrementNumber()
public void setUnitIncrementNumber(java.lang.Number unit)
setUnitIncrementNumber
in interface com.sas.models.IncrementInterface
unit
- the new blockIncrement number.getUnitIncrementNumber()
public void setNumberValue(java.lang.Number newValue)
newValue
- the new SpinButton value.getNumberValue()
public void setVisibleAmount(int amount)
setVisibleAmount
in interface java.awt.Adjustable
public int swapButtonFunction()
setOrientation(int)
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |