8340713: Open source DnD tests - Set5
Reviewed-by: azvegint, dnguyen
This commit is contained in:
parent
f7bb647dc8
commit
fc7244da96
@ -128,6 +128,8 @@ java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion.java 8060176
|
|||||||
java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion_1.java 8060176 windows-all,macosx-all
|
java/awt/event/MouseWheelEvent/InfiniteRecursion/InfiniteRecursion_1.java 8060176 windows-all,macosx-all
|
||||||
java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.java 8171510 macosx-all
|
java/awt/dnd/URIListBetweenJVMsTest/URIListBetweenJVMsTest.java 8171510 macosx-all
|
||||||
java/awt/dnd/MissingDragExitEventTest/MissingDragExitEventTest.java 8288839 windows-x64
|
java/awt/dnd/MissingDragExitEventTest/MissingDragExitEventTest.java 8288839 windows-x64
|
||||||
|
java/awt/dnd/DragExitBeforeDropTest.java 8242805 macosx-all
|
||||||
|
java/awt/dnd/DragThresholdTest.java 8076299 macosx-all
|
||||||
java/awt/Focus/ChoiceFocus/ChoiceFocus.java 8169103 windows-all,macosx-all
|
java/awt/Focus/ChoiceFocus/ChoiceFocus.java 8169103 windows-all,macosx-all
|
||||||
java/awt/Focus/ClearLwQueueBreakTest/ClearLwQueueBreakTest.java 8198618 macosx-all
|
java/awt/Focus/ClearLwQueueBreakTest/ClearLwQueueBreakTest.java 8198618 macosx-all
|
||||||
java/awt/Focus/ConsumeNextKeyTypedOnModalShowTest/ConsumeNextKeyTypedOnModalShowTest.java 6986252 macosx-all
|
java/awt/Focus/ConsumeNextKeyTypedOnModalShowTest/ConsumeNextKeyTypedOnModalShowTest.java 6986252 macosx-all
|
||||||
@ -806,3 +808,4 @@ java/awt/List/HandlingKeyEventIfMousePressedTest.java 6848358 macosx-all,windows
|
|||||||
java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all
|
java/awt/Checkbox/CheckboxBoxSizeTest.java 8340870 windows-all
|
||||||
java/awt/Checkbox/CheckboxIndicatorSizeTest.java 8340870 windows-all
|
java/awt/Checkbox/CheckboxIndicatorSizeTest.java 8340870 windows-all
|
||||||
java/awt/Checkbox/CheckboxNullLabelTest.java 8340870 windows-all
|
java/awt/Checkbox/CheckboxNullLabelTest.java 8340870 windows-all
|
||||||
|
java/awt/dnd/WinMoveFileToShellTest.java 8341665 windows-all
|
||||||
|
257
test/jdk/java/awt/dnd/DragExitBeforeDropTest.java
Normal file
257
test/jdk/java/awt/dnd/DragExitBeforeDropTest.java
Normal file
@ -0,0 +1,257 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.awt.Button;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.Panel;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
import java.awt.dnd.DnDConstants;
|
||||||
|
import java.awt.dnd.DragGestureEvent;
|
||||||
|
import java.awt.dnd.DragGestureListener;
|
||||||
|
import java.awt.dnd.DragSource;
|
||||||
|
import java.awt.dnd.DragSourceDragEvent;
|
||||||
|
import java.awt.dnd.DragSourceDropEvent;
|
||||||
|
import java.awt.dnd.DragSourceEvent;
|
||||||
|
import java.awt.dnd.DragSourceListener;
|
||||||
|
import java.awt.dnd.DropTarget;
|
||||||
|
import java.awt.dnd.DropTargetContext;
|
||||||
|
import java.awt.dnd.DropTargetDragEvent;
|
||||||
|
import java.awt.dnd.DropTargetDropEvent;
|
||||||
|
import java.awt.dnd.DropTargetEvent;
|
||||||
|
import java.awt.dnd.DropTargetListener;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 4395290
|
||||||
|
* @key headful
|
||||||
|
* @summary tests that dragExit() is not called before drop()
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DragExitBeforeDropTest {
|
||||||
|
private static Frame frame;
|
||||||
|
private static final DragSourceButton dragSourceButton = new DragSourceButton();
|
||||||
|
private static final DropTargetPanel dropTargetPanel = new DropTargetPanel();
|
||||||
|
private static volatile Point srcPoint;
|
||||||
|
private static volatile Point dstPoint;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
try {
|
||||||
|
Robot robot = new Robot();
|
||||||
|
EventQueue.invokeAndWait(DragExitBeforeDropTest::createAndShowUI);
|
||||||
|
robot.waitForIdle();
|
||||||
|
robot.delay(1000);
|
||||||
|
|
||||||
|
EventQueue.invokeAndWait(() -> {
|
||||||
|
Point p = dragSourceButton.getLocationOnScreen();
|
||||||
|
Dimension d = dragSourceButton.getSize();
|
||||||
|
p.translate(d.width / 2, d.height / 2);
|
||||||
|
srcPoint = p;
|
||||||
|
|
||||||
|
p = dropTargetPanel.getLocationOnScreen();
|
||||||
|
d = dropTargetPanel.getSize();
|
||||||
|
p.translate(d.width / 2, d.height / 2);
|
||||||
|
dstPoint = p;
|
||||||
|
});
|
||||||
|
|
||||||
|
robot.mouseMove(srcPoint.x, srcPoint.y);
|
||||||
|
robot.keyPress(KeyEvent.VK_CONTROL);
|
||||||
|
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||||
|
for (; !srcPoint.equals(dstPoint);
|
||||||
|
srcPoint.translate(sign(dstPoint.x - srcPoint.x),
|
||||||
|
sign(dstPoint.y - srcPoint.y))) {
|
||||||
|
robot.mouseMove(srcPoint.x, srcPoint.y);
|
||||||
|
robot.delay(10);
|
||||||
|
}
|
||||||
|
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||||
|
robot.keyRelease(KeyEvent.VK_CONTROL);
|
||||||
|
robot.waitForIdle();
|
||||||
|
robot.delay(1000);
|
||||||
|
|
||||||
|
if (!dropTargetPanel.getStatus()) {
|
||||||
|
throw new RuntimeException("The test failed: dragExit()"
|
||||||
|
+ " is called before drop()");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
EventQueue.invokeAndWait(() -> {
|
||||||
|
if (frame != null) {
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createAndShowUI() {
|
||||||
|
frame = new Frame("DragExitBeforeDropTest");
|
||||||
|
frame.setLayout(new GridLayout(2, 1));
|
||||||
|
frame.add(dragSourceButton);
|
||||||
|
frame.add(dropTargetPanel);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
frame.setSize(300, 400);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int sign(int n) {
|
||||||
|
return Integer.compare(n, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DragSourceButton extends Button implements Serializable,
|
||||||
|
Transferable,
|
||||||
|
DragGestureListener,
|
||||||
|
DragSourceListener {
|
||||||
|
private final DataFlavor dataflavor =
|
||||||
|
new DataFlavor(Button.class, "DragSourceButton");
|
||||||
|
|
||||||
|
public DragSourceButton() {
|
||||||
|
this("DragSourceButton");
|
||||||
|
}
|
||||||
|
|
||||||
|
public DragSourceButton(String str) {
|
||||||
|
super(str);
|
||||||
|
|
||||||
|
DragSource ds = DragSource.getDefaultDragSource();
|
||||||
|
ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY,
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragGestureRecognized(DragGestureEvent dge) {
|
||||||
|
dge.startDrag(null, this, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragEnter(DragSourceDragEvent dsde) {}
|
||||||
|
|
||||||
|
public void dragExit(DragSourceEvent dse) {}
|
||||||
|
|
||||||
|
public void dragOver(DragSourceDragEvent dsde) {}
|
||||||
|
|
||||||
|
public void dragDropEnd(DragSourceDropEvent dsde) {}
|
||||||
|
|
||||||
|
public void dropActionChanged(DragSourceDragEvent dsde) {}
|
||||||
|
|
||||||
|
public Object getTransferData(DataFlavor flavor)
|
||||||
|
throws UnsupportedFlavorException, IOException {
|
||||||
|
|
||||||
|
if (!isDataFlavorSupported(flavor)) {
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object retObj;
|
||||||
|
|
||||||
|
ByteArrayOutputStream baoStream = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream ooStream = new ObjectOutputStream(baoStream);
|
||||||
|
ooStream.writeObject(this);
|
||||||
|
|
||||||
|
ByteArrayInputStream baiStream =
|
||||||
|
new ByteArrayInputStream(baoStream.toByteArray());
|
||||||
|
ObjectInputStream ois = new ObjectInputStream(baiStream);
|
||||||
|
try {
|
||||||
|
retObj = ois.readObject();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException(e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return retObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return new DataFlavor[] { dataflavor };
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor dflavor) {
|
||||||
|
return dataflavor.equals(dflavor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class DropTargetPanel extends Panel implements DropTargetListener {
|
||||||
|
|
||||||
|
final Dimension preferredDimension = new Dimension(200, 100);
|
||||||
|
volatile boolean testPassed = true;
|
||||||
|
|
||||||
|
public DropTargetPanel() {
|
||||||
|
setDropTarget(new DropTarget(this, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getStatus() {
|
||||||
|
return testPassed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dimension getPreferredSize() {
|
||||||
|
return preferredDimension;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragEnter(DropTargetDragEvent dtde) {}
|
||||||
|
|
||||||
|
public void dragExit(DropTargetEvent dte) {
|
||||||
|
testPassed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dragOver(DropTargetDragEvent dtde) {}
|
||||||
|
|
||||||
|
public void dropActionChanged(DropTargetDragEvent dtde) {}
|
||||||
|
|
||||||
|
public void drop(DropTargetDropEvent dtde) {
|
||||||
|
DropTargetContext dtc = dtde.getDropTargetContext();
|
||||||
|
|
||||||
|
if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY) != 0) {
|
||||||
|
dtde.acceptDrop(DnDConstants.ACTION_COPY);
|
||||||
|
} else {
|
||||||
|
dtde.rejectDrop();
|
||||||
|
}
|
||||||
|
|
||||||
|
DataFlavor[] dfs = dtde.getCurrentDataFlavors();
|
||||||
|
Component comp = null;
|
||||||
|
|
||||||
|
if(dfs != null && dfs.length >= 1) {
|
||||||
|
Transferable transfer = dtde.getTransferable();
|
||||||
|
|
||||||
|
try {
|
||||||
|
comp = (Component)transfer.getTransferData(dfs[0]);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
dtc.dropComplete(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dtc.dropComplete(true);
|
||||||
|
add(comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
134
test/jdk/java/awt/dnd/DragThresholdTest.java
Normal file
134
test/jdk/java/awt/dnd/DragThresholdTest.java
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.awt.EventQueue;
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.Panel;
|
||||||
|
import java.awt.Point;
|
||||||
|
import java.awt.Robot;
|
||||||
|
import java.awt.dnd.DnDConstants;
|
||||||
|
import java.awt.dnd.DragGestureListener;
|
||||||
|
import java.awt.dnd.DragSource;
|
||||||
|
import java.awt.event.InputEvent;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseMotionAdapter;
|
||||||
|
|
||||||
|
/*
|
||||||
|
@test
|
||||||
|
@key headful
|
||||||
|
@bug 4415175
|
||||||
|
@summary tests DragSource.getDragThreshold() and
|
||||||
|
that the AWT default drag gesture recognizers
|
||||||
|
honor the drag gesture motion threshold
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DragThresholdTest {
|
||||||
|
private static Frame frame;
|
||||||
|
private static Panel panel;
|
||||||
|
private static MouseEvent lastMouseEvent;
|
||||||
|
private static volatile boolean failed;
|
||||||
|
private static volatile Point startPoint;
|
||||||
|
private static volatile Point endPoint;
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
try {
|
||||||
|
Robot robot = new Robot();
|
||||||
|
|
||||||
|
EventQueue.invokeAndWait(DragThresholdTest::createAndShowDnD);
|
||||||
|
robot.waitForIdle();
|
||||||
|
robot.delay(1000);
|
||||||
|
|
||||||
|
EventQueue.invokeAndWait(() -> {
|
||||||
|
Point p = panel.getLocationOnScreen();
|
||||||
|
p.translate(50, 50);
|
||||||
|
startPoint = p;
|
||||||
|
endPoint = new Point(p.x + 2 * DragSource.getDragThreshold(),
|
||||||
|
p.y + 2 * DragSource.getDragThreshold());
|
||||||
|
});
|
||||||
|
|
||||||
|
robot.mouseMove(startPoint.x, startPoint.y);
|
||||||
|
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||||
|
for (Point p = new Point(startPoint); !p.equals(endPoint);
|
||||||
|
p.translate(sign(endPoint.x - p.x),
|
||||||
|
sign(endPoint.y - p.y))) {
|
||||||
|
robot.mouseMove(p.x, p.y);
|
||||||
|
robot.delay(100);
|
||||||
|
}
|
||||||
|
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||||
|
robot.waitForIdle();
|
||||||
|
robot.delay(200);
|
||||||
|
|
||||||
|
if (failed) {
|
||||||
|
throw new RuntimeException("drag gesture recognized too early");
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
EventQueue.invokeAndWait(() -> {
|
||||||
|
if (frame != null) {
|
||||||
|
frame.dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createAndShowDnD() {
|
||||||
|
frame = new Frame("DragThresholdTest");
|
||||||
|
panel = new Panel();
|
||||||
|
// Mouse motion listener mml is added to the panel first.
|
||||||
|
// We rely on it that this listener will be called first.
|
||||||
|
panel.addMouseMotionListener(new MouseMotionAdapter() {
|
||||||
|
public void mouseDragged(MouseEvent evt) {
|
||||||
|
lastMouseEvent = evt;
|
||||||
|
System.out.println(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
frame.add(panel);
|
||||||
|
frame.setSize(200, 200);
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
DragGestureListener dgl = dge -> {
|
||||||
|
Point dragOrigin = dge.getDragOrigin();
|
||||||
|
int diffx = Math.abs(dragOrigin.x - lastMouseEvent.getX());
|
||||||
|
int diffy = Math.abs(dragOrigin.y - lastMouseEvent.getY());
|
||||||
|
System.out.println("dragGestureRecognized(): " +
|
||||||
|
" diffx=" + diffx + " diffy=" + diffy +
|
||||||
|
" DragSource.getDragThreshold()="
|
||||||
|
+ DragSource.getDragThreshold());
|
||||||
|
if (diffx <= DragSource.getDragThreshold() &&
|
||||||
|
diffy <= DragSource.getDragThreshold()) {
|
||||||
|
failed = true;
|
||||||
|
System.out.println("drag gesture recognized too early!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Default drag gesture recognizer is a mouse motion listener.
|
||||||
|
// It is added to the panel second.
|
||||||
|
new DragSource().createDefaultDragGestureRecognizer(
|
||||||
|
panel,
|
||||||
|
DnDConstants.ACTION_COPY_OR_MOVE, dgl);
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int sign(int n) {
|
||||||
|
return Integer.compare(n, 0);
|
||||||
|
}
|
||||||
|
}
|
131
test/jdk/java/awt/dnd/WinMoveFileToShellTest.java
Normal file
131
test/jdk/java/awt/dnd/WinMoveFileToShellTest.java
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.awt.Frame;
|
||||||
|
import java.awt.datatransfer.DataFlavor;
|
||||||
|
import java.awt.datatransfer.Transferable;
|
||||||
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
import java.awt.dnd.DnDConstants;
|
||||||
|
import java.awt.dnd.DragGestureListener;
|
||||||
|
import java.awt.dnd.DragSource;
|
||||||
|
import java.awt.dnd.DragSourceAdapter;
|
||||||
|
import java.awt.dnd.DragSourceDropEvent;
|
||||||
|
import java.awt.dnd.DragSourceListener;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @bug 4414739
|
||||||
|
* @requires (os.family == "windows")
|
||||||
|
* @summary verifies that getDropSuccess() returns correct value for moving
|
||||||
|
a file from a Java drag source to the Windows shell
|
||||||
|
* @library /java/awt/regtesthelpers
|
||||||
|
* @build PassFailJFrame
|
||||||
|
* @run main/manual WinMoveFileToShellTest
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class WinMoveFileToShellTest {
|
||||||
|
private static final String INSTRUCTIONS = """
|
||||||
|
Drag from the frame titled "Drag Frame" and drop on to Windows Desktop.
|
||||||
|
After Drag and Drop, check for "Drop Success" status in the log area.
|
||||||
|
If "Drop Success" is true press PASS else FAIL.
|
||||||
|
""";
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
PassFailJFrame.builder()
|
||||||
|
.title("Test Instructions")
|
||||||
|
.instructions(INSTRUCTIONS)
|
||||||
|
.columns(40)
|
||||||
|
.testUI(WinMoveFileToShellTest::createAndShowUI)
|
||||||
|
.logArea(5)
|
||||||
|
.build()
|
||||||
|
.awaitAndCheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Frame createAndShowUI() {
|
||||||
|
Frame frame = new Frame("Drag Frame");
|
||||||
|
final DragSourceListener dsl = new DragSourceAdapter() {
|
||||||
|
public void dragDropEnd(DragSourceDropEvent e) {
|
||||||
|
PassFailJFrame.log("Drop Success: " + e.getDropSuccess());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DragGestureListener dgl = dge -> {
|
||||||
|
File file = new File(System.getProperty("test.classes", ".")
|
||||||
|
+ File.separator + "move.me");
|
||||||
|
try {
|
||||||
|
file.createNewFile();
|
||||||
|
} catch (IOException exc) {
|
||||||
|
exc.printStackTrace();
|
||||||
|
}
|
||||||
|
ArrayList<File> list = new ArrayList<>();
|
||||||
|
list.add(file);
|
||||||
|
dge.startDrag(null, new FileListSelection(list), dsl);
|
||||||
|
};
|
||||||
|
|
||||||
|
new DragSource().createDefaultDragGestureRecognizer(frame,
|
||||||
|
DnDConstants.ACTION_MOVE, dgl);
|
||||||
|
frame.setSize(200, 100);
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class FileListSelection implements Transferable {
|
||||||
|
private static final int FL = 0;
|
||||||
|
|
||||||
|
private static final DataFlavor[] flavors =
|
||||||
|
new DataFlavor[] { DataFlavor.javaFileListFlavor };
|
||||||
|
|
||||||
|
|
||||||
|
private List data;
|
||||||
|
|
||||||
|
public FileListSelection(List data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
|
return flavors.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
|
for (DataFlavor dataFlavor : flavors) {
|
||||||
|
if (flavor.equals(dataFlavor)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getTransferData(DataFlavor flavor)
|
||||||
|
throws UnsupportedFlavorException, IOException
|
||||||
|
{
|
||||||
|
if (flavor.equals(flavors[FL])) {
|
||||||
|
return data;
|
||||||
|
} else {
|
||||||
|
throw new UnsupportedFlavorException(flavor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user