|
| 1 | +/* |
| 2 | + * Copyright (c) 1999, 2025, 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 | +/* |
| 25 | + * @test |
| 26 | + * @bug 4118860 |
| 27 | + * @summary setToggleClickCount/getToggleClickCount have been added. |
| 28 | + * @library /java/awt/regtesthelpers |
| 29 | + * @build PassFailJFrame |
| 30 | + * @run main/manual bug4118860 |
| 31 | + */ |
| 32 | + |
| 33 | +import java.awt.BorderLayout; |
| 34 | +import java.awt.Color; |
| 35 | +import java.awt.GridLayout; |
| 36 | + |
| 37 | +import javax.swing.JButton; |
| 38 | +import javax.swing.JFrame; |
| 39 | +import javax.swing.JPanel; |
| 40 | +import javax.swing.JTree; |
| 41 | + |
| 42 | +public class bug4118860 { |
| 43 | + static final String INSTRUCTIONS = """ |
| 44 | + Push the "Single Click" button and try expanding/contracting |
| 45 | + branch nodes of the tree with one left mouse button click |
| 46 | + on the label part of the node (not the icon or handles). |
| 47 | +
|
| 48 | + Then push the "Double Click" button and try doing the same using |
| 49 | + left mouse button double click. Single click shouldn't cause |
| 50 | + expanding/contracting. A double click should now be required |
| 51 | + to expand/contract nodes. |
| 52 | +
|
| 53 | + If it works then the test PASSES, else the test FAILS. |
| 54 | + """; |
| 55 | + |
| 56 | + public static void main(String[] args) throws Exception { |
| 57 | + PassFailJFrame.builder() |
| 58 | + .title("bug4118860 Test Instructions") |
| 59 | + .instructions(INSTRUCTIONS) |
| 60 | + .columns(40) |
| 61 | + .testUI(bug4118860::createUI) |
| 62 | + .build() |
| 63 | + .awaitAndCheck(); |
| 64 | + } |
| 65 | + |
| 66 | + static JFrame createUI() { |
| 67 | + JFrame f = new JFrame("ToggleClickCount Test"); |
| 68 | + JTree tr = new JTree(); |
| 69 | + JPanel p = new JPanel(); |
| 70 | + p.setBackground(Color.red); |
| 71 | + p.setLayout(new GridLayout(1, 1)); |
| 72 | + tr.setOpaque(false); |
| 73 | + p.add(tr); |
| 74 | + f.add(p, BorderLayout.CENTER); |
| 75 | + JPanel bp = new JPanel(); |
| 76 | + JButton bt1 = new JButton("Single Click"); |
| 77 | + bt1.addActionListener(e -> { |
| 78 | + tr.setToggleClickCount(1); |
| 79 | + if (tr.getToggleClickCount() != 1) { |
| 80 | + throw new RuntimeException("ToggleClickCount doesn't set..."); |
| 81 | + } |
| 82 | + }); |
| 83 | + JButton bt2 = new JButton("Double Click"); |
| 84 | + bt2.addActionListener(e -> { |
| 85 | + tr.setToggleClickCount(2); |
| 86 | + if (tr.getToggleClickCount() != 2) { |
| 87 | + throw new RuntimeException("ToggleClickCount doesn't set..."); |
| 88 | + } |
| 89 | + }); |
| 90 | + bp.setLayout(new GridLayout(1, 2)); |
| 91 | + bp.add(bt1); |
| 92 | + bp.add(bt2); |
| 93 | + f.add(bp, BorderLayout.SOUTH); |
| 94 | + f.setSize(300, 200); |
| 95 | + return f; |
| 96 | + } |
| 97 | +} |
0 commit comments