1 package com.sun.glass.ui.monocle; 2 3 /* 4 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Oracle designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Oracle in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 24 * or visit www.oracle.com if you need additional information or have any 25 * questions. 26 */ 27 28 import com.sun.glass.ui.monocle.input.devices.TestTouchDevice; 29 import com.sun.glass.ui.monocle.input.devices.TestTouchDevices; 30 import javafx.scene.Node; 31 import javafx.scene.input.ClipboardContent; 32 import javafx.scene.input.Dragboard; 33 import javafx.scene.input.InputEvent; 34 import javafx.scene.input.TransferMode; 35 import javafx.scene.shape.Rectangle; 36 import org.junit.Test; 37 import org.junit.runners.Parameterized; 38 39 import java.util.Collection; 40 41 public class DragAndDropTest extends ParameterizedTestBase { 42 43 public DragAndDropTest(TestTouchDevice device) { 44 super(device); 45 } 46 47 48 @Parameterized.Parameters 49 public static Collection<Object[]> data() { 50 return TestTouchDevices.getTouchDeviceParameters(1); 51 } 52 53 @Test 54 public void testDragOneNodeToAnother() throws Exception { 55 TestRunnable.invokeAndWait(() -> { 56 Node n1 = new Rectangle(10, 10, 10, 10); 57 Node n2 = new Rectangle(210, 10, 10, 10); 58 TestApplication.getRootGroup().getChildren().add(n1); 59 TestApplication.getRootGroup().getChildren().add(n2); 60 n1.setOnDragDetected((event) -> { 61 TestLog.log("Drag detected on n1"); 62 Dragboard db = n1.startDragAndDrop(TransferMode.ANY); 63 ClipboardContent content = new ClipboardContent(); 64 content.putString(""); 65 db.setContent(content); 66 }); 67 n2.setOnDragEntered((e) -> TestLog.log("Drag entered on n2")); 68 n2.setOnDragOver((event) -> { 69 TestLog.log("Drag over on n2"); 70 event.acceptTransferModes(TransferMode.COPY_OR_MOVE); 71 }); 72 n2.setOnDragDropped((e) -> TestLog.log("Drag dropped on n2")); 73 n1.setOnDragDone((e) -> TestLog.log("Drag done on n1")); 74 n1.addEventHandler(InputEvent.ANY, (e) -> TestLog.log(e.toString())); 75 n2.addEventHandler(InputEvent.ANY, (e) -> TestLog.log(e.toString())); 76 }); 77 try { 78 int p = device.addPoint(15, 15); 79 device.sync(); 80 device.setPoint(p, 110, 15); 81 device.sync(); 82 TestLog.waitForLogContaining("Drag detected on n1"); 83 TestLog.clear(); 84 device.setPoint(p, 215, 15); 85 device.sync(); 86 TestLog.waitForLogContaining("Drag entered on n2"); 87 TestLog.waitForLogContaining("Drag over on n2"); 88 device.removePoint(p); 89 device.sync(); 90 TestLog.waitForLogContaining("Drag dropped on n2"); 91 TestLog.waitForLogContaining("Drag done on n1"); 92 } finally { 93 TestRunnable.invokeAndWait(() -> TestApplication.getRootGroup().getChildren().clear()); 94 } 95 } 96 97 }