|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.plaf.ComponentUI javax.swing.plaf.ComboBoxUI javax.swing.plaf.basic.BasicComboBoxUI
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.
Nested Class Summary | |
(package private) static class |
BasicComboBoxUI.AltAction
|
class |
BasicComboBoxUI.ComboBoxLayoutManager
This layout manager handles the 'standard' layout of combo boxes. |
(package private) static class |
BasicComboBoxUI.DownAction
|
(package private) class |
BasicComboBoxUI.EditorActionListener
|
(package private) class |
BasicComboBoxUI.EditorFocusListener
|
(package private) static class |
BasicComboBoxUI.EnterAction
|
class |
BasicComboBoxUI.FocusHandler
This listener hides the popup when the focus is lost. |
(package private) class |
BasicComboBoxUI.HidePopupAction
|
class |
BasicComboBoxUI.ItemHandler
This listener watches for changes to the selection in the combo box. |
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 ComboBoxModel .
|
(package private) static class |
BasicComboBoxUI.NavigationalAction
|
class |
BasicComboBoxUI.PropertyChangeHandler
This listener watches for bound properties that have changed in the combo box. |
(package private) static class |
BasicComboBoxUI.SpaceAction
|
(package private) static class |
BasicComboBoxUI.UpAction
|
Field Summary | |
protected JButton |
arrowButton
|
private Dimension |
cachedDisplaySize
|
protected Dimension |
cachedMinimumSize
|
private static Object |
COMBO_UI_LIST_CELL_RENDERER_KEY
|
protected JComboBox |
comboBox
|
protected CellRendererPane |
currentValuePane
|
protected Component |
editor
|
private ActionListener |
editorActionListener
|
private FocusListener |
editorFocusListener
|
(package private) static Action |
endAction
|
protected FocusListener |
focusListener
This protected field is implementation specific. |
protected boolean |
hasFocus
This protected field is implementation specific. |
(package private) static Action |
homeAction
|
private static String |
IS_TABLE_CELL_EDITOR
|
private boolean |
isDisplaySizeDirty
|
protected boolean |
isMinimumSizeDirty
|
private boolean |
isTableCellEditor
|
protected ItemListener |
itemListener
This protected field is implementation specific. |
protected KeyListener |
keyListener
This protected field is implementation specific. |
protected JList |
listBox
|
protected ListDataListener |
listDataListener
This protected field is implementation specific. |
(package private) static Action |
pgDownAction
|
(package private) static Action |
pgUpAction
|
protected ComboPopup |
popup
|
protected KeyListener |
popupKeyListener
|
protected MouseListener |
popupMouseListener
|
protected MouseMotionListener |
popupMouseMotionListener
|
protected java.beans.PropertyChangeListener |
propertyChangeListener
This protected field is implementation specific. |
Constructor Summary | |
BasicComboBoxUI()
|
Method Summary | |
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. |
(package private) ActionMap |
createActionMap()
|
protected JButton |
createArrowButton()
Creates an button which will be used as the control to show or hide the popup portion of the combo box. |
protected ComboBoxEditor |
createEditor()
Creates the default editor that will be used in editable combo boxes. |
protected FocusListener |
createFocusListener()
Creates a FocusListener which will be added to the combo box.
|
protected ItemListener |
createItemListener()
Creates an ItemListener which will be added to the
combo box. |
protected KeyListener |
createKeyListener()
Creates a KeyListener which will be added to the
combo box. |
protected LayoutManager |
createLayoutManager()
Creates a layout manager for managing the components which make up the combo box. |
protected ListDataListener |
createListDataListener()
Creates a list data listener which will be added to the ComboBoxModel . |
protected ComboPopup |
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 ListCellRenderer |
createRenderer()
Creates the default renderer that will be used in a non-editiable combo box. |
static ComponentUI |
createUI(JComponent c)
Returns an instance of the UI delegate for the specified component. |
javax.accessibility.Accessible |
getAccessibleChild(JComponent c,
int i)
Returns the i th Accessible child of the object.
|
int |
getAccessibleChildrenCount(JComponent c)
Returns the number of accessible children in the object. |
(package private) ActionMap |
getActionMap()
|
private static ListCellRenderer |
getDefaultListCellRenderer()
|
protected Dimension |
getDefaultSize()
Return the default size of an empty display area of the combo box using the current renderer and font. |
protected Dimension |
getDisplaySize()
Returns the calculated size of the display area. |
(package private) InputMap |
getInputMap(int condition)
|
protected Insets |
getInsets()
Gets the insets from the JComboBox. |
Dimension |
getMaximumSize(JComponent c)
Returns the specified component's maximum size appropriate for the look and feel. |
Dimension |
getMinimumSize(JComponent c)
The minumum size is the size of the display area plus insets plus the button. |
Dimension |
getPreferredSize(JComponent c)
Returns the specified component's preferred size appropriate for the look and feel. |
private Dimension |
getSizeForComponent(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(JComponent c)
Configures the specified component appropriate for the look and feel. |
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. |
(package private) boolean |
isTableCellEditor()
|
void |
paint(Graphics g,
JComponent c)
Paints the specified component appropriate for the look and feel. |
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()
This public method is implementation specific and should be private. |
(package private) void |
repaintCurrentValue()
Repaint the currently selected item. |
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()
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(JComponent c)
Reverses configuration which was done on the specified component during installUI . |
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 |
protected JComboBox comboBox
protected boolean hasFocus
private boolean isTableCellEditor
private static final String IS_TABLE_CELL_EDITOR
protected JList listBox
protected CellRendererPane currentValuePane
protected ComboPopup popup
protected Component editor
protected JButton arrowButton
protected KeyListener keyListener
createKeyListener()
protected FocusListener focusListener
createFocusListener()
protected java.beans.PropertyChangeListener propertyChangeListener
createPropertyChangeListener()
private FocusListener editorFocusListener
private ActionListener editorActionListener
protected ItemListener itemListener
createItemListener()
protected MouseListener popupMouseListener
protected MouseMotionListener popupMouseMotionListener
protected KeyListener popupKeyListener
protected ListDataListener listDataListener
createListDataListener()
protected boolean isMinimumSizeDirty
protected Dimension cachedMinimumSize
private boolean isDisplaySizeDirty
private Dimension cachedDisplaySize
private static final Object COMBO_UI_LIST_CELL_RENDERER_KEY
static Action homeAction
static Action endAction
static Action pgUpAction
static Action pgDownAction
Constructor Detail |
public BasicComboBoxUI()
Method Detail |
private static ListCellRenderer getDefaultListCellRenderer()
public static ComponentUI createUI(JComponent c)
ComponentUI
createUI
method that returns an instance of that UI delegate subclass.
If the UI delegate subclass is stateless, it may return an instance
that is shared by multiple components. If the UI delegate is
stateful, then it should return a new instance per component.
The default implementation of this method throws an error, as it
should never be invoked.
public void installUI(JComponent c)
ComponentUI
ComponentUI
instance is being installed
as the UI delegate on the specified component. This method should
completely configure the component for the look and feel,
including the following:
LayoutManager
on the component if necessary.
PropertyChangeListener
on the component in order
to detect and respond to component property changes appropriately.
installUI
in class ComponentUI
c
- the component where this UI delegate is being installedComponentUI.uninstallUI(javax.swing.JComponent)
,
JComponent.setUI(javax.swing.plaf.ComponentUI)
,
JComponent.updateUI()
public void uninstallUI(JComponent c)
ComponentUI
installUI
. This method is invoked when this
UIComponent
instance is being removed as the UI delegate
for the specified component. This method should undo the
configuration performed in installUI
, being careful to
leave the JComponent
instance in a clean state (no
extraneous listeners, look-and-feel-specific property objects, etc.).
This should include the following:
uninstallUI
in class ComponentUI
c
- the component from which this UI delegate is being removed;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple componentsComponentUI.installUI(javax.swing.JComponent)
,
JComponent.updateUI()
protected void installDefaults()
protected void installListeners()
protected void uninstallDefaults()
protected void uninstallListeners()
installListeners
protected ComboPopup createPopup()
ComboPopup
ComboPopup
protected KeyListener createKeyListener()
KeyListener
which will be added to the
combo box. If this method returns null then it will not be added
to the combo box.
KeyListener
or nullprotected FocusListener createFocusListener()
FocusListener
which will be added to the combo box.
If this method returns null then it will not be added to the combo box.
FocusListener
or nullprotected ListDataListener createListDataListener()
ComboBoxModel
. If this method returns null then
it will not be added to the combo box model.
ListDataListener
or nullprotected ItemListener createItemListener()
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.
ItemListener
or nullprotected java.beans.PropertyChangeListener createPropertyChangeListener()
PropertyChangeListener
which will be added to
the combo box. If this method returns null then it will not
be added to the combo box.
PropertyChangeListener
or nullprotected LayoutManager createLayoutManager()
protected ListCellRenderer createRenderer()
setRenderer
.
ListCellRender
used for the combo boxJComboBox.setRenderer(javax.swing.ListCellRenderer)
protected ComboBoxEditor createEditor()
setEditor
.
ComboBoxEditor
used for the combo boxJComboBox.setEditor(javax.swing.ComboBoxEditor)
private void updateToolTipTextForChildren()
protected void installComponents()
protected void uninstallComponents()
public void addEditor()
ComboBoxEditor
createEditor()
,
JComboBox.setEditor(javax.swing.ComboBoxEditor)
,
ComboBoxEditor
public void removeEditor()
addEditor()
protected void configureEditor()
addEditor()
protected void unconfigureEditor()
addEditor()
public void configureArrowButton()
createArrowButton()
public void unconfigureArrowButton()
createArrowButton()
protected JButton createArrowButton()
public boolean isPopupVisible(JComboBox c)
isPopupVisible
in class ComboBoxUI
public void setPopupVisible(JComboBox c, boolean v)
setPopupVisible
in class ComboBoxUI
public boolean isFocusTraversable(JComboBox c)
isFocusTraversable
in class ComboBoxUI
public void paint(Graphics g, JComponent c)
ComponentUI
ComponentUI.update
method when
the specified component is being painted. Subclasses should override
this method and use the specified Graphics
object to
render the content of the component.
paint
in class ComponentUI
g
- the Graphics
context in which to paintc
- the component being painted;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple componentsComponentUI.update(java.awt.Graphics, javax.swing.JComponent)
public Dimension getPreferredSize(JComponent c)
ComponentUI
null
is returned, the preferred
size will be calculated by the component's layout manager instead
(this is the preferred approach for any component with a specific
layout manager installed). The default implementation of this
method returns null
.
getPreferredSize
in class ComponentUI
c
- the component whose preferred size is being queried;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple componentsJComponent.getPreferredSize()
,
LayoutManager.preferredLayoutSize(java.awt.Container)
public Dimension getMinimumSize(JComponent c)
getMinimumSize
in class ComponentUI
c
- the component whose minimum size is being queried;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple components
Dimension
object or null
JComponent.getMinimumSize()
,
LayoutManager.minimumLayoutSize(java.awt.Container)
,
ComponentUI.getPreferredSize(javax.swing.JComponent)
public Dimension getMaximumSize(JComponent c)
ComponentUI
null
is returned, the maximum
size will be calculated by the component's layout manager instead
(this is the preferred approach for any component with a specific
layout manager installed). The default implementation of this
method invokes getPreferredSize
and returns that value.
getMaximumSize
in class ComponentUI
c
- the component whose maximum size is being queried;
this argument is often ignored,
but might be used if the UI object is stateless
and shared by multiple components
Dimension
object or null
JComponent.getMaximumSize()
,
LayoutManager2.maximumLayoutSize(java.awt.Container)
public int getAccessibleChildrenCount(JComponent c)
ComponentUI
Accessible
,
this
method should return the number of children of this object.
UIs might wish to override this if they present areas on the
screen that can be viewed as components, but actual components
are not used for presenting those areas.
Note: As of v1.3, it is recommended that developers call
Component.AccessibleAWTComponent.getAccessibleChildrenCount()
instead
of this method.
getAccessibleChildrenCount
in class ComponentUI
ComponentUI.getAccessibleChild(javax.swing.JComponent, int)
public javax.accessibility.Accessible getAccessibleChild(JComponent c, int i)
ComponentUI
i
th Accessible
child of the object.
UIs might need to override this if they present areas on the
screen that can be viewed as components, but actual components
are not used for presenting those areas.
Note: As of v1.3, it is recommended that developers call
Component.AccessibleAWTComponent.getAccessibleChild()
instead of
this method.
getAccessibleChild
in class ComponentUI
i
- zero-based index of child
i
th Accessible
child of the objectComponentUI.getAccessibleChildrenCount(javax.swing.JComponent)
protected boolean isNavigationKey(int keyCode)
protected void selectNextPossibleValue()
protected void selectPreviousPossibleValue()
protected void toggleOpenClose()
protected Rectangle rectangleForCurrentValue()
protected Insets getInsets()
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus)
public void paintCurrentValueBackground(Graphics g, Rectangle bounds, boolean hasFocus)
void repaintCurrentValue()
protected Dimension getDefaultSize()
getDisplaySize()
protected Dimension getDisplaySize()
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.
JComboBox.setPrototypeDisplayValue(java.lang.Object)
private Dimension getSizeForComponent(Component comp)
protected void installKeyboardActions()
InputMap getInputMap(int condition)
ActionMap getActionMap()
ActionMap createActionMap()
boolean isTableCellEditor()
protected void uninstallKeyboardActions()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |