< prev index next >

test/jdk/java/awt/dnd/ImageTransferTest/ImageTransferTest.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2018, 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.

@@ -20,20 +20,20 @@
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
 /*
-  @test
-  @key headful
-  @bug 4397404 4720930
-  @summary tests that images of all supported native image formats are transfered properly
-  @library ../../../../lib/testlibrary
-  @library ../../regtesthelpers/process/
-  @build jdk.testlibrary.OSInfo ProcessResults ProcessCommunicator
-  @author gas@sparc.spb.su area=Clipboard
-  @run main ImageTransferTest
-*/
+ * @test
+ * @key headful
+ * @bug 4397404 4720930 8197926
+ * @summary tests that images of all supported native image formats are transfered properly
+ * @library ../../../../lib/testlibrary
+ * @library ../../regtesthelpers/process/
+ * @build jdk.testlibrary.OSInfo ProcessResults ProcessCommunicator
+ * @author gas@sparc.spb.su area=Clipboard
+ * @run main ImageTransferTest
+ */
 
 import test.java.awt.regtesthelpers.process.ProcessCommunicator;
 import test.java.awt.regtesthelpers.process.ProcessResults;
 import jdk.testlibrary.OSInfo;
 

@@ -56,10 +56,12 @@
 import java.util.stream.Stream;
 
 public class ImageTransferTest {
     public static void main(String[] arg) throws Exception {
         ImageDragSource ids = new ImageDragSource();
+        try {
+            ids.frame.setUndecorated(true);
         ids.frame.setLocation(100, 100);
         ids.frame.setVisible(true);
         Util.sync();
         String classpath = System.getProperty("java.class.path");
         String[] args = new String[ids.formats.length + 4];

@@ -99,10 +101,15 @@
                     "native formats are not transferred properly: " + failedFormats);
         } else {
             System.err.println("images in following " +
                     "native formats are transferred properly: " + passedFormats);
         }
+        } finally {
+            if (ids.frame != null) {
+                ids.frame.dispose();
+            }
+        }
     }
 }
 
 
 class Util {

@@ -259,10 +266,11 @@
 }
 
 
 class ImageDropTarget extends ImageTransferer {
     private final Robot robot;
+    private static ImageDropTarget idt;
     private static Point startPoint, endPoint = new Point(250, 150);
 
     ImageDropTarget() throws AWTException {
         DropTargetAdapter dropTargetAdapter = new DropTargetAdapter() {
             @Override

@@ -315,10 +323,13 @@
         leaveFormat(formats[fi]);
         new Thread(() -> {
             try {
                 Thread.sleep(1000);
             } catch (InterruptedException e) {
+                if (idt.frame != null) {
+                    idt.frame.dispose();
+                }
                 e.printStackTrace();
                 // Exit from the child process
                 System.exit(1);
             }
             robot.mouseMove(startPoint.x, startPoint.y);

@@ -339,10 +350,13 @@
 
     void notifyTransferSuccess(boolean status) {
         if (status) {
             System.err.println("format passed: " + formats[fi]);
         } else {
+            if (idt.frame != null) {
+                idt.frame.dispose();
+            }
             System.err.println("format failed: " + formats[fi]);
             System.exit(1);
         }
         if (fi < formats.length - 1) {
             leaveFormat(formats[++fi]);

@@ -357,13 +371,14 @@
             }).start();
         }
     }
 
 
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
+        idt = new ImageDropTarget();
         try {
-            ImageDropTarget idt = new ImageDropTarget();
+            idt.frame.setUndecorated(true);
 
             int x = Integer.parseInt(args[0]);
             int y = Integer.parseInt(args[1]);
             startPoint = new Point(Integer.parseInt(args[2]), Integer.parseInt(args[3]));
 

@@ -375,10 +390,13 @@
             idt.frame.setVisible(true);
             Util.sync();
 
             idt.startImageDrag();
         } catch (Throwable e) {
+            if (idt.frame != null) {
+                idt.frame.dispose();
+            }
             e.printStackTrace();
             System.exit(1);
         }
     }
 

@@ -413,5 +431,6 @@
         } else {
             throw new UnsupportedFlavorException(flavor);
         }
     }
 }
+
< prev index next >