net.sf.sbcc.componentcombo.plaf.basic
Class BasicComponentComboBoxUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by net.sf.sbcc.componentcombo.plaf.ComponentComboBoxUI
          extended by net.sf.sbcc.componentcombo.plaf.basic.BasicComponentComboBoxUI
Direct Known Subclasses:
MetalComponentComboBoxUI, MotifComponentComboBoxUI

public class BasicComponentComboBoxUI
extends ComponentComboBoxUI

Basic UI implementation for JComboBox.

The combo box is a compound component which means that it is an agregate of many simpler components. This class creates and manages the listeners on the combo box and the combo box model. These listeners update the user interface in response to changes in the properties and state of the combo box.

All event handling is handled by listener classes created with the createxxxListener() methods and internal classes. You can change the behavior of this class by overriding the createxxxListener() methods and supplying your own event listeners or subclassing from the ones supplied in this class.

For adding specific actions, overide installKeyboardActions to add actions in response to KeyStroke bindings. See the article Keyboard Bindings in Swing at The Swing Connection.

Version:
1.171 09/10/04
Author:
Arnaud Weber, Tom Santos, Mark Davidson

Nested Class Summary
private static class BasicComponentComboBoxUI.Actions
           
 class BasicComponentComboBoxUI.ComboBoxLayoutManager
          This layout manager handles the 'standard' layout of combo boxes.
(package private)  class BasicComponentComboBoxUI.DefaultKeySelectionManager
           
 class BasicComponentComboBoxUI.FocusHandler
          This listener hides the popup when the focus is lost.
private  class BasicComponentComboBoxUI.Handler
           
 class BasicComponentComboBoxUI.ItemHandler
          This listener watches for changes to the selection in the combo box.
 class BasicComponentComboBoxUI.KeyHandler
          This listener checks to see if the key event isn't a navigation key.
 class BasicComponentComboBoxUI.PropertyChangeHandler
          This listener watches for bound properties that have changed in the combo box.
 class BasicComponentComboBoxUI.SimpleDataHandler
          This listener watches for changes in the ComboBoxModel.
 
Field Summary
protected  javax.swing.JButton arrowButton
           
private  java.awt.Dimension cachedDisplaySize
           
protected  java.awt.Dimension cachedMinimumSize
           
private static java.lang.Object COMBO_UI_LIST_CELL_RENDERER_KEY
           
protected  JAbstractComponentComboBox comboBox
           
protected  javax.swing.CellRendererPane currentValuePane
           
protected  SimpleDataListener dataListener
          This protected field is implementation specific.
protected  java.awt.Component editor
           
protected  java.awt.event.FocusListener focusListener
          This protected field is implementation specific.
private  BasicComponentComboBoxUI.Handler handler
          Implements all the Listeners needed by this class, all existing listeners redirect to it.
protected  boolean hasFocus
          This protected field is implementation specific.
(package private) static java.lang.StringBuffer HIDE_POPUP_KEY
           
private  boolean isDisplaySizeDirty
           
protected  boolean isMinimumSizeDirty
           
protected  java.awt.event.ItemListener itemListener
          This protected field is implementation specific.
protected  java.awt.event.KeyListener keyListener
          This protected field is implementation specific.
(package private)  JAbstractComponentComboBox.KeySelectionManager keySelectionManager
          The default key selection manager
private  long lastTime
          This is tricky, this variables is needed for DefaultKeySelectionManager to take into account time factor.
protected  ComponentComboPopup popup
           
protected  javax.swing.JComponent popupComponent
           
protected  java.awt.event.KeyListener popupKeyListener
           
protected  java.awt.event.MouseListener popupMouseListener
           
protected  java.awt.event.MouseMotionListener popupMouseMotionListener
           
protected  java.beans.PropertyChangeListener propertyChangeListener
          This protected field is implementation specific.
private  long time
           
private  long timeFactor
          The time factor to treate the series of typed alphanumeric key as prefix for first letter navigation.
 
Constructor Summary
BasicComponentComboBoxUI()
           
 
Method Summary
private static java.lang.Object _getUIOfType(javax.swing.plaf.ComponentUI ui, java.lang.Class klass)
          Returns the ui that is of type klass, or null if one can not be found.
 void addEditor()
          This public method is implementation specific and should be private.
 void configureArrowButton()
          This public method is implementation specific and should be private.
protected  void configureEditor()
          This protected method is implementation specific and should be private.
protected  javax.swing.JButton createArrowButton()
          Creates an button which will be used as the control to show or hide the popup portion of the combo box.
protected  SimpleDataListener createDataListener()
          Creates a list data listener which will be added to the ComboBoxModel.
protected  javax.swing.ComboBoxEditor createEditor()
          Creates the default editor that will be used in editable combo boxes.
protected  java.awt.event.FocusListener createFocusListener()
          Creates a FocusListener which will be added to the combo box.
protected  java.awt.event.ItemListener createItemListener()
          Creates an ItemListener which will be added to the combo box.
protected  java.awt.event.KeyListener createKeyListener()
          Creates a KeyListener which will be added to the combo box.
protected  java.awt.LayoutManager createLayoutManager()
          Creates a layout manager for managing the components which make up the combo box.
protected  ComponentComboPopup createPopup()
          Creates the popup portion of the combo box.
protected  java.beans.PropertyChangeListener createPropertyChangeListener()
          Creates a PropertyChangeListener which will be added to the combo box.
protected  javax.swing.ListCellRenderer createRenderer()
          Creates the default renderer that will be used in a non-editiable combo box.
static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)
           
 javax.accessibility.Accessible getAccessibleChild(javax.swing.JComponent c, int i)
           
 int getAccessibleChildrenCount(javax.swing.JComponent c)
           
private static javax.swing.ListCellRenderer getDefaultListCellRenderer()
           
protected  java.awt.Dimension getDisplaySize()
          Returns the calculated size of the display area.
private  BasicComponentComboBoxUI.Handler getHandler()
          Returns the shared listener.
(package private)  javax.swing.InputMap getInputMap(int condition)
           
protected  java.awt.Insets getInsets()
          Gets the insets from the JComboBox.
 java.awt.Dimension getMaximumSize(javax.swing.JComponent c)
           
 java.awt.Dimension getMinimumSize(javax.swing.JComponent c)
          The minumum size is the size of the display area plus insets plus the button.
 java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
           
private  java.awt.Dimension getSizeForComponent(java.awt.Component comp)
          This has been refactored out in hopes that it may be investigated and simplified for the next major release. adding/removing the component to the currentValuePane and changing the font may be redundant operations.
protected  void installComponents()
          Creates and initializes the components which make up the aggregate combo box.
protected  void installDefaults()
          Installs the default colors, default font, default renderer, and default editor into the JComboBox.
protected  void installKeyboardActions()
          Adds keyboard actions to the JComboBox.
protected  void installListeners()
          Create and install the listeners for the combo box and its model.
 void installUI(javax.swing.JComponent c)
           
 boolean isFocusTraversable(JAbstractComponentComboBox c)
          Determines if the JComboBox is focus traversable.
protected  boolean isNavigationKey(int keyCode)
          Returns whether or not the supplied keyCode maps to a key that is used for navigation.
private  boolean isNavigationKey(int keyCode, int modifiers)
           
 boolean isPopupVisible(JAbstractComponentComboBox c)
          Tells if the popup is visible or not.
(package private) static void loadActionMap(LazyActionMap map)
          Populates ComboBox's actions.
 void paint(java.awt.Graphics g, javax.swing.JComponent c)
           
 void paintCurrentValue(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)
          Paints the currently selected item.
 void paintCurrentValueBackground(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)
          Paints the background of the currently selected item.
protected  java.awt.Rectangle rectangleForCurrentValue()
          Returns the area that is reserved for drawing the currently selected item.
 void removeEditor()
          This public method is implementation specific and should be private.
(package private)  void repaintCurrentValue()
          Repaint the currently selected item.
 void setPopupVisible(JAbstractComponentComboBox c, boolean v)
          Hides the popup.
protected  void toggleOpenClose()
          Hides the popup if it is showing and shows the popup if it is hidden.
 void unconfigureArrowButton()
          This public method is implementation specific and should be private.
protected  void unconfigureEditor()
          This protected method is implementation specific and should be private.
protected  void uninstallComponents()
          The aggregate components which compise the combo box are unregistered and uninitialized.
protected  void uninstallDefaults()
          Uninstalls the default colors, default font, default renderer, and default editor into the JComboBox.
protected  void uninstallKeyboardActions()
          Removes the focus InputMap and ActionMap.
protected  void uninstallListeners()
          Remove the installed listeners from the combo box and its model.
 void uninstallUI(javax.swing.JComponent c)
           
private  void updateToolTipTextForChildren()
           
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

comboBox

protected JAbstractComponentComboBox comboBox

hasFocus

protected boolean hasFocus
This protected field is implementation specific. Do not access directly or override.


popupComponent

protected javax.swing.JComponent popupComponent

currentValuePane

protected javax.swing.CellRendererPane currentValuePane

popup

protected ComponentComboPopup popup

editor

protected java.awt.Component editor

arrowButton

protected javax.swing.JButton arrowButton

keyListener

protected java.awt.event.KeyListener keyListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

See Also:
createKeyListener()

focusListener

protected java.awt.event.FocusListener focusListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

See Also:
createFocusListener()

propertyChangeListener

protected java.beans.PropertyChangeListener propertyChangeListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

See Also:
createPropertyChangeListener()

itemListener

protected java.awt.event.ItemListener itemListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

See Also:
createItemListener()

popupMouseListener

protected java.awt.event.MouseListener popupMouseListener

popupMouseMotionListener

protected java.awt.event.MouseMotionListener popupMouseMotionListener

popupKeyListener

protected java.awt.event.KeyListener popupKeyListener

dataListener

protected SimpleDataListener dataListener
This protected field is implementation specific. Do not access directly or override. Override the listener construction method instead.

See Also:
#createListDataListener

handler

private BasicComponentComboBoxUI.Handler handler
Implements all the Listeners needed by this class, all existing listeners redirect to it.


timeFactor

private long timeFactor
The time factor to treate the series of typed alphanumeric key as prefix for first letter navigation.


lastTime

private long lastTime
This is tricky, this variables is needed for DefaultKeySelectionManager to take into account time factor.


time

private long time

keySelectionManager

JAbstractComponentComboBox.KeySelectionManager keySelectionManager
The default key selection manager


isMinimumSizeDirty

protected boolean isMinimumSizeDirty

cachedMinimumSize

protected java.awt.Dimension cachedMinimumSize

isDisplaySizeDirty

private boolean isDisplaySizeDirty

cachedDisplaySize

private java.awt.Dimension cachedDisplaySize

COMBO_UI_LIST_CELL_RENDERER_KEY

private static final java.lang.Object COMBO_UI_LIST_CELL_RENDERER_KEY

HIDE_POPUP_KEY

static final java.lang.StringBuffer HIDE_POPUP_KEY
Constructor Detail

BasicComponentComboBoxUI

public BasicComponentComboBoxUI()
Method Detail

getDefaultListCellRenderer

private static javax.swing.ListCellRenderer getDefaultListCellRenderer()

loadActionMap

static void loadActionMap(LazyActionMap map)
Populates ComboBox's actions.


createUI

public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent c)

installUI

public void installUI(javax.swing.JComponent c)
Overrides:
installUI in class javax.swing.plaf.ComponentUI

uninstallUI

public void uninstallUI(javax.swing.JComponent c)
Overrides:
uninstallUI in class javax.swing.plaf.ComponentUI

installDefaults

protected void installDefaults()
Installs the default colors, default font, default renderer, and default editor into the JComboBox.


installListeners

protected void installListeners()
Create and install the listeners for the combo box and its model. This method is called when the UI is installed.


uninstallDefaults

protected void uninstallDefaults()
Uninstalls the default colors, default font, default renderer, and default editor into the JComboBox.


uninstallListeners

protected void uninstallListeners()
Remove the installed listeners from the combo box and its model. The number and types of listeners removed and in this method should be the same that was added in installListeners


createPopup

protected ComponentComboPopup createPopup()
Creates the popup portion of the combo box.

Returns:
an instance of ComboPopup
See Also:
ComponentComboPopup

createKeyListener

protected java.awt.event.KeyListener createKeyListener()
Creates a KeyListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Returns:
an instance KeyListener or null

createFocusListener

protected java.awt.event.FocusListener createFocusListener()
Creates a FocusListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Returns:
an instance of a FocusListener or null

createDataListener

protected SimpleDataListener createDataListener()
Creates a list data listener which will be added to the ComboBoxModel. If this method returns null then it will not be added to the combo box model.

Returns:
an instance of a ListDataListener or null

createItemListener

protected java.awt.event.ItemListener createItemListener()
Creates an ItemListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Subclasses may override this method to return instances of their own ItemEvent handlers.

Returns:
an instance of an ItemListener or null

createPropertyChangeListener

protected java.beans.PropertyChangeListener createPropertyChangeListener()
Creates a PropertyChangeListener which will be added to the combo box. If this method returns null then it will not be added to the combo box.

Returns:
an instance of a PropertyChangeListener or null

createLayoutManager

protected java.awt.LayoutManager createLayoutManager()
Creates a layout manager for managing the components which make up the combo box.

Returns:
an instance of a layout manager

createRenderer

protected javax.swing.ListCellRenderer createRenderer()
Creates the default renderer that will be used in a non-editiable combo box. A default renderer will used only if a renderer has not been explicitly set with setRenderer.

Returns:
a ListCellRender used for the combo box
See Also:
JComboBox.setRenderer(javax.swing.ListCellRenderer)

createEditor

protected javax.swing.ComboBoxEditor createEditor()
Creates the default editor that will be used in editable combo boxes. A default editor will be used only if an editor has not been explicitly set with setEditor.

Returns:
a ComboBoxEditor used for the combo box
See Also:
javax.swing.JAbstractComponentComboBox#setEditor

getHandler

private BasicComponentComboBoxUI.Handler getHandler()
Returns the shared listener.


updateToolTipTextForChildren

private void updateToolTipTextForChildren()

installComponents

protected void installComponents()
Creates and initializes the components which make up the aggregate combo box. This method is called as part of the UI installation process.


uninstallComponents

protected void uninstallComponents()
The aggregate components which compise the combo box are unregistered and uninitialized. This method is called as part of the UI uninstallation process.


addEditor

public void addEditor()
This public method is implementation specific and should be private. do not call or override. To implement a specific editor create a custom ComboBoxEditor

See Also:
createEditor(), JComboBox.setEditor(javax.swing.ComboBoxEditor), ComboBoxEditor

removeEditor

public void removeEditor()
This public method is implementation specific and should be private. do not call or override.

See Also:
addEditor()

configureEditor

protected void configureEditor()
This protected method is implementation specific and should be private. do not call or override.

See Also:
addEditor()

unconfigureEditor

protected void unconfigureEditor()
This protected method is implementation specific and should be private. Do not call or override.

See Also:
addEditor()

configureArrowButton

public void configureArrowButton()
This public method is implementation specific and should be private. Do not call or override.

See Also:
createArrowButton()

unconfigureArrowButton

public void unconfigureArrowButton()
This public method is implementation specific and should be private. Do not call or override.

See Also:
createArrowButton()

createArrowButton

protected javax.swing.JButton createArrowButton()
Creates an button which will be used as the control to show or hide the popup portion of the combo box.

Returns:
a button which represents the popup control

isPopupVisible

public boolean isPopupVisible(JAbstractComponentComboBox c)
Tells if the popup is visible or not.

Specified by:
isPopupVisible in class ComponentComboBoxUI

setPopupVisible

public void setPopupVisible(JAbstractComponentComboBox c,
                            boolean v)
Hides the popup.

Specified by:
setPopupVisible in class ComponentComboBoxUI

isFocusTraversable

public boolean isFocusTraversable(JAbstractComponentComboBox c)
Determines if the JComboBox is focus traversable. If the JComboBox is editable this returns false, otherwise it returns true.

Specified by:
isFocusTraversable in class ComponentComboBoxUI

paint

public void paint(java.awt.Graphics g,
                  javax.swing.JComponent c)
Overrides:
paint in class javax.swing.plaf.ComponentUI

getPreferredSize

public java.awt.Dimension getPreferredSize(javax.swing.JComponent c)
Overrides:
getPreferredSize in class javax.swing.plaf.ComponentUI

getMinimumSize

public java.awt.Dimension getMinimumSize(javax.swing.JComponent c)
The minumum size is the size of the display area plus insets plus the button.

Overrides:
getMinimumSize in class javax.swing.plaf.ComponentUI

getMaximumSize

public java.awt.Dimension getMaximumSize(javax.swing.JComponent c)
Overrides:
getMaximumSize in class javax.swing.plaf.ComponentUI

getAccessibleChildrenCount

public int getAccessibleChildrenCount(javax.swing.JComponent c)
Overrides:
getAccessibleChildrenCount in class javax.swing.plaf.ComponentUI

getAccessibleChild

public javax.accessibility.Accessible getAccessibleChild(javax.swing.JComponent c,
                                                         int i)
Overrides:
getAccessibleChild in class javax.swing.plaf.ComponentUI

isNavigationKey

protected boolean isNavigationKey(int keyCode)
Returns whether or not the supplied keyCode maps to a key that is used for navigation. This is used for optimizing key input by only passing non- navigation keys to the type-ahead mechanism. Subclasses should override this if they change the navigation keys.


isNavigationKey

private boolean isNavigationKey(int keyCode,
                                int modifiers)

toggleOpenClose

protected void toggleOpenClose()
Hides the popup if it is showing and shows the popup if it is hidden.


rectangleForCurrentValue

protected java.awt.Rectangle rectangleForCurrentValue()
Returns the area that is reserved for drawing the currently selected item.


getInsets

protected java.awt.Insets getInsets()
Gets the insets from the JComboBox.


paintCurrentValue

public void paintCurrentValue(java.awt.Graphics g,
                              java.awt.Rectangle bounds,
                              boolean hasFocus)
Paints the currently selected item.


paintCurrentValueBackground

public void paintCurrentValueBackground(java.awt.Graphics g,
                                        java.awt.Rectangle bounds,
                                        boolean hasFocus)
Paints the background of the currently selected item.


repaintCurrentValue

void repaintCurrentValue()
Repaint the currently selected item.


getDisplaySize

protected java.awt.Dimension getDisplaySize()
Returns the calculated size of the display area. The display area is the portion of the combo box in which the selected item is displayed. This method will use the prototype display value if it has been set.

For combo boxes with a non trivial number of items, it is recommended to use a prototype display value to significantly speed up the display size calculation.

Returns:
the size of the display area calculated from the combo box items
See Also:
JComboBox.setPrototypeDisplayValue(java.lang.Object)

getSizeForComponent

private java.awt.Dimension getSizeForComponent(java.awt.Component comp)
This has been refactored out in hopes that it may be investigated and simplified for the next major release. adding/removing the component to the currentValuePane and changing the font may be redundant operations.


installKeyboardActions

protected void installKeyboardActions()
Adds keyboard actions to the JComboBox. Actions on enter and esc are already supplied. Add more actions as you need them.


getInputMap

javax.swing.InputMap getInputMap(int condition)

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Removes the focus InputMap and ActionMap.


_getUIOfType

private static java.lang.Object _getUIOfType(javax.swing.plaf.ComponentUI ui,
                                             java.lang.Class klass)
Returns the ui that is of type klass, or null if one can not be found.