--- /dev/null 2014-07-28 16:11:16.120781410 +0400 +++ new/test/java/awt/reliability/GUIXDnDJava.java 2014-07-28 16:21:59.532769628 +0400 @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2004, 2014, 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.*; +import java.awt.datatransfer.*; +import java.awt.dnd.*; + +/* + * @author Girish R (girish.ramachandran@sun.com) + */ + +public class GUIXDnDJava extends Frame implements ClipboardOwner { + + Process process; + volatile boolean framesVisible; + final Clipboard selection = Toolkit.getDefaultToolkit().getSystemSelection(); + + Object dropData = new String(""); + volatile boolean dragDropEnd, dropSuccess; + int dropAction; + DragSource ds; + DragSourceListener dsl; + DragGestureListener dgl; + DropTargetListener dtl; + static String data = "DragDropEnd TEST"; + + + public GUIXDnDJava() throws Exception { + this.setSize(500, 300); + this.setLocation(new Point(6, 200)); + this.setVisible(true); + ds = DragSource.getDefaultDragSource(); + dsl = new DragSourceAdapter() { + public void dragDropEnd(DragSourceDropEvent dsde) { + dragDropEnd = true; + dropSuccess = dsde.getDropSuccess(); + dropAction = dsde.getDropAction(); + + System.out.println("getDropSuccess: " + dsde.getDropSuccess()); + System.out.println("getDropAction: " + dsde.getDropAction()); + } + }; + + dgl = dge -> { + System.out.println("Drag gesture"); + dge.startDrag(null, new StringSelection(data), dsl); + }; + + ds.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, dgl); + dtl = new DropTargetAdapter() { + public void drop(DropTargetDropEvent dtde) { + System.out.println("Drop occured"); + dtde.acceptDrop(DnDConstants.ACTION_COPY); + Transferable t = dtde.getTransferable(); + try { + dropData = t.getTransferData(DataFlavor.stringFlavor); + } catch (Exception e) { + throw new RuntimeException(e); + } + dtde.dropComplete(true); + } + }; + new DropTarget(this, dtl); + + String childName = "xdnd-child"; + + Runtime runtime = Runtime.getRuntime(); + Process proc = runtime.exec("/bin/chmod u+x "+childName); + proc.waitFor(); + + // Only a way to receive notification when the child is ready. + selection.setContents(new StringSelection("Sun"), this); + + //Run the native process and wait for it to get over + process = Runtime.getRuntime().exec("./"+childName); + } + + /** + * This will be notified when the Native window comes up. Test starts here. + */ + public void lostOwnership(Clipboard clipboard, Transferable contents) { + this.framesVisible = true; + } + + public void destroyProcess() { + if (process != null) + process.destroy(); + } +}