jdk/src/share/classes/com/sun/java/swing/plaf/windows/WindowsComboBoxUI.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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 com.sun.java.swing.plaf.windows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.basic.*;
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.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import static com.sun.java.swing.plaf.windows.TMSchema.Part;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import static com.sun.java.swing.plaf.windows.TMSchema.State;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import static com.sun.java.swing.plaf.windows.XPStyle.Skin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.swing.DefaultLookup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.swing.StringUIClientPropertyKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Windows combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @author Tom Santos
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @author Igor Kushnirskiy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class WindowsComboBoxUI extends BasicComboBoxUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static final MouseListener rolloverListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        new MouseAdapter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            private void handleRollover(MouseEvent e, boolean isRollover) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                JComboBox comboBox = getComboBox(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                WindowsComboBoxUI comboBoxUI = getWindowsComboBoxUI(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                if (comboBox == null || comboBoxUI == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                if (! comboBox.isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                    //mouse over editable ComboBox does not switch rollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    //for the arrow button
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    ButtonModel m = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    if (comboBoxUI.arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                        m = comboBoxUI.arrowButton.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                    if (m != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                        m.setRollover(isRollover);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                comboBoxUI.isRollover = isRollover;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                comboBox.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            public void mouseEntered(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                handleRollover(e, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            public void mouseExited(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                handleRollover(e, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            private JComboBox getComboBox(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                Object source = event.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                JComboBox rv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                if (source instanceof JComboBox) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    rv = (JComboBox) source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                } else if (source instanceof XPComboBoxButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    rv = ((XPComboBoxButton) source)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                        .getWindowsComboBoxUI().comboBox;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            private WindowsComboBoxUI getWindowsComboBoxUI(MouseEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                JComboBox comboBox = getComboBox(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                WindowsComboBoxUI rv = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                if (comboBox != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    && comboBox.getUI() instanceof WindowsComboBoxUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    rv = (WindowsComboBoxUI) comboBox.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private boolean isRollover = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private static final PropertyChangeListener componentOrientationListener =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                Object source = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                if ("componentOrientation" == propertyName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    && (source = e.getSource()) instanceof JComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    && ((JComboBox) source).getUI() instanceof
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                      WindowsComboBoxUI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    JComboBox comboBox = (JComboBox) source;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    WindowsComboBoxUI comboBoxUI = (WindowsComboBoxUI) comboBox.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                    if (comboBoxUI.arrowButton instanceof XPComboBoxButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        ((XPComboBoxButton) comboBoxUI.arrowButton).setPart(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                                    (comboBox.getComponentOrientation() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                       ComponentOrientation.RIGHT_TO_LEFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                                    ? Part.CP_DROPDOWNBUTTONLEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                    : Part.CP_DROPDOWNBUTTONRIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                            }
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
    public static ComponentUI createUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        return new WindowsComboBoxUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public void installUI( JComponent c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        super.installUI( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        isRollover = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        comboBox.setRequestFocusEnabled( true );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (XPStyle.getXP() != null && arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            //we can not do it in installListeners because arrowButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            //is initialized after installListeners is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            comboBox.addMouseListener(rolloverListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            arrowButton.addMouseListener(rolloverListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void uninstallUI(JComponent c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        comboBox.removeMouseListener(rolloverListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if(arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            arrowButton.removeMouseListener(rolloverListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        super.uninstallUI( c );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    protected void installListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        super.installListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        //button glyph for LTR and RTL combobox might differ
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (xp != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
              && xp.isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            comboBox.addPropertyChangeListener("componentOrientation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                               componentOrientationListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    protected void uninstallListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        super.uninstallListeners();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        comboBox.removePropertyChangeListener("componentOrientation",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                                              componentOrientationListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    protected void configureEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        super.configureEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            editor.addMouseListener(rolloverListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    protected void unconfigureEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        super.unconfigureEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        editor.removeMouseListener(rolloverListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            paintXPComboBoxBackground(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        super.paint(g, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    State getXPComboBoxState(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        State state = State.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (!c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            state = State.DISABLED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } else if (isPopupVisible(comboBox)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            state = State.PRESSED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        } else if (isRollover) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            state = State.HOT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return state;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private void paintXPComboBoxBackground(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        State state = getXPComboBoxState(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        Skin skin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (! comboBox.isEditable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
              && xp.isSkinDefined(c, Part.CP_READONLY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            skin = xp.getSkin(c, Part.CP_READONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        if (skin == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            skin = xp.getSkin(c, Part.CP_COMBOBOX);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        skin.paintSkin(g, 0, 0, c.getWidth(), c.getHeight(), state);
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
     * If necessary paints the currently selected item.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param g Graphics to paint to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param bounds Region to paint current value to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @param hasFocus whether or not the JComboBox has focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @throws NullPointerException if any of the arguments are null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public void paintCurrentValue(Graphics g, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                  boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if ( xp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            bounds.x += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            bounds.y += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            bounds.width -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            bounds.height -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            bounds.x += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            bounds.y += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            bounds.width -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            bounds.height -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        if (! comboBox.isEditable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            && xp != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            && xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            // On vista for READNLY ComboBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            // color for currentValue is the same as for any other item
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            // mostly copied from javax.swing.plaf.basic.BasicComboBoxUI.paintCurrentValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            ListCellRenderer renderer = comboBox.getRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            Component c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if ( hasFocus && !isPopupVisible(comboBox) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                c = renderer.getListCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                        listBox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                        comboBox.getSelectedItem(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                        -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                        true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                c = renderer.getListCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        listBox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        comboBox.getSelectedItem(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                        false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                        false );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            c.setFont(comboBox.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if ( comboBox.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                c.setForeground(comboBox.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                c.setBackground(comboBox.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                c.setForeground(DefaultLookup.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                         comboBox, this, "ComboBox.disabledForeground", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                c.setBackground(DefaultLookup.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                         comboBox, this, "ComboBox.disabledBackground", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            boolean shouldValidate = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (c instanceof JPanel)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                shouldValidate = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                            bounds.width, bounds.height, shouldValidate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            super.paintCurrentValue(g, bounds, hasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public void paintCurrentValueBackground(Graphics g, Rectangle bounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                            boolean hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if (XPStyle.getXP() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            super.paintCurrentValueBackground(g, bounds, hasFocus);
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
    public Dimension getMinimumSize( JComponent c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        Dimension d = super.getMinimumSize(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            d.width += 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            d.width += 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        d.height += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * Creates a layout manager for managing the components which make up the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @return an instance of a layout manager
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    protected LayoutManager createLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        return new BasicComboBoxUI.ComboBoxLayoutManager() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            public void layoutContainer(Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                super.layoutContainer(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                if (XPStyle.getXP() != null && arrowButton != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    Dimension d = parent.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                    Insets insets = getInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    int buttonWidth = arrowButton.getPreferredSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    arrowButton.setBounds(WindowsGraphicsUtils.isLeftToRight((JComboBox)parent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                                          ? (d.width - insets.right - buttonWidth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                          : insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                          insets.top,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                          buttonWidth, d.height - insets.top - insets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        super.installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    protected ComboPopup createPopup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return super.createPopup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Creates the default editor that will be used in editable combo boxes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * A default editor will be used only if an editor has not been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * explicitly set with <code>setEditor</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @return a <code>ComboBoxEditor</code> used for the combo box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see javax.swing.JComboBox#setEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    protected ComboBoxEditor createEditor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return new WindowsComboBoxEditor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    protected ListCellRenderer createRenderer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        XPStyle xp = XPStyle.getXP();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        if (xp != null && xp.isSkinDefined(comboBox, Part.CP_READONLY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return new WindowsComboBoxRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            return super.createRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Creates an button which will be used as the control to show or hide
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * the popup portion of the combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @return a button which represents the popup control
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    protected JButton createArrowButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (XPStyle.getXP() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return new XPComboBoxButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return super.createArrowButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    private class XPComboBoxButton extends XPStyle.GlyphButton {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public XPComboBoxButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            super(null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                  (! XPStyle.getXP().isSkinDefined(comboBox, Part.CP_DROPDOWNBUTTONRIGHT))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                   ? Part.CP_DROPDOWNBUTTON
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                   : (comboBox.getComponentOrientation() == ComponentOrientation.RIGHT_TO_LEFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                     ? Part.CP_DROPDOWNBUTTONLEFT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                     : Part.CP_DROPDOWNBUTTONRIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        protected State getState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            State rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            rv = super.getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            if (rv != State.DISABLED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                && ! comboBox.isEditable()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                && XPStyle.getXP().isSkinDefined(comboBox,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                                 Part.CP_DROPDOWNBUTTONRIGHT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                 * for non editable ComboBoxes Vista seems to have the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                 * same glyph for all non DISABLED states
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                rv = State.NORMAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return new Dimension(17, 21);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        void setPart(Part part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            setPart(comboBox, part);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        WindowsComboBoxUI getWindowsComboBoxUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            return WindowsComboBoxUI.this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * Subclassed to add Windows specific Key Bindings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * This class is now obsolete and doesn't do anything.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Only included for backwards API compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Do not call or override.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @deprecated As of Java 2 platform v1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    protected class WindowsComboPopup extends BasicComboPopup {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        public WindowsComboPopup( JComboBox cBox ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            super( cBox );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        protected KeyListener createKeyListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return new InvocationKeyHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        protected class InvocationKeyHandler extends BasicComboPopup.InvocationKeyHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            protected InvocationKeyHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                WindowsComboPopup.this.super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Subclassed to highlight selected item in an editable combo box.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    public static class WindowsComboBoxEditor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        extends BasicComboBoxEditor.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        protected JTextField createEditorComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            JTextField editor = super.createEditorComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            Border border = (Border)UIManager.get("ComboBox.editorBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            if (border != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                editor.setBorder(border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            editor.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            return editor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        public void setItem(Object item) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            super.setItem(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            if (editor.hasFocus()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                editor.selectAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * Subclassed to set opacity {@code false} on the renderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * and to show border for focused cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    private static class WindowsComboBoxRenderer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
          extends BasicComboBoxRenderer.UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        private static final Object BORDER_KEY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            = new StringUIClientPropertyKey("BORDER_KEY");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        private static final Border NULL_BORDER = new EmptyBorder(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        public Component getListCellRendererComponent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                                 JList list,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                                 Object value,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                                 int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                                 boolean isSelected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                                                 boolean cellHasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            Component rv =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                super.getListCellRendererComponent(list, value, index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                                   isSelected, cellHasFocus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            if (rv instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                JComponent component = (JComponent) rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                if (index == -1 && isSelected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    Border border = component.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    Border dashedBorder =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                        new WindowsBorders.DashedBorder(list.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    component.setBorder(dashedBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    //store current border in client property if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    if (component.getClientProperty(BORDER_KEY) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                        component.putClientProperty(BORDER_KEY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                       (border == null) ? NULL_BORDER : border);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    if (component.getBorder() instanceof
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                          WindowsBorders.DashedBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                        Object storedBorder = component.getClientProperty(BORDER_KEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                        if (storedBorder instanceof Border) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                            component.setBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                (storedBorder == NULL_BORDER) ? null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                                    : (Border) storedBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                        component.putClientProperty(BORDER_KEY, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    component.setOpaque(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    component.setForeground(list.getForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    component.setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
}