Methods Summary |
---|
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
removeEditor();
editor = comboBox.getEditor().getEditorComponent();
if ( editor != null ) {
configureEditor();
comboBox.add(editor);
if(comboBox.isFocusOwner()) {
// Switch focus to the editor component
editor.requestFocusInWindow();
}
}
|
public void | configureArrowButton()This public method is implementation specific and should be private. Do
not call or override.
if ( arrowButton != null ) {
arrowButton.setEnabled( comboBox.isEnabled() );
arrowButton.setRequestFocusEnabled(false);
arrowButton.addMouseListener( popup.getMouseListener() );
arrowButton.addMouseMotionListener( popup.getMouseMotionListener() );
arrowButton.resetKeyboardActions();
arrowButton.putClientProperty("doNotCancelPopup", HIDE_POPUP_KEY);
arrowButton.setInheritsPopupMenu(true);
}
|
protected void | configureEditor()This protected method is implementation specific and should be private.
do not call or override.
// Should be in the same state as the combobox
editor.setEnabled(comboBox.isEnabled());
editor.setFont( comboBox.getFont() );
if (focusListener != null) {
editor.addFocusListener(focusListener);
}
editor.addFocusListener( getHandler() );
comboBox.getEditor().addActionListener(getHandler());
if(editor instanceof JComponent) {
((JComponent)editor).putClientProperty("doNotCancelPopup",
HIDE_POPUP_KEY);
((JComponent)editor).setInheritsPopupMenu(true);
}
comboBox.configureEditor(comboBox.getEditor(),comboBox.getSelectedItem());
|
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.
JButton button = new BasicArrowButton(BasicArrowButton.SOUTH,
UIManager.getColor("ComboBox.buttonBackground"),
UIManager.getColor("ComboBox.buttonShadow"),
UIManager.getColor("ComboBox.buttonDarkShadow"),
UIManager.getColor("ComboBox.buttonHighlight"));
button.setName("ComboBox.arrowButton");
return button;
|
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 .
return new BasicComboBoxEditor.UIResource();
|
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.
return getHandler();
|
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.
return null;
|
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.
return getHandler();
|
protected java.awt.LayoutManager | createLayoutManager()Creates a layout manager for managing the components which make up the
combo box.
return getHandler();
|
protected javax.swing.event.ListDataListener | createListDataListener()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.
return getHandler();
|
protected javax.swing.plaf.basic.ComboPopup | createPopup()Creates the popup portion of the combo box.
return new BasicComboPopup( comboBox );
|
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.
return getHandler();
|
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 .
return new BasicComboBoxRenderer.UIResource();
|
public static javax.swing.plaf.ComponentUI | createUI(javax.swing.JComponent c)
return new BasicComboBoxUI();
|
public javax.accessibility.Accessible | getAccessibleChild(javax.swing.JComponent c, int i)
// 0 = the popup
// 1 = the editor
switch ( i ) {
case 0:
if ( popup instanceof Accessible ) {
AccessibleContext ac = ((Accessible) popup).getAccessibleContext();
ac.setAccessibleParent(comboBox);
return(Accessible) popup;
}
break;
case 1:
if ( comboBox.isEditable()
&& (editor instanceof Accessible) ) {
AccessibleContext ac = ((Accessible) editor).getAccessibleContext();
ac.setAccessibleParent(comboBox);
return(Accessible) editor;
}
break;
}
return null;
|
public int | getAccessibleChildrenCount(javax.swing.JComponent c)
if ( comboBox.isEditable() ) {
return 2;
}
else {
return 1;
}
|
private static javax.swing.ListCellRenderer | getDefaultListCellRenderer()
// Used for calculating the default size.
ListCellRenderer renderer = (ListCellRenderer)AppContext.
getAppContext().get(COMBO_UI_LIST_CELL_RENDERER_KEY);
if (renderer == null) {
renderer = new DefaultListCellRenderer();
AppContext.getAppContext().put(COMBO_UI_LIST_CELL_RENDERER_KEY,
new DefaultListCellRenderer());
}
return renderer;
|
protected java.awt.Dimension | getDefaultSize()Return the default size of an empty display area of the combo box using
the current renderer and font.
// Calculates the height and width using the default text renderer
Dimension d = getSizeForComponent(getDefaultListCellRenderer().getListCellRendererComponent(listBox, " ", -1, false, false));
return new Dimension(d.width, d.height);
|
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.
if (!isDisplaySizeDirty) {
return new Dimension(cachedDisplaySize);
}
Dimension result = new Dimension();
ListCellRenderer renderer = comboBox.getRenderer();
if (renderer == null) {
renderer = new DefaultListCellRenderer();
}
Object prototypeValue = comboBox.getPrototypeDisplayValue();
if (prototypeValue != null) {
// Calculates the dimension based on the prototype value
result = getSizeForComponent(renderer.getListCellRendererComponent(listBox,
prototypeValue,
-1, false, false));
} else {
// Calculate the dimension by iterating over all the elements in the combo
// box list.
ComboBoxModel model = comboBox.getModel();
int modelSize = model.getSize();
Dimension d;
Component cpn;
if (modelSize > 0 ) {
for (int i = 0; i < modelSize ; i++ ) {
// Calculates the maximum height and width based on the largest
// element
d = getSizeForComponent(renderer.getListCellRendererComponent(listBox,
model.getElementAt(i),
-1, false, false));
result.width = Math.max(result.width,d.width);
result.height = Math.max(result.height,d.height);
}
} else {
result = getDefaultSize();
if (comboBox.isEditable()) {
result.width = 100;
}
}
}
if ( comboBox.isEditable() ) {
Dimension d = editor.getPreferredSize();
result.width = Math.max(result.width,d.width);
result.height = Math.max(result.height,d.height);
}
// Set the cached value
cachedDisplaySize.setSize(result.width, result.height);
isDisplaySizeDirty = false;
return result;
|
private javax.swing.plaf.basic.BasicComboBoxUI$Handler | getHandler()Returns the shared listener.
if (handler == null) {
handler = new Handler();
}
return handler;
|
javax.swing.InputMap | getInputMap(int condition)
if (condition == JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) {
return (InputMap)DefaultLookup.get(comboBox, this,
"ComboBox.ancestorInputMap");
}
return null;
|
protected java.awt.Insets | getInsets()Gets the insets from the JComboBox.
return comboBox.getInsets();
|
public java.awt.Dimension | getMaximumSize(javax.swing.JComponent c)
return new Dimension(Short.MAX_VALUE, Short.MAX_VALUE);
|
public java.awt.Dimension | getMinimumSize(javax.swing.JComponent c)The minumum size is the size of the display area plus insets plus the button.
if ( !isMinimumSizeDirty ) {
return new Dimension(cachedMinimumSize);
}
Dimension size = getDisplaySize();
Insets insets = getInsets();
size.height += insets.top + insets.bottom;
int buttonSize = size.height - (insets.top + insets.bottom);
size.width += insets.left + insets.right + buttonSize;
cachedMinimumSize.setSize( size.width, size.height );
isMinimumSizeDirty = false;
return new Dimension(size);
|
public java.awt.Dimension | getPreferredSize(javax.swing.JComponent c)
return getMinimumSize(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.
currentValuePane.add(comp);
comp.setFont(comboBox.getFont());
Dimension d = comp.getPreferredSize();
currentValuePane.remove(comp);
return d;
|
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.
arrowButton = createArrowButton();
comboBox.add( arrowButton );
if (arrowButton != null) {
configureArrowButton();
}
if ( comboBox.isEditable() ) {
addEditor();
}
comboBox.add( currentValuePane );
|
protected void | installDefaults()Installs the default colors, default font, default renderer, and default
editor into the JComboBox.
LookAndFeel.installColorsAndFont( comboBox,
"ComboBox.background",
"ComboBox.foreground",
"ComboBox.font" );
LookAndFeel.installBorder( comboBox, "ComboBox.border" );
LookAndFeel.installProperty( comboBox, "opaque", Boolean.TRUE);
Long l = (Long)UIManager.get("ComboBox.timeFactor");
timeFactor = (l!=null) ? l.longValue() : 1000L;
|
protected void | installKeyboardActions()Adds keyboard actions to the JComboBox. Actions on enter and esc are already
supplied. Add more actions as you need them.
InputMap km = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
SwingUtilities.replaceUIInputMap(comboBox, JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, km);
LazyActionMap.installLazyActionMap(comboBox, BasicComboBoxUI.class,
"ComboBox.actionMap");
|
protected void | installListeners()Create and install the listeners for the combo box and its model.
This method is called when the UI is installed.
if ( (itemListener = createItemListener()) != null) {
comboBox.addItemListener( itemListener );
}
if ( (propertyChangeListener = createPropertyChangeListener()) != null ) {
comboBox.addPropertyChangeListener( propertyChangeListener );
}
if ( (keyListener = createKeyListener()) != null ) {
comboBox.addKeyListener( keyListener );
}
if ( (focusListener = createFocusListener()) != null ) {
comboBox.addFocusListener( focusListener );
}
if ((popupMouseListener = popup.getMouseListener()) != null) {
comboBox.addMouseListener( popupMouseListener );
}
if ((popupMouseMotionListener = popup.getMouseMotionListener()) != null) {
comboBox.addMouseMotionListener( popupMouseMotionListener );
}
if ((popupKeyListener = popup.getKeyListener()) != null) {
comboBox.addKeyListener(popupKeyListener);
}
if ( comboBox.getModel() != null ) {
if ( (listDataListener = createListDataListener()) != null ) {
comboBox.getModel().addListDataListener( listDataListener );
}
}
|
public void | installUI(javax.swing.JComponent c)
isMinimumSizeDirty = true;
comboBox = (JComboBox)c;
installDefaults();
popup = createPopup();
listBox = popup.getList();
// Is this combo box a cell editor?
Boolean inTable = (Boolean)c.getClientProperty(IS_TABLE_CELL_EDITOR );
if (inTable != null) {
isTableCellEditor = inTable.equals(Boolean.TRUE) ? true : false;
}
if ( comboBox.getRenderer() == null || comboBox.getRenderer() instanceof UIResource ) {
comboBox.setRenderer( createRenderer() );
}
if ( comboBox.getEditor() == null || comboBox.getEditor() instanceof UIResource ) {
comboBox.setEditor( createEditor() );
}
installListeners();
installComponents();
comboBox.setLayout( createLayoutManager() );
comboBox.setRequestFocusEnabled( true );
installKeyboardActions();
comboBox.putClientProperty("doNotCancelPopup", HIDE_POPUP_KEY);
if (keySelectionManager == null || keySelectionManager instanceof UIResource) {
keySelectionManager = new DefaultKeySelectionManager();
}
comboBox.setKeySelectionManager(keySelectionManager);
|
public boolean | isFocusTraversable(javax.swing.JComboBox c)Determines if the JComboBox is focus traversable. If the JComboBox is editable
this returns false, otherwise it returns true.
return !comboBox.isEditable();
|
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.
return keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN ||
keyCode == KeyEvent.VK_KP_UP || keyCode == KeyEvent.VK_KP_DOWN;
|
private boolean | isNavigationKey(int keyCode, int modifiers)
InputMap inputMap = comboBox.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
KeyStroke key = KeyStroke.getKeyStroke(keyCode, modifiers);
if (inputMap != null && inputMap.get(key) != null) {
return true;
}
return false;
|
public boolean | isPopupVisible(javax.swing.JComboBox c)Tells if the popup is visible or not.
return popup.isVisible();
|
boolean | isTableCellEditor()
return isTableCellEditor;
|
static void | loadActionMap(javax.swing.plaf.basic.LazyActionMap map)Populates ComboBox's actions.
map.put(new Actions(Actions.HIDE));
map.put(new Actions(Actions.PAGE_DOWN));
map.put(new Actions(Actions.PAGE_UP));
map.put(new Actions(Actions.HOME));
map.put(new Actions(Actions.END));
map.put(new Actions(Actions.DOWN));
map.put(new Actions(Actions.DOWN_2));
map.put(new Actions(Actions.TOGGLE));
map.put(new Actions(Actions.TOGGLE_2));
map.put(new Actions(Actions.UP));
map.put(new Actions(Actions.UP_2));
map.put(new Actions(Actions.ENTER));
|
public void | paint(java.awt.Graphics g, javax.swing.JComponent c)
hasFocus = comboBox.hasFocus();
if ( !comboBox.isEditable() ) {
Rectangle r = rectangleForCurrentValue();
paintCurrentValueBackground(g,r,hasFocus);
paintCurrentValue(g,r,hasFocus);
}
|
public void | paintCurrentValue(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)Paints the currently selected item.
ListCellRenderer renderer = comboBox.getRenderer();
Component c;
if ( hasFocus && !isPopupVisible(comboBox) ) {
c = renderer.getListCellRendererComponent( listBox,
comboBox.getSelectedItem(),
-1,
true,
false );
}
else {
c = renderer.getListCellRendererComponent( listBox,
comboBox.getSelectedItem(),
-1,
false,
false );
c.setBackground(UIManager.getColor("ComboBox.background"));
}
c.setFont(comboBox.getFont());
if ( hasFocus && !isPopupVisible(comboBox) ) {
c.setForeground(listBox.getSelectionForeground());
c.setBackground(listBox.getSelectionBackground());
}
else {
if ( comboBox.isEnabled() ) {
c.setForeground(comboBox.getForeground());
c.setBackground(comboBox.getBackground());
}
else {
c.setForeground(DefaultLookup.getColor(
comboBox, this, "ComboBox.disabledForeground", null));
c.setBackground(DefaultLookup.getColor(
comboBox, this, "ComboBox.disabledBackground", null));
}
}
// Fix for 4238829: should lay out the JPanel.
boolean shouldValidate = false;
if (c instanceof JPanel) {
shouldValidate = true;
}
currentValuePane.paintComponent(g,c,comboBox,bounds.x,bounds.y,
bounds.width,bounds.height, shouldValidate);
|
public void | paintCurrentValueBackground(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)Paints the background of the currently selected item.
Color t = g.getColor();
if ( comboBox.isEnabled() )
g.setColor(DefaultLookup.getColor(comboBox, this,
"ComboBox.background", null));
else
g.setColor(DefaultLookup.getColor(comboBox, this,
"ComboBox.disabledBackground", null));
g.fillRect(bounds.x,bounds.y,bounds.width,bounds.height);
g.setColor(t);
|
protected java.awt.Rectangle | rectangleForCurrentValue()Returns the area that is reserved for drawing the currently selected item.
int width = comboBox.getWidth();
int height = comboBox.getHeight();
Insets insets = getInsets();
int buttonSize = height - (insets.top + insets.bottom);
if ( arrowButton != null ) {
buttonSize = arrowButton.getWidth();
}
if(BasicGraphicsUtils.isLeftToRight(comboBox)) {
return new Rectangle(insets.left, insets.top,
width - (insets.left + insets.right + buttonSize),
height - (insets.top + insets.bottom));
}
else {
return new Rectangle(insets.left + buttonSize, insets.top,
width - (insets.left + insets.right + buttonSize),
height - (insets.top + insets.bottom));
}
|
public void | removeEditor()This public method is implementation specific and should be private.
do not call or override.
if ( editor != null ) {
unconfigureEditor();
comboBox.remove( editor );
editor = null;
}
|
void | repaintCurrentValue()Repaint the currently selected item.
Rectangle r = rectangleForCurrentValue();
comboBox.repaint(r.x,r.y,r.width,r.height);
|
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.
int si;
if ( isTableCellEditor ) {
si = listBox.getSelectedIndex();
}
else {
si = comboBox.getSelectedIndex();
}
if ( si < comboBox.getModel().getSize() - 1 ) {
if ( isTableCellEditor ) {
listBox.setSelectedIndex( si + 1 );
listBox.ensureIndexIsVisible( si + 1 );
}
else {
comboBox.setSelectedIndex(si+1);
}
comboBox.repaint();
}
|
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.
int si;
if ( isTableCellEditor ) {
si = listBox.getSelectedIndex();
}
else {
si = comboBox.getSelectedIndex();
}
if ( si > 0 ) {
if ( isTableCellEditor ) {
listBox.setSelectedIndex( si - 1 );
listBox.ensureIndexIsVisible( si - 1 );
}
else {
comboBox.setSelectedIndex(si-1);
}
comboBox.repaint();
}
|
public void | setPopupVisible(javax.swing.JComboBox c, boolean v)Hides the popup.
if ( v ) {
popup.show();
} else {
popup.hide();
}
|
protected void | toggleOpenClose()Hides the popup if it is showing and shows the popup if it is hidden.
setPopupVisible(comboBox, !isPopupVisible(comboBox));
|
public void | unconfigureArrowButton()This public method is implementation specific and should be private. Do
not call or override.
if ( arrowButton != null ) {
arrowButton.removeMouseListener( popup.getMouseListener() );
arrowButton.removeMouseMotionListener( popup.getMouseMotionListener() );
}
|
protected void | unconfigureEditor()This protected method is implementation specific and should be private.
Do not call or override.
if (focusListener != null) {
editor.removeFocusListener(focusListener);
}
editor.removeFocusListener(getHandler());
comboBox.getEditor().removeActionListener(getHandler());
|
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.
if ( arrowButton != null ) {
unconfigureArrowButton();
}
if ( editor != null ) {
unconfigureEditor();
}
comboBox.removeAll(); // Just to be safe.
arrowButton = null;
|
protected void | uninstallDefaults()Uninstalls the default colors, default font, default renderer, and default
editor into the JComboBox.
LookAndFeel.installColorsAndFont( comboBox,
"ComboBox.background",
"ComboBox.foreground",
"ComboBox.font" );
LookAndFeel.uninstallBorder( comboBox );
|
protected void | uninstallKeyboardActions()Removes the focus InputMap and ActionMap.
SwingUtilities.replaceUIInputMap(comboBox, JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
SwingUtilities.replaceUIActionMap(comboBox, null);
|
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
if ( keyListener != null ) {
comboBox.removeKeyListener( keyListener );
}
if ( itemListener != null) {
comboBox.removeItemListener( itemListener );
}
if ( propertyChangeListener != null ) {
comboBox.removePropertyChangeListener( propertyChangeListener );
}
if ( focusListener != null) {
comboBox.removeFocusListener( focusListener );
}
if ( popupMouseListener != null) {
comboBox.removeMouseListener( popupMouseListener );
}
if ( popupMouseMotionListener != null) {
comboBox.removeMouseMotionListener( popupMouseMotionListener );
}
if (popupKeyListener != null) {
comboBox.removeKeyListener(popupKeyListener);
}
if ( comboBox.getModel() != null ) {
if ( listDataListener != null ) {
comboBox.getModel().removeListDataListener( listDataListener );
}
}
|
public void | uninstallUI(javax.swing.JComponent c)
setPopupVisible( comboBox, false);
popup.uninstallingUI();
uninstallKeyboardActions();
comboBox.setLayout( null );
uninstallComponents();
uninstallListeners();
uninstallDefaults();
if ( comboBox.getRenderer() == null || comboBox.getRenderer() instanceof UIResource ) {
comboBox.setRenderer( null );
}
if ( comboBox.getEditor() == null || comboBox.getEditor() instanceof UIResource ) {
if(comboBox.getEditor().getEditorComponent().hasFocus()) {
// Leave focus in JComboBox.
comboBox.requestFocusInWindow();
}
comboBox.setEditor( null );
}
if (keySelectionManager instanceof UIResource) {
comboBox.setKeySelectionManager(null);
}
handler = null;
keyListener = null;
focusListener = null;
listDataListener = null;
propertyChangeListener = null;
popup = null;
listBox = null;
comboBox = null;
|
private void | updateToolTipTextForChildren()
Component[] children = comboBox.getComponents();
for ( int i = 0; i < children.length; ++i ) {
if ( children[i] instanceof JComponent ) {
((JComponent)children[i]).setToolTipText( comboBox.getToolTipText() );
}
}
|