com.tensegrity.gui.swing.control.multiselect
Class MultiSelectComboBox

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.AbstractButton
                  extended byjavax.swing.JButton
                      extended bycom.tensegrity.gui.swing.control.multiselect.MultiSelectComboBox
All Implemented Interfaces:
javax.accessibility.Accessible, Evaluable, java.util.EventListener, java.awt.image.ImageObserver, java.awt.event.ItemListener, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable, javax.swing.SwingConstants
Direct Known Subclasses:
AnchorComboBox, ColorComboBox, MarkerComboBox, PaintFormatComboBox, RasterComboBox, StrokeFormatComboBox

public abstract class MultiSelectComboBox
extends javax.swing.JButton
implements java.awt.ItemSelectable, java.awt.event.ItemListener, Evaluable

A MultiSelectComboBox follows the general principle of a combobox but offers the possibility to use a different component as list. Items of a combobox are usually listed below the control. A MultiSelectComboBox allows to display all contained elements at once by using a MultiSelectPanel. This class is by intention abstract. Users of this class must extend the class and implement 3 methods.

  1. createLabel: This method must return a Component which will be used as Label for the combo. The label is the most left component of the collapsed combo and should reflect the current selected item of the internal multiselectpanel.
  2. 2. createMultiSelect: This method returns the MultiSelectPanel which should be used to display when the user clicks on the button.
  3. 3. updateLabel: This method will be invoked each time the label must be updated. That happens on setSelection, setSelectedIndex or whenever the internal multiselect fires an itemStateChanged.

Version:
$Id: MultiSelectComboBox.java,v 1.50 2006/03/02 11:40:57 BurkhardWick Exp $
Author:
Gilles Iachelini
See Also:
createLabel(), updateItemLabel(MultiSelectItem), createMultiSelect(), Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JButton
javax.swing.JButton.AccessibleJButton
 
Nested classes inherited from class javax.swing.AbstractButton
javax.swing.AbstractButton.AccessibleAbstractButton, javax.swing.AbstractButton.ButtonChangeListener
 
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  java.util.ArrayList listeners
          The list of item listeners.
protected  MultiSelectPanel multiSelect
          MultiSelectPanel for the various colors.
 UIItemEvaluationList uiItemEvList
          the item list
protected  UIManager uiManager
          uiManager: The registered UIManager for resolving resources
 
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected MultiSelectComboBox()
          Empty default constructor for the MultiSelectComboBox.
  MultiSelectComboBox(UIManager uiManager)
          The Constructor for ColorComboBox creates a new ColorComboBox with the Default colors and a button within the popup to let user pick a custom color.
  MultiSelectComboBox(UIManager uiManager, int preferredControlHeight)
          The Constructor for ColorComboBox creates a new ColorComboBox with the Default colors and a button within the popup to let user pick a custom color.
 
Method Summary
 void addItemListener(java.awt.event.ItemListener listener)
          Creates a new Listener-list if necessary and adds the given listener instance to it.
 void applyEvList()
          Triggers the update mechanism for the installed controls.
protected  void createCombo()
          Method createCombo creates the combo consisting of a label, separator, a button and a popup, which pops up if the user clicks on the button.
protected abstract  javax.swing.JLabel createLabel()
          Implemented by subclasses to specify the label to be used next to the button.
protected abstract  MultiSelectPanel createMultiSelect()
          Implemented by subclass to specify the MultiSelectPanel control used within the popup menu.
 void fireEvent(MultiSelectItem item)
          Fires an ItemEvent to all listeners of this ComboBox.
 void fireEvent(java.lang.Object object)
          Allows subclasses to fire ItemEvents with a custom object "by hand".
protected  java.awt.event.ItemEvent getItemEvent(MultiSelectItem item)
          This method returns a new ItemEvent with this as source and the given MultMultiSelectItem instance as item.
 javax.swing.JLabel getItemLabel()
          Method getLabel returns the internal used instance of the label.
 java.awt.Dimension getMinimumSize()
           
 MultiSelectPanel getMultiSelect()
          Method getMultiSelect returns the internal MultiSelectPanel.
 javax.swing.JPopupMenu getPopup()
          Returns the popup window used in this ComboBox.
 java.awt.Dimension getPreferredSize()
           
 int getSelectedIndex()
          Method getSelectedIndex returns the index of the current selected item.
 java.lang.Object[] getSelectedObjects()
          Returns an array with the current selection.
 MultiSelectItem getSelection()
          Method getSelection returns the current selected MultiSelectItem.
 int indexOf(java.lang.Object object)
          Method indexOf returns the index in the internal MultiSelectPanel of the given object.
 void installEvList()
          Resets the uiItemEvList.
 void itemStateChanged(java.awt.event.ItemEvent e)
          Sets the color for the label and closes the popup, then fires an ItemEvent with the combo as source to all listeners.
protected  void paintChildren(java.awt.Graphics g)
           
 void removeItemListener(java.awt.event.ItemListener listener)
          Removes the given listener from the internal ItemListener list.
 void setEnabled(boolean enabled)
          Sets the enable flag for this ComboBox.
 void setSelectedIndex(int i)
          Method setSelectedIndex sets the selected item within the multiselect to the given index.
protected  void togglePopup()
          Opens the internal itemWindow instance
protected abstract  void updateItemLabel(MultiSelectItem item)
          Called by the ComboBox when a selection occurs within the MultiSelectPanel.
 
Methods inherited from class javax.swing.JButton
configurePropertiesFromAction, getAccessibleContext, getUIClassID, isDefaultButton, isDefaultCapable, paramString, removeNotify, setDefaultCapable, updateUI
 
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, checkHorizontalKey, checkVerticalKey, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, removeActionListener, removeChangeListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
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, getNextFocusableComponent, 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, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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, 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

uiItemEvList

public UIItemEvaluationList uiItemEvList
the item list


uiManager

protected UIManager uiManager
uiManager: The registered UIManager for resolving resources


multiSelect

protected MultiSelectPanel multiSelect
MultiSelectPanel for the various colors.


listeners

protected java.util.ArrayList listeners
The list of item listeners.

Constructor Detail

MultiSelectComboBox

protected MultiSelectComboBox()
Empty default constructor for the MultiSelectComboBox. Useful for subclasses which like to create custom ComboBoxes.


MultiSelectComboBox

public MultiSelectComboBox(UIManager uiManager)
The Constructor for ColorComboBox creates a new ColorComboBox with the Default colors and a button within the popup to let user pick a custom color.

Parameters:
uiManager - UIManager to obtain strings from.

MultiSelectComboBox

public MultiSelectComboBox(UIManager uiManager,
                           int preferredControlHeight)
The Constructor for ColorComboBox creates a new ColorComboBox with the Default colors and a button within the popup to let user pick a custom color.

Parameters:
uiManager - UIManager to obtain strings from.
preferredControlHeight - The height of the control
Method Detail

createLabel

protected abstract javax.swing.JLabel createLabel()
Implemented by subclasses to specify the label to be used next to the button. This label usually reflects the current selection. Overwrite updateLabel to get notified when the label needs to be updated.

Returns:
the label to be used.
See Also:
updateItemLabel(MultiSelectItem)

Find more information in the class documentation


getItemLabel

public javax.swing.JLabel getItemLabel()
Method getLabel returns the internal used instance of the label.

Returns:
JLabel the internal label of this combo.

updateItemLabel

protected abstract void updateItemLabel(MultiSelectItem item)
Called by the ComboBox when a selection occurs within the MultiSelectPanel. Subclasses should specify how to update the label according to the selection.

Parameters:
item - the selected item.
See Also:
createLabel()

Find more information in the class documentation


indexOf

public int indexOf(java.lang.Object object)
Method indexOf returns the index in the internal MultiSelectPanel of the given object. or -1 if no such object was found.

Parameters:
object - the object to find the index for.
Returns:
int the index or -1 if no such object is found.

getItemEvent

protected java.awt.event.ItemEvent getItemEvent(MultiSelectItem item)
This method returns a new ItemEvent with this as source and the given MultMultiSelectItem instance as item.

Subclasses may overwrite this method and return a custom event with different source or item. E.g. a ColorComboBox may wish to send out ItemEvent's with a Color instance as item, rather then a MultiSelectItem item.

Parameters:
item - The item which has been selected by user.
Returns:
ItemEvent a newly created ItemEvent instance.

createMultiSelect

protected abstract MultiSelectPanel createMultiSelect()
Implemented by subclass to specify the MultiSelectPanel control used within the popup menu. Implementations of this method usually create a list of MultiSelectItems, add these to a new instance of MultiSelectPanel and return that instance.

Returns:
the MultiSelectPanel used for the popup of this ComboBox.

Find more information in the class documentation


getMultiSelect

public MultiSelectPanel getMultiSelect()
Method getMultiSelect returns the internal MultiSelectPanel.

Returns:
the MultiSelectPanel instance.

getPreferredSize

public java.awt.Dimension getPreferredSize()

getMinimumSize

public java.awt.Dimension getMinimumSize()

setSelectedIndex

public void setSelectedIndex(int i)
Method setSelectedIndex sets the selected item within the multiselect to the given index.

Parameters:
i - the index of the element.
See Also:
MultiSelectPanel.setSelectedIndex(int)

addItemListener

public void addItemListener(java.awt.event.ItemListener listener)
Creates a new Listener-list if necessary and adds the given listener instance to it.

Specified by:
addItemListener in interface java.awt.ItemSelectable
Parameters:
listener - the listener to add to the internal list.
See Also:
ItemSelectable.addItemListener(ItemListener)

removeItemListener

public void removeItemListener(java.awt.event.ItemListener listener)
Removes the given listener from the internal ItemListener list. If the list is empty after the removal, the list is discharded.

Specified by:
removeItemListener in interface java.awt.ItemSelectable
Parameters:
listener - the listener to remove.
See Also:
ItemSelectable.removeItemListener(ItemListener)

setEnabled

public void setEnabled(boolean enabled)
Sets the enable flag for this ComboBox. Usually a combo reflects the disabled state by calling setEnabled(false) for all of its components. This call is delegated to the internal button, separator and label. A different border is used for the label and the raisedBevelBorder for this combo is removed as well to give the control a nifty disabled look.

See Also:
JComponent.setEnabled(boolean)

getSelectedObjects

public java.lang.Object[] getSelectedObjects()
Returns an array with the current selection.

Specified by:
getSelectedObjects in interface java.awt.ItemSelectable
Returns:
Object[] the list of elements, which are current selected.
See Also:
ItemSelectable.getSelectedObjects()

getSelectedIndex

public int getSelectedIndex()
Method getSelectedIndex returns the index of the current selected item. Basically this call is directly delegated to the internal MultiSelect control.

Returns:
the index of the selected element as integer.

getSelection

public MultiSelectItem getSelection()
Method getSelection returns the current selected MultiSelectItem.

Returns:
the current selection.

togglePopup

protected void togglePopup()
Opens the internal itemWindow instance


createCombo

protected void createCombo()
Method createCombo creates the combo consisting of a label, separator, a button and a popup, which pops up if the user clicks on the button. The popup contains by default the internal MultiSelectPanel instance.


itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent e)
Sets the color for the label and closes the popup, then fires an ItemEvent with the combo as source to all listeners.

Specified by:
itemStateChanged in interface java.awt.event.ItemListener
See Also:
ItemListener.itemStateChanged(ItemEvent)

fireEvent

public void fireEvent(MultiSelectItem item)
Fires an ItemEvent to all listeners of this ComboBox. The source of the event is the combo and *NOT* the multiselect (This is consistant with the event model). The event is created by calling the the getItemEvent method. This allows users of this class to overwrite this method and provide their own ItemEvent instance.

Parameters:
item - MultiSelectItem which originated the event.

fireEvent

public void fireEvent(java.lang.Object object)
Allows subclasses to fire ItemEvents with a custom object "by hand". Usually ItemEvents are triggered, when the internal MultiSelect triggers such events. But they are scenarios imaginable where a ComboBox uses external controls which are used to modify the selection of the MultiSelect (Imagine "Other"-Button in a ColorCombo, where users select a Custom color). The parameter is used as "item" parameter for the newly fired ItemEvent.

Parameters:
object - the instance to send to all listeneners.

getPopup

public javax.swing.JPopupMenu getPopup()
Returns the popup window used in this ComboBox.

Returns:
JPopupMenu the popup the combo uses.

paintChildren

protected void paintChildren(java.awt.Graphics g)

installEvList

public void installEvList()
Resets the uiItemEvList. Panel implementation must overwrite this method to create the association between GUI ID's and GUI Controls. This is absolute mandatory to guarantee the smooth switch between languages at runtime.
For example:
    class MyPanelImpl {
    JTextField userName;
    // ...
    protected void installEvList() {
        uiItemEvList.add(GUIItem.MYPANEL_SHEET_ID, this);
        uiItemEvList.add(GUIItem.MYPANEL_EDTUSERNAME_ID, userName);
    }
    }
    

Specified by:
installEvList in interface Evaluable

applyEvList

public void applyEvList()
Triggers the update mechanism for the installed controls.

Specified by:
applyEvList in interface Evaluable


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