javax.swing.plaf.basic

Class BasicComboBoxUI

Known Direct Subclasses:
MetalComboBoxUI

public class BasicComboBoxUI
extends ComboBoxUI

A UI delegate for the JComboBox component.

Nested Class Summary

class
BasicComboBoxUI.ComboBoxLayoutManager
A LayoutManager used to position the sub-components of the JComboBox.
class
BasicComboBoxUI.FocusHandler
Handles focus changes occuring in the combo box.
class
BasicComboBoxUI.ItemHandler
Handles ItemEvents fired by the JComboBox when its selected item changes.
class
BasicComboBoxUI.KeyHandler
KeyHandler handles key events occuring while JComboBox has focus.
class
BasicComboBoxUI.ListDataHandler
Handles the changes occurring in the JComboBox's data model.
class
BasicComboBoxUI.PropertyChangeHandler
Handles PropertyChangeEvents fired by the JComboBox.

Field Summary

protected JButton
arrowButton
The arrow button that is displayed in the right side of JComboBox.
protected Dimension
cachedMinimumSize
The current minimum size if isMinimumSizeDirty is false.
protected JComboBox
comboBox
The combo box represented by this UI delegate.
protected CellRendererPane
currentValuePane
Used to render the combo box values.
protected Component
editor
The component that is responsible for displaying/editing the selected item of the combo box.
protected FocusListener
focusListener
A listener listening to focus events occurring in the JComboBox.
protected boolean
hasFocus
A flag indicating whether JComboBox currently has the focus.
protected boolean
isMinimumSizeDirty
Indicates whether or not the cachedMinimumSize field is valid or not.
protected ItemListener
itemListener
A listener listening to item events fired by the JComboBox.
protected KeyListener
keyListener
A listener listening to key events that occur while JComboBox has the focus.
protected JList
listBox
List used when rendering selected item of the combo box.
protected ListDataListener
listDataListener
ListDataListener listening to JComboBox model
protected ComboPopup
popup
Popup list containing the combo box's menu items.
protected KeyListener
popupKeyListener
protected MouseListener
popupMouseListener
protected MouseMotionListener
popupMouseMotionListener
protected PropertyChangeListener
propertyChangeListener
Listener listening to changes in the bound properties of JComboBox

Constructor Summary

BasicComboBoxUI()
Creates a new BasicComboBoxUI object.

Method Summary

void
addEditor()
Adds the current editor to the combo box.
void
configureArrowButton()
Configures the arrow button.
protected void
configureEditor()
Configures the editor for this combo box.
protected JButton
createArrowButton()
Creates an arrow button for this JComboBox.
protected ComboBoxEditor
createEditor()
Creates the component that will be responsible for displaying/editing the selected item in the combo box.
protected FocusListener
createFocusListener()
Creates the FocusListener that will listen to changes in this JComboBox's focus.
protected ItemListener
createItemListener()
Creates an ItemListener that will listen to the changes in the JComboBox's selection.
protected KeyListener
createKeyListener()
Creates a KeyListener to listen to key events.
protected LayoutManager
createLayoutManager()
Creates and returns a layout manager for the combo box.
protected ListDataListener
createListDataListener()
Creates a ListDataListener to listen to the combo box's data model.
protected ComboPopup
createPopup()
Creates the popup that will contain list of combo box's items.
protected PropertyChangeListener
createPropertyChangeListener()
Creates a PropertyChangeListener to listen to the changes in the JComboBox's bound properties.
protected ListCellRenderer
createRenderer()
Creates a component that will be responsible for rendering the selected component in the combo box.
static ComponentUI
createUI(JComponent c)
A factory method to create a UI delegate for the given JComponent, which should be a JComboBox.
Accessible
getAccessibleChild(JComponent c, int i)
Returns the accessible child with the specified index.
int
getAccessibleChildrenCount(JComponent c)
Returns the number of accessible children of the combobox.
protected Dimension
getDefaultSize()
Returns the default size for the display area of a combo box that does not contain any elements.
protected Dimension
getDisplaySize()
Returns the size of the display area for the combo box.
protected Insets
getInsets()
Returns the insets of the current border.
Dimension
getMaximumSize(JComponent c)
Returns the maximum size for this JComboBox for this look and feel.
Dimension
getMinimumSize(JComponent c)
Returns the minimum size for this JComboBox for this look and feel.
Dimension
getPreferredSize(JComponent c)
Returns preferred size for the combo box.
protected void
installComponents()
Installs the components for this JComboBox.
protected void
installDefaults()
Installs the defaults that are defined in the BasicLookAndFeel for this JComboBox.
protected void
installKeyboardActions()
Installs the keyboard actions for the JComboBox as specified by the look and feel.
protected void
installListeners()
Creates and installs the listeners for this UI.
void
installUI(JComponent c)
Installs the UI for the given JComponent.
boolean
isFocusTraversable(JComboBox c)
JComboBox is focus traversable if it is editable and not otherwise.
protected boolean
isNavigationKey(int keyCode)
Returns true if the specified key is a navigation key and false otherwise
boolean
isPopupVisible(JComboBox c)
Returns true if the popup is visible, and false otherwise.
void
paint(Graphics g, JComponent c)
Paints given menu item using specified graphics context
void
paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
Paints currently selected value in the main part of the combo box (part without popup).
void
paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
Paints the background of part of the combo box, where currently selected value is displayed.
protected Rectangle
rectangleForCurrentValue()
Returns the bounds in which comboBox's selected item will be displayed.
void
removeEditor()
Removes the current editor from the combo box.
protected void
selectNextPossibleValue()
Selects next possible item relative to the current selection to be next selected item in the combo box.
protected void
selectPreviousPossibleValue()
Selects previous item relative to current selection to be next selected item.
void
setPopupVisible(JComboBox c, boolean v)
Displays/hides the JComboBox's list of items on the screen.
protected void
toggleOpenClose()
Displays combo box popup if the popup is not currently shown on the screen and hides it if it is currently shown
void
unconfigureArrowButton()
Unconfigures the arrow button.
protected void
unconfigureEditor()
Unconfigures the editor for this combo box.
protected void
uninstallComponents()
Uninstalls components from this JComboBox.
protected void
uninstallDefaults()
Uninstalls the defaults and sets any objects created during install to null.
protected void
uninstallKeyboardActions()
Uninstalls the keyboard actions for the JComboBox there were installed by in installListeners().
protected void
uninstallListeners()
Detaches all the listeners we attached in installListeners().
void
uninstallUI(JComponent c)
Uninstalls the UI for the given JComponent.

Methods inherited from class javax.swing.plaf.ComboBoxUI

isFocusTraversable, isPopupVisible, setPopupVisible

Methods inherited from class javax.swing.plaf.ComponentUI

contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, installUI, paint, uninstallUI, update

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

arrowButton

protected JButton arrowButton
The arrow button that is displayed in the right side of JComboBox. This button is used to hide and show combo box's list of items.

cachedMinimumSize

protected Dimension cachedMinimumSize
The current minimum size if isMinimumSizeDirty is false. Setup by getMinimumSize() and invalidated by the various listeners.

comboBox

protected JComboBox comboBox
The combo box represented by this UI delegate.

currentValuePane

protected CellRendererPane currentValuePane
Used to render the combo box values.

editor

protected Component editor
The component that is responsible for displaying/editing the selected item of the combo box.

focusListener

protected FocusListener focusListener
A listener listening to focus events occurring in the JComboBox.

hasFocus

protected boolean hasFocus
A flag indicating whether JComboBox currently has the focus.

isMinimumSizeDirty

protected boolean isMinimumSizeDirty
Indicates whether or not the cachedMinimumSize field is valid or not.

itemListener

protected ItemListener itemListener
A listener listening to item events fired by the JComboBox.

keyListener

protected KeyListener keyListener
A listener listening to key events that occur while JComboBox has the focus.

listBox

protected JList listBox
List used when rendering selected item of the combo box. The selection and foreground colors for combo box renderer are configured from this list.

listDataListener

protected ListDataListener listDataListener
ListDataListener listening to JComboBox model

popup

protected ComboPopup popup
Popup list containing the combo box's menu items.

popupKeyListener

protected KeyListener popupKeyListener

popupMouseListener

protected MouseListener popupMouseListener

popupMouseMotionListener

protected MouseMotionListener popupMouseMotionListener

propertyChangeListener

protected PropertyChangeListener propertyChangeListener
Listener listening to changes in the bound properties of JComboBox

Constructor Details

BasicComboBoxUI

public BasicComboBoxUI()
Creates a new BasicComboBoxUI object.

Method Details

addEditor

public void addEditor()
Adds the current editor to the combo box.

configureArrowButton

public void configureArrowButton()
Configures the arrow button.

configureEditor

protected void configureEditor()
Configures the editor for this combo box.

createArrowButton

protected JButton createArrowButton()
Creates an arrow button for this JComboBox. The arrow button is displayed at the right end of the combo box and is used to display/hide the drop down list of items.
Returns:
A new button.

createEditor

protected ComboBoxEditor createEditor()
Creates the component that will be responsible for displaying/editing the selected item in the combo box. This editor is used only when combo box is editable.
Returns:
A new component that will be responsible for displaying/editing the selected item in the combo box.

createFocusListener

protected FocusListener createFocusListener()
Creates the FocusListener that will listen to changes in this JComboBox's focus.
Returns:
the FocusListener.

createItemListener

protected ItemListener createItemListener()
Creates an ItemListener that will listen to the changes in the JComboBox's selection.
Returns:
The ItemListener

createKeyListener

protected KeyListener createKeyListener()
Creates a KeyListener to listen to key events.
Returns:
KeyListener that listens to key events.

createLayoutManager

protected LayoutManager createLayoutManager()
Creates and returns a layout manager for the combo box. Subclasses can override this method to provide a different layout.
Returns:
a layout manager for the combo box.

createListDataListener

protected ListDataListener createListDataListener()
Creates a ListDataListener to listen to the combo box's data model.
Returns:
The new listener.

createPopup

protected ComboPopup createPopup()
Creates the popup that will contain list of combo box's items.
Returns:
popup containing list of combo box's items

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Creates a PropertyChangeListener to listen to the changes in the JComboBox's bound properties.
Returns:
The PropertyChangeListener

createRenderer

protected ListCellRenderer createRenderer()
Creates a component that will be responsible for rendering the selected component in the combo box.
Returns:
A renderer for the combo box.

createUI

public static ComponentUI createUI(JComponent c)
A factory method to create a UI delegate for the given JComponent, which should be a JComboBox.
Overrides:
createUI in interface ComponentUI
Parameters:
c - The JComponent a UI is being created for.
Returns:
A UI delegate for the JComponent.

getAccessibleChild

public Accessible getAccessibleChild(JComponent c,
                                     int i)
Returns the accessible child with the specified index.
Overrides:
getAccessibleChild in interface ComponentUI
Parameters:
c - the component, this is ignored
i - the index of the accessible child to return

getAccessibleChildrenCount

public int getAccessibleChildrenCount(JComponent c)
Returns the number of accessible children of the combobox.
Overrides:
getAccessibleChildrenCount in interface ComponentUI
Parameters:
c - the component (combobox) to check, ignored
Returns:
the number of accessible children of the combobox

getDefaultSize

protected Dimension getDefaultSize()
Returns the default size for the display area of a combo box that does not contain any elements. This method returns the width and height of a single space in the current font, plus a margin of 1 pixel.
Returns:
The default display size.

getDisplaySize

protected Dimension getDisplaySize()
Returns the size of the display area for the combo box. This size will be the size of the combo box, not including the arrowButton.
Returns:
The size of the display area for the combo box.

getInsets

protected Insets getInsets()
Returns the insets of the current border.
Returns:
Insets representing space between combo box and its border

getMaximumSize

public Dimension getMaximumSize(JComponent c)
Returns the maximum size for this JComboBox for this look and feel.
Overrides:
getMaximumSize in interface ComponentUI
Parameters:
c - The JComponent to find the maximum size for
Returns:
The maximum size (Dimension(32767, 32767)).

getMinimumSize

public Dimension getMinimumSize(JComponent c)
Returns the minimum size for this JComboBox for this look and feel. Also makes sure cachedMinimimSize is setup correctly.
Overrides:
getMinimumSize in interface ComponentUI
Parameters:
c - The JComponent to find the minimum size for.
Returns:
The dimensions of the minimum size.

getPreferredSize

public Dimension getPreferredSize(JComponent c)
Returns preferred size for the combo box.
Overrides:
getPreferredSize in interface ComponentUI
Parameters:
c - comboBox for which to get preferred size
Returns:
The preferred size for the given combo box

installComponents

protected void installComponents()
Installs the components for this JComboBox. ArrowButton, main part of combo box (upper part) and popup list of items are created and configured here.

installDefaults

protected void installDefaults()
Installs the defaults that are defined in the BasicLookAndFeel for this JComboBox.

installKeyboardActions

protected void installKeyboardActions()
Installs the keyboard actions for the JComboBox as specified by the look and feel.

installListeners

protected void installListeners()
Creates and installs the listeners for this UI.

installUI

public void installUI(JComponent c)
Installs the UI for the given JComponent.
Overrides:
installUI in interface ComponentUI
Parameters:
c - the JComponent to install a UI for.

isFocusTraversable

public boolean isFocusTraversable(JComboBox c)
JComboBox is focus traversable if it is editable and not otherwise.
Overrides:
isFocusTraversable in interface ComboBoxUI
Parameters:
c - combo box for which to check whether it is focus traversable
Returns:
true if focus tranversable and false otherwise

isNavigationKey

protected boolean isNavigationKey(int keyCode)
Returns true if the specified key is a navigation key and false otherwise
Parameters:
keyCode - a key for which to check whether it is navigation key or not.
Returns:
true if the specified key is a navigation key and false otherwis

isPopupVisible

public boolean isPopupVisible(JComboBox c)
Returns true if the popup is visible, and false otherwise.
Overrides:
isPopupVisible in interface ComboBoxUI
Parameters:
c - The JComboBox to check
Returns:
true if popup part of the JComboBox is visible and false otherwise.

paint

public void paint(Graphics g,
                  JComponent c)
Paints given menu item using specified graphics context
Overrides:
paint in interface ComponentUI
Parameters:
g - The graphics context used to paint this combo box
c - comboBox which needs to be painted.

paintCurrentValue

public void paintCurrentValue(Graphics g,
                              Rectangle bounds,
                              boolean hasFocus)
Paints currently selected value in the main part of the combo box (part without popup).
Parameters:
g - graphics context
bounds - Rectangle representing the size of the area in which selected item should be drawn
hasFocus - true if combo box has focus and false otherwise

paintCurrentValueBackground

public void paintCurrentValueBackground(Graphics g,
                                        Rectangle bounds,
                                        boolean hasFocus)
Paints the background of part of the combo box, where currently selected value is displayed. If the combo box has focus this method should also paint focus rectangle around the combo box.
Parameters:
g - graphics context
bounds - Rectangle representing the size of the largest item in the comboBox
hasFocus - true if combo box has fox and false otherwise

rectangleForCurrentValue

protected Rectangle rectangleForCurrentValue()
Returns the bounds in which comboBox's selected item will be displayed.
Returns:
rectangle bounds in which comboBox's selected Item will be displayed

removeEditor

public void removeEditor()
Removes the current editor from the combo box.

selectNextPossibleValue

protected void selectNextPossibleValue()
Selects next possible item relative to the current selection to be next selected item in the combo box.

selectPreviousPossibleValue

protected void selectPreviousPossibleValue()
Selects previous item relative to current selection to be next selected item.

setPopupVisible

public void setPopupVisible(JComboBox c,
                            boolean v)
Displays/hides the JComboBox's list of items on the screen.
Overrides:
setPopupVisible in interface ComboBoxUI
Parameters:
c - The combo box, for which list of items should be displayed/hidden
v - true if show popup part of the jcomboBox and false to hide.

toggleOpenClose

protected void toggleOpenClose()
Displays combo box popup if the popup is not currently shown on the screen and hides it if it is currently shown

unconfigureArrowButton

public void unconfigureArrowButton()
Unconfigures the arrow button.

unconfigureEditor

protected void unconfigureEditor()
Unconfigures the editor for this combo box.

uninstallComponents

protected void uninstallComponents()
Uninstalls components from this JComboBox.

uninstallDefaults

protected void uninstallDefaults()
Uninstalls the defaults and sets any objects created during install to null.

uninstallKeyboardActions

protected void uninstallKeyboardActions()
Uninstalls the keyboard actions for the JComboBox there were installed by in installListeners().

uninstallListeners

protected void uninstallListeners()
Detaches all the listeners we attached in installListeners().

uninstallUI

public void uninstallUI(JComponent c)
Uninstalls the UI for the given JComponent.
Overrides:
uninstallUI in interface ComponentUI
Parameters:
c - The JComponent that is having this UI removed.

BasicComboBoxUI.java -- Copyright (C) 2004, 2005, 2006, Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.