jdk/src/share/classes/javax/swing/plaf/metal/MetalComboBoxButton.java
author yan
Mon, 30 Jun 2014 16:32:36 +0400
changeset 25178 dbab904451e9
parent 22574 7f8ce0c8c20a
child 25565 ce603b34c98d
permissions -rw-r--r--
8046434: Fix doclint warnings from javax.swing.plaf.metal package Reviewed-by: alexsch Contributed-by: Andrei Eremeev <andrei.eremeev@oracle.com>
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.plaf.basic.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * JButton subclass to help out MetalComboBoxUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * 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: 5506
diff changeset
    44
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see MetalComboBoxButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 */
22574
7f8ce0c8c20a 8032627: Add @SuppressWarnings("serial") to appropriate javax.swing classes
darcy
parents: 20458
diff changeset
    51
@SuppressWarnings("serial") // Same-version serialization only
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class MetalComboBoxButton extends JButton {
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    53
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    54
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    55
     * The instance of {@code JComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    56
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    protected JComboBox comboBox;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    58
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
     * The instance of {@code JList}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    61
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    protected JList listBox;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    63
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    64
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    65
     * The instance of {@code CellRendererPane}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    66
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    protected CellRendererPane rendererPane;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    68
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    69
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    70
     * The icon.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    71
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected Icon comboIcon;
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    73
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    74
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    75
     * The {@code iconOnly} value.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    76
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    protected boolean iconOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    79
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    80
     * Returns the {@code JComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    81
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    82
     * @return the {@code JComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    83
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public final JComboBox getComboBox() { return comboBox;}
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    85
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    86
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    87
     * Sets the {@code JComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    88
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    89
     * @param cb the {@code JComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    90
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public final void setComboBox( JComboBox cb ) { comboBox = cb;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    93
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    94
     * Returns the icon of the {@code JComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    95
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    96
     * @return the icon of the {@code JComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    97
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public final Icon getComboIcon() { return comboIcon;}
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
    99
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   100
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   101
     * Sets the icon of the {@code JComboBox}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   102
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   103
     * @param i the icon of the {@code JComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   104
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public final void setComboIcon( Icon i ) { comboIcon = i;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   107
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   108
     * Returns the {@code isIconOnly} value.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   109
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   110
     * @return the {@code isIconOnly} value
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   111
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public final boolean isIconOnly() { return iconOnly;}
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   113
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   114
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   115
     * If {@code isIconOnly} is {@code true} then only icon is painted.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   116
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   117
     * @param isIconOnly if {@code true} then only icon is painted
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   118
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public final void setIconOnly( boolean isIconOnly ) { iconOnly = isIconOnly;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    MetalComboBoxButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        super( "" );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        DefaultButtonModel model = new DefaultButtonModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            public void setArmed( boolean armed ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                super.setArmed( isPressed() ? true : armed );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        setModel( model );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   131
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   132
     * Constructs a new instance of {@code MetalComboBoxButton}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   133
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   134
     * @param cb an instance of {@code JComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   135
     * @param i an icon
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   136
     * @param pane an instance of {@code CellRendererPane}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   137
     * @param list an instance of {@code JList}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   138
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public MetalComboBoxButton( JComboBox cb, Icon i,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                CellRendererPane pane, JList list ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        comboBox = cb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        comboIcon = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        rendererPane = pane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        listBox = list;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        setEnabled( comboBox.isEnabled() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
25178
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   149
    /**
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   150
     * Constructs a new instance of {@code MetalComboBoxButton}.
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   151
     *
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   152
     * @param cb an instance of {@code JComboBox}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   153
     * @param i an icon
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   154
     * @param onlyIcon if {@code true} only icon is painted
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   155
     * @param pane an instance of {@code CellRendererPane}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   156
     * @param list an instance of {@code JList}
dbab904451e9 8046434: Fix doclint warnings from javax.swing.plaf.metal package
yan
parents: 22574
diff changeset
   157
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public MetalComboBoxButton( JComboBox cb, Icon i, boolean onlyIcon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                CellRendererPane pane, JList list ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        this( cb, i, pane, list );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        iconOnly = onlyIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public void setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        super.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // Set the background and foreground to the combobox colors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        if (enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            setBackground(comboBox.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            setForeground(comboBox.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            setBackground(UIManager.getColor("ComboBox.disabledBackground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            setForeground(UIManager.getColor("ComboBox.disabledForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public void paintComponent( Graphics g ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        boolean leftToRight = MetalUtils.isLeftToRight(comboBox);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        // Paint the button as usual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        super.paintComponent( g );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        int width = getWidth() - (insets.left + insets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        int height = getHeight() - (insets.top + insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if ( height <= 0 || width <= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int left = insets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        int top = insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        int right = left + (width - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        int bottom = top + (height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        int iconWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        int iconLeft = (leftToRight) ? right : left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // Paint the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if ( comboIcon != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            iconWidth = comboIcon.getIconWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            int iconHeight = comboIcon.getIconHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            int iconTop = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if ( iconOnly ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                iconLeft = (getWidth() / 2) - (iconWidth / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                iconTop = (getHeight() / 2) - (iconHeight / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                    iconLeft = (left + (width - 1)) - iconWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    iconLeft = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                iconTop = (top + ((bottom - top) / 2)) - (iconHeight / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            comboIcon.paintIcon( this, g, iconLeft, iconTop );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            // Paint the focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if ( comboBox.hasFocus() && (!MetalLookAndFeel.usingOcean() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                         comboBox.isEditable())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                g.setColor( MetalLookAndFeel.getFocusColor() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                g.drawRect( left - 1, top - 1, width + 3, height + 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // With Ocean the button only paints the arrow, bail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        // Let the renderer paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if ( ! iconOnly && comboBox != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ListCellRenderer renderer = comboBox.getRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            Component c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            boolean renderPressed = getModel().isPressed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            c = renderer.getListCellRendererComponent(listBox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                                                      comboBox.getSelectedItem(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                                                      -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                                                      renderPressed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                                                      false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            c.setFont(rendererPane.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            if ( model.isArmed() && model.isPressed() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                if ( isOpaque() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                    c.setBackground(UIManager.getColor("Button.select"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                c.setForeground(comboBox.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            else if ( !comboBox.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                if ( isOpaque() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    c.setBackground(UIManager.getColor("ComboBox.disabledBackground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                c.setForeground(UIManager.getColor("ComboBox.disabledForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                c.setForeground(comboBox.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                c.setBackground(comboBox.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            int cWidth = width - (insets.right + iconWidth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            // Fix for 4238829: should lay out the JPanel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            boolean shouldValidate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            if (c instanceof JPanel)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                shouldValidate = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (leftToRight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                rendererPane.paintComponent( g, c, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                                             left, top, cWidth, height, shouldValidate );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                rendererPane.paintComponent( g, c, this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                             left + iconWidth, top, cWidth, height, shouldValidate );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        Dimension ret = new Dimension();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        ret.width = insets.left + getComboIcon().getIconWidth() + insets.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        ret.height = insets.bottom + getComboIcon().getIconHeight() + insets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}