JClass DesktopViews 6.3.0 API
Documentation

com.klg.jclass.util.swing
Class JCSpinBox

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--com.klg.jclass.util.swing.AbstractSpinBox
                          |
                          +--com.klg.jclass.util.swing.JCSpinBox
All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable
Direct Known Subclasses:
MonthSpin

public class JCSpinBox
extends AbstractSpinBox
implements ItemSelectable

A spinbox component. This spin box will display a list of objects. The renderer and editor can be replaced to display the and edit the objects in any form. The default editor and renderer is designed to work with Strings.

See Also:
Serialized Form

Nested Class Summary
static interface JCSpinBox.KeySelectionManager
          The interface that defines a KeySelectionManager.
 
Nested classes inherited from class com.klg.jclass.util.swing.AbstractSpinBox
AbstractSpinBox.ArrowButton, AbstractSpinBox.MetalArrowButton, AbstractSpinBox.MetalBorder
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  String actionCommand
           
protected  com.klg.jclass.util.JCListenerList actionListeners
           
protected  boolean firstPaint
           
protected  com.klg.jclass.util.JCListenerList itemListeners
           
protected  JCSpinBox.KeySelectionManager keySelectionManager
           
protected  Object lastSelectedItem
           
protected  ListDataListener listDataListener
           
protected  com.klg.jclass.util.swing.JCSpinBoxModel model
           
protected  boolean modelChanging
           
 
Fields inherited from class com.klg.jclass.util.swing.AbstractSpinBox
arrowKeySpinningAllowed, buttonTimer, continuousScroll, currentButton, DECREMENT, downArrow, editable, editor, editorIsValidateRoot, INCREMENT, l, metalBorder, minimumHeight, NONE, renderer, renderPanel, rl, upArrow, userFont, valueListeners, valueModel
 
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
JCSpinBox()
          Creates a JCSpinBox with a default data model.
JCSpinBox(com.klg.jclass.util.swing.JCSpinBoxModel aModel)
          Creates a JCSpinBox that takes its items from an existing JCSpinBoxModel.
JCSpinBox(Object[] items)
          Creates a JCSpinBox that contains the elements in the specified array.
JCSpinBox(Vector items)
          Creates a JCSpinBox that contains the elements in the specified Vector.
 
Method Summary
 void addActionListener(ActionListener l)
          Adds an ActionListener.
 void addItem(Object o)
          Adds an item to the item list.
 void addItemListener(ItemListener l)
          Adds a java.awt.event.ItemListener.
protected  void checkArrowButtons()
          Disables the arrow buttons if the end of the range is reached.
protected  void checkSpinBoxMutableModel()
          Checks if the current model is mutable.
 String getAbout()
          Returns vendor information.
 String getActionCommand()
          Returns the action command that is included in the event sent to action listeners.
 Object getItemAt(int index)
          Returns the list item at the specified index.
 int getItemCount()
          Returns the number of items in the list.
 JCSpinBox.KeySelectionManager getKeySelectionManager()
          Returns the list's key-selection manager.
 com.klg.jclass.util.swing.JCSpinBoxModel getModel()
          Returns the data model currently used by the JCSpinBox.
 int getSelectedIndex()
          Returns the index of the currently selected item in the list.
 Object getSelectedItem()
          Returns the currently selected item.
 Object[] getSelectedObjects()
          Returns an array containing the selected item.
protected  void handleKeyPressed(KeyEvent e)
          Overridden in JCSpinBox to add keySelectionManager functionality.
 void insertItemAt(Object o, int index)
          Inserts an item into the item list at a given index.
protected  void modelChanged()
          This method is invoked by listeners on the data model when the model changes.
 void paint(Graphics g)
          Paints the spinbox.
protected  int preferredWidthOfView()
          Overrides preferred width to make sure the width is big enough for the formatted max and min values.
protected  void processValueChanged(com.klg.jclass.util.value.JCValueEvent event)
          This method can be overridded by the subclass
 void removeActionListener(ActionListener l)
          Removes an ActionListener.
 void removeAllItems()
          Removes all items from the item list.
 void removeItem(Object o)
          Removes an item from the item list.
 void removeItemAt(int anIndex)
          Removes the item at anIndex This method works only if the JCSpinBox model implements JCSpinBoxMutableModel.
 void removeItemListener(ItemListener l)
          Removes an ItemListener.
 boolean selectWithKeyChar(char keyChar)
          Selects the list item that correponds to the specified keyboard character and returns true if there is an item corresponding to that character.
 void setAbout(String s)
          Provided for Beans property editors - has no effect.
 void setActionCommand(String aCommand)
          Sets the action command that should be included in the event sent to action listeners.
 void setKeySelectionManager(JCSpinBox.KeySelectionManager aManager)
          Sets the object that translates a keyboard character into a list selection.
 void setModel(com.klg.jclass.util.swing.JCSpinBoxModel aModel)
          Sets the data model that the JCSpinBox uses to obtain the list of items.
 void setSelectedIndex(int index)
          Selects the item at index index.
 void setSelectedItem(Object item)
          Sets the selected item in the JCSpinBox by specifying the object in the list.
protected  Object spinDown()
          Returns the new value generated when spinning down a notch.
protected  Object spinUp()
          Returns the new value generated when spinning up a notch.
 
Methods inherited from class com.klg.jclass.util.swing.AbstractSpinBox
addValueListener, compareToValue, configureArrowButtons, createDecrArrow, createIncrArrow, doBorder, doFocusedLook, doLayout, doNonFocusedLook, getDecrementArrow, getEditor, getIncrementArrow, getPreferredSize, getRenderer, getValueModel, isArrowKeySpinningAllowed, isContinuousScroll, isEditable, isEnabled, isFocusTraversable, preferredHeightOfView, processFocusLost, processValueChanging, removeValueListener, requestFocus, setArrowEnabled, setArrowKeySpinningAllowed, setBackground, setContinuousScroll, setEditable, setEditor, setEnabled, setFont, setForeground, setLayout, setLocale, setRenderer, setUI, setValue, setValueModel, swapEditorRenderer, updateUI
 
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, getAccessibleContext, 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, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, 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, 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, isFocusable, isFocusOwner, 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, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, 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

model

protected com.klg.jclass.util.swing.JCSpinBoxModel model

itemListeners

protected com.klg.jclass.util.JCListenerList itemListeners

actionListeners

protected com.klg.jclass.util.JCListenerList actionListeners

actionCommand

protected String actionCommand

listDataListener

protected ListDataListener listDataListener

modelChanging

protected boolean modelChanging

keySelectionManager

protected JCSpinBox.KeySelectionManager keySelectionManager

lastSelectedItem

protected Object lastSelectedItem

firstPaint

protected boolean firstPaint
Constructor Detail

JCSpinBox

public JCSpinBox(com.klg.jclass.util.swing.JCSpinBoxModel aModel)
Creates a JCSpinBox that takes its items from an existing JCSpinBoxModel.

Parameters:
aModel - the SpinBoxModel that provides the displayed list of items

JCSpinBox

public JCSpinBox(Object[] items)
Creates a JCSpinBox that contains the elements in the specified array.

Parameters:
items -

JCSpinBox

public JCSpinBox(Vector items)
Creates a JCSpinBox that contains the elements in the specified Vector.

Parameters:
items -
Since:
JClass 4.0K for Java 2. If you are using JClass 4.0J, which is based on JDK 1.1, this method's parameter must be a com.sun.java.util.collections.Vector.

JCSpinBox

public JCSpinBox()
Creates a JCSpinBox with a default data model. The default data model is an empty list of objects. Use addItem to add items.

Method Detail

paint

public void paint(Graphics g)
Paints the spinbox.

Overrides:
paint in class AbstractSpinBox
Parameters:
g -

spinUp

protected Object spinUp()
Returns the new value generated when spinning up a notch. Currently we only support wraparound lists in this control.

Specified by:
spinUp in class AbstractSpinBox
Returns:
new value generated when spinning up a notch

spinDown

protected Object spinDown()
Returns the new value generated when spinning down a notch. Currently we only support wraparound lists in this control.

Specified by:
spinDown in class AbstractSpinBox
Returns:
new value generated when spinning down a notch

getSelectedObjects

public Object[] getSelectedObjects()
Returns an array containing the selected item. This method is implemented for compatibility with ItemSelectable.

Specified by:
getSelectedObjects in interface ItemSelectable
Returns:
an array of Objects containing one element -- the selected item

processValueChanged

protected void processValueChanged(com.klg.jclass.util.value.JCValueEvent event)
Description copied from class: AbstractSpinBox
This method can be overridded by the subclass

Overrides:
processValueChanged in class AbstractSpinBox

checkArrowButtons

protected void checkArrowButtons()
Disables the arrow buttons if the end of the range is reached. This is an empty implementation since all spinning is wrap around.

Specified by:
checkArrowButtons in class AbstractSpinBox
See Also:
AbstractSpinBox.setArrowEnabled(javax.swing.JButton, boolean)

setAbout

public void setAbout(String s)
Provided for Beans property editors - has no effect.

Parameters:
s -

getAbout

public String getAbout()
Returns vendor information.

Returns:
vendor information

setModel

public void setModel(com.klg.jclass.util.swing.JCSpinBoxModel aModel)
Sets the data model that the JCSpinBox uses to obtain the list of items.

Parameters:
aModel - the JCSpinBoxModel that provides the displayed list of items

getModel

public com.klg.jclass.util.swing.JCSpinBoxModel getModel()
Returns the data model currently used by the JCSpinBox.

Returns:
the JCSpinBoxModel that provides the displayed list of items

getItemAt

public Object getItemAt(int index)
Returns the list item at the specified index.

Parameters:
index - an int indicating the list position, where the first item starts at zero
Returns:
the Object at that list position

getItemCount

public int getItemCount()
Returns the number of items in the list.

Returns:
an int equal to the number of items in the list

setKeySelectionManager

public void setKeySelectionManager(JCSpinBox.KeySelectionManager aManager)
Sets the object that translates a keyboard character into a list selection. Typically, the first selection with a matching first character becomes the selected item.

Parameters:
aManager -

getKeySelectionManager

public JCSpinBox.KeySelectionManager getKeySelectionManager()
Returns the list's key-selection manager.

Returns:
the KeySelectionManager currently in use

selectWithKeyChar

public boolean selectWithKeyChar(char keyChar)
Selects the list item that correponds to the specified keyboard character and returns true if there is an item corresponding to that character.

Parameters:
keyChar - a char, typically this is a keyboard key typed by the user
Returns:

setSelectedIndex

public void setSelectedIndex(int index)
Selects the item at index index.

Parameters:
index - an int specifying the list item to select, where 0 specifies the first item in the list

getSelectedIndex

public int getSelectedIndex()
Returns the index of the currently selected item in the list. The result is not always defined if the JCSpinBox box allows selected items that are not in the list.
Returns -1 if there is no selected item or if the user specified an item which is not in the list.

Returns:
an int specifying the currently selected list item, where 0 specifies the first item in the list, or -1 if no item is selected or if the currently selected item is not in the list

setSelectedItem

public void setSelectedItem(Object item)
Sets the selected item in the JCSpinBox by specifying the object in the list. If item is in the list, the list displays with item selected. If the object does not exist in the list, the default data model selects the first item in the list.

Parameters:
item - the list object to select

getSelectedItem

public Object getSelectedItem()
Returns the currently selected item.

Returns:
the currently selected list object from the data model

insertItemAt

public void insertItemAt(Object o,
                         int index)
Inserts an item into the item list at a given index. This method works only if the JCSpinBox uses a data model that implements JCMutableSpinBoxModel.

Parameters:
o - the Object to add to the list
index - an int specifying the position at which to add the item

addItem

public void addItem(Object o)
Adds an item to the item list. This method works only if the JComboBox uses a JCSpinBoxMutableModel.

Parameters:
o - the Object to add to the list

removeItem

public void removeItem(Object o)
Removes an item from the item list. This method works only if the JCSpinBox uses a model that implements JCSpinBoxMutableModel. JCSpinBox uses the default data model when created with the empty constructor and no other model has been set.

Parameters:
o - the object to remove from the item list

removeItemAt

public void removeItemAt(int anIndex)
Removes the item at anIndex This method works only if the JCSpinBox model implements JCSpinBoxMutableModel.

Parameters:
anIndex - an int specifying the idex of the item to remove, where 0 indicates the first item in the list

removeAllItems

public void removeAllItems()
Removes all items from the item list. This method works only if the JCSpinBox model implements JCSpinBoxMutableModel.


addItemListener

public void addItemListener(ItemListener l)
Adds a java.awt.event.ItemListener. aListener will receive an event when the selected item changes.

Specified by:
addItemListener in interface ItemSelectable
Parameters:
l - the ItemListener that is to be notified

removeItemListener

public void removeItemListener(ItemListener l)
Removes an ItemListener.

Specified by:
removeItemListener in interface ItemSelectable
Parameters:
l - the ItemListener to remove

addActionListener

public void addActionListener(ActionListener l)
Adds an ActionListener.

Parameters:
l - the actionListener that is to be notified

removeActionListener

public void removeActionListener(ActionListener l)
Removes an ActionListener.

Parameters:
l - the ActionListener to remove

setActionCommand

public void setActionCommand(String aCommand)
Sets the action command that should be included in the event sent to action listeners.

Parameters:
aCommand - A String containing the "command" that is sent to action listeners. The same listener can then do different things depending on the command it receives.

getActionCommand

public String getActionCommand()
Returns the action command that is included in the event sent to action listeners.

Returns:
the String containing the "command" that is sent to action listeners

preferredWidthOfView

protected int preferredWidthOfView()
Overrides preferred width to make sure the width is big enough for the formatted max and min values.

Overrides:
preferredWidthOfView in class AbstractSpinBox
Returns:

checkSpinBoxMutableModel

protected void checkSpinBoxMutableModel()
Checks if the current model is mutable.


modelChanged

protected void modelChanged()
This method is invoked by listeners on the data model when the model changes.


handleKeyPressed

protected void handleKeyPressed(KeyEvent e)
Overridden in JCSpinBox to add keySelectionManager functionality.

Overrides:
handleKeyPressed in class AbstractSpinBox
Parameters:
e -

Copyright © 2004 Quest Software Inc..
All rights reserved.