jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxUI.java
author darcy
Wed, 02 Jul 2014 23:03:27 -0700
changeset 25565 ce603b34c98d
parent 25178 dbab904451e9
permissions -rw-r--r--
8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.* 8042849: Fix raw and unchecked warnings in com.sun.java.swing Reviewed-by: pchelko, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
     2
 * Copyright (c) 1998, 2014, 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
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 9230
diff changeset
    46
 * of all JavaBeans&trade;
2
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
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    54
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class MetalComboBoxUI extends BasicComboBoxUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    57
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    58
     * Constructs an instance of {@code MetalComboBoxUI}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    59
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    60
     * @param c a component
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    61
     * @return an instance of {@code MetalComboBoxUI}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    62
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return new MetalComboBoxUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            super.paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * If necessary paints the currently selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @param bounds Region to paint current value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param hasFocus whether or not the JComboBox has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @throws NullPointerException if any of the arguments are null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void paintCurrentValue(Graphics g, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                                  boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // This is really only called if we're using ocean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            bounds.x += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            bounds.width -= 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            if (arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                Insets buttonInsets = arrowButton.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                bounds.y += buttonInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                bounds.height -= (buttonInsets.top + buttonInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                bounds.y += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                bounds.height -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            super.paintCurrentValue(g, bounds, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        else if (g == null || bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                "Must supply a non-null Graphics and Rectangle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * If necessary paints the background of the currently selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param bounds Region to paint background to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param hasFocus whether or not the JComboBox has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @throws NullPointerException if any of the arguments are null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                            boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        // This is really only called if we're using ocean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            g.setColor(MetalLookAndFeel.getControlShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            g.drawRect(bounds.x + 1, bounds.y + 1, bounds.width - 2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                       bounds.height - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (hasFocus && !isPopupVisible(comboBox) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                    arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                g.setColor(listBox.getSelectionBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                Insets buttonInsets = arrowButton.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                if (buttonInsets.top > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    g.fillRect(bounds.x + 2, bounds.y + 2, bounds.width - 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                               buttonInsets.top - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                if (buttonInsets.bottom > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    g.fillRect(bounds.x + 2, bounds.y + bounds.height -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                               buttonInsets.bottom, bounds.width - 3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                               buttonInsets.bottom - 2);
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
        else if (g == null || bounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                "Must supply a non-null Graphics and Rectangle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public int getBaseline(JComponent c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        int baseline;
6649
3a9910603ab2 6632953: MetalComboBoxUI.getBaseline(JComponent, int, int) throws IAE for valid width/height
alexp
parents: 5506
diff changeset
   154
        if (MetalLookAndFeel.usingOcean() && height >= 4) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            height -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            baseline = super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (baseline >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                baseline += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            baseline = super.getBaseline(c, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return baseline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected ComboBoxEditor createEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return new MetalComboBoxEditor.UIResource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    protected ComboPopup createPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return super.createPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    protected JButton createArrowButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        boolean iconOnly = (comboBox.isEditable() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                            MetalLookAndFeel.usingOcean());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        JButton button = new MetalComboBoxButton( comboBox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                                  new MetalComboBoxIcon(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                                                  iconOnly,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                                  currentValuePane,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                                  listBox );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        button.setMargin( new Insets( 0, 1, 1, 3 ) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            // Disabled rollover effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            button.putClientProperty(MetalBorders.NO_BUTTON_ROLLOVER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                                     Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        updateButtonForOcean(button);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        return button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * Resets the necessary state on the ComboBoxButton for ocean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    private void updateButtonForOcean(JButton button) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            // Ocean renders the focus in a different way, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            // would be redundant.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            button.setFocusPainted(comboBox.isEditable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public PropertyChangeListener createPropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return new MetalPropertyChangeListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * This class should be treated as a &quot;protected&quot; inner class.
9230
c5674561cb9e 6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents: 7668
diff changeset
   210
     * Instantiate it only within subclasses of {@code MetalComboBoxUI}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    public class MetalPropertyChangeListener extends BasicComboBoxUI.PropertyChangeHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            super.propertyChange( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if ( propertyName == "editable" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                if(arrowButton instanceof MetalComboBoxButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                            MetalComboBoxButton button = (MetalComboBoxButton)arrowButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                            button.setIconOnly( comboBox.isEditable() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                    MetalLookAndFeel.usingOcean() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                        comboBox.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                updateButtonForOcean(arrowButton);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            } else if ( propertyName == "background" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                Color color = (Color)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                arrowButton.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                listBox.setBackground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            } else if ( propertyName == "foreground" ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                Color color = (Color)e.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                arrowButton.setForeground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                listBox.setForeground(color);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * As of Java 2 platform v1.4 this method is no longer used. Do not call or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * override. All the functionality of this method is in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * MetalPropertyChangeListener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   243
     * @param e an instance of {@code PropertyChangeEvent}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @deprecated As of Java 2 platform v1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    protected void editablePropertyChanged( PropertyChangeEvent e ) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    protected LayoutManager createLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return new MetalComboBoxLayoutManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * This class should be treated as a &quot;protected&quot; inner class.
9230
c5674561cb9e 6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents: 7668
diff changeset
   255
     * Instantiate it only within subclasses of {@code MetalComboBoxUI}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public class MetalComboBoxLayoutManager extends BasicComboBoxUI.ComboBoxLayoutManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        public void layoutContainer( Container parent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            layoutComboBox( parent, this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   261
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   262
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   263
         * Lays out the parent container.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   264
         *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   265
         * @param parent a container
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   266
         */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        public void superLayout( Container parent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            super.layoutContainer( parent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   272
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   273
     * Lays out the {@code JComboBox} in the {@code parent} container.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   274
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   275
     * @param parent a container
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   276
     * @param manager an instance of {@code MetalComboBoxLayoutManager}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   277
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    // This is here because of a bug in the compiler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    // When a protected-inner-class-savvy compiler comes out we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    // should move this into MetalComboBoxLayoutManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    public void layoutComboBox( Container parent, MetalComboBoxLayoutManager manager ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if (comboBox.isEditable() && !MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            manager.superLayout( parent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        if (arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            if (MetalLookAndFeel.usingOcean() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                Insets insets = comboBox.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                int buttonWidth = arrowButton.getMinimumSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                arrowButton.setBounds(MetalUtils.isLeftToRight(comboBox)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                                ? (comboBox.getWidth() - insets.right - buttonWidth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                                : insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                            insets.top, buttonWidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                            comboBox.getHeight() - insets.top - insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                Insets insets = comboBox.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                int width = comboBox.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                int height = comboBox.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                arrowButton.setBounds( insets.left, insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                       width - (insets.left + insets.right),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                       height - (insets.top + insets.bottom) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (editor != null && MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            Rectangle cvb = rectangleForCurrentValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            editor.setBounds(cvb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * As of Java 2 platform v1.4 this method is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * longer used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @deprecated As of Java 2 platform v1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    protected void removeListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if ( propertyChangeListener != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            comboBox.removePropertyChangeListener( propertyChangeListener );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    // These two methods were overloaded and made public. This was probably a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    // mistake in the implementation. The functionality that they used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    // provide is no longer necessary and should be removed. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    // removing them will create an uncompatible API change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public void configureEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        super.configureEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public void unconfigureEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        super.unconfigureEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public Dimension getMinimumSize( JComponent c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if ( !isMinimumSizeDirty ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            return new Dimension( cachedMinimumSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        Dimension size = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        if ( !comboBox.isEditable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
             arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            Insets buttonInsets = arrowButton.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            Insets insets = comboBox.getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            size = getDisplaySize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            size.width += insets.left + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            size.width += buttonInsets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            size.width += arrowButton.getMinimumSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            size.height += insets.top + insets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            size.height += buttonInsets.top + buttonInsets.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        else if ( comboBox.isEditable() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                  arrowButton != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                  editor != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            size = super.getMinimumSize( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            Insets margin = arrowButton.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            size.height += margin.top + margin.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            size.width += margin.left + margin.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            size = super.getMinimumSize( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        cachedMinimumSize.setSize( size.width, size.height );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        isMinimumSizeDirty = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        return new Dimension( cachedMinimumSize );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * This class should be treated as a &quot;protected&quot; inner class.
9230
c5674561cb9e 6985329: 9 classes in swing.plaf contains words inappropriate for public spec - about some compiler bug
alexp
parents: 7668
diff changeset
   378
     * Instantiate it only within subclasses of {@code MetalComboBoxUI}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * This class is now obsolete and doesn't do anything and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * is only included for backwards API compatibility. Do not call or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @deprecated As of Java 2 platform v1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public class MetalComboPopup extends BasicComboPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   389
        /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   390
         * Constructs a new instance of {@code MetalComboPopup}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   391
         *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   392
         * @param cBox an instance of {@code JComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   393
         */
25565
ce603b34c98d 8043548: Fix raw and unchecked lint warnings in javax.swing.plaf.*
darcy
parents: 25178
diff changeset
   394
        public MetalComboPopup( JComboBox<Object> cBox) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            super( cBox );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        // This method was overloaded and made public. This was probably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        // mistake in the implementation. The functionality that they used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        // provide is no longer necessary and should be removed. However,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        // removing them will create an uncompatible API change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        public void delegateFocus(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            super.delegateFocus(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
}