dsto.dfc.swing.controls
Class NumericSpinner

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by dsto.dfc.swing.controls.NumericSpinner
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable

public class NumericSpinner
extends JComponent

A spinner component for numeric values stored in a BoundedRangeModel object. Provides a text field for numeric entry and increment/decrement buttons.

Version:
$Revision$
Author:
Matthew Phillips
See Also:
BoundedRangeModel, Serialized Form

Nested Class Summary
protected  class NumericSpinner.ArrowButton
          A small extension of JButton to implement arrow buttons.
protected  class NumericSpinner.BoundedRangeModelChangeListener
           
protected  class NumericSpinner.ButtonChangeListener
          Listens for changes to the arrow button models and timer ticks that signal auto repeats when buttons are held down.
protected  class NumericSpinner.LayoutManager
          Custom layout manager for NumericSpinner.
protected  class NumericSpinner.TextFieldListener
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  NumericSpinner.BoundedRangeModelChangeListener boundedRangeModelChangeListener
           
protected static Insets buttonMargin
           
protected  boolean changing
           
protected  NumericSpinner.ArrowButton downButton
           
protected  int increment
           
protected static int MIN_ARROW_HEIGHT
           
protected static int MIN_BUTTON_WIDTH
           
protected  BoundedRangeModel model
           
protected  JTextField textField
           
protected  NumericSpinner.ArrowButton upButton
           
 
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.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
NumericSpinner()
          Creates a default spinner with min = 0, max = 100, value = 50.
NumericSpinner(BoundedRangeModel model)
          Creates a spinner using model as the model.
NumericSpinner(int minimum, int maximum, int value)
          Creates a numeric spinner with a default model intialised to minimum, maximum and value.
 
Method Summary
 void addActionListener(ActionListener l)
          Add an ActionListener, by passing it onto the TextField.
protected  void doIncrement(int newIncrement)
          Perform an increment operation.
 int getIncrement()
          Returns the amount by which the value is increased/decreased by clicking on the arrow buttons.
 int getMaximum()
          Get the current maximum value.
 int getMinimum()
          Get the current minimum value.
 BoundedRangeModel getModel()
          Returns the model currently being used by the spinner.
 int getValue()
          Get the current value.
protected  void init()
          Performs common initialisation of the spinner.
protected  void loadModelFromTextField()
          Loads the model from the text field.
protected  void loadTextFieldFromModel()
          Loads the text field value from the model.
 void removeActionListener(ActionListener l)
          Remove the ActionListener, by telling the TextField to remove it.
 void setEnabled(boolean enabled)
          Set the textfield and the arrow buttons to be enabled/disabled
 void setIncrement(int increment)
          Sets the amount by which the value is increased/decreased by clicking on the arrow buttons.
 void setMaximum(int maximum)
          Set the current model value.
 void setMinimum(int minimum)
          Set the current minimum value.
 void setModel(BoundedRangeModel model)
          Sets the model to be used by the spinner.
 void setToolTipText(String text)
           
 void setValue(int value)
          Set the current value.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
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, setName, 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

MIN_ARROW_HEIGHT

protected static final int MIN_ARROW_HEIGHT
See Also:
Constant Field Values

MIN_BUTTON_WIDTH

protected static final int MIN_BUTTON_WIDTH
See Also:
Constant Field Values

buttonMargin

protected static final Insets buttonMargin

model

protected BoundedRangeModel model

textField

protected JTextField textField

upButton

protected NumericSpinner.ArrowButton upButton

downButton

protected NumericSpinner.ArrowButton downButton

increment

protected int increment

changing

protected transient boolean changing

boundedRangeModelChangeListener

protected NumericSpinner.BoundedRangeModelChangeListener boundedRangeModelChangeListener
Constructor Detail

NumericSpinner

public NumericSpinner()
Creates a default spinner with min = 0, max = 100, value = 50.


NumericSpinner

public NumericSpinner(BoundedRangeModel model)
Creates a spinner using model as the model.

See Also:
getModel(), setModel(javax.swing.BoundedRangeModel)

NumericSpinner

public NumericSpinner(int minimum,
                      int maximum,
                      int value)
Creates a numeric spinner with a default model intialised to minimum, maximum and value.

See Also:
getModel(), setModel(javax.swing.BoundedRangeModel)
Method Detail

addActionListener

public void addActionListener(ActionListener l)
Add an ActionListener, by passing it onto the TextField.


removeActionListener

public void removeActionListener(ActionListener l)
Remove the ActionListener, by telling the TextField to remove it.


setEnabled

public void setEnabled(boolean enabled)
Set the textfield and the arrow buttons to be enabled/disabled

Overrides:
setEnabled in class JComponent
Parameters:
enabled - Enable the textfield and arrow buttons.

getValue

public int getValue()
Get the current value.

Returns:
The current value.

setValue

public void setValue(int value)
Set the current value.

Parameters:
value - The new value.

getMinimum

public int getMinimum()
Get the current minimum value.

Returns:
The current minimum value.

setMinimum

public void setMinimum(int minimum)
Set the current minimum value.

Parameters:
minimum - The new minimum value.

getMaximum

public int getMaximum()
Get the current maximum value.

Returns:
The current maximum value.

setMaximum

public void setMaximum(int maximum)
Set the current model value.

Parameters:
maximum - The new maximum value.

getIncrement

public int getIncrement()
Returns the amount by which the value is increased/decreased by clicking on the arrow buttons.

Returns:
The current increment value.
See Also:
setIncrement(int)

setIncrement

public void setIncrement(int increment)
Sets the amount by which the value is increased/decreased by clicking on the arrow buttons.

Parameters:
increment - The new increment value.
See Also:
getIncrement()

getModel

public BoundedRangeModel getModel()
Returns the model currently being used by the spinner.

Returns:
The current model.
See Also:
setModel(javax.swing.BoundedRangeModel)

setModel

public void setModel(BoundedRangeModel model)
Sets the model to be used by the spinner.

Parameters:
model - The new model.
See Also:
getModel()

setToolTipText

public void setToolTipText(String text)
Overrides:
setToolTipText in class JComponent

init

protected void init()
Performs common initialisation of the spinner.


doIncrement

protected void doIncrement(int newIncrement)
Perform an increment operation.

Parameters:
newIncrement - The amount to increase/decrease the current value by.

loadTextFieldFromModel

protected void loadTextFieldFromModel()
Loads the text field value from the model. Sets changing to prevent circular change event propagation.

See Also:
loadModelFromTextField()

loadModelFromTextField

protected void loadModelFromTextField()
Loads the model from the text field. Sets changing to prevent circular change event propagation.

See Also:
loadTextFieldFromModel()


Copyright © 2008 Commonwealth of Australia