jdk/test/javax/swing/JColorChooser/Test8152419.java
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 39518 cf5567d544b4
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39518
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     1
/*
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     4
 *
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     8
 *
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    13
 * accompanied this code).
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    14
 *
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    18
 *
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    21
 * questions.
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    22
 */
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    23
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    24
 /*
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    25
* @test
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    26
* @bug 8152419
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    27
* @summary To Verify JColorChooser tab selection
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    28
* @run main/manual Test8152419
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    29
 */
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    30
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    31
import java.awt.Color;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    32
import java.awt.GridBagConstraints;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    33
import java.awt.GridBagLayout;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    34
import java.awt.event.ActionEvent;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    35
import java.awt.event.ActionListener;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    36
import java.util.concurrent.CountDownLatch;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    37
import javax.swing.JButton;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    38
import javax.swing.JColorChooser;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    39
import javax.swing.JFrame;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    40
import javax.swing.JPanel;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    41
import javax.swing.JTextArea;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    42
import javax.swing.SwingUtilities;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    43
import javax.swing.UIManager;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    44
import javax.swing.border.EmptyBorder;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    45
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    46
public class Test8152419 {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    47
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    48
    public static void main(String args[]) throws Exception {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    49
        final CountDownLatch latch = new CountDownLatch(1);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    50
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    51
        JColorChooserTest test = new JColorChooserTest(latch);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    52
        Thread T1 = new Thread(test);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    53
        T1.start();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    54
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    55
        // wait for latch to complete
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    56
        try {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    57
            latch.await();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    58
        } catch (InterruptedException ie) {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    59
            throw ie;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    60
        }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    61
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    62
        if (test.testResult == false) {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    63
            throw new RuntimeException("User Clicked Fail!");
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    64
        }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    65
    }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    66
}
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    67
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    68
class JColorChooserTest implements Runnable {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    69
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    70
    private static GridBagLayout layout;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    71
    private static JPanel mainControlPanel;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    72
    private static JPanel resultButtonPanel;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    73
    private static JTextArea instructionTextArea;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    74
    private static JButton passButton;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    75
    private static JButton failButton;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    76
    private static JFrame mainFrame;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    77
    private static JColorChooser colorChooser;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    78
    private final CountDownLatch latch;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    79
    public volatile boolean testResult = false;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    80
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    81
    public JColorChooserTest(CountDownLatch latch) throws Exception {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    82
        this.latch = latch;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    83
    }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    84
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    85
    @Override
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    86
    public void run() {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    87
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    88
        try {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    89
            createUI();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    90
        } catch (Exception ex) {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    91
            if (mainFrame != null) {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    92
                mainFrame.dispose();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    93
            }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    94
            latch.countDown();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    95
            throw new RuntimeException("createUI Failed: " + ex.getMessage());
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    96
        }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    97
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    98
    }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
    99
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   100
    public final void createUI() throws Exception {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   101
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   102
        SwingUtilities.invokeAndWait(new Runnable() {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   103
            @Override
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   104
            public void run() {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   105
                mainFrame = new JFrame("JColorChooser Test");
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   106
                layout = new GridBagLayout();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   107
                mainControlPanel = new JPanel(layout);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   108
                resultButtonPanel = new JPanel(layout);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   109
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   110
                GridBagConstraints gbc = new GridBagConstraints();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   111
                String instructions
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   112
                        = "INSTRUCTIONS:"
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   113
                        + "\n Select HSV, HSL, RGB or CMYK tab."
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   114
                        + "\n If able to shift and view JColorChooser tabs"
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   115
                        + "\n then click Pass, else Fail.";
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   116
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   117
                instructionTextArea = new JTextArea();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   118
                instructionTextArea.setText(instructions);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   119
                instructionTextArea.setEnabled(true);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   120
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   121
                gbc.gridx = 0;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   122
                gbc.gridy = 0;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   123
                gbc.fill = GridBagConstraints.HORIZONTAL;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   124
                mainControlPanel.add(instructionTextArea, gbc);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   125
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   126
                UIManager.put("FormattedTextField.border",
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   127
                        new EmptyBorder(0, 10, 0, 10));
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   128
                colorChooser = new JColorChooser(Color.BLUE);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   129
                gbc.gridx = 0;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   130
                gbc.gridy = 1;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   131
                mainControlPanel.add(colorChooser, gbc);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   132
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   133
                passButton = new JButton("Pass");
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   134
                passButton.setActionCommand("Pass");
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   135
                passButton.addActionListener((ActionEvent e) -> {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   136
                    testResult = true;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   137
                    mainFrame.dispose();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   138
                    latch.countDown();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   139
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   140
                });
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   141
                failButton = new JButton("Fail");
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   142
                failButton.setActionCommand("Fail");
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   143
                failButton.addActionListener(new ActionListener() {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   144
                    @Override
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   145
                    public void actionPerformed(ActionEvent e) {
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   146
                        testResult = false;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   147
                        mainFrame.dispose();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   148
                        latch.countDown();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   149
                    }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   150
                });
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   151
                gbc.gridx = 0;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   152
                gbc.gridy = 0;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   153
                resultButtonPanel.add(passButton, gbc);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   154
                gbc.gridx = 1;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   155
                gbc.gridy = 0;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   156
                resultButtonPanel.add(failButton, gbc);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   157
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   158
                gbc.gridx = 0;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   159
                gbc.gridy = 2;
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   160
                mainControlPanel.add(resultButtonPanel, gbc);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   161
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   162
                mainFrame.add(mainControlPanel);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   163
                mainFrame.pack();
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   164
                mainFrame.setVisible(true);
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   165
            }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   166
        });
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   167
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   168
    }
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   169
}
cf5567d544b4 8152419: JColorChooser throws Exception
pkbalakr
parents:
diff changeset
   170