|
1 | 1 | /* |
2 | | - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2009, 2024, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
21 | 21 | * questions. |
22 | 22 | */ |
23 | 23 |
|
24 | | -/* |
25 | | - test %W% %E% |
26 | | - @bug 4874070 |
27 | | - @summary Tests basic DnD functionality |
28 | | - @author Your Name: Alexey Utkin area=dnd |
29 | | - @run applet/manual=yesno ImageDecoratedDnD.html |
30 | | -*/ |
31 | | - |
32 | | -import java.applet.Applet; |
33 | | -import java.awt.*; |
| 24 | +import java.awt.BorderLayout; |
| 25 | +import java.awt.Color; |
| 26 | +import java.awt.Component; |
| 27 | +import java.awt.Frame; |
| 28 | +import java.awt.Panel; |
34 | 29 | import java.awt.dnd.DragSource; |
35 | 30 |
|
| 31 | +/* |
| 32 | + * @test |
| 33 | + * @bug 4874070 |
| 34 | + * @summary Tests CTRL + DnD functionality |
| 35 | + * @library /java/awt/regtesthelpers |
| 36 | + * @build PassFailJFrame |
| 37 | + * @run main/manual ImageDecoratedDnD |
| 38 | + */ |
36 | 39 |
|
| 40 | +public class ImageDecoratedDnD { |
| 41 | + private static final String INSTRUCTIONS = """ |
| 42 | + When test runs a Frame which contains a yellow button labeled |
| 43 | + "Drag ME!" and a RED Panel will appear. |
| 44 | +
|
| 45 | + 1. Click on the button and drag it to the red panel while holding |
| 46 | + the "CTRL" key on the keyboard. |
| 47 | +
|
| 48 | + 2. When the mouse enters the red panel during the drag, the panel |
| 49 | + should turn yellow. |
| 50 | +
|
| 51 | + On systems that supports pictured drag, the image under the |
| 52 | + drag-cursor should appear. |
| 53 | + "Image under drag-cursor" is a translucent blue rectangle + red |
| 54 | + circle and includes an anchor that is shifted from top-left |
| 55 | + corner of the picture to inside the picture to 10pt |
| 56 | + in both dimensions. |
| 57 | +
|
| 58 | + On Windows, the image under the cursor would be visible ONLY over |
| 59 | + drop targets with activated extended D'n'D support. |
| 60 | + It means the image may not be displayed when dragging over some |
| 61 | + windows, this is not an error. |
| 62 | + The image should be displayed when dragging over the red/yellow panel. |
| 63 | +
|
| 64 | + 3. Release the mouse button. |
| 65 | +
|
| 66 | + The panel should turn red again and a yellow button labeled |
| 67 | + "Drag ME!" should appear inside the panel. You should be able |
| 68 | + to repeat this operation multiple times. |
| 69 | +
|
| 70 | + If above is true press PASS, else press FAIL. |
| 71 | + """; |
| 72 | + |
| 73 | + public static void main(String[] args) throws Exception { |
| 74 | + PassFailJFrame.builder() |
| 75 | + .title("Test Instructions") |
| 76 | + .instructions(INSTRUCTIONS) |
| 77 | + .rows((int) INSTRUCTIONS.lines().count() + 2) |
| 78 | + .columns(38) |
| 79 | + .testUI(ImageDecoratedDnD::createUI) |
| 80 | + .build() |
| 81 | + .awaitAndCheck(); |
| 82 | + } |
37 | 83 |
|
38 | | -public class ImageDecoratedDnD extends Applet { |
39 | | - //Declare things used in the test, like buttons and labels here |
40 | | - |
41 | | - public void init() { |
42 | | - //Create instructions for the user here, as well as set up |
43 | | - // the environment -- set the layout manager, add buttons, |
44 | | - // etc. |
45 | | - this.setLayout(new BorderLayout()); |
46 | | - |
47 | | - String[] instructions = |
48 | | - { |
49 | | - "A Frame, which contains a yellow button labeled \"Drag ME!\" and ", |
50 | | - "a red panel, will appear below. ", |
51 | | - "1. Click on the button and drag to the red panel. ", |
52 | | - "2. When the mouse enters the red panel during the drag, the panel ", |
53 | | - "should turn yellow. On the systems that supports pictured drag, ", |
54 | | - "the image under the drag-cursor should appear (ancor is shifted ", |
55 | | - "from top-left corner of the picture inside the picture to 10pt in both dimensions ). ", |
56 | | - "In WIN32 systems the image under cursor would be visible ONLY over ", |
57 | | - "the drop targets with activated extended OLE D\'n\'D support (that are ", |
58 | | - "the desktop and IE ).", |
59 | | - "3. Release the mouse button.", |
60 | | - "The panel should turn red again and a yellow button labeled ", |
61 | | - "\"Drag ME!\" should appear inside the panel. You should be able ", |
62 | | - "to repeat this operation multiple times." |
63 | | - }; |
64 | | - Sysout.createDialogWithInstructions(instructions); |
65 | | - |
66 | | - }//End init() |
67 | | - |
68 | | - public void start() { |
69 | | - Frame f = new Frame("Use keyboard for DnD change"); |
| 84 | + public static Frame createUI() { |
| 85 | + Frame frame = new Frame("Ctrl + Drag - Image DnD test"); |
70 | 86 | Panel mainPanel; |
71 | 87 | Component dragSource, dropTarget; |
72 | 88 |
|
73 | | - f.setBounds(0, 400, 200, 200); |
74 | | - f.setLayout(new BorderLayout()); |
| 89 | + frame.setSize(400, 400); |
| 90 | + frame.setLayout(new BorderLayout()); |
75 | 91 |
|
76 | 92 | mainPanel = new Panel(); |
77 | 93 | mainPanel.setLayout(new BorderLayout()); |
78 | 94 |
|
79 | | - mainPanel.setBackground(Color.blue); |
| 95 | + mainPanel.setBackground(Color.BLUE); |
80 | 96 |
|
81 | | - dropTarget = new DnDTarget(Color.red, Color.yellow); |
82 | | - dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" ); |
| 97 | + dropTarget = new DnDTarget(Color.RED, Color.YELLOW); |
| 98 | + dragSource = new DnDSource("Drag ME! (" |
| 99 | + + (DragSource.isDragImageSupported() ? "with " : "without") + " image)"); |
83 | 100 |
|
84 | 101 | mainPanel.add(dragSource, "North"); |
85 | 102 | mainPanel.add(dropTarget, "Center"); |
86 | | - f.add(mainPanel, BorderLayout.CENTER); |
87 | | - |
88 | | - f.setVisible(true); |
89 | | - }// start() |
90 | | -}// class DnDAcceptanceTest |
91 | | - |
92 | | - |
93 | | -/** |
94 | | - * ************************************************* |
95 | | - * Standard Test Machinery |
96 | | - * DO NOT modify anything below -- it's a standard |
97 | | - * chunk of code whose purpose is to make user |
98 | | - * interaction uniform, and thereby make it simpler |
99 | | - * to read and understand someone else's test. |
100 | | - * ************************************************** |
101 | | - */ |
102 | | -class Sysout { |
103 | | - private static TestDialog dialog; |
104 | | - |
105 | | - public static void createDialogWithInstructions(String[] instructions) { |
106 | | - dialog = new TestDialog(new Frame(), "Instructions"); |
107 | | - dialog.printInstructions(instructions); |
108 | | - dialog.show(); |
109 | | - println("Any messages for the tester will display here."); |
110 | | - } |
111 | | - |
112 | | - public static void createDialog() { |
113 | | - dialog = new TestDialog(new Frame(), "Instructions"); |
114 | | - String[] defInstr = {"Instructions will appear here. ", ""}; |
115 | | - dialog.printInstructions(defInstr); |
116 | | - dialog.show(); |
117 | | - println("Any messages for the tester will display here."); |
| 103 | + frame.add(mainPanel, BorderLayout.CENTER); |
| 104 | + frame.setAlwaysOnTop(true); |
| 105 | + return frame; |
118 | 106 | } |
119 | | - |
120 | | - |
121 | | - public static void printInstructions(String[] instructions) { |
122 | | - dialog.printInstructions(instructions); |
123 | | - } |
124 | | - |
125 | | - |
126 | | - public static void println(String messageIn) { |
127 | | - dialog.displayMessage(messageIn); |
128 | | - } |
129 | | - |
130 | | -}// Sysout class |
131 | | - |
132 | | - |
133 | | -class TestDialog extends Dialog { |
134 | | - |
135 | | - TextArea instructionsText; |
136 | | - TextArea messageText; |
137 | | - int maxStringLength = 80; |
138 | | - |
139 | | - //DO NOT call this directly, go through Sysout |
140 | | - public TestDialog(Frame frame, String name) { |
141 | | - super(frame, name); |
142 | | - int scrollBoth = TextArea.SCROLLBARS_BOTH; |
143 | | - instructionsText = new TextArea("", 15, maxStringLength, scrollBoth); |
144 | | - add("North", instructionsText); |
145 | | - |
146 | | - messageText = new TextArea("", 5, maxStringLength, scrollBoth); |
147 | | - add("South", messageText); |
148 | | - |
149 | | - pack(); |
150 | | - |
151 | | - show(); |
152 | | - }// TestDialog() |
153 | | - |
154 | | - //DO NOT call this directly, go through Sysout |
155 | | - public void printInstructions(String[] instructions) { |
156 | | - //Clear out any current instructions |
157 | | - instructionsText.setText(""); |
158 | | - |
159 | | - //Go down array of instruction strings |
160 | | - |
161 | | - String printStr, remainingStr; |
162 | | - for (int i = 0; i < instructions.length; i++) { |
163 | | - //chop up each into pieces maxSringLength long |
164 | | - remainingStr = instructions[i]; |
165 | | - while (remainingStr.length() > 0) { |
166 | | - //if longer than max then chop off first max chars to print |
167 | | - if (remainingStr.length() >= maxStringLength) { |
168 | | - //Try to chop on a word boundary |
169 | | - int posOfSpace = remainingStr. |
170 | | - lastIndexOf(' ', maxStringLength - 1); |
171 | | - |
172 | | - if (posOfSpace <= 0) posOfSpace = maxStringLength - 1; |
173 | | - |
174 | | - printStr = remainingStr.substring(0, posOfSpace + 1); |
175 | | - remainingStr = remainingStr.substring(posOfSpace + 1); |
176 | | - } |
177 | | - //else just print |
178 | | - else { |
179 | | - printStr = remainingStr; |
180 | | - remainingStr = ""; |
181 | | - } |
182 | | - |
183 | | - instructionsText.append(printStr + "\n"); |
184 | | - |
185 | | - }// while |
186 | | - |
187 | | - }// for |
188 | | - |
189 | | - }//printInstructions() |
190 | | - |
191 | | - //DO NOT call this directly, go through Sysout |
192 | | - public void displayMessage(String messageIn) { |
193 | | - messageText.append(messageIn + "\n"); |
194 | | - } |
195 | | - |
196 | | -}// TestDialog class |
197 | | - |
| 107 | +} |
0 commit comments