jdk/test/javax/swing/JColorChooser/Test6524757.java
author goetz
Tue, 14 Jun 2016 10:44:59 +0200
changeset 39056 d99e63b6d962
parent 31448 1066345d2a8a
permissions -rw-r--r--
8159690: [TESTBUG] Mark headful tests with @key headful. Reviewed-by: simonis, alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 31448
diff changeset
     2
 * Copyright (c) 2007, 2016, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1282
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1282
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1282
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
39056
d99e63b6d962 8159690: [TESTBUG] Mark headful tests with @key headful.
goetz
parents: 31448
diff changeset
    26
 * @key headful
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @bug 6524757
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @summary Tests different locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Sergey Malenkov
31448
1066345d2a8a 8076468: Add @modules to tests in jdk_desktop test group
yan
parents: 10138
diff changeset
    30
 * @modules java.desktop/sun.swing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Locale;
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    39
import javax.swing.AbstractButton;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.JColorChooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.JComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.JDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.JFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.JLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.JPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.swing.UIManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.swing.WindowConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.swing.colorchooser.AbstractColorChooserPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public class Test6524757 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    private static final String[] KEYS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            "ColorChooser.okText", // NON-NLS: string key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            "ColorChooser.cancelText", // NON-NLS: string key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            "ColorChooser.resetText", // NON-NLS: string key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            "ColorChooser.resetMnemonic", // NON-NLS: int key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
//NotAvail: "ColorChooser.sampleText", // NON-NLS: string key from DefaultPreviewPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            "ColorChooser.swatchesNameText", // NON-NLS: string key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            "ColorChooser.swatchesMnemonic", // NON-NLS: string key from DefaultSwatchChooserPanel:int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            "ColorChooser.swatchesSwatchSize", // NON-NLS: dimension key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            "ColorChooser.swatchesRecentText", // NON-NLS: string key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            "ColorChooser.swatchesRecentSwatchSize", // NON-NLS: dimension key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
//NotAvail: "ColorChooser.swatchesDefaultRecentColor", // NON-NLS: color key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    68
            "ColorChooser.hsvNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    69
            "ColorChooser.hsvMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    70
            "ColorChooser.hsvHueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    71
            "ColorChooser.hsvSaturationText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    72
            "ColorChooser.hsvValueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    73
            "ColorChooser.hsvTransparencyText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    74
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    75
            "ColorChooser.hslNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    76
            "ColorChooser.hslMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    77
            "ColorChooser.hslHueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    78
            "ColorChooser.hslSaturationText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    79
            "ColorChooser.hslLightnessText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    80
            "ColorChooser.hslTransparencyText", // NON-NLS: string key from HSV ColorChooserPanel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    82
            "ColorChooser.rgbNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    83
            "ColorChooser.rgbMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    84
            "ColorChooser.rgbRedText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    85
            "ColorChooser.rgbGreenText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    86
            "ColorChooser.rgbBlueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    87
            "ColorChooser.rgbAlphaText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    88
            "ColorChooser.rgbHexCodeText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    89
            "ColorChooser.rgbHexCodeMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    90
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    91
            "ColorChooser.cmykNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    92
            "ColorChooser.cmykMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    93
            "ColorChooser.cmykCyanText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    94
            "ColorChooser.cmykMagentaText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    95
            "ColorChooser.cmykYellowText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    96
            "ColorChooser.cmykBlackText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    97
            "ColorChooser.cmykAlphaText", // NON-NLS: string key from HSV ColorChooserPanel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    private static final Object[] KOREAN = convert(Locale.KOREAN, KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private static final Object[] FRENCH = convert(Locale.FRENCH, KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static void main(String[] args) {
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   103
        Locale reservedLocale = Locale.getDefault();
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   104
        try {
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   105
            // it affects Swing because it is not initialized
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   106
            Locale.setDefault(Locale.KOREAN);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   107
            validate(KOREAN, create());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   109
            // it does not affect Swing because it is initialized
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   110
            Locale.setDefault(Locale.CANADA);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   111
            validate(KOREAN, create());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   113
            // it definitely should affect Swing
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   114
            JComponent.setDefaultLocale(Locale.FRENCH);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   115
            validate(FRENCH, create());
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   116
        } finally {
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   117
            // restore the reserved locale
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   118
            Locale.setDefault(reservedLocale);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   119
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private static void validate(Object[] expected, Object[] actual) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        int count = expected.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (count != actual.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            throw new Error("different size: " + count + " <> " + actual.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            if (!expected[i].equals(actual[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                throw new Error("unexpected value for key: " + KEYS[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private static Object[] convert(Locale locale, String[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        int count = keys.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        Object[] array = new Object[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            array[i] = convert(locale, keys[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static Object convert(Locale locale, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        if (key.endsWith("Text")) { // NON-NLS: suffix for text message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            return UIManager.getString(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (key.endsWith("Size")) { // NON-NLS: suffix for dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            return UIManager.getDimension(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        if (key.endsWith("Color")) { // NON-NLS: suffix for color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            return UIManager.getColor(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        int value = SwingUtilities2.getUIDefaultsInt(key, locale, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return Integer.valueOf(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    private static Object[] create() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        JFrame frame = new JFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // show color chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        JColorChooser chooser = new JColorChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        JDialog dialog = JColorChooser.createDialog(frame, null, false, chooser, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // process all values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        List<Object> list = new ArrayList<Object>(KEYS.length);
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   169
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   170
        Component component = getC(getC(dialog.getLayeredPane(), 0), 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   171
        AbstractButton ok = (AbstractButton) getC(component, 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   172
        AbstractButton cancel = (AbstractButton) getC(component, 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   173
        AbstractButton reset = (AbstractButton) getC(component, 2);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   174
        list.add(ok.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   175
        list.add(cancel.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   176
        list.add(reset.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   177
        list.add(Integer.valueOf(reset.getMnemonic()));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   178
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   179
        for (int i = 0; i < 5; i++) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   180
            AbstractColorChooserPanel panel = (AbstractColorChooserPanel) getC(getC(getC(chooser, 0), i), 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   181
            list.add(panel.getDisplayName());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   182
            list.add(Integer.valueOf(panel.getMnemonic()));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   183
            if (i == 0) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   184
                JLabel label = (JLabel) getC(getC(panel, 0), 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   185
                JPanel upper = (JPanel) getC(getC(getC(panel, 0), 0), 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   186
                JPanel lower = (JPanel) getC(getC(getC(panel, 0), 2), 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   187
                addSize(list, upper, 1, 1, 31, 9);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   188
                list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   189
                addSize(list, lower, 1, 1, 5, 7);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   190
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   191
            else {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   192
                Component container = getC(panel, 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   193
                for (int j = 0; j < 3; j++) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   194
                    AbstractButton button = (AbstractButton) getC(container, j);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   195
                    list.add(button.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   196
                }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   197
                JLabel label = (JLabel) getC(container, 3);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   198
                list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   199
                if (i == 4) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   200
                    label = (JLabel) getC(container, 4);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   201
                    list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   202
                }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   203
                if (i == 3) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   204
                    label = (JLabel) getC(panel, 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   205
                    list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   206
                    list.add(Integer.valueOf(label.getDisplayedMnemonic()));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   207
                }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   208
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   209
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // close dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        dialog.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // close frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        frame.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        return list.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    private static void addSize(List<Object> list, Component component, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        Dimension size = component.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        int width = (size.width + 1) / w - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        int height = (size.height + 1) / h - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        list.add(new Dimension(width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    private static Component getC(Component component, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        Container container = (Container) component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        return container.getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
}