jdk/test/sun/awt/dnd/8024061/bug8024061.java
author ihse
Tue, 09 May 2017 12:57:30 +0200
changeset 45028 b0ea3c0bfb81
parent 44763 56f74283845e
permissions -rw-r--r--
8179889: Fix typographic errors in copyright headers Reviewed-by: erikj, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     1
/*
45028
b0ea3c0bfb81 8179889: Fix typographic errors in copyright headers
ihse
parents: 44763
diff changeset
     2
 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     4
 *
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     8
 *
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    13
 * accompanied this code).
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    14
 *
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    18
 *
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    21
 * questions.
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    22
 */
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    23
40128
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 28225
diff changeset
    24
/*
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 28225
diff changeset
    25
 * @test
e635645d2a8a 8160974: [TESTBUG] Mark more headful tests with @key headful.
goetz
parents: 28225
diff changeset
    26
 * @key headful
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    27
 * @bug 8024061
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    28
 * @summary Checks that no exception is thrown if dragGestureRecognized
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    29
 *          takes a while to complete.
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
    30
 * @library ../../../../lib/testlibrary
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
    31
 * @build jdk.testlibrary.OSInfo
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
    32
 * @run main bug8024061
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    33
 */
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    34
import java.awt.*;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    35
import java.awt.datatransfer.DataFlavor;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    36
import java.awt.datatransfer.Transferable;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    37
import java.awt.datatransfer.UnsupportedFlavorException;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    38
import java.awt.dnd.DnDConstants;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    39
import java.awt.dnd.DragGestureEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    40
import java.awt.dnd.DragGestureListener;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    41
import java.awt.dnd.DragSource;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    42
import java.awt.dnd.DragSourceDragEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    43
import java.awt.dnd.DragSourceDropEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    44
import java.awt.dnd.DragSourceEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    45
import java.awt.dnd.DragSourceListener;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    46
import java.awt.dnd.DropTarget;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    47
import java.awt.dnd.DropTargetDragEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    48
import java.awt.dnd.DropTargetDropEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    49
import java.awt.dnd.DropTargetEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    50
import java.awt.dnd.DropTargetListener;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    51
import java.awt.event.InputEvent;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    52
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    53
import java.io.IOException;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    54
import java.lang.reflect.InvocationTargetException;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    55
import java.util.concurrent.CountDownLatch;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    56
import java.util.concurrent.TimeUnit;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    57
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    58
import javax.swing.*;
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
    59
import jdk.testlibrary.OSInfo;
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
    60
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    61
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    62
/**
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    63
 * If dragGestureRecognized() takes a while to complete and if user performs a drag quickly,
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    64
 * an exception is thrown from DropTargetListener.dragEnter when it calls
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    65
 * DropTargetDragEvent.getTransferable().
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    66
 * <p>
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    67
 * This class introduces a delay in dragGestureRecognized() to cause the exception.
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    68
 */
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    69
public class bug8024061 {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    70
    private static final DataFlavor DropObjectFlavor;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    71
    private static final int DELAY = 1000;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    72
44763
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    73
    static final DnDPanel panel1 = new DnDPanel(Color.yellow);
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    74
    static final DnDPanel panel2 = new DnDPanel(Color.pink);
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    75
    private final JFrame frame;
44763
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    76
    static Point here;
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    77
    static Point there;
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    78
    static Dimension d;
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    79
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    80
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    81
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    82
    private static final CountDownLatch lock = new CountDownLatch(1);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    83
    private static volatile Exception dragEnterException = null;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    84
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    85
    static {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    86
        DataFlavor flavor = null;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    87
        try {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    88
            flavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    89
        } catch (ClassNotFoundException e) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    90
            e.printStackTrace();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    91
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    92
        DropObjectFlavor = flavor;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    93
    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    94
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    95
    bug8024061() {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    96
        frame = new JFrame("DnDWithRobot");
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    97
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
    98
44763
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
    99
        d = new Dimension(100, 100);
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   100
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   101
        panel1.setPreferredSize(d);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   102
        panel2.setPreferredSize(d);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   103
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   104
        Container content = frame.getContentPane();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   105
        content.setLayout(new GridLayout(1, 2, 5, 5));
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   106
        content.add(panel1);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   107
        content.add(panel2);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   108
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   109
        frame.pack();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   110
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   111
        DropObject drop = new DropObject();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   112
        drop.place(panel1, new Point(10, 10));
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   113
        frame.setVisible(true);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   114
    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   115
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   116
    public static void main(String[] args) throws AWTException, InvocationTargetException, InterruptedException {
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
   117
        OSInfo.OSType type = OSInfo.getOSType();
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
   118
        if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) {
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   119
            System.out.println("This test is for Linux and Solaris only... " +
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   120
                               "skipping!");
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   121
            return;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   122
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   123
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   124
        final bug8024061[] dnd = {null};
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   125
        SwingUtilities.invokeAndWait(new Runnable() {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   126
            @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   127
            public void run() {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   128
                dnd[0] = new bug8024061();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   129
            }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   130
        });
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   131
        final Robot robot = new Robot();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   132
        robot.setAutoDelay(10);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
   133
        robot.waitForIdle();
44763
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   134
        robot.delay(200);
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   135
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   136
        JFrame frame = dnd[0].frame;
44763
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   137
        SwingUtilities.invokeAndWait(() -> {
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   138
            here = panel1.getLocationOnScreen();
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   139
            there = panel2.getLocationOnScreen();
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   140
        });
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   141
        here.translate(d.width / 2, d.height / 2);
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   142
        there.translate(d.width / 2, d.height / 2);
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   143
        robot.mouseMove(here.x, here.y);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   144
        robot.mousePress(InputEvent.BUTTON1_MASK);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   145
        while (here.x < there.x) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   146
            here.x += 20;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   147
            robot.mouseMove(here.x, here.y);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   148
            System.out.println("x = " + here.x);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   149
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   150
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
28087
622b2f420bc3 8063104: Change open awt regression tests to avoid sun.awt.SunToolkit.realSync, part 2
yan
parents: 24525
diff changeset
   151
        robot.waitForIdle();
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   152
        robot.mousePress(InputEvent.BUTTON1_MASK);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   153
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   154
        System.out.println("finished");
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   155
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   156
        try {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   157
            if (lock.await(5, TimeUnit.SECONDS)) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   158
                if (dragEnterException == null) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   159
                    System.out.println("Test passed.");
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   160
                } else {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   161
                    System.out.println("Test failed.");
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   162
                    dragEnterException.printStackTrace();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   163
                    throw new RuntimeException(dragEnterException);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   164
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   165
            } else {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   166
                System.out.println("Test failed. Timeout reached");
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   167
                throw new RuntimeException("Timed out waiting for dragEnter()");
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   168
            }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   169
        } finally {
44763
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   170
            SwingUtilities.invokeLater(frame::dispose);
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   171
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   172
    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   173
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   174
    class DropObject implements Transferable {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   175
        DnDPanel panel;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   176
        Color color = Color.CYAN;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   177
        int width = 50;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   178
        int height = 50;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   179
        int x;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   180
        int y;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   181
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   182
        void draw(Graphics2D g) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   183
            Color savedColor = g.getColor();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   184
            g.setColor(color);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   185
            g.fillRect(x, y, width, height);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   186
            g.setColor(Color.lightGray);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   187
            g.drawRect(x, y, width, height);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   188
            g.setColor(savedColor);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   189
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   190
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   191
        boolean contains(int x, int y) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   192
            return (x > this.x && x < this.x + width)
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   193
                    && (y > this.y && y < this.y + height);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   194
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   195
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   196
        @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   197
        public DataFlavor[] getTransferDataFlavors() {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   198
            return new DataFlavor[]{DropObjectFlavor};
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   199
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   200
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   201
        void place(DnDPanel panel, Point location) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   202
            if (panel != this.panel) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   203
                x = location.x;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   204
                y = location.y;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   205
                if (this.panel != null) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   206
                    this.panel.setDropObject(null);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   207
                    this.panel.repaint();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   208
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   209
                this.panel = panel;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   210
                this.panel.setDropObject(this);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   211
                this.panel.repaint();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   212
            }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   213
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   214
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   215
        @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   216
        public boolean isDataFlavorSupported(DataFlavor flavor) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   217
            return DropObjectFlavor.equals(flavor);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   218
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   219
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   220
        @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   221
        public Object getTransferData(DataFlavor flavor)
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   222
                throws UnsupportedFlavorException, IOException {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   223
            if (isDataFlavorSupported(flavor)) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   224
                return this;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   225
            } else {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   226
                throw new UnsupportedFlavorException(flavor);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   227
            }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   228
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   229
    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   230
44763
56f74283845e 8142540: [TEST_BUG] Test sun/awt/dnd/8024061/bug8024061.java fails on ubuntu
ssadetsky
parents: 40128
diff changeset
   231
    static class DnDPanel extends JPanel {
24525
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   232
        DropObject dropObject;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   233
        final DragSource dragSource;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   234
        final DropTarget dropTarget;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   235
        final Color color;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   236
        final DragGestureListener dgListener;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   237
        final DragSourceListener dsListener;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   238
        final DropTargetListener dtListener;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   239
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   240
        DnDPanel(Color color) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   241
            this.color = color;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   242
            this.dragSource = DragSource.getDefaultDragSource();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   243
            dgListener = new DragGestureListener() {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   244
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   245
                public void dragGestureRecognized(DragGestureEvent dge) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   246
                    Point location = dge.getDragOrigin();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   247
                    if (dropObject != null && dropObject.contains(location.x, location.y)) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   248
                        dragSource.startDrag(dge, DragSource.DefaultCopyNoDrop, dropObject, dsListener);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   249
                        try {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   250
                            Thread.sleep(DELAY);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   251
                        } catch (InterruptedException e) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   252
                        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   253
                    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   254
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   255
            };
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   256
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   257
            dsListener = new DragSourceListener() {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   258
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   259
                public void dragEnter(DragSourceDragEvent dsde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   260
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   261
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   262
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   263
                public void dragOver(DragSourceDragEvent dsde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   264
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   265
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   266
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   267
                public void dropActionChanged(DragSourceDragEvent dsde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   268
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   269
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   270
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   271
                public void dragExit(DragSourceEvent dse) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   272
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   273
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   274
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   275
                public void dragDropEnd(DragSourceDropEvent dsde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   276
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   277
            };
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   278
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   279
            dtListener = new DropTargetListener() {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   280
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   281
                public void dragEnter(DropTargetDragEvent dtde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   282
                    if (dropObject != null) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   283
                        dtde.rejectDrag();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   284
                        return;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   285
                    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   286
                    dtde.acceptDrag(DnDConstants.ACTION_MOVE);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   287
                    try {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   288
                        Transferable t = dtde.getTransferable();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   289
                        Object data = t.getTransferData(DropObjectFlavor);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   290
                    } catch (Exception e) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   291
                        dragEnterException = e;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   292
                        e.printStackTrace();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   293
                    } finally {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   294
                        lock.countDown();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   295
                    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   296
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   297
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   298
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   299
                public void dragOver(DropTargetDragEvent dtde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   300
                    if (dropObject != null) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   301
                        dtde.rejectDrag();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   302
                        return;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   303
                    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   304
                    dtde.acceptDrag(DnDConstants.ACTION_MOVE);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   305
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   306
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   307
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   308
                public void dropActionChanged(DropTargetDragEvent dtde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   309
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   310
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   311
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   312
                public void dragExit(DropTargetEvent dte) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   313
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   314
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   315
                @Override
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   316
                public void drop(DropTargetDropEvent dtde) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   317
                    if (dropObject != null) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   318
                        dtde.rejectDrop();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   319
                        return;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   320
                    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   321
                    try {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   322
                        dtde.acceptDrop(DnDConstants.ACTION_MOVE);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   323
                        Transferable t = dtde.getTransferable();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   324
                        DropObject dropObject = (DropObject) t.getTransferData(DropObjectFlavor);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   325
                        Point location = dtde.getLocation();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   326
                        dropObject.place(DnDPanel.this, location);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   327
                        dtde.dropComplete(true);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   328
                    } catch (Exception e) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   329
                        e.printStackTrace();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   330
                    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   331
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   332
                }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   333
            };
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   334
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   335
            dragSource.createDefaultDragGestureRecognizer(this,
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   336
                    DnDConstants.ACTION_MOVE, dgListener);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   337
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   338
            dropTarget = new DropTarget(this, DnDConstants.ACTION_MOVE, dtListener, true);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   339
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   340
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   341
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   342
        public void paintComponent(Graphics g) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   343
            super.paintComponent(g);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   344
            Color savedColor = g.getColor();
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   345
            g.setColor(color);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   346
            g.fillRect(0, 0, getWidth(), getHeight());
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   347
            g.setColor(savedColor);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   348
            if (dropObject != null) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   349
                dropObject.draw((Graphics2D) g);
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   350
            }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   351
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   352
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   353
        void setDropObject(DropObject dropObject) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   354
            this.dropObject = dropObject;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   355
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   356
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   357
        DropObject findDropObject(int x, int y) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   358
            if (dropObject != null && dropObject.contains(x, y)) {
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   359
                return dropObject;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   360
            }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   361
            return null;
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   362
        }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   363
    }
8bb9924dc95b 8024061: Exception thrown when drag and drop between two components is executed quickly
alitvinov
parents:
diff changeset
   364
}