com.ibm.spinner
Class NumericSpinner

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.ibm.spinner.SpinnerGUI
                                |
                                +--com.ibm.spinner.Spinner
                                      |
                                      +--com.ibm.spinner.NumericSpinner

public class NumericSpinner
extends Spinner
implements javax.swing.event.ChangeListener

A spinner which scrolls through a list of integers with bounded range. The current selected value is displayed in a textfield. The user can also enters an integer value as the current value.


Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Fields inherited from class com.ibm.spinner.SpinnerGUI
SPIN_HORIZONTAL, SPIN_VERTICAL
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
 
Constructor Summary
NumericSpinner()
          Creates a NumericSpinner using a bounded range model with a minimum as 0, maximum as 100, increment as 1 and current value as 0.
NumericSpinner(int increment)
          Creates a NumericSpinner using a bounded range model with a minimum as 0, maximum as 100 and current value as 0.
NumericSpinner(int min, int max)
          Creates a NumericSpinner using a bounded range model with specified minimum and maximum value.
NumericSpinner(int value, int min, int max, int increment)
          Creates a NumericSpinner using a bounded range model with specified values.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
           
 void addSpinnerErrorEventListener(SpinnerErrorEventListener l)
          Adds a SpinnerErrorEventListener.
 int getIncrement()
          Returns the increment value of NumericSpinner.
 int getMaximum()
          Returns the maximum value of NumericSpinner.
 int getMinimum()
          Returns the minimum value of NumericSpinner.
 javax.swing.BoundedRangeModel getModel()
          Returns the data model currently used by the NumericSpinner.
 int getValue()
          Returns the current value of NumericSpinner.
 void keyReleased(java.awt.event.KeyEvent keyEvent)
           
 void removeSpinnerErrorEventListener(SpinnerErrorEventListener l)
          Removes a SpinnerErrorEventListener.
 void scrollDown()
          Decrements the spinner's value by the increment.
 void scrollUp()
          Increments the spinner's value by the increment.
 void setIncrement(int increment)
          Sets the increment value of NumericSpinner.
 void setMaximum(int maximum)
          Sets the maximum value of NumericSpinner.
 void setMinimum(int minimum)
          Sets the minimum value of NumericSpinner.
 void setModel(javax.swing.BoundedRangeModel newModel)
          Sets the data model that the NumericSpinner uses to spin through.
 void setValue(int value)
          Sets the current value of NumericSpinner.
 void stateChanged(javax.swing.event.ChangeEvent e)
           
 
Methods inherited from class com.ibm.spinner.Spinner
addChangeListener, isWrap, keyPressed, removeChangeListener, setWrap
 
Methods inherited from class com.ibm.spinner.SpinnerGUI
focusGained, focusLost, getColumns, getDecrButtonArrowColor, getIncrButtonArrowColor, getMaximumSize, getMinimumSize, getOrientation, getPreferredSize, isEditable, isEnabled, keyTyped, mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased, setBackground, setColumns, setDecrButtonArrowColor, setEditable, setEnabled, setFont, setForeground, setIncrButtonArrowColor, setOpaque, setOrientation
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getNextFocusableComponent, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setMaximumSize, setMinimumSize, setNextFocusableComponent, setPreferredSize, setRequestFocusEnabled, setToolTipText, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, remove, removeAll, removeContainerListener, setLayout, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, contains, createImage, createImage, disable, dispatchEvent, enable, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NumericSpinner

public NumericSpinner()
Creates a NumericSpinner using a bounded range model with a minimum as 0, maximum as 100, increment as 1 and current value as 0.

NumericSpinner

public NumericSpinner(int increment)
Creates a NumericSpinner using a bounded range model with a minimum as 0, maximum as 100 and current value as 0.
Parameters:
increment - the amount of the current value changes when scrolling up or down.

NumericSpinner

public NumericSpinner(int min,
                      int max)
Creates a NumericSpinner using a bounded range model with specified minimum and maximum value. The current value is set to the min value and the increment is set to 1.
Parameters:
min - the minimum value of the bounded range model.
max - the maximum value of the bounded range model.

NumericSpinner

public NumericSpinner(int value,
                      int min,
                      int max,
                      int increment)
Creates a NumericSpinner using a bounded range model with specified values.
Parameters:
value - the current value being displayed.
min - the minimum value of the bounded range model.
max - the maximum value of the bounded range model.
increment - the amount of the current value changes when scrolling up or down.
Method Detail

addSpinnerErrorEventListener

public void addSpinnerErrorEventListener(SpinnerErrorEventListener l)
Adds a SpinnerErrorEventListener.
Parameters:
l - the SpinnerErrorEventListener.
Overrides:
addSpinnerErrorEventListener in class Spinner

getIncrement

public int getIncrement()
Returns the increment value of NumericSpinner.
Returns:
the increment value.

getMaximum

public int getMaximum()
Returns the maximum value of NumericSpinner.
Returns:
the maximum value.

getMinimum

public int getMinimum()
Returns the minimum value of NumericSpinner.
Returns:
the minimum value.

getModel

public javax.swing.BoundedRangeModel getModel()
Returns the data model currently used by the NumericSpinner.
Returns:
the BoundedRangeModel that provides numeric values to spin through.

getValue

public int getValue()
Returns the current value of NumericSpinner.
Returns:
the current value.

keyReleased

public void keyReleased(java.awt.event.KeyEvent keyEvent)
Overrides:
keyReleased in class SpinnerGUI

removeSpinnerErrorEventListener

public void removeSpinnerErrorEventListener(SpinnerErrorEventListener l)
Removes a SpinnerErrorEventListener.
Parameters:
l - the SpinnerErrorEventListener.
Overrides:
removeSpinnerErrorEventListener in class Spinner

scrollDown

public void scrollDown()
Decrements the spinner's value by the increment.
Overrides:
scrollDown in class Spinner

scrollUp

public void scrollUp()
Increments the spinner's value by the increment.
Overrides:
scrollUp in class Spinner

setIncrement

public void setIncrement(int increment)
Sets the increment value of NumericSpinner.
Parameters:
increment - the increment value to set.
Throws:
java.lang.IllegalArgumentException - if the increment is not greater than 0 or is bigger than the difference of maximum and minimum.

setMaximum

public void setMaximum(int maximum)
Sets the maximum value of NumericSpinner.
Parameters:
the - maximum value to set.

setMinimum

public void setMinimum(int minimum)
Sets the minimum value of NumericSpinner.
Parameters:
minimum - the minimum value to set.

setModel

public void setModel(javax.swing.BoundedRangeModel newModel)
Sets the data model that the NumericSpinner uses to spin through.
Parameters:
newModel - the BoundedRangeModel that provides numeric values to spin through.

setValue

public void setValue(int value)
Sets the current value of NumericSpinner.
Parameters:
the - value to be set.
Throws:
java.lang.IllegalArgumentException - when the value is entered from actionPerformed or focusLost, if the value is greater than the maximum and less than the minimum.

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Specified by:
stateChanged in interface javax.swing.event.ChangeListener

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Overrides:
actionPerformed in class Spinner