FileDocCategorySizeDatePackage
MetalComboBoxUI.javaAPI DocJava SE 6 API13271Tue Jun 10 00:26:50 BST 2008javax.swing.plaf.metal

MetalComboBoxUI

public class MetalComboBoxUI extends BasicComboBoxUI
Metal UI for JComboBox

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see {@link java.beans.XMLEncoder}.

see
MetalComboBoxEditor
see
MetalComboBoxButton
version
1.53 11/17/05
author
Tom Santos

Fields Summary
Constructors Summary
Methods Summary
public voidconfigureEditor()

	super.configureEditor();
    
protected javax.swing.JButtoncreateArrowButton()

        boolean iconOnly = (comboBox.isEditable() ||
                            MetalLookAndFeel.usingOcean());
        JButton button = new MetalComboBoxButton( comboBox,
                                                  new MetalComboBoxIcon(),
                                                  iconOnly,
                                                  currentValuePane,
                                                  listBox );
        button.setMargin( new Insets( 0, 1, 1, 3 ) );
        if (MetalLookAndFeel.usingOcean()) {
            // Disabled rollover effect.
            button.putClientProperty(MetalBorders.NO_BUTTON_ROLLOVER,
                                     Boolean.TRUE);
        }
        updateButtonForOcean(button);
        return button;
    
protected javax.swing.ComboBoxEditorcreateEditor()

        return new MetalComboBoxEditor.UIResource();
    
protected java.awt.LayoutManagercreateLayoutManager()

        return new MetalComboBoxLayoutManager();
    
protected javax.swing.plaf.basic.ComboPopupcreatePopup()

        return super.createPopup();
    
public java.beans.PropertyChangeListenercreatePropertyChangeListener()

        return new MetalPropertyChangeListener();
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)

        return new MetalComboBoxUI();
    
protected voideditablePropertyChanged(java.beans.PropertyChangeEvent e)
As of Java 2 platform v1.4 this method is no longer used. Do not call or override. All the functionality of this method is in the MetalPropertyChangeListener.

deprecated
As of Java 2 platform v1.4.

 
public intgetBaseline(javax.swing.JComponent c, int width, int height)
Returns the baseline.

throws
NullPointerException {@inheritDoc}
throws
IllegalArgumentException {@inheritDoc}
see
javax.swing.JComponent#getBaseline(int, int)
since
1.6

        int baseline;
        if (MetalLookAndFeel.usingOcean()) {
            height -= 4;
            baseline = super.getBaseline(c, width, height);
            if (baseline >= 0) {
                baseline += 2;
            }
        }
        else {
            baseline = super.getBaseline(c, width, height);
        }
        return baseline;
    
public java.awt.DimensiongetMinimumSize(javax.swing.JComponent c)

        if ( !isMinimumSizeDirty ) {
            return new Dimension( cachedMinimumSize );
        }

        Dimension size = null;

        if ( !comboBox.isEditable() &&
             arrowButton != null) {
            Insets buttonInsets = arrowButton.getInsets();
            Insets insets = comboBox.getInsets();

            size = getDisplaySize();
            size.width += insets.left + insets.right;
            size.width += buttonInsets.right;
            size.width += arrowButton.getMinimumSize().width;
            size.height += insets.top + insets.bottom;
            size.height += buttonInsets.top + buttonInsets.bottom;
        }
        else if ( comboBox.isEditable() &&
                  arrowButton != null &&
                  editor != null ) {
            size = super.getMinimumSize( c );
            Insets margin = arrowButton.getMargin();
            size.height += margin.top + margin.bottom;
            size.width += margin.left + margin.right;
        }
        else {
            size = super.getMinimumSize( c );
        }

        cachedMinimumSize.setSize( size.width, size.height ); 
        isMinimumSizeDirty = false;

        return new Dimension( cachedMinimumSize );
    
public voidlayoutComboBox(java.awt.Container parent, javax.swing.plaf.metal.MetalComboBoxUI$MetalComboBoxLayoutManager manager)

        if (comboBox.isEditable() && !MetalLookAndFeel.usingOcean()) {
            manager.superLayout( parent );
            return;
        }

        if (arrowButton != null) {
            if (MetalLookAndFeel.usingOcean() ) {
                Insets insets = comboBox.getInsets();
                int buttonWidth = arrowButton.getMinimumSize().width;
		arrowButton.setBounds(MetalUtils.isLeftToRight(comboBox)
				? (comboBox.getWidth() - insets.right - buttonWidth)
				: insets.left,
                            insets.top, buttonWidth,
                            comboBox.getHeight() - insets.top - insets.bottom);
            }
            else {
                Insets insets = comboBox.getInsets();
                int width = comboBox.getWidth();
                int height = comboBox.getHeight();
                arrowButton.setBounds( insets.left, insets.top,
                                       width - (insets.left + insets.right),
                                       height - (insets.top + insets.bottom) );
            }
        }

        if (editor != null && MetalLookAndFeel.usingOcean()) {
            Rectangle cvb = rectangleForCurrentValue();
            editor.setBounds(cvb);
        }
    
public voidpaint(java.awt.Graphics g, javax.swing.JComponent c)

        if (MetalLookAndFeel.usingOcean()) {
            super.paint(g, c);
        }
    
public voidpaintCurrentValue(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)
If necessary paints the currently selected item.

param
g Graphics to paint to
param
bounds Region to paint current value to
param
hasFocus whether or not the JComboBox has focus
throws
NullPointerException if any of the arguments are null.
since
1.5

        // This is really only called if we're using ocean.
        if (MetalLookAndFeel.usingOcean()) {
            bounds.x += 2;
            bounds.width -= 3;
            if (arrowButton != null) {
                Insets buttonInsets = arrowButton.getInsets();
                bounds.y += buttonInsets.top;
                bounds.height -= (buttonInsets.top + buttonInsets.bottom);
            }
            else {
                bounds.y += 2;
                bounds.height -= 4;
            }
            super.paintCurrentValue(g, bounds, hasFocus);
        }
        else if (g == null || bounds == null) {
            throw new NullPointerException(
                "Must supply a non-null Graphics and Rectangle");
        }
    
public voidpaintCurrentValueBackground(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)
If necessary paints the background of the currently selected item.

param
g Graphics to paint to
param
bounds Region to paint background to
param
hasFocus whether or not the JComboBox has focus
throws
NullPointerException if any of the arguments are null.
since
1.5

        // This is really only called if we're using ocean.
        if (MetalLookAndFeel.usingOcean()) {
            g.setColor(MetalLookAndFeel.getControlDarkShadow());
            g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height - 1);
            g.setColor(MetalLookAndFeel.getControlShadow());
            g.drawRect(bounds.x + 1, bounds.y + 1, bounds.width - 2,
                       bounds.height - 3);
            if (hasFocus && !isPopupVisible(comboBox) &&
                    arrowButton != null) {
                g.setColor(listBox.getSelectionBackground());
                Insets buttonInsets = arrowButton.getInsets();
                if (buttonInsets.top > 2) {
                    g.fillRect(bounds.x + 2, bounds.y + 2, bounds.width - 3,
                               buttonInsets.top - 2);
                }
                if (buttonInsets.bottom > 2) {
                    g.fillRect(bounds.x + 2, bounds.y + bounds.height -
                               buttonInsets.bottom, bounds.width - 3,
                               buttonInsets.bottom - 2);
                }
            }
        }
        else if (g == null || bounds == null) {
            throw new NullPointerException(
                "Must supply a non-null Graphics and Rectangle");
        }
    
protected voidremoveListeners()
As of Java 2 platform v1.4 this method is no longer used.

deprecated
As of Java 2 platform v1.4.

        if ( propertyChangeListener != null ) {
            comboBox.removePropertyChangeListener( propertyChangeListener );
        }
    
public voidunconfigureEditor()

	super.unconfigureEditor();
    
private voidupdateButtonForOcean(javax.swing.JButton button)
Resets the necessary state on the ComboBoxButton for ocean.

        if (MetalLookAndFeel.usingOcean()) {
            // Ocean renders the focus in a different way, this
            // would be redundant.
            button.setFocusPainted(comboBox.isEditable());
        }