FileDocCategorySizeDatePackage
WindowsComboBoxUI.javaAPI DocJava SE 6 API18656Tue Jun 10 00:21:58 BST 2008com.sun.java.swing.plaf.windows

WindowsComboBoxUI

public class WindowsComboBoxUI extends BasicComboBoxUI
Windows combo box.

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. A future release of Swing will provide support for long term persistence.

version
1.59, 11/30/06
author
Tom Santos
author
Igor Kushnirskiy

Fields Summary
private static final MouseListener
rolloverListener
private boolean
isRollover
private static final PropertyChangeListener
componentOrientationListener
Constructors Summary
Methods Summary
protected voidconfigureEditor()
{@inheritDoc}

since
1.6

        super.configureEditor();
        if (XPStyle.getXP() != null) {
            editor.addMouseListener(rolloverListener);
        }
    
protected javax.swing.JButtoncreateArrowButton()
Creates an button which will be used as the control to show or hide the popup portion of the combo box.

return
a button which represents the popup control

	if (XPStyle.getXP() != null) {
            return new XPComboBoxButton();
	} else {
	    return super.createArrowButton();
	}
    
protected javax.swing.ComboBoxEditorcreateEditor()
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
a ComboBoxEditor used for the combo box
see
javax.swing.JComboBox#setEditor

	return new WindowsComboBoxEditor();
    
protected java.awt.LayoutManagercreateLayoutManager()
Creates a layout manager for managing the components which make up the combo box.

return
an instance of a layout manager

        return new BasicComboBoxUI.ComboBoxLayoutManager() {
	    public void layoutContainer(Container parent) {
		super.layoutContainer(parent);

		if (XPStyle.getXP() != null && arrowButton != null) {
		    Dimension d = parent.getSize();
		    Insets insets = getInsets();
		    int buttonWidth = arrowButton.getPreferredSize().width;
		    arrowButton.setBounds(WindowsGraphicsUtils.isLeftToRight((JComboBox)parent)
					  ? (d.width - insets.right - buttonWidth)
					  : insets.left,
					  insets.top,
					  buttonWidth, d.height - insets.top - insets.bottom);
		}
	    }
	};
    
protected javax.swing.plaf.basic.ComboPopupcreatePopup()

        return super.createPopup();
    
protected javax.swing.ListCellRenderercreateRenderer()
{@inheritDoc}

since
1.6

        XPStyle xp = XPStyle.getXP();
        if (xp != null && xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
            return new WindowsComboBoxRenderer();
        } else {
            return super.createRenderer();
        }
    
public static javax.swing.plaf.ComponentUIcreateUI(javax.swing.JComponent c)

    
         
        return new WindowsComboBoxUI();
    
public java.awt.DimensiongetPreferredSize(javax.swing.JComponent c)

        Dimension d = super.getPreferredSize(c);
        if (XPStyle.getXP() != null) {
            d.width += 5;
        } else {
            d.width += 4;
        }
        d.height += 2;
        return d;
    
com.sun.java.swing.plaf.windows.TMSchema.StategetXPComboBoxState(javax.swing.JComponent c)

        State state = State.NORMAL;
        if (!c.isEnabled()) {
            state = State.DISABLED;
        } else if (isPopupVisible(comboBox)) {
            state = State.PRESSED;
        } else if (isRollover) {
            state = State.HOT;
        } 
        return state;
    
protected voidinstallKeyboardActions()

        super.installKeyboardActions();
    
protected voidinstallListeners()
{@inheritDoc}

since
1.6

        super.installListeners();
        XPStyle xp = XPStyle.getXP();
        //button glyph for LTR and RTL combobox might differ
        if (xp != null
              && xp.isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT)) {
            comboBox.addPropertyChangeListener("componentOrientation", 
                                               componentOrientationListener);
        }
    
public voidinstallUI(javax.swing.JComponent c)

        super.installUI( c );
        isRollover = false;
        comboBox.setRequestFocusEnabled( true );
        if (XPStyle.getXP() != null && arrowButton != null) {
            //we can not do it in installListeners because arrowButton
            //is initialized after installListeners is invoked
            comboBox.addMouseListener(rolloverListener);
            arrowButton.addMouseListener(rolloverListener);
        }
    
public voidpaint(java.awt.Graphics g, javax.swing.JComponent c)
{@inheritDoc}

since
1.6

        if (XPStyle.getXP() != null) {
            paintXPComboBoxBackground(g, c);
        }
        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

        XPStyle xp = XPStyle.getXP();
        if ( xp != null) {
            bounds.x += 2;
            bounds.y += 2;
            bounds.width -= 4;
            bounds.height -= 4;
	} else {
	    bounds.x += 1;
	    bounds.y += 1;
	    bounds.width -= 2;
	    bounds.height -= 2;
	}
        if (! comboBox.isEditable() 
            && xp != null
            && xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
            // On vista for READNLY ComboBox 
            // color for currentValue is the same as for any other item
            
            // mostly copied from javax.swing.plaf.basic.BasicComboBoxUI.paintCurrentValue
            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.setFont(comboBox.getFont());
            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));
            }
            boolean shouldValidate = false;
            if (c instanceof JPanel)  {
                shouldValidate = true;
            }
            currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y,
                                            bounds.width, bounds.height, shouldValidate);
            
        } else {
            super.paintCurrentValue(g, bounds, hasFocus);
        }
    
public voidpaintCurrentValueBackground(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)
{@inheritDoc}

since
1.6

        if (XPStyle.getXP() == null) {
            super.paintCurrentValueBackground(g, bounds, hasFocus);
        }
    
private voidpaintXPComboBoxBackground(java.awt.Graphics g, javax.swing.JComponent c)

        XPStyle xp = XPStyle.getXP();
        State state = getXPComboBoxState(c);
        Skin skin = null;
        if (! comboBox.isEditable()
              && xp.isSkinDefined(c, Part.CP_READONLY)) {
            skin = xp.getSkin(c, Part.CP_READONLY);
        }
        if (skin == null) {
            skin = xp.getSkin(c, Part.CP_COMBOBOX);
        }
        skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state);
    
protected voidunconfigureEditor()
{@inheritDoc}

since
1.6

        super.unconfigureEditor();
        editor.removeMouseListener(rolloverListener);
    
protected voiduninstallListeners()
{@inheritDoc}

since
1.6

        super.uninstallListeners();
        comboBox.removePropertyChangeListener("componentOrientation",
                                              componentOrientationListener);
    
public voiduninstallUI(javax.swing.JComponent c)

        comboBox.removeMouseListener(rolloverListener);
        if(arrowButton != null) {
            arrowButton.removeMouseListener(rolloverListener);
        }
        super.uninstallUI( c );