|
| 1 | +/* |
| 2 | + * Copyright (c) 2002, 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 4546134 |
| 27 | + * @summary Tests that JList shows the right drop location when it has multiple columns. |
| 28 | + * @library /java/awt/regtesthelpers |
| 29 | + * @build PassFailJFrame |
| 30 | + * @run main/manual ListDragOverFeedbackTest |
| 31 | + */ |
| 32 | + |
| 33 | +import java.awt.BorderLayout; |
| 34 | +import java.awt.Color; |
| 35 | +import java.awt.Dimension; |
| 36 | +import java.awt.GridLayout; |
| 37 | +import java.awt.datatransfer.DataFlavor; |
| 38 | +import java.awt.event.MouseAdapter; |
| 39 | +import java.awt.event.MouseEvent; |
| 40 | +import javax.swing.BorderFactory; |
| 41 | +import javax.swing.JComponent; |
| 42 | +import javax.swing.JFrame; |
| 43 | +import javax.swing.JLabel; |
| 44 | +import javax.swing.JList; |
| 45 | +import javax.swing.JPanel; |
| 46 | +import javax.swing.TransferHandler; |
| 47 | + |
| 48 | +public class ListDragOverFeedbackTest { |
| 49 | + private static final String INSTRUCTIONS = """ |
| 50 | + JList should provide visual feedback when a DnD drag operation is |
| 51 | + occurring over it. This test is to check that it provides the |
| 52 | + feedback about the drop location correctly. |
| 53 | +
|
| 54 | + Click on the label where it says "DRAG FROM HERE" and begin dragging. |
| 55 | + Drag over each column in each of the three JLists and make sure that |
| 56 | + the drop location indicated is appropriate for the mouse location. For |
| 57 | + instance, if the mouse is in the first column, the drop location should |
| 58 | + also be indicated in that first column. |
| 59 | +
|
| 60 | + If above is true press PASS else press FAIL. |
| 61 | + """; |
| 62 | + |
| 63 | + public static void main(String[] args) throws Exception { |
| 64 | + PassFailJFrame.builder() |
| 65 | + .instructions(INSTRUCTIONS) |
| 66 | + .columns(50) |
| 67 | + .testUI(ListDragOverFeedbackTest::createTestUI) |
| 68 | + .build() |
| 69 | + .awaitAndCheck(); |
| 70 | + } |
| 71 | + |
| 72 | + private static final TransferHandler handler = new TransferHandler() { |
| 73 | + public boolean canImport(JComponent comp, DataFlavor[] flavors) { |
| 74 | + return true; |
| 75 | + } |
| 76 | + }; |
| 77 | + |
| 78 | + private static JFrame createTestUI() { |
| 79 | + String[] vals = new String[] { |
| 80 | + "one", "two", "three", "four", "five", "six", "seven", "eight", |
| 81 | + "nine", "ten", "eleven", "twelve", "thirteen", "fourteen"}; |
| 82 | + |
| 83 | + JFrame frame = new JFrame("ListDragOverFeedbackTest"); |
| 84 | + final JLabel label = new JLabel("DRAG FROM HERE"); |
| 85 | + label.setPreferredSize(new Dimension(400, 25)); |
| 86 | + label.setTransferHandler(new TransferHandler("text")); |
| 87 | + label.addMouseListener(new MouseAdapter() { |
| 88 | + public void mousePressed(MouseEvent me) { |
| 89 | + label.getTransferHandler().exportAsDrag(label, me, |
| 90 | + TransferHandler.COPY); |
| 91 | + } |
| 92 | + }); |
| 93 | + |
| 94 | + JList list1 = new JList(vals); |
| 95 | + list1.setTransferHandler(handler); |
| 96 | + list1.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
| 97 | + |
| 98 | + JList list2 = new JList(vals); |
| 99 | + list2.setLayoutOrientation(JList.VERTICAL_WRAP); |
| 100 | + list2.setTransferHandler(handler); |
| 101 | + list2.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
| 102 | + |
| 103 | + JList list3 = new JList(vals); |
| 104 | + list3.setLayoutOrientation(JList.HORIZONTAL_WRAP); |
| 105 | + list3.setTransferHandler(handler); |
| 106 | + list3.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
| 107 | + |
| 108 | + JPanel wrapper = new JPanel(); |
| 109 | + wrapper.setLayout(new GridLayout(3, 1)); |
| 110 | + wrapper.add(list1); |
| 111 | + wrapper.add(list2); |
| 112 | + wrapper.add(list3); |
| 113 | + |
| 114 | + frame.add(label, BorderLayout.NORTH); |
| 115 | + frame.add(wrapper); |
| 116 | + frame.setSize(400, 500); |
| 117 | + return frame; |
| 118 | + } |
| 119 | +} |
0 commit comments