jdk/test/javax/swing/JColorChooser/Test6524757.java
author goetz
Tue, 09 Dec 2014 11:57:46 +0100
changeset 28187 fc19df82d6ee
parent 10138 b7572da25d15
child 31448 1066345d2a8a
permissions -rw-r--r--
8066964: ppc64: argument and return type profiling, fix problem with popframe Reviewed-by: roland, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
     2
 * Copyright (c) 2007, 2011, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6524757
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Tests different locales
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Sergey Malenkov
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Locale;
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    37
import javax.swing.AbstractButton;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.JColorChooser;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.JComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.JDialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.JFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.JLabel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.JPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.UIManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.WindowConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.swing.colorchooser.AbstractColorChooserPanel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class Test6524757 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static final String[] KEYS = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            "ColorChooser.okText", // NON-NLS: string key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            "ColorChooser.cancelText", // NON-NLS: string key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            "ColorChooser.resetText", // NON-NLS: string key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            "ColorChooser.resetMnemonic", // NON-NLS: int key from JColorChooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
//NotAvail: "ColorChooser.sampleText", // NON-NLS: string key from DefaultPreviewPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            "ColorChooser.swatchesNameText", // NON-NLS: string key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            "ColorChooser.swatchesMnemonic", // NON-NLS: string key from DefaultSwatchChooserPanel:int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            "ColorChooser.swatchesSwatchSize", // NON-NLS: dimension key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            "ColorChooser.swatchesRecentText", // NON-NLS: string key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            "ColorChooser.swatchesRecentSwatchSize", // NON-NLS: dimension key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
//NotAvail: "ColorChooser.swatchesDefaultRecentColor", // NON-NLS: color key from DefaultSwatchChooserPanel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    66
            "ColorChooser.hsvNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    67
            "ColorChooser.hsvMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    68
            "ColorChooser.hsvHueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    69
            "ColorChooser.hsvSaturationText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    70
            "ColorChooser.hsvValueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    71
            "ColorChooser.hsvTransparencyText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    72
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    73
            "ColorChooser.hslNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    74
            "ColorChooser.hslMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    75
            "ColorChooser.hslHueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    76
            "ColorChooser.hslSaturationText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    77
            "ColorChooser.hslLightnessText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    78
            "ColorChooser.hslTransparencyText", // NON-NLS: string key from HSV ColorChooserPanel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    80
            "ColorChooser.rgbNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    81
            "ColorChooser.rgbMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    82
            "ColorChooser.rgbRedText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    83
            "ColorChooser.rgbGreenText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    84
            "ColorChooser.rgbBlueText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    85
            "ColorChooser.rgbAlphaText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    86
            "ColorChooser.rgbHexCodeText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    87
            "ColorChooser.rgbHexCodeMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    88
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    89
            "ColorChooser.cmykNameText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    90
            "ColorChooser.cmykMnemonic", // NON-NLS: int key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    91
            "ColorChooser.cmykCyanText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    92
            "ColorChooser.cmykMagentaText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    93
            "ColorChooser.cmykYellowText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    94
            "ColorChooser.cmykBlackText", // NON-NLS: string key from HSV ColorChooserPanel
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
    95
            "ColorChooser.cmykAlphaText", // NON-NLS: string key from HSV ColorChooserPanel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private static final Object[] KOREAN = convert(Locale.KOREAN, KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private static final Object[] FRENCH = convert(Locale.FRENCH, KEYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static void main(String[] args) {
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   101
        Locale reservedLocale = Locale.getDefault();
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   102
        try {
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   103
            // it affects Swing because it is not initialized
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   104
            Locale.setDefault(Locale.KOREAN);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   105
            validate(KOREAN, create());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   107
            // it does not affect Swing because it is initialized
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   108
            Locale.setDefault(Locale.CANADA);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   109
            validate(KOREAN, create());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   111
            // it definitely should affect Swing
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   112
            JComponent.setDefaultLocale(Locale.FRENCH);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   113
            validate(FRENCH, create());
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   114
        } finally {
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   115
            // restore the reserved locale
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   116
            Locale.setDefault(reservedLocale);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
   117
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static void validate(Object[] expected, Object[] actual) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        int count = expected.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (count != actual.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new Error("different size: " + count + " <> " + actual.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (!expected[i].equals(actual[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                throw new Error("unexpected value for key: " + KEYS[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private static Object[] convert(Locale locale, String[] keys) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        int count = keys.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        Object[] array = new Object[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            array[i] = convert(locale, keys[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        return array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private static Object convert(Locale locale, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (key.endsWith("Text")) { // NON-NLS: suffix for text message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            return UIManager.getString(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (key.endsWith("Size")) { // NON-NLS: suffix for dimension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            return UIManager.getDimension(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        if (key.endsWith("Color")) { // NON-NLS: suffix for color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            return UIManager.getColor(key, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        int value = SwingUtilities2.getUIDefaultsInt(key, locale, -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return Integer.valueOf(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private static Object[] create() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        JFrame frame = new JFrame();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        frame.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        // show color chooser
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        JColorChooser chooser = new JColorChooser();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        JDialog dialog = JColorChooser.createDialog(frame, null, false, chooser, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        dialog.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        // process all values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        List<Object> list = new ArrayList<Object>(KEYS.length);
1282
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   167
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   168
        Component component = getC(getC(dialog.getLayeredPane(), 0), 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   169
        AbstractButton ok = (AbstractButton) getC(component, 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   170
        AbstractButton cancel = (AbstractButton) getC(component, 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   171
        AbstractButton reset = (AbstractButton) getC(component, 2);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   172
        list.add(ok.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   173
        list.add(cancel.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   174
        list.add(reset.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   175
        list.add(Integer.valueOf(reset.getMnemonic()));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   176
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   177
        for (int i = 0; i < 5; i++) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   178
            AbstractColorChooserPanel panel = (AbstractColorChooserPanel) getC(getC(getC(chooser, 0), i), 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   179
            list.add(panel.getDisplayName());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   180
            list.add(Integer.valueOf(panel.getMnemonic()));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   181
            if (i == 0) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   182
                JLabel label = (JLabel) getC(getC(panel, 0), 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   183
                JPanel upper = (JPanel) getC(getC(getC(panel, 0), 0), 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   184
                JPanel lower = (JPanel) getC(getC(getC(panel, 0), 2), 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   185
                addSize(list, upper, 1, 1, 31, 9);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   186
                list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   187
                addSize(list, lower, 1, 1, 5, 7);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   188
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   189
            else {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   190
                Component container = getC(panel, 0);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   191
                for (int j = 0; j < 3; j++) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   192
                    AbstractButton button = (AbstractButton) getC(container, j);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   193
                    list.add(button.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   194
                }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   195
                JLabel label = (JLabel) getC(container, 3);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   196
                list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   197
                if (i == 4) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   198
                    label = (JLabel) getC(container, 4);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   199
                    list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   200
                }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   201
                if (i == 3) {
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   202
                    label = (JLabel) getC(panel, 1);
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   203
                    list.add(label.getText());
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   204
                    list.add(Integer.valueOf(label.getDisplayedMnemonic()));
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   205
                }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   206
            }
00a51b36c173 6552812: Add HSL tab to JColorChooser
malenkov
parents: 2
diff changeset
   207
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // close dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        dialog.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        dialog.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // close frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        frame.setVisible(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        frame.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return list.toArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    private static void addSize(List<Object> list, Component component, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        Dimension size = component.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        int width = (size.width + 1) / w - x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        int height = (size.height + 1) / h - y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        list.add(new Dimension(width, height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    private static Component getC(Component component, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        Container container = (Container) component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return container.getComponent(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}