org.formaria.swing
Class ComboBox

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JComboBox
                  extended by org.formaria.swing.ComboBox
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ListDataListener, ErrorDisplay, ListHolder
Direct Known Subclasses:
CheckCombo

public class ComboBox
extends javax.swing.JComboBox
implements ListHolder, ErrorDisplay

A wrapper for the Swing JComboBox class

Copyright (c) Formaria Ltd., 2008
License: see license.txt

See Also:
Serialized Form

Nested Class Summary
 class ComboBox.SystemSelectionManager
          A search manager for finding list entries as the user types a value
 
Nested classes/interfaces inherited from class javax.swing.JComboBox
javax.swing.JComboBox.AccessibleJComboBox, javax.swing.JComboBox.KeySelectionManager
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  boolean autoComplete
           
protected  int errorStatus
           
protected  boolean isCaseSensitive
           
 
Fields inherited from class javax.swing.JComboBox
actionCommand, dataModel, editor, isEditable, keySelectionManager, lightWeightPopupEnabled, maximumRowCount, renderer, selectedItemReminder
 
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
ComboBox()
          Create a new combo
 
Method Summary
 void add(java.lang.String s)
          Add an item to the list
 void addItem(java.lang.String s)
          Add an item to the drop down list
 boolean getCaseSensitive()
           
 int getErrorStatus()
           
 java.lang.Object getSelectedObject()
          Get the selected object
 java.lang.Object[] getSelectedObjects()
          Get the selected objects
 int getSelectionMode()
          Get the list selection mode.
 boolean isAutoComplete()
          Is the auto complete functionality being used.
 boolean isSearchable()
          Is the current key selectionmanager searchable
 void paintComponent(java.awt.Graphics g)
          Intercept the normal painting and add an error badge if needed
 void removeAll()
          Remove everythibg from the list
 void select(int i)
          Select an item in the list
 void select(java.lang.Object o)
          Select an item in the list
 void setAlphaNum(boolean value)
          Restrict the search to alpha numeric characters
 void setAutoComplete(boolean b)
          Sets whether to use auto complete functionality when selecting strings.
 void setBackground(java.awt.Color c)
          Set the background color for the edit field
 void setCaseSensitive(boolean value)
          Is this combo case sensitive when searching
 void setDefaultSelection()
          Set the list to its default selection state
 void setErrorMessage(java.lang.String value)
          Set the error message
 void setErrorStatus(int errorStatus)
          Set the error status
 void setForeground(java.awt.Color c)
          Set the foreground color for the edit field
 void setPause(long pause)
          Set the pause between keystrokes.
 void setRenderer(javax.swing.ListCellRenderer renderer)
          Set the list cell renderer, preserving the foreground and background colors in the process
 void setSearch(boolean doSearch)
          Set the combo as searchable
 void setSearchable(boolean doSearch)
          Set the combo as searchable
 void setSelectedObject(java.lang.Object o)
          Get the selected object
 void setSelectedObjects(java.lang.Object[] values)
          Set the selected objects
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, actionPropertyChanged, addActionListener, addItem, addItemListener, addPopupMenuListener, configureEditor, configurePropertiesFromAction, contentsChanged, createActionPropertyChangeListener, createDefaultKeySelectionManager, fireActionEvent, fireItemStateChanged, firePopupMenuCanceled, firePopupMenuWillBecomeInvisible, firePopupMenuWillBecomeVisible, getAccessibleContext, getAction, getActionCommand, getActionListeners, getEditor, getItemAt, getItemCount, getItemListeners, getKeySelectionManager, getMaximumRowCount, getModel, getPopupMenuListeners, getPrototypeDisplayValue, getRenderer, getSelectedIndex, getSelectedItem, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditable, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setModel, setPopupVisible, setPrototypeDisplayValue, setSelectedIndex, setSelectedItem, setUI, showPopup, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setInheritsPopupMenu, 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, 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, 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
 
Methods inherited from interface org.formaria.aria.ListHolder
addItem, getItemCount, getSelectedIndex
 

Field Detail

autoComplete

protected boolean autoComplete

isCaseSensitive

protected boolean isCaseSensitive

errorStatus

protected int errorStatus
Constructor Detail

ComboBox

public ComboBox()
Create a new combo

Method Detail

setDefaultSelection

public void setDefaultSelection()
Set the list to its default selection state

Specified by:
setDefaultSelection in interface ListHolder

addItem

public void addItem(java.lang.String s)
Add an item to the drop down list

Parameters:
s - the new list item

select

public void select(int i)
Select an item in the list

Specified by:
select in interface ListHolder
Parameters:
i - the selected item's index

select

public void select(java.lang.Object o)
Select an item in the list

Specified by:
select in interface ListHolder
Parameters:
o - the item to select

getSelectedObject

public java.lang.Object getSelectedObject()
Get the selected object

Specified by:
getSelectedObject in interface ListHolder
Returns:
the selection

getSelectedObjects

public java.lang.Object[] getSelectedObjects()
Get the selected objects

Specified by:
getSelectedObjects in interface java.awt.ItemSelectable
Specified by:
getSelectedObjects in interface ListHolder
Overrides:
getSelectedObjects in class javax.swing.JComboBox
Returns:
the selected object

setSelectedObject

public void setSelectedObject(java.lang.Object o)
Get the selected object

Specified by:
setSelectedObject in interface ListHolder
Parameters:
o - the selected object

setSelectedObjects

public void setSelectedObjects(java.lang.Object[] values)
Set the selected objects

Specified by:
setSelectedObjects in interface ListHolder
Parameters:
values - the selected object

add

public void add(java.lang.String s)
Add an item to the list

Parameters:
s - the new item

removeAll

public void removeAll()
Remove everythibg from the list

Specified by:
removeAll in interface ListHolder
Overrides:
removeAll in class java.awt.Container

setBackground

public void setBackground(java.awt.Color c)
Set the background color for the edit field

Overrides:
setBackground in class javax.swing.JComponent
Parameters:
c - the color

setForeground

public void setForeground(java.awt.Color c)
Set the foreground color for the edit field

Overrides:
setForeground in class javax.swing.JComponent
Parameters:
c - the color

setRenderer

public void setRenderer(javax.swing.ListCellRenderer renderer)
Set the list cell renderer, preserving the foreground and background colors in the process

Overrides:
setRenderer in class javax.swing.JComboBox
Parameters:
renderer - the new renderer.

paintComponent

public void paintComponent(java.awt.Graphics g)
Intercept the normal painting and add an error badge if needed

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g -

setSearchable

public void setSearchable(boolean doSearch)
Set the combo as searchable

Parameters:
doSearch - true to search using keys as they are typed to form a search word, or false to use only the key as the first character of the search - match only the first letter.

setSearch

public void setSearch(boolean doSearch)
Set the combo as searchable

Parameters:
doSearch - true to search using keys as they are typed to form a search word, or false to use only the key as the first character of the search - match only the first letter.

isSearchable

public boolean isSearchable()
Is the current key selectionmanager searchable

Returns:
true if a complex search is performed, false if only a single letter match is performed

setPause

public void setPause(long pause)
Set the pause between keystrokes. When the pause time is exceeded a new search begins

Parameters:
pause -

setAlphaNum

public void setAlphaNum(boolean value)
Restrict the search to alpha numeric characters

Parameters:
value -

getCaseSensitive

public boolean getCaseSensitive()

setCaseSensitive

public void setCaseSensitive(boolean value)
Is this combo case sensitive when searching

Parameters:
value - the case sensitive mode

getErrorStatus

public int getErrorStatus()

setErrorStatus

public void setErrorStatus(int errorStatus)
Description copied from interface: ErrorDisplay
Set the error status

Specified by:
setErrorStatus in interface ErrorDisplay

setErrorMessage

public void setErrorMessage(java.lang.String value)
Set the error message

Specified by:
setErrorMessage in interface ErrorDisplay
Parameters:
value - the new message

getSelectionMode

public int getSelectionMode()
Get the list selection mode. This method returns 0.

Specified by:
getSelectionMode in interface ListHolder
Returns:
  • 0=ListSelectionModel.SINGLE_SELECTION,
  • 1=ListSelectionModel.SINGLE_INTERVAL_SELECTION,
  • 2=ListSelectionModel.MULTIPLE_INTERVAL_SELECTION

setAutoComplete

public void setAutoComplete(boolean b)
Sets whether to use auto complete functionality when selecting strings.

Parameters:
autoComplete - boolean specifying whether to use auto complete or not

isAutoComplete

public boolean isAutoComplete()
Is the auto complete functionality being used.

Returns:
boolean specifying whether auto complete functionality is being used or not.