|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||
java.lang.Object
|
+--java.awt.Component
|
+--java.awt.Container
|
+--javax.swing.JComponent
|
+--com.sas.swing.visuals.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 Form| Inner classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
| Inner classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
| Inner classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
protected ArrowIcon |
decrementArrow
|
protected JButton |
decrementButton
|
protected BoundedNumberInterface |
defaultRangeModel
the default range model for the spin button |
protected long |
delay
|
protected ArrowIcon |
incrementArrow
|
protected JButton |
incrementButton
|
static int |
LEFT_RIGHT
int values representing the orientation of the spinButton- LEFT_RIGHT |
protected BoundedNumberInterface |
spinButtonModel
|
protected long |
startInterval
|
static int |
UP_DOWN
int values representing the orientation of the spinButton- UP_DOWN |
protected Alarm |
valueChangeAlarm
|
| 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 java.awt.Adjustable |
HORIZONTAL, NO_ORIENTATION, VERTICAL |
| Fields inherited from interface com.sas.models.IncrementInterface |
BLOCK, UNIT |
| Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| 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(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. |
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. |
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 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. |
Number |
getMaximumNumber()
Get the maximum bounds number based on the model. |
int |
getMinimum()
Get the value of the minimum property. |
Number |
getMinimumNumber()
Get the minimum bounds number based on the model. |
Dimension |
getMinimumSize()
Get the preferredSize of the RadioButton. |
BoundedNumberInterface |
getModel()
Returns the BoundedNumberInterface model that is set on the spinButton. |
Number |
getNumberValue()
Get the value number based on the model. |
int |
getOrientation()
Get the value of the orientation property. |
Dimension |
getPreferredSize()
Get the preferredSize of the RadioButton. |
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. |
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 |
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(KeyEvent e)
Process the key pressed event on one of the buttons. |
void |
keyReleased(KeyEvent e)
Process the key being released on one of the buttons. |
void |
keyTyped(KeyEvent e)
Process any key typed events down on the buttons. |
void |
mouseClicked(MouseEvent e)
Process any mouse click events down on the buttons. |
void |
mouseEntered(MouseEvent e)
Process the mouse entering event. |
void |
mouseExited(MouseEvent e)
Process the mouse exiting event. |
void |
mousePressed(MouseEvent e)
Process the mouse pressed event on one of the buttons. |
void |
mouseReleased(MouseEvent e)
Process the mouse being released on one of the buttons. |
void |
paintComponent(Graphics g)
Paint the SpinButton. |
protected void |
processAdjustmentEvent(AdjustmentEvent e)
Process adjustment events. |
protected void |
processEvent(AWTEvent e)
Process events. |
void |
propertyChange(PropertyChangeEvent event)
Invoked when a bound property is changed. |
void |
refresh(ModelInterface model)
Refresh the spinButton based on its model. |
void |
removeAdjustmentListener(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(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(Number max)
Sets the maximum bounds number. |
void |
setMinimum(int min)
Sets the integer value of the minimum property. |
void |
setMinimumNumber(Number min)
Sets the minimum bounds number. |
void |
setModel(BoundedNumberInterface model)
Sets the BoundedNUmberInterface model on the spinButton. |
void |
setNumberValue(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(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(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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected Alarm valueChangeAlarm
protected long startInterval
protected long delay
protected JButton incrementButton
protected JButton decrementButton
protected ArrowIcon incrementArrow
protected ArrowIcon decrementArrow
protected BoundedNumberInterface defaultRangeModel
protected 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 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(String text)
setToolTipText in class JComponenttext - the string to display; if the text is null,
the tool tip is turned off for this componentpublic void addAdjustmentListener(AdjustmentListener l)
addAdjustmentListener in interface Adjustablel - the adjustment listenerAdjustable.addAdjustmentListener(java.awt.event.AdjustmentListener),
AdjustmentEventpublic void removeAdjustmentListener(AdjustmentListener l)
removeAdjustmentListener in interface Adjustablel - the adjustment listeneraddAdjustmentListener(java.awt.event.AdjustmentListener),
AdjustmentEventprotected void checkEnabled()
public Dimension computePreferredSize()
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 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 AdjustablesetMaximum(int)public final int getMinimum()
getMinimum in interface AdjustablesetMinimum(int)public int getOrientation()
getOrientation in interface AdjustableAdjustable,
setOrientation(int)public Vector getRequiredInterfaces()
ViewInterface.getRequiredInterfaces()public Dimension getPreferredSize()
getPreferredSize in class JComponentpublic Dimension getMinimumSize()
getMinimumSize in class JComponentpublic 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 AdjustablesetUnitIncrement(int)public final int getValue()
getValue in interface AdjustablesetValue(int)public int getVisibleAmount()
getVisibleAmount in interface Adjustablepublic boolean isCycleOn()
public boolean isDecrementEnabled()
public boolean isIncrementEnabled()
public Number incrementBy(int increment,
int incrementType)
incrementBy in interface 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 paintComponent(Graphics g)
paintComponent in class JComponentg - the graphics contextpublic void stopAdjusting()
protected void processEvent(AWTEvent e)
processEvent in class Containere - the awt event that has changedprotected void processAdjustmentEvent(AdjustmentEvent e)
e - the adjustment event that has changedpublic void mouseClicked(MouseEvent e)
mouseClicked in interface MouseListenere - the mouse clicked eventpublic void mouseEntered(MouseEvent e)
mouseEntered in interface MouseListenere - the mouse entered eventpublic void mouseExited(MouseEvent e)
mouseExited in interface MouseListenerthe - mouse exiting eventpublic void mousePressed(MouseEvent e)
mousePressed in interface MouseListenere - the mouse pressed event on one of the buttonspublic void mouseReleased(MouseEvent e)
mouseReleased in interface MouseListenerthe - mouse released event on one of the buttonspublic void keyTyped(KeyEvent e)
keyTyped in interface KeyListenere - the key typed eventpublic void keyPressed(KeyEvent e)
keyPressed in interface KeyListenere - the key pressed event on one of the buttonspublic void keyReleased(KeyEvent e)
keyReleased in interface KeyListenerthe - key released event on one of the buttonspublic void propertyChange(PropertyChangeEvent event)
propertyChange in interface PropertyChangeListenerevent - the property event that has changedpublic boolean isDefaultModelAttached()
isDefaultModelAttached in interface ViewDefaultModelViewDefaultModelpublic BoundedNumberInterface getModel()
public void setModel(BoundedNumberInterface model)
the - model to set on the spinButton, null to dettach the modelpublic void refresh(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 AdjustableblockIncrement - the new value of the blockIncrement property.getBlockIncrement()
public void setBounds(int x,
int y,
int width,
int height)
setBounds in class ComponentComponentVisualComponent.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(),
AlarmListenerpublic void setDelay(long d)
d - the milliseconds to delay firing the alarm.getDelay()public void setEnabled(boolean enabled)
setEnabled in class JComponentenabled - 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 Adjustablemax - the new value of the maximum bounds.getMaximum()public final void setMinimum(int min)
setMinimum in interface 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 Adjustableunit - the amount the value is incremented/decremented when
the SpinButton is triggered.getUnitIncrement()public final void setValue(int newValue)
setValue in interface AdjustablenewValue - the new value of the SpinButton.getValue()public Number getUnitIncrementNumber()
getUnitIncrementNumber in interface IncrementInterfacesetUnitIncrementNumber(java.lang.Number)public Number getBlockIncrementNumber()
getBlockIncrementNumber in interface IncrementInterfacesetBlockIncrementNumber(java.lang.Number)public Number getMaximumNumber()
setMaximumNumber(java.lang.Number)public Number getMinimumNumber()
setMinimumNumber(java.lang.Number)public Number getNumberValue()
setNumberValue(java.lang.Number)public void setMaximumNumber(Number max)
max - the new maximum bounds for the SpinButton value.getMaximumNumber()public void setMinimumNumber(Number min)
min - the new minimum bounds for the SpinButton value.getMinimumNumber()public void setBlockIncrementNumber(Number block)
setBlockIncrementNumber in interface IncrementInterfaceblock - the new blockIncrement number.getBlockIncrementNumber()public void setUnitIncrementNumber(Number unit)
setUnitIncrementNumber in interface IncrementInterfaceunit - the new blockIncrement number.getUnitIncrementNumber()public void setNumberValue(Number newValue)
newValue - the new SpinButton value.getNumberValue()public void setVisibleAmount(int amount)
setVisibleAmount in interface Adjustablepublic int swapButtonFunction()
setOrientation(int)
|
| Components |
|
| |||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||||||