jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxUI.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 6649 3a9910603ab2
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.metal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.beans.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Metal UI for JComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @see MetalComboBoxEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @see MetalComboBoxButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class MetalComboBoxUI extends BasicComboBoxUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return new MetalComboBoxUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            super.paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * If necessary paints the currently selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param bounds Region to paint current value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param hasFocus whether or not the JComboBox has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @throws NullPointerException if any of the arguments are null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public void paintCurrentValue(Graphics g, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                  boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        // This is really only called if we're using ocean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            bounds.x += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            bounds.width -= 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                Insets buttonInsets = arrowButton.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                bounds.y += buttonInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                bounds.height -= (buttonInsets.top + buttonInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                bounds.y += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                bounds.height -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            super.paintCurrentValue(g, bounds, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        else if (g == null || bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                "Must supply a non-null Graphics and Rectangle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * If necessary paints the background of the currently selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param bounds Region to paint background to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param hasFocus whether or not the JComboBox has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @throws NullPointerException if any of the arguments are null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                            boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        // This is really only called if we're using ocean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            g.setColor(MetalLookAndFeel.getControlShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            g.drawRect(bounds.x + 1, bounds.y + 1, bounds.width - 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                       bounds.height - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (hasFocus && !isPopupVisible(comboBox) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                    arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                g.setColor(listBox.getSelectionBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                Insets buttonInsets = arrowButton.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                if (buttonInsets.top > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                    g.fillRect(bounds.x + 2, bounds.y + 2, bounds.width - 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                               buttonInsets.top - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                if (buttonInsets.bottom > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    g.fillRect(bounds.x + 2, bounds.y + bounds.height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                               buttonInsets.bottom, bounds.width - 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                               buttonInsets.bottom - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        else if (g == null || bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                "Must supply a non-null Graphics and Rectangle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        int baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            height -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            baseline = super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (baseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                baseline += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            baseline = super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    protected ComboBoxEditor createEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        return new MetalComboBoxEditor.UIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    protected ComboPopup createPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return super.createPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    protected JButton createArrowButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        boolean iconOnly = (comboBox.isEditable() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                            MetalLookAndFeel.usingOcean());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        JButton button = new MetalComboBoxButton( comboBox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                                                  new MetalComboBoxIcon(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                                                  iconOnly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                                  currentValuePane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                                  listBox );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        button.setMargin( new Insets( 0, 1, 1, 3 ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            // Disabled rollover effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            button.putClientProperty(MetalBorders.NO_BUTTON_ROLLOVER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                     Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        updateButtonForOcean(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        return button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Resets the necessary state on the ComboBoxButton for ocean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    private void updateButtonForOcean(JButton button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            // Ocean renders the focus in a different way, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            // would be redundant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            button.setFocusPainted(comboBox.isEditable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return new MetalPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * This inner class is marked &quot;public&quot; due to a compiler bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Instantiate it only within subclasses of <FooUI>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public class MetalPropertyChangeListener extends BasicComboBoxUI.PropertyChangeHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            super.propertyChange( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if ( propertyName == "editable" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                if(arrowButton instanceof MetalComboBoxButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                            MetalComboBoxButton button = (MetalComboBoxButton)arrowButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                            button.setIconOnly( comboBox.isEditable() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                                    MetalLookAndFeel.usingOcean() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                        comboBox.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                updateButtonForOcean(arrowButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else if ( propertyName == "background" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                Color color = (Color)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                arrowButton.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                listBox.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            } else if ( propertyName == "foreground" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                Color color = (Color)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                arrowButton.setForeground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                listBox.setForeground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * As of Java 2 platform v1.4 this method is no longer used. Do not call or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * override. All the functionality of this method is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * MetalPropertyChangeListener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @deprecated As of Java 2 platform v1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    protected void editablePropertyChanged( PropertyChangeEvent e ) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    protected LayoutManager createLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return new MetalComboBoxLayoutManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * This inner class is marked &quot;public&quot; due to a compiler bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Instantiate it only within subclasses of <FooUI>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public class MetalComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        public void layoutContainer( Container parent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            layoutComboBox( parent, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        public void superLayout( Container parent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            super.layoutContainer( parent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    // This is here because of a bug in the compiler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    // When a protected-inner-class-savvy compiler comes out we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    // should move this into MetalComboBoxLayoutManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public void layoutComboBox( Container parent, MetalComboBoxLayoutManager manager ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (comboBox.isEditable() && !MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            manager.superLayout( parent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            if (MetalLookAndFeel.usingOcean() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                Insets insets = comboBox.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                int buttonWidth = arrowButton.getMinimumSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                arrowButton.setBounds(MetalUtils.isLeftToRight(comboBox)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                ? (comboBox.getWidth() - insets.right - buttonWidth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                : insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                            insets.top, buttonWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                            comboBox.getHeight() - insets.top - insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                Insets insets = comboBox.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                int width = comboBox.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                int height = comboBox.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                arrowButton.setBounds( insets.left, insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                       width - (insets.left + insets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                       height - (insets.top + insets.bottom) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (editor != null && MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            Rectangle cvb = rectangleForCurrentValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            editor.setBounds(cvb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * As of Java 2 platform v1.4 this method is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @deprecated As of Java 2 platform v1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    protected void removeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        if ( propertyChangeListener != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            comboBox.removePropertyChangeListener( propertyChangeListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    // These two methods were overloaded and made public. This was probably a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    // mistake in the implementation. The functionality that they used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    // provide is no longer necessary and should be removed. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    // removing them will create an uncompatible API change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public void configureEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        super.configureEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public void unconfigureEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        super.unconfigureEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public Dimension getMinimumSize( JComponent c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if ( !isMinimumSizeDirty ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            return new Dimension( cachedMinimumSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        Dimension size = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if ( !comboBox.isEditable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
             arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            Insets buttonInsets = arrowButton.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            Insets insets = comboBox.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            size = getDisplaySize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            size.width += buttonInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            size.width += arrowButton.getMinimumSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            size.height += buttonInsets.top + buttonInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        else if ( comboBox.isEditable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                  arrowButton != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                  editor != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            size = super.getMinimumSize( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            Insets margin = arrowButton.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            size.height += margin.top + margin.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            size.width += margin.left + margin.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            size = super.getMinimumSize( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        cachedMinimumSize.setSize( size.width, size.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        isMinimumSizeDirty = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return new Dimension( cachedMinimumSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * This inner class is marked &quot;public&quot; due to a compiler bug.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * This class should be treated as a &quot;protected&quot; inner class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * Instantiate it only within subclasses of <FooUI>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * This class is now obsolete and doesn't do anything and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * is only included for backwards API compatibility. Do not call or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @deprecated As of Java 2 platform v1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public class MetalComboPopup extends BasicComboPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        public MetalComboPopup( JComboBox cBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            super( cBox );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        // This method was overloaded and made public. This was probably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        // mistake in the implementation. The functionality that they used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        // provide is no longer necessary and should be removed. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        // removing them will create an uncompatible API change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        public void delegateFocus(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            super.delegateFocus(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
}