|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | +/* |
| 24 | + * @test |
| 25 | + * @bug 8266510 8271315 |
| 26 | + * @summary Verifies Nimbus JTree default tree cell renderer use selected text color |
| 27 | + * @run main/manual NimbusJTreeSelTextColor |
| 28 | + */ |
| 29 | +import java.util.concurrent.CountDownLatch; |
| 30 | +import java.util.concurrent.TimeUnit; |
| 31 | +import java.awt.Color; |
| 32 | +import java.awt.GridBagLayout; |
| 33 | +import java.awt.Insets; |
| 34 | +import java.awt.GridBagConstraints; |
| 35 | +import java.awt.event.ActionEvent; |
| 36 | +import java.awt.event.ActionListener; |
| 37 | +import java.awt.event.WindowAdapter; |
| 38 | +import java.awt.event.WindowEvent; |
| 39 | +import javax.swing.JButton; |
| 40 | +import javax.swing.JComponent; |
| 41 | +import javax.swing.JFrame; |
| 42 | +import javax.swing.JPanel; |
| 43 | +import javax.swing.JTextArea; |
| 44 | +import javax.swing.JTree; |
| 45 | +import javax.swing.SwingUtilities; |
| 46 | +import javax.swing.tree.DefaultTreeCellRenderer; |
| 47 | +import javax.swing.UIManager; |
| 48 | + |
| 49 | +public class NimbusJTreeSelTextColor { |
| 50 | + |
| 51 | + private static JFrame frame; |
| 52 | + private static JTree tree; |
| 53 | + private static DefaultTreeCellRenderer treeCellRenderer; |
| 54 | + private static volatile CountDownLatch countDownLatch; |
| 55 | + private static volatile boolean testResult; |
| 56 | + |
| 57 | + private static final String INSTRUCTIONS = "INSTRUCTIONS:\n\n" |
| 58 | + + "Verify selected text color is same as selected tree leaf icon color.\n " |
| 59 | + + "If the color is same ie, white\n" |
| 60 | + + "then press Pass otherwise press Fail."; |
| 61 | + |
| 62 | + public static void main(String args[]) throws Exception{ |
| 63 | + countDownLatch = new CountDownLatch(1); |
| 64 | + |
| 65 | + SwingUtilities.invokeAndWait(NimbusJTreeSelTextColor::createUI); |
| 66 | + countDownLatch.await(5, TimeUnit.MINUTES); |
| 67 | + |
| 68 | + if (!testResult) { |
| 69 | + throw new RuntimeException("Selected text color not same as selected tree leaf icon color!"); |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + private static void createUI() { |
| 74 | + try { |
| 75 | + UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); |
| 76 | + } catch (Exception e) { |
| 77 | + throw new RuntimeException(e); |
| 78 | + } |
| 79 | + |
| 80 | + JFrame mainFrame = new JFrame(); |
| 81 | + GridBagLayout layout = new GridBagLayout(); |
| 82 | + JPanel mainControlPanel = new JPanel(layout); |
| 83 | + JPanel resultButtonPanel = new JPanel(layout); |
| 84 | + |
| 85 | + GridBagConstraints gbc = new GridBagConstraints(); |
| 86 | + |
| 87 | + gbc.gridx = 0; |
| 88 | + gbc.gridy = 0; |
| 89 | + gbc.insets = new Insets(5, 15, 5, 15); |
| 90 | + gbc.fill = GridBagConstraints.HORIZONTAL; |
| 91 | + mainControlPanel.add(createComponent(), gbc); |
| 92 | + |
| 93 | + JTextArea instructionTextArea = new JTextArea(); |
| 94 | + instructionTextArea.setText(INSTRUCTIONS); |
| 95 | + instructionTextArea.setEditable(false); |
| 96 | + instructionTextArea.setBackground(Color.white); |
| 97 | + |
| 98 | + gbc.gridx = 0; |
| 99 | + gbc.gridy = 1; |
| 100 | + gbc.fill = GridBagConstraints.HORIZONTAL; |
| 101 | + mainControlPanel.add(instructionTextArea, gbc); |
| 102 | + |
| 103 | + JButton passButton = new JButton("Pass"); |
| 104 | + passButton.setActionCommand("Pass"); |
| 105 | + passButton.addActionListener((ActionEvent e) -> { |
| 106 | + testResult = true; |
| 107 | + mainFrame.dispose(); |
| 108 | + countDownLatch.countDown(); |
| 109 | + |
| 110 | + }); |
| 111 | + |
| 112 | + JButton failButton = new JButton("Fail"); |
| 113 | + failButton.setActionCommand("Fail"); |
| 114 | + failButton.addActionListener(new ActionListener() { |
| 115 | + @Override |
| 116 | + public void actionPerformed(ActionEvent e) { |
| 117 | + mainFrame.dispose(); |
| 118 | + countDownLatch.countDown(); |
| 119 | + } |
| 120 | + }); |
| 121 | + |
| 122 | + gbc.gridx = 0; |
| 123 | + gbc.gridy = 0; |
| 124 | + |
| 125 | + resultButtonPanel.add(passButton, gbc); |
| 126 | + gbc.gridx = 1; |
| 127 | + gbc.gridy = 0; |
| 128 | + resultButtonPanel.add(failButton, gbc); |
| 129 | + |
| 130 | + gbc.gridx = 0; |
| 131 | + gbc.gridy = 2; |
| 132 | + mainControlPanel.add(resultButtonPanel, gbc); |
| 133 | + |
| 134 | + mainFrame.add(mainControlPanel); |
| 135 | + mainFrame.pack(); |
| 136 | + |
| 137 | + mainFrame.addWindowListener(new WindowAdapter() { |
| 138 | + |
| 139 | + @Override |
| 140 | + public void windowClosing(WindowEvent e) { |
| 141 | + mainFrame.dispose(); |
| 142 | + countDownLatch.countDown(); |
| 143 | + } |
| 144 | + }); |
| 145 | + mainFrame.setLocationRelativeTo(null); |
| 146 | + mainFrame.setVisible(true); |
| 147 | + } |
| 148 | + |
| 149 | + private static JComponent createComponent() { |
| 150 | + tree = new JTree(); |
| 151 | + |
| 152 | + treeCellRenderer = new DefaultTreeCellRenderer(); |
| 153 | + tree.setRootVisible(true); |
| 154 | + tree.setShowsRootHandles(true); |
| 155 | + |
| 156 | + tree.setCellRenderer(treeCellRenderer); |
| 157 | + tree.setSelectionRow(1); |
| 158 | + return tree; |
| 159 | + } |
| 160 | +} |
| 161 | + |
0 commit comments