author | pbansal |
Mon, 30 Oct 2017 15:45:55 +0530 | |
changeset 47512 | fc3ec7e40a12 |
permissions | -rw-r--r-- |
47512
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
1 |
/* |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
2 |
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
4 |
* |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
8 |
* |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
13 |
* accompanied this code). |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
14 |
* |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
18 |
* |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
21 |
* questions. |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
22 |
*/ |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
23 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
24 |
/* |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
25 |
* @test |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
26 |
* @key headful |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
27 |
* @bug 8159062 |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
28 |
* @summary Tests DnD property with HIDPI scale set to non-interger value 2.5 |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
29 |
* @run main/othervm -Dsun.java2d.uiScale=2.5 DragTestWithHIDPI |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
30 |
*/ |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
31 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
32 |
import javax.swing.JList; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
33 |
import javax.swing.TransferHandler; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
34 |
import javax.swing.JFrame; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
35 |
import javax.swing.JComponent; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
36 |
import javax.swing.SwingUtilities; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
37 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
38 |
import java.awt.Robot; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
39 |
import java.awt.BorderLayout; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
40 |
import java.awt.Point; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
41 |
import java.awt.Dimension; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
42 |
import java.awt.MouseInfo; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
43 |
import java.awt.event.InputEvent; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
44 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
45 |
public class DragTestWithHIDPI extends TransferHandler { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
46 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
47 |
private static boolean didDrag = false; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
48 |
private static int threshold = 10; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
49 |
private static int DEFAULT_DELAY = 550; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
50 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
51 |
private Robot robot = null; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
52 |
private static JList list = null; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
53 |
private static Point listLocation = null; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
54 |
private static Dimension listSize = null; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
55 |
private static JFrame f = null; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
56 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
57 |
private enum Direction { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
58 |
RIGHT, LEFT, BOTTOM, TOP |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
59 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
60 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
61 |
public static void main(String[] args) throws Exception { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
62 |
DragTestWithHIDPI test = new DragTestWithHIDPI(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
63 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
64 |
// set the mouse move drag threshold |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
65 |
System.setProperty("awt.dnd.drag.threshold", String.valueOf(threshold)); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
66 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
67 |
test.createGUI(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
68 |
test.doTest(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
69 |
System.out.println("Test Passed"); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
70 |
test.disposeGUI(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
71 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
72 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
73 |
public void exportAsDrag(JComponent comp, InputEvent e, int action) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
74 |
didDrag = true; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
75 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
76 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
77 |
public DragTestWithHIDPI() { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
78 |
super("foreground"); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
79 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
80 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
81 |
private void createGUI() throws Exception{ |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
82 |
SwingUtilities.invokeAndWait(() -> { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
83 |
String[] listData = |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
84 |
new String[]{"Pacific Ocean", "Atlantic Ocean", "Indian Ocean", |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
85 |
"Arctic Ocean"}; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
86 |
list = new JList(listData); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
87 |
list.setDragEnabled(true); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
88 |
list.setTransferHandler(new DragTestWithHIDPI()); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
89 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
90 |
f = new JFrame("DragTestWithHIDPI"); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
91 |
f.getContentPane().add(list, BorderLayout.CENTER); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
92 |
f.pack(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
93 |
f.toFront(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
94 |
f.setVisible(true); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
95 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
96 |
listLocation = list.getLocationOnScreen(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
97 |
listSize = list.getSize(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
98 |
}); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
99 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
100 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
101 |
private void disposeGUI () throws Exception { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
102 |
SwingUtilities.invokeAndWait(() -> { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
103 |
f.dispose(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
104 |
}); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
105 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
106 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
107 |
private void doTest() throws Exception { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
108 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
109 |
robot = new Robot(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
110 |
robot.waitForIdle(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
111 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
112 |
for (Direction direction : Direction.values()) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
113 |
//Drag should not start only by moving (threshold - 1) pixels |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
114 |
didDrag = false; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
115 |
test(threshold - 1, direction); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
116 |
if (didDrag) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
117 |
disposeGUI(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
118 |
throw new RuntimeException( |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
119 |
"Shouldn't start drag until > " + threshold + |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
120 |
" pixels " + " while moving " + direction); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
121 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
122 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
123 |
// Drag should not start only by moving threshold pixels |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
124 |
didDrag = false; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
125 |
test(threshold, direction); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
126 |
if (didDrag) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
127 |
disposeGUI(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
128 |
throw new RuntimeException( |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
129 |
"Shouldn't start drag until > " + threshold + |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
130 |
" pixels" + " while moving " + direction); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
131 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
132 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
133 |
// Drag should start after moving threshold + 1 pixel |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
134 |
didDrag = false; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
135 |
test(threshold + 1, direction); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
136 |
if (!didDrag) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
137 |
disposeGUI(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
138 |
throw new RuntimeException( |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
139 |
"Should start drag after > " + threshold + " pixels" + |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
140 |
" while moving " + direction); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
141 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
142 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
143 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
144 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
145 |
private void test(int threshold, Direction direction) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
146 |
clickMouseOnList(InputEvent.BUTTON1_DOWN_MASK); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
147 |
Point p = MouseInfo.getPointerInfo().getLocation(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
148 |
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
149 |
robot.delay(DEFAULT_DELAY); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
150 |
glide(p, direction, threshold); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
151 |
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
152 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
153 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
154 |
private void glide(Point p, Direction direction, int toAdd) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
155 |
switch (direction) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
156 |
case RIGHT: |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
157 |
// move towards right |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
158 |
glide(p.x, p.y, p.x + toAdd, p.y); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
159 |
break; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
160 |
case LEFT: |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
161 |
// move towards left |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
162 |
glide(p.x, p.y, p.x - toAdd, p.y); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
163 |
break; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
164 |
case BOTTOM: |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
165 |
// move towards bottom |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
166 |
glide(p.x, p.y, p.x, p.y + toAdd); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
167 |
break; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
168 |
case TOP: |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
169 |
// move towards top |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
170 |
glide(p.x, p.y, p.x, p.y - toAdd); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
171 |
break; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
172 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
173 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
174 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
175 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
176 |
/* |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
177 |
Some utilities functions from JRobot class. |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
178 |
*/ |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
179 |
private void moveMouseToList() { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
180 |
int x = listLocation.x + listSize.width/2; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
181 |
int y = listLocation.y + listSize.height/2; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
182 |
robot.mouseMove(x, y); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
183 |
robot.delay(DEFAULT_DELAY); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
184 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
185 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
186 |
private void clickMouse(int buttons) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
187 |
robot.mousePress(buttons); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
188 |
robot.mouseRelease(buttons); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
189 |
robot.delay(DEFAULT_DELAY); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
190 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
191 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
192 |
private void clickMouseOnList(int buttons) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
193 |
moveMouseToList(); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
194 |
clickMouse(buttons); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
195 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
196 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
197 |
private void glide(int x0, int y0, int x1, int y1) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
198 |
float dmax = (float)Math.max(Math.abs(x1 - x0), Math.abs(y1 - y0)); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
199 |
float dx = (x1 - x0) / dmax; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
200 |
float dy = (y1 - y0) / dmax; |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
201 |
|
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
202 |
robot.mouseMove(x0, y0); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
203 |
for (int i=1; i<=dmax; i++) { |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
204 |
robot.mouseMove((int)(x0 + dx*i), (int)(y0 + dy*i)); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
205 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
206 |
robot.delay(DEFAULT_DELAY); |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
207 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
208 |
} |
fc3ec7e40a12
8159062: [hidpi] DnD on Windows while scaling is non-integer
pbansal
parents:
diff
changeset
|
209 |