Java Platform 1.2

javax.swing.plaf.basic
Class BasicComboBoxUI

java.lang.Object
  |
  +--javax.swing.plaf.ComponentUI
        |
        +--javax.swing.plaf.ComboBoxUI
              |
              +--javax.swing.plaf.basic.BasicComboBoxUI
Direct Known Subclasses:
MetalComboBoxUI

public class BasicComboBoxUI
extends ComboBoxUI

Basic UI for JComboBox. This class adds and removes components from the JComboBox. The arrow button and the editor are managed by this object. The popup menu is handled by BasicComboPopup. BasicComboPopup supplies this class with a MouseListener, MouseMotionListener, and a KeyListener. These listeners are added to the arrow button and the JComboBox by default. Subclasses of BasicComboBoxUI should attach the listeners to whichever components they like. installListeners() is where listeners get added to the JComboBox (and model). configureEditor() is where listeners get added to the editor. configureArrowButton() is where listeners get added to the arrow button. Inner classes for handling events: FocusHandler ItemHandler ListDataHandler PropertyChangeHandler KeyHandler


Inner Class Summary
 class BasicComboBoxUI.ComboBoxLayoutManager
          This layout manager handles the 'standard' layout of combo boxes.
 class BasicComboBoxUI.FocusHandler
          This listener hides the popup when the focus is lost.
 class BasicComboBoxUI.ItemHandler
          This listener watches for changes to the selection in the combo box and updates the display of the currently selected item.
 class BasicComboBoxUI.KeyHandler
          This listener checks to see if the key event isn't a navigation key.
 class BasicComboBoxUI.ListDataHandler
          This listener watches for changes in the data and revalidates.
 class BasicComboBoxUI.PropertyChangeHandler
          This listener watches for bound properties that have changed in the JComboBox.
 
Field Summary
protected  JButton arrowButton
           
protected  Dimension cachedMinimumSize
           
protected  JComboBox comboBox
           
protected  CellRendererPane currentValuePane
           
protected  Component editor
           
protected  FocusListener focusListener
           
protected  boolean hasFocus
           
protected  boolean isMinimumSizeDirty
           
protected  ItemListener itemListener
           
protected  KeyListener keyListener
           
protected  JList listBox
           
protected  ListDataListener listDataListener
           
protected  ComboPopup popup
           
protected  KeyListener popupKeyListener
           
protected  MouseListener popupMouseListener
           
protected  MouseMotionListener popupMouseMotionListener
           
protected  PropertyChangeListener propertyChangeListener
           
 
Constructor Summary
BasicComboBoxUI()
           
 
Method Summary
 void addEditor()
          Adds the editor to the JComboBox.
 void configureArrowButton()
          Configures the arrow button by adding listeners.
protected  void configureEditor()
          Configures the editor by setting its font and adding listeners.
protected  JButton createArrowButton()
          Creates the arrow button.
protected  ComboBoxEditor createEditor()
          Creates the editor that is to be used in editable combo boxes.
protected  FocusListener createFocusListener()
          Creates the focus listener that hides the popup when the focus is lost.
protected  ItemListener createItemListener()
          Creates the item listener that watches for updates in the current selection so that it can update the display.
protected  KeyListener createKeyListener()
          Creates the key listener for handling type-ahead.
protected  LayoutManager createLayoutManager()
          Creates the standard combo box layout manager that has the arrow button to the right and the editor to the left.
protected  ListDataListener createListDataListener()
          Creates the list data listener that is used for caching the preferred sizes.
protected  ComboPopup createPopup()
          Creates an implementation of the ComboPopup interface.
protected  PropertyChangeListener createPropertyChangeListener()
          Creates the list data listener that is used for caching the preferred sizes.
protected  ListCellRenderer createRenderer()
          Creates the renderer that is to be used in the combo box.
static ComponentUI createUI(JComponent c)
           
 Accessible getAccessibleChild(JComponent c, int i)
           
 int getAccessibleChildrenCount(JComponent c)
           
protected  Dimension getDefaultSize()
          Return the dimension the the combo box should have if by default if there is no current value and no value in the list of possible values.
protected  Dimension getDisplaySize()
           
protected  Insets getInsets()
          Gets the insets from the JComboBox.
 Dimension getMaximumSize(JComponent c)
           
 Dimension getMinimumSize(JComponent c)
           
 Dimension getPreferredSize(JComponent c)
           
protected  void installComponents()
          The editor and arrow button are added to the JComboBox here.
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()
          Attaches listeners to the JComboBox and JComboBoxModel.
 void installUI(JComponent c)
           
 boolean isFocusTraversable(JComboBox 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.
 boolean isPopupVisible(JComboBox c)
          Tells if the popup is visible or not.
 void paint(Graphics g, JComponent c)
           
 void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
          Paints the currently selected item.
 void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
          Paints the background of the currently selected item.
protected  Rectangle rectangleForCurrentValue()
          Returns the area that is reserved for drawing the currently selected item.
 void removeEditor()
          Removes the editor from the JComboBox.
protected  void selectNextPossibleValue()
          Selects the next item in the list.
protected  void selectPreviousPossibleValue()
          Selects the previous item in the list.
 void setPopupVisible(JComboBox 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()
          Unconfigures the arrow button by removing listeners.
protected  void unconfigureEditor()
          Unconfigures the editor by removing listeners.
protected  void uninstallComponents()
          The editor and/or arrow button are removed from the JComboBox here.
protected  void uninstallDefaults()
          Uninstalls the default colors, default font, default renderer, and default editor into the JComboBox.
protected  void uninstallKeyboardActions()
          Removes the keyboard actions that were added by installKeyboardActions().
protected  void uninstallListeners()
          Removes listeners from the JComboBox and JComboBoxModel.
 void uninstallUI(JComponent c)
           
 
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 JComboBox comboBox

hasFocus

protected boolean hasFocus

listBox

protected JList listBox

currentValuePane

protected CellRendererPane currentValuePane

popup

protected ComboPopup popup

editor

protected Component editor

arrowButton

protected JButton arrowButton

keyListener

protected KeyListener keyListener

focusListener

protected FocusListener focusListener

itemListener

protected ItemListener itemListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener

popupMouseListener

protected MouseListener popupMouseListener

popupMouseMotionListener

protected MouseMotionListener popupMouseMotionListener

popupKeyListener

protected KeyListener popupKeyListener

listDataListener

protected ListDataListener listDataListener

isMinimumSizeDirty

protected boolean isMinimumSizeDirty

cachedMinimumSize

protected Dimension cachedMinimumSize
Constructor Detail

BasicComboBoxUI

public BasicComboBoxUI()
Method Detail

createUI

public static ComponentUI createUI(JComponent c)

installUI

public void installUI(JComponent c)
Overrides:
installUI in class ComponentUI

uninstallUI

public void uninstallUI(JComponent c)
Overrides:
uninstallUI in class ComponentUI

installDefaults

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

installListeners

protected void installListeners()
Attaches listeners to the JComboBox and JComboBoxModel.

uninstallDefaults

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

uninstallListeners

protected void uninstallListeners()
Removes listeners from the JComboBox and JComboBoxModel.

createPopup

protected ComboPopup createPopup()
Creates an implementation of the ComboPopup interface. Returns an instance of BasicComboPopup.

createKeyListener

protected KeyListener createKeyListener()
Creates the key listener for handling type-ahead. Returns an instance of BasicComboBoxUI$KeyHandler.

createFocusListener

protected FocusListener createFocusListener()
Creates the focus listener that hides the popup when the focus is lost. Returns an instance of BasicComboBoxUI$FocusHandler.

createListDataListener

protected ListDataListener createListDataListener()
Creates the list data listener that is used for caching the preferred sizes. Returns an instance of BasicComboBoxUI$ListDataHandler.

createItemListener

protected ItemListener createItemListener()
Creates the item listener that watches for updates in the current selection so that it can update the display. Returns an instance of BasicComboBoxUI$ItemHandler.

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates the list data listener that is used for caching the preferred sizes. Returns an instance of BasicComboBoxUI$PropertyChangeHandler.

createLayoutManager

protected LayoutManager createLayoutManager()
Creates the standard combo box layout manager that has the arrow button to the right and the editor to the left. Returns an instance of BasicComboBoxUI$ComboBoxLayoutManager.

createRenderer

protected ListCellRenderer createRenderer()
Creates the renderer that is to be used in the combo box. This method only gets called if a custom renderer has nto already been installed in the JComboBox.

createEditor

protected ComboBoxEditor createEditor()
Creates the editor that is to be used in editable combo boxes. This method only gets called if a custom editor has not already been installed in the JComboBox.

installComponents

protected void installComponents()
The editor and arrow button are added to the JComboBox here.

uninstallComponents

protected void uninstallComponents()
The editor and/or arrow button are removed from the JComboBox here. This method calls removeAll() on the JComboBox just to make sure that everything gets removed.

addEditor

public void addEditor()
Adds the editor to the JComboBox.

removeEditor

public void removeEditor()
Removes the editor from the JComboBox. It also calls unconfigureEditor()

configureEditor

protected void configureEditor()
Configures the editor by setting its font and adding listeners.

unconfigureEditor

protected void unconfigureEditor()
Unconfigures the editor by removing listeners.

configureArrowButton

public void configureArrowButton()
Configures the arrow button by adding listeners.

unconfigureArrowButton

public void unconfigureArrowButton()
Unconfigures the arrow button by removing listeners.

createArrowButton

protected JButton createArrowButton()
Creates the arrow button. Subclasses can create any button they like. The default behavior of this class is to attach various listeners to the button returned by this method. Returns an instance of BasicArrowButton.

isPopupVisible

public boolean isPopupVisible(JComboBox c)
Tells if the popup is visible or not.
Overrides:
isPopupVisible in class ComboBoxUI

setPopupVisible

public void setPopupVisible(JComboBox c,
                            boolean v)
Hides the popup.
Overrides:
setPopupVisible in class ComboBoxUI

isFocusTraversable

public boolean isFocusTraversable(JComboBox c)
Determines if the JComboBox is focus traversable. If the JComboBox is editable this returns false, otherwise it returns true.
Overrides:
isFocusTraversable in class ComboBoxUI

paint

public void paint(Graphics g,
                  JComponent c)
Overrides:
paint in class ComponentUI

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Overrides:
getPreferredSize in class ComponentUI

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Overrides:
getMinimumSize in class ComponentUI

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Overrides:
getMaximumSize in class ComponentUI

getAccessibleChildrenCount

public int getAccessibleChildrenCount(JComponent c)
Overrides:
getAccessibleChildrenCount in class ComponentUI

getAccessibleChild

public Accessible getAccessibleChild(JComponent c,
                                     int i)
Overrides:
getAccessibleChild in class 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.

selectNextPossibleValue

protected void selectNextPossibleValue()
Selects the next item in the list. It won't change the selection if the currently selected item is already the last item.

selectPreviousPossibleValue

protected void selectPreviousPossibleValue()
Selects the previous item in the list. It won't change the selection if the currently selected item is already the first item.

toggleOpenClose

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

rectangleForCurrentValue

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

getInsets

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

paintCurrentValue

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

paintCurrentValueBackground

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

getDefaultSize

protected Dimension getDefaultSize()
Return the dimension the the combo box should have if by default if there is no current value and no value in the list of possible values.

getDisplaySize

protected Dimension getDisplaySize()

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.

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Removes the keyboard actions that were added by installKeyboardActions().

Java Platform 1.2

Submit a bug or feature Version 1.2 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.