*/
Dimension displaySize;
- // FIXME: This fields aren't used anywhere at this moment.
- protected Dimension cachedMinimumSize;
+ // FIXME: This field isn't used anywhere at this moment.
protected CellRendererPane currentValuePane;
- protected boolean isMinimumSizeDirty;
+
+ /**
+ * The current minimum size if isMinimumSizeDirty is false.
+ * Setup by getMinimumSize() and invalidated by the various listeners.
+ */
+ protected Dimension cachedMinimumSize;
+
+ /**
+ * Indicates whether or not the cachedMinimumSize field is valid or not.
+ */
+ protected boolean isMinimumSizeDirty = true;
/**
* Creates a new <code>BasicComboBoxUI</code> object.
comboBox.addPropertyChangeListener(propertyChangeListener);
focusListener = createFocusListener();
- comboBox.addFocusListener(focusListener);
- listBox.addFocusListener(focusListener);
+ editor.addFocusListener(focusListener);
itemListener = createItemListener();
comboBox.addItemListener(itemListener);
{
arrowButton.setEnabled(comboBox.isEnabled());
arrowButton.setFont(comboBox.getFont());
+ arrowButton.setFocusable(false);
}
/**
public void setPopupVisible(JComboBox c, boolean v)
{
if (v)
- {
- popup.show();
- popup.getList().requestFocus();
- }
+ popup.show();
else
popup.hide();
+
+ if (comboBox.isEditable())
+ editor.requestFocus();
+ else
+ comboBox.requestFocus();
}
/**
/**
* Returns the minimum size for this {@link JComboBox} for this
- * look and feel.
+ * look and feel. Also makes sure cachedMinimimSize is setup correctly.
*
* @param c The {@link JComponent} to find the minimum size for.
*
*/
public Dimension getMinimumSize(JComponent c)
{
- Dimension d = getDisplaySize();
- int arrowButtonWidth = d.height;
- Dimension result = new Dimension(d.width + arrowButtonWidth, d.height);
- return result;
+ if (isMinimumSizeDirty)
+ {
+ Dimension d = getDisplaySize();
+ int arrowButtonWidth = d.height;
+ cachedMinimumSize = new Dimension(d.width + arrowButtonWidth,
+ d.height);
+ isMinimumSizeDirty = false;
+ }
+ return new Dimension(cachedMinimumSize);
}
/** The value returned by the getMaximumSize() method. */
*/
public void focusGained(FocusEvent e)
{
+ // Lets assume every change invalidates the minimumsize.
+ isMinimumSizeDirty = true;
+
hasFocus = true;
comboBox.repaint();
}
*/
public void focusLost(FocusEvent e)
{
+ // Lets assume every change invalidates the minimumsize.
+ isMinimumSizeDirty = true;
+
hasFocus = false;
setPopupVisible(comboBox, false);
comboBox.repaint();
*/
public void itemStateChanged(ItemEvent e)
{
+ // Lets assume every change invalidates the minimumsize.
+ isMinimumSizeDirty = true;
+
if (e.getStateChange() == ItemEvent.SELECTED && comboBox.isEditable())
comboBox.getEditor().setItem(e.getItem());
comboBox.repaint();
public void contentsChanged(ListDataEvent e)
{
// if the item is selected or deselected
+
+ // Lets assume every change invalidates the minimumsize.
+ isMinimumSizeDirty = true;
}
/**
*/
public void intervalAdded(ListDataEvent e)
{
+ // Lets assume every change invalidates the minimumsize.
+ isMinimumSizeDirty = true;
+
ComboBoxModel model = comboBox.getModel();
ListCellRenderer renderer = comboBox.getRenderer();
*/
public void intervalRemoved(ListDataEvent e)
{
+ // Lets assume every change invalidates the minimumsize.
+ isMinimumSizeDirty = true;
+
// recalculate display size of the JComboBox.
displaySize = getDisplaySize();
comboBox.repaint();
*/
public void propertyChange(PropertyChangeEvent e)
{
+ // Lets assume every change invalidates the minimumsize.
+ isMinimumSizeDirty = true;
+
if (e.getPropertyName().equals("enabled"))
{
arrowButton.setEnabled(comboBox.isEnabled());