|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
com.sas.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(). If the model is ever set to null, the default model is reattached.
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 Form| Field Summary | |
|---|---|
protected com.sas.models.BoundedNumberInterface |
defaultRangeModel
the default range model for the spin button |
protected long |
delay
|
static int |
LEFT_RIGHT
int values representing the orientation of the spinButton- LEFT_RIGHT |
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 |
detachModel(com.sas.ModelInterface model)
Detach the specified model from the SpinBox. |
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. |
java.lang.Number |
getNumberValue()
Get the value number based on the model. |
int |
getOrientation()
Get the value of the orientation property. |
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 whether the model is attached or not |
boolean |
isIncrementEnabled()
Get the enabled state of the button that increments the value. |
void |
paint(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. |
protected void |
processMouseEvent(java.awt.event.MouseEvent evt)
Process the any MouseEvents on the SpinButton. |
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 |
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 |
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. |
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 com.sas.models.BoundedNumberInterface defaultRangeModel
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 addAdjustmentListener(java.awt.event.AdjustmentListener l)
addAdjustmentListener in interface java.awt.Adjustablel - the adjustment listenerAdjustable.addAdjustmentListener(java.awt.event.AdjustmentListener),
AdjustmentEventpublic void removeAdjustmentListener(java.awt.event.AdjustmentListener l)
removeAdjustmentListener in interface java.awt.Adjustablel - the adjustment listeneraddAdjustmentListener(java.awt.event.AdjustmentListener),
AdjustmentEventprotected void checkEnabled()
public java.awt.Dimension computePreferredSize()
computePreferredSize in interface VisualInterfacecomputePreferredSize in class ComponentVisualComponentVisualInterface.computePreferredSize()public void detachModel(com.sas.ModelInterface model)
detachModel in interface com.sas.ViewInterfacedetachModel in class ComponentVisualComponentmodel - - ModelInterface object to be removed from the SpinButtonViewInterface.detachModel(com.sas.ModelInterface)public void fireAlarm(AlarmEvent evt)
fireAlarm in interface AlarmListenerevt - the AlarmEvent firedpublic Alarm getAlarm()
setAlarm(com.sas.util.Alarm)public int getArrowDirection()
setArrowDirection(int)public final int getBlockIncrement()
getBlockIncrement in interface java.awt.AdjustablesetBlockIncrement(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.AdjustablesetMaximum(int)public final int getMinimum()
getMinimum in interface java.awt.AdjustablesetMinimum(int)public int getOrientation()
getOrientation in interface java.awt.AdjustableAdjustable,
setOrientation(int)public java.util.Vector getRequiredInterfaces()
getRequiredInterfaces in interface com.sas.ViewInterfacegetRequiredInterfaces in class ComponentVisualComponentViewInterface.getRequiredInterfaces()public java.awt.Dimension getMinimumSize()
getMinimumSize in interface VisualInterfacegetMinimumSize in class ComponentVisualInterface.getMinimumSize()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.AdjustablesetUnitIncrement(int)public final int getValue()
getValue in interface java.awt.AdjustablesetValue(int)public int getVisibleAmount()
getVisibleAmount in interface java.awt.Adjustablepublic boolean isCycleOn()
public boolean isDefaultModelAttached()
isDefaultModelAttached in interface com.sas.ViewDefaultModelInterfacepublic boolean isDecrementEnabled()
public boolean isIncrementEnabled()
public java.lang.Number incrementBy(int increment,
int incrementType)
incrementBy in interface com.sas.models.IncrementInterfaceincrement - 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 paint(java.awt.Graphics g)
paint in class ComponentVisualComponentg - the graphics contextVisualInterfaceSupport.paint(com.sas.ComponentInterface, com.sas.awt.VisualInterface, java.awt.Component, java.awt.Graphics)protected void processEvent(java.awt.AWTEvent e)
processEvent in class java.awt.Componente - the awt event that has changedprotected void processAdjustmentEvent(java.awt.event.AdjustmentEvent e)
e - the adjustment event that has changedprotected void processMouseEvent(java.awt.event.MouseEvent evt)
processMouseEvent in class java.awt.Componentevt - the mouse event that has occurredpublic void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange in interface java.beans.PropertyChangeListenerpropertyChange in class ComponentVisualComponentevent - the property event that has changedPropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)public void refresh(com.sas.ModelInterface model)
refresh in interface com.sas.ViewInterfacerefresh in class ComponentVisualComponentmodel - the ModelInterface that has changed and need to be refreshedViewInterface.refresh(com.sas.ModelInterface)public 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.AdjustableblockIncrement - the new value of the blockIncrement property.getBlockIncrement()
public void setBounds(int x,
int y,
int width,
int height)
setBounds in interface VisualInterfacesetBounds in class ComponentVisualComponentComponentVisualComponent.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()
setDefaultValues in interface VisualInterfacesetDefaultValues in interface com.sas.ComponentInterfacesetDefaultValues in class ComponentComponentInterface.setDefaultValues()public void setAlarm(Alarm alarm)
alarm - the alarm to trigger the value change.getAlarm(),
AlarmListenerpublic void setDelay(long d)
d - the milliseconds to delay firing the alarm.getDelay()public void setEnabled(boolean enabled)
setEnabled in interface VisualInterfacesetEnabled in class ComponentVisualComponentenabled - true to allow user input, false otherwiseComponentVisualComponent.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.Adjustablemax - the new value of the maximum bounds.getMaximum()public final void setMinimum(int min)
setMinimum in interface java.awt.Adjustablemin - 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.Adjustableunit - the amount the value is incremented/decremented when
the SpinButton is triggered.getUnitIncrement()public final void setValue(int newValue)
setValue in interface java.awt.AdjustablenewValue - the new value of the SpinButton.getValue()public java.lang.Number getUnitIncrementNumber()
getUnitIncrementNumber in interface com.sas.models.IncrementInterfacesetUnitIncrementNumber(java.lang.Number)public java.lang.Number getBlockIncrementNumber()
getBlockIncrementNumber in interface com.sas.models.IncrementInterfacesetBlockIncrementNumber(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.IncrementInterfaceblock - the new blockIncrement number.getBlockIncrementNumber()public void setUnitIncrementNumber(java.lang.Number unit)
setUnitIncrementNumber in interface com.sas.models.IncrementInterfaceunit - 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.Adjustablepublic int swapButtonFunction()
setOrientation(int)
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||