FileDocCategorySizeDatePackage
MotifComboBoxUI.javaAPI DocJava SE 6 API10845Tue Jun 10 00:21:56 BST 2008com.sun.java.swing.plaf.motif

MotifComboBoxUI

public class MotifComboBoxUI extends BasicComboBoxUI implements Serializable
ComboBox motif look and feel

* 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.41, 03/28/06
author
Arnaud Weber

Fields Summary
Icon
arrowIcon
static final int
HORIZ_MARGIN
Constructors Summary
Methods Summary
public voidconfigureEditor()

        super.configureEditor();
        editor.setBackground( UIManager.getColor( "text" ) );
    
protected java.awt.LayoutManagercreateLayoutManager()

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

        return new MotifComboPopup( comboBox );
    
protected java.beans.PropertyChangeListenercreatePropertyChangeListener()
{@inheritDoc}

since
1.6

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


         
        return new MotifComboBoxUI();
    
public java.awt.DimensiongetMinimumSize(javax.swing.JComponent c)

        if ( !isMinimumSizeDirty ) {
            return new Dimension( cachedMinimumSize );
        }
        Dimension size;
        Insets insets = getInsets();
        size = getDisplaySize();
        size.height += insets.top + insets.bottom;
        int buttonSize = iconAreaWidth();
        size.width +=  insets.left + insets.right + buttonSize;

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

        return size;
    
public inticonAreaWidth()

        if ( comboBox.isEditable() )
            return arrowIcon.getIconWidth() + (2 * HORIZ_MARGIN);
        else
            return arrowIcon.getIconWidth() + (3 * HORIZ_MARGIN) + 2;
    
protected voidinstallComponents()

        if ( comboBox.isEditable() ) {
            addEditor();
        }

        comboBox.add( currentValuePane );
    
public voidinstallUI(javax.swing.JComponent c)

        super.installUI(c);
        arrowIcon = new MotifComboBoxArrowIcon(UIManager.getColor("controlHighlight"),
                                               UIManager.getColor("controlShadow"),
                                               UIManager.getColor("control"));

        Runnable initCode = new Runnable() {
            public void run(){
                if ( motifGetEditor() != null ) {
                    motifGetEditor().setBackground( UIManager.getColor( "text" ) );
                }
            }
        };

        SwingUtilities.invokeLater( initCode ); 
    
private java.awt.ComponentmotifGetEditor()

        return editor;
    
public voidpaint(java.awt.Graphics g, javax.swing.JComponent c)

        boolean hasFocus = comboBox.hasFocus();
        Rectangle r;

	if (comboBox.isEnabled()) {
	    g.setColor(comboBox.getBackground());
	} else {
	    g.setColor(UIManager.getColor("ComboBox.disabledBackground"));
	}	    
        g.fillRect(0,0,c.getWidth(),c.getHeight());

        if ( !comboBox.isEditable() ) {
            r = rectangleForCurrentValue();
            paintCurrentValue(g,r,hasFocus);
        }
        r = rectangleForArrowIcon();
        arrowIcon.paintIcon(c,g,r.x,r.y);
        if ( !comboBox.isEditable() ) {
            Border border = comboBox.getBorder();
            Insets in;
            if ( border != null ) {
                in = border.getBorderInsets(comboBox);
            }
            else {
                in = new Insets( 0, 0, 0, 0 );
            }
            // Draw the separation
	    if(MotifGraphicsUtils.isLeftToRight(comboBox)) {
	        r.x -= (HORIZ_MARGIN + 2);
	    }
	    else {
	        r.x += r.width + HORIZ_MARGIN + 1;
	    }
            r.y = in.top;
            r.width = 1;
            r.height = comboBox.getBounds().height - in.bottom - in.top;
            g.setColor(UIManager.getColor("controlShadow"));
            g.fillRect(r.x,r.y,r.width,r.height);
            r.x++;
            g.setColor(UIManager.getColor("controlHighlight"));
            g.fillRect(r.x,r.y,r.width,r.height);
        }
    
public voidpaintCurrentValue(java.awt.Graphics g, java.awt.Rectangle bounds, boolean hasFocus)

        ListCellRenderer renderer = comboBox.getRenderer();
        Component c;
        Dimension d;
        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(UIManager.getColor("ComboBox.disabledForeground"));
            c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
	}
        d  = c.getPreferredSize();
        currentValuePane.paintComponent(g,c,comboBox,bounds.x,bounds.y,
                                        bounds.width,d.height);
    
protected java.awt.RectanglerectangleForArrowIcon()

        Rectangle b = comboBox.getBounds();
        Border border = comboBox.getBorder();
        Insets in;
        if ( border != null ) {
            in = border.getBorderInsets(comboBox);
        }
        else {
            in = new Insets( 0, 0, 0, 0 );
        }
        b.x = in.left;
        b.y = in.top;
        b.width -= (in.left + in.right);
        b.height -= (in.top + in.bottom);

	if(MotifGraphicsUtils.isLeftToRight(comboBox)) {
	    b.x = b.x + b.width - HORIZ_MARGIN - arrowIcon.getIconWidth();
	}
	else {
	    b.x += HORIZ_MARGIN;
	}
        b.y = b.y + (b.height - arrowIcon.getIconHeight()) / 2;
        b.width = arrowIcon.getIconWidth();
        b.height = arrowIcon.getIconHeight();
        return b;
    
protected java.awt.RectanglerectangleForCurrentValue()

        int width = comboBox.getWidth();
        int height = comboBox.getHeight();
        Insets insets = getInsets();
	if(MotifGraphicsUtils.isLeftToRight(comboBox)) {
	    return new Rectangle(insets.left, insets.top,
				 (width - (insets.left + insets.right)) - 
				                        iconAreaWidth(),
				 height - (insets.top + insets.bottom));
	}
	else {
	    return new Rectangle(insets.left + iconAreaWidth(), insets.top,
				 (width - (insets.left + insets.right)) - 
				                        iconAreaWidth(),
				 height - (insets.top + insets.bottom));
	}
    
protected voiduninstallComponents()

        removeEditor();
        comboBox.removeAll();