Copyright © 2011 Citra Technologies. All Rights Reserved.

com.citra.component
Class CheckComboBox

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 com.citra.component.CheckComboBox
All Implemented Interfaces:
ActionListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListDataListener

public class CheckComboBox
extends JComboBox

CheckComboBox is a JComboBox that allows multiple values to be selected, instead of just one, via checkboxes. The selected values can be retrieved with getSelectedValues and can also be assigned with setSelectedValues.

CheckComboBox uses its own list cell renderer in order to display a checkbox on every row of the box's popup menu.
It also assigns a list cell renderer wrapper under the box's normal renderer, which can be retrieved with the getRealRenderer method.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComboBox
JComboBox.AccessibleJComboBox, JComboBox.KeySelectionManager
 
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JPanel buttonPanel
          the panel that contains buttons for accepting/canceling the current selection
protected  JButton cancelButton
          the button that cancels the current selection
protected  boolean multipleSelection
          controls whether the combobox allows multiple values to be selected
protected  JButton okButton
          the button that accepts the current selection
 
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
CheckComboBox()
          Constructs a CheckComboBox.
 
Method Summary
 void addSelection(Object selectedValue)
          Adds a given object to the checkbox selection.
 void clearSelection()
          Clears all of the selected checkboxes.
 JButton getCancelButton()
          Returns the button that cancels the current selection.
protected  int getCheckBoxState(TreePath path)
          Retrieves the state of the check box for a given path.
 boolean getMultipleSelection()
          Determines whether the combobox allows the selection of multiple values via checkboxes.
 JButton getOkButton()
          Returns the button that accepts the current selection.
 ListCellRenderer getRealRenderer()
          Returns the combo box's cell renderer used for rendering the list after the checkbox part.
 List getSelectedValues()
          Retrieves the list of selected values.
 String getValue(Object selectedValue)
          Formats the selected value into a string.
 void removeSelection(Object selectedValue)
          Removes a given object from the checkbox selection.
 void selectAll()
          Adds all values to the checkbox selection.
 void setEditable(boolean editable)
          Determines whether the JComboBox field is editable.
 void setModel(ComboBoxModel model)
          Sets the data model that the JComboBox uses to obtain the list of items.
 void setMultipleSelection(boolean multipleSelection)
          Determines whether the combobox allows the selection of multiple values via checkboxes.
 void setPopupVisible(boolean show)
          Sets the visibility of the popup.
 void setRenderer(ListCellRenderer aRenderer)
          Sets the renderer that paints the list items and the item selected from the list in the JComboBox field.
 void setSelectedValues(List values)
          Assigns a list of values to the checkbox selection.
 void updateUI()
          Resets the UI property to a value from the current look and feel.
 
Methods inherited from class javax.swing.JComboBox
actionPerformed, 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, getSelectedObjects, getUI, getUIClassID, hidePopup, insertItemAt, installAncestorListener, intervalAdded, intervalRemoved, isEditable, isLightWeightPopupEnabled, isPopupVisible, paramString, processKeyEvent, removeActionListener, removeAllItems, removeItem, removeItemAt, removeItemListener, removePopupMenuListener, selectedItemChanged, selectWithKeyChar, setAction, setActionCommand, setEditor, setEnabled, setKeySelectionManager, setLightWeightPopupEnabled, setMaximumRowCount, setPrototypeDisplayValue, setSelectedIndex, setSelectedItem, setUI, showPopup
 
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, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, 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, 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, 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, removeKeyListener, 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

multipleSelection

protected boolean multipleSelection
controls whether the combobox allows multiple values to be selected


buttonPanel

protected JPanel buttonPanel
the panel that contains buttons for accepting/canceling the current selection


okButton

protected JButton okButton
the button that accepts the current selection


cancelButton

protected JButton cancelButton
the button that cancels the current selection

Constructor Detail

CheckComboBox

public CheckComboBox()
Constructs a CheckComboBox.

Method Detail

addSelection

public void addSelection(Object selectedValue)
Adds a given object to the checkbox selection.

Parameters:
selectedValue - the value to select

clearSelection

public void clearSelection()
Clears all of the selected checkboxes.


getCancelButton

public JButton getCancelButton()
Returns the button that cancels the current selection.

Returns:
the cancel button

getCheckBoxState

protected int getCheckBoxState(TreePath path)
Retrieves the state of the check box for a given path. By default, the state based on the selections of the checkbox selection model is returned.

Parameters:
path - the path to check
Returns:
the state of the check box

getMultipleSelection

public boolean getMultipleSelection()
Determines whether the combobox allows the selection of multiple values via checkboxes.

Returns:
true if selection of multiple values is allowed, false otherwise

getOkButton

public JButton getOkButton()
Returns the button that accepts the current selection.

Returns:
the accept button

getRealRenderer

public ListCellRenderer getRealRenderer()
Returns the combo box's cell renderer used for rendering the list after the checkbox part.

Returns:
the combo box's underlying cell renderer

getSelectedValues

public List getSelectedValues()
Retrieves the list of selected values.

Returns:
the selected values

getValue

public String getValue(Object selectedValue)
Formats the selected value into a string.

Parameters:
selectedValue - the value to format
Returns:
the formatted string

removeSelection

public void removeSelection(Object selectedValue)
Removes a given object from the checkbox selection.

Parameters:
selectedValue - the value to remove

selectAll

public void selectAll()
Adds all values to the checkbox selection.


setEditable

public void setEditable(boolean editable)
Determines whether the JComboBox field is editable. An editable JComboBox allows the user to type into the field or selected an item from the list to initialize the field, after which it can be edited. (The editing affects only the field, the list item remains intact.) A non editable JComboBox displays the selected item in the field, but the selection cannot be modified.

Overrides:
setEditable in class JComboBox
Parameters:
editable - a boolean value, where true indicates that the field is editable

setModel

public void setModel(ComboBoxModel model)
Sets the data model that the JComboBox uses to obtain the list of items.

Overrides:
setModel in class JComboBox
Parameters:
model - the ComboBoxModel that provides the displayed list of items

setMultipleSelection

public void setMultipleSelection(boolean multipleSelection)
Determines whether the combobox allows the selection of multiple values via checkboxes.

Parameters:
multipleSelection - true, if selection of multiple values is allowed, false otherwise

setPopupVisible

public void setPopupVisible(boolean show)
Sets the visibility of the popup.

Overrides:
setPopupVisible in class JComboBox

setRenderer

public void setRenderer(ListCellRenderer aRenderer)
Sets the renderer that paints the list items and the item selected from the list in the JComboBox field. The renderer is used if the JComboBox is not editable. If it is editable, the editor is used to render and edit the selected item.

The default renderer displays a string or an icon. Other renderers can handle graphic images and composite items.

To display the selected item, aRenderer.getListCellRendererComponent is called, passing the list object and an index of -1.

Overrides:
setRenderer in class JComboBox
Parameters:
aRenderer - the ListCellRenderer that displays the selected item
See Also:
JComboBox.setEditor(javax.swing.ComboBoxEditor)

setSelectedValues

public void setSelectedValues(List values)
Assigns a list of values to the checkbox selection.

Parameters:
values - the values to assign

updateUI

public void updateUI()
Resets the UI property to a value from the current look and feel.

Overrides:
updateUI in class JComboBox
See Also:
JComponent.updateUI()

Copyright © 2011 Citra Technologies. All Rights Reserved.