com.tensegrity.gui.swing.control.spinbutton
Class AbstractSpinTextField

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bycom.tensegrity.gui.swing.control.spinbutton.AbstractSpinTextField
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, javax.swing.event.DocumentListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.LayoutManager, java.awt.MenuContainer, java.io.Serializable
Direct Known Subclasses:
DoubleSpinTextField, IntegerSpinTextField

public abstract class AbstractSpinTextField
extends javax.swing.JPanel
implements java.awt.LayoutManager, java.awt.event.ActionListener, javax.swing.event.DocumentListener

The AbstractSpinTextField class offers jdk1.3. users a simplified clone of the jdk1.4 JSpinner control.

The AbstractSpinTextField is a TextField right next to a SpinButton which enables the user to enter values manually and see the current value of the SpinButton. This TextField receives ActionEvents from the SpinButton to reflect changes and also updates the SpinButton value according to users input.

This class only defines the basic behavior. Its required to add implementations according to a value type like Integer, Double, Float, etc.

Version:
$Id: AbstractSpinTextField.java,v 1.12 2005/09/14 11:13:01 BurkhardWick Exp $
Author:
Gilles Iachelini
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int digits
          The amount of digits the internal TextField should provide space for.
protected  java.util.ArrayList listeners
          List of listeners.
protected  com.tensegrity.gui.swing.control.spinbutton.AbstractSpinButton spinButton
          the spin button.
protected  javax.swing.JTextField textField
          The swing TextField.
 
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
AbstractSpinTextField(java.lang.Number min, java.lang.Number max, java.lang.Number step, java.lang.Number initial)
          Creates a new AbstractSpinTextField with the specified minimum-, maximum-, initial- and step value.
AbstractSpinTextField(java.lang.Number min, java.lang.Number max, java.lang.Number step, java.lang.Number initial, int digits)
          Creates a new SpinTextField the specified minimum-, maximum-, initial- and step value.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Invoked by the SpinButton.
 void addActionListener(java.awt.event.ActionListener listener)
          Method addActionListener adds an ActionListener to the internal list of listeners.
 void addKeyListener(java.awt.event.KeyListener l)
           
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
          does nothing.
 void changedUpdate(javax.swing.event.DocumentEvent e)
          does nothing.
protected abstract  javax.swing.text.Document createDocument()
          Creates a Document used for the TextField.
protected abstract  com.tensegrity.gui.swing.control.spinbutton.AbstractSpinButton createSpinButton(java.lang.Number min, java.lang.Number max, java.lang.Number step, java.lang.Number initial)
          Creates the required SpinButton control, which allows user to increase or decrease the current value of this SpinTextField.
protected abstract  int getColumnCount()
          Returns the number of columns for the resulting TextField.
protected  java.text.DecimalFormat getFormatter()
          Returns the DecimalFormatter for the TextField String.
protected  java.lang.Number getMaximum()
          Returns the maximum from the SpinButton.
protected  java.lang.Number getMinimum()
          Returns the minimum as it is set on the SpinButton.
abstract  java.lang.Number getValue()
          Method getValue returns the current value of the SpinTextField.
 void insertUpdate(javax.swing.event.DocumentEvent e)
          Sets the value at the internal SpinButton and posts an Event.
 void layoutContainer(java.awt.Container parent)
          Layouts the components.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
          Returns the preferredLayoutSize of the parent.
protected  void postEvent(java.lang.Number value)
          Method postEvent is called every time an ActionEvent occurs.
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
          Returns the preferred size of the Container.
 void removeKeyListener(java.awt.event.KeyListener l)
           
 void removeLayoutComponent(java.awt.Component comp)
          does nothing.
 void removeListener(java.awt.event.ActionListener listener)
          Method removeListener removes the given listener from the internal list.
 void removeUpdate(javax.swing.event.DocumentEvent e)
          Does nothing.
 void requestFocus()
           
 void setEnabled(boolean enabled)
           
 void setMaximum(java.lang.Number max)
          Changes the upper bound on the SpinButton to the given one.
 void setMinimum(java.lang.Number min)
          Changes the lower bound for numbers to the given one.
abstract  void setValue(java.lang.Number number)
          Sets the new value on the TextField and the SpinButton.
 void updateUI()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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

spinButton

protected com.tensegrity.gui.swing.control.spinbutton.AbstractSpinButton spinButton
the spin button.


textField

protected javax.swing.JTextField textField
The swing TextField.


listeners

protected java.util.ArrayList listeners
List of listeners.


digits

protected int digits
The amount of digits the internal TextField should provide space for.

Constructor Detail

AbstractSpinTextField

public AbstractSpinTextField(java.lang.Number min,
                             java.lang.Number max,
                             java.lang.Number step,
                             java.lang.Number initial)
Creates a new AbstractSpinTextField with the specified minimum-, maximum-, initial- and step value.

Parameters:
min - the minimum value as float.
max - the maximum value as float.
step - the value the SpinTextField should increase or decrease the current value.
initial - the initial value for the SpinTextField.

AbstractSpinTextField

public AbstractSpinTextField(java.lang.Number min,
                             java.lang.Number max,
                             java.lang.Number step,
                             java.lang.Number initial,
                             int digits)
Creates a new SpinTextField the specified minimum-, maximum-, initial- and step value. Furthermore you are able to specify how many digits this field will show. The constructor first creates a TextField, based on the given Document, obtained through the createDocument() call. Then a appropriate SpinButton is created by calling the createSpinButton(Number, Number, Number, Number) -method.

The digits parameter is then used to create a suitable DecimalFormat instance to format the String output for the internal TextField.

Parameters:
min - the minimum value as float.
max - the maximum value as float.
step - the value the SpinTextField should increase or decrease the current value.
initial - the initial value for the SpinTextField.
digits - number of digits to display.
Method Detail

getFormatter

protected java.text.DecimalFormat getFormatter()
Returns the DecimalFormatter for the TextField String. This Formatter is responsible to create a human readable String from the current Value.

Returns:
this class DecimalFormat instance.

createDocument

protected abstract javax.swing.text.Document createDocument()
Creates a Document used for the TextField. Users of this class are responsible to create a Document which does not allow entering characters which might lead to invalid inputs.

Returns:
an instance of Document.

createSpinButton

protected abstract com.tensegrity.gui.swing.control.spinbutton.AbstractSpinButton createSpinButton(java.lang.Number min,
                                                                                                   java.lang.Number max,
                                                                                                   java.lang.Number step,
                                                                                                   java.lang.Number initial)
Creates the required SpinButton control, which allows user to increase or decrease the current value of this SpinTextField.

Parameters:
min - the minimum value of this SpinTextField.
max - the maximum value of this SpinTextField.
step - the value to step up or down, whenever an ArrowButton is clicked.
initial - the initial value.
Returns:
an implementation of class AbstractSpinButton.

getColumnCount

protected abstract int getColumnCount()
Returns the number of columns for the resulting TextField.

Returns:
an integer describing the number of columns for the internal TextField.
See Also:
JTextField.JTextField(javax.swing.text.Document, java.lang.String, int)

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Method addActionListener adds an ActionListener to the internal list of listeners. ActionListeners will be notified when the internal TextField or the SpinButtons create such events.

Parameters:
listener - an instance of class ActionListener.

removeListener

public void removeListener(java.awt.event.ActionListener listener)
Method removeListener removes the given listener from the internal list. if the list is empty after the removal, the list is discarded as well.

Parameters:
listener - the ActionListener to remove.

postEvent

protected void postEvent(java.lang.Number value)
Method postEvent is called every time an ActionEvent occurs. All stored ActionListener will then be notified and the new value will sent to all listeners.

Parameters:
value - the new value to distribute among the listeners.

getValue

public abstract java.lang.Number getValue()
Method getValue returns the current value of the SpinTextField. This means for subclasses to retrieve the String from the TextField and convert it to a proper Number instance like Integer, Double, Float, etc.

Returns:
the current value of the TextField as an instance of Number.

setEnabled

public void setEnabled(boolean enabled)
See Also:
JComponent.setEnabled(boolean)

setValue

public abstract void setValue(java.lang.Number number)
Sets the new value on the TextField and the SpinButton.

Parameters:
number - the new value as Number.

setMinimum

public void setMinimum(java.lang.Number min)
Changes the lower bound for numbers to the given one.

Parameters:
min - the new lower bound

getMinimum

protected java.lang.Number getMinimum()
Returns the minimum as it is set on the SpinButton.

Returns:
the minimum as an instance of Number.

setMaximum

public void setMaximum(java.lang.Number max)
Changes the upper bound on the SpinButton to the given one.

Parameters:
max - the new upper bound

getMaximum

protected java.lang.Number getMaximum()
Returns the maximum from the SpinButton.

Returns:
the current upper bound as instance of Number.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Invoked by the SpinButton. Updates the TextField.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
See Also:
ActionListener.actionPerformed(ActionEvent)

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
does nothing.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
See Also:
LayoutManager.addLayoutComponent(String, Component)

layoutContainer

public void layoutContainer(java.awt.Container parent)
Layouts the components. All components are layout'ed according to their preferred size. The TextLabel to the left; the spin button right next to it.

Specified by:
layoutContainer in interface java.awt.LayoutManager
See Also:
LayoutManager.layoutContainer(Container)

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Returns the preferredLayoutSize of the parent.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
See Also:
LayoutManager.minimumLayoutSize(Container), LayoutManager.preferredLayoutSize(Container)

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Returns the preferred size of the Container.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
See Also:
LayoutManager.preferredLayoutSize(Container)

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
does nothing.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
See Also:
LayoutManager.removeLayoutComponent(Component)

changedUpdate

public void changedUpdate(javax.swing.event.DocumentEvent e)
does nothing.

Specified by:
changedUpdate in interface javax.swing.event.DocumentListener
See Also:
DocumentListener.changedUpdate(DocumentEvent)

insertUpdate

public void insertUpdate(javax.swing.event.DocumentEvent e)
Sets the value at the internal SpinButton and posts an Event.

Specified by:
insertUpdate in interface javax.swing.event.DocumentListener
See Also:
DocumentListener.insertUpdate(DocumentEvent), postEvent(Number)

removeUpdate

public void removeUpdate(javax.swing.event.DocumentEvent e)
Does nothing.

Specified by:
removeUpdate in interface javax.swing.event.DocumentListener
See Also:
DocumentListener.removeUpdate(DocumentEvent)

updateUI

public void updateUI()

addKeyListener

public void addKeyListener(java.awt.event.KeyListener l)

removeKeyListener

public void removeKeyListener(java.awt.event.KeyListener l)

requestFocus

public void requestFocus()


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.