70 private static final DataFlavor DropObjectFlavor; 71 private static final int DELAY = 1000; 72 73 private final DnDPanel panel1 = new DnDPanel(Color.yellow); 74 private final DnDPanel panel2 = new DnDPanel(Color.pink); 75 private final JFrame frame; 76 77 private static final CountDownLatch lock = new CountDownLatch(1); 78 private static volatile Exception dragEnterException = null; 79 80 static { 81 DataFlavor flavor = null; 82 try { 83 flavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType); 84 } catch (ClassNotFoundException e) { 85 e.printStackTrace(); 86 } 87 DropObjectFlavor = flavor; 88 } 89 90 bug8024061() { 91 frame = new JFrame("DnDWithRobot"); 92 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 93 94 Dimension d = new Dimension(100, 100); 95 96 panel1.setPreferredSize(d); 97 panel2.setPreferredSize(d); 98 99 Container content = frame.getContentPane(); 100 content.setLayout(new GridLayout(1, 2, 5, 5)); 101 content.add(panel1); 102 content.add(panel2); 103 104 frame.pack(); 105 106 DropObject drop = new DropObject(); 107 drop.place(panel1, new Point(10, 10)); 108 frame.setVisible(true); 109 } 110 111 public static void main(String[] args) throws AWTException, InvocationTargetException, InterruptedException { 112 OSInfo.OSType type = OSInfo.getOSType(); 113 if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) { 114 System.out.println("This test is for Linux and Solaris only... " + 115 "skipping!"); 116 return; 117 } 118 119 final bug8024061[] dnd = {null}; 120 SwingUtilities.invokeAndWait(new Runnable() { 121 @Override 122 public void run() { 123 dnd[0] = new bug8024061(); 124 } 125 }); 126 final Robot robot = new Robot(); 127 robot.setAutoDelay(10); 128 robot.waitForIdle(); 129 130 JFrame frame = dnd[0].frame; 131 Point point = frame.getLocationOnScreen(); 132 Point here = new Point(point.x + 35, point.y + 45); 133 Point there = new Point(point.x + 120, point.y + 45); 134 here.x += 25; 135 robot.mouseMove(here.x, here.y); 136 robot.mousePress(InputEvent.BUTTON1_MASK); 137 while (here.x < there.x) { 138 here.x += 20; 139 robot.mouseMove(here.x, here.y); 140 System.out.println("x = " + here.x); 141 } 142 robot.mouseRelease(InputEvent.BUTTON1_MASK); 143 robot.waitForIdle(); 144 robot.mousePress(InputEvent.BUTTON1_MASK); 145 robot.mouseRelease(InputEvent.BUTTON1_MASK); 146 System.out.println("finished"); 147 148 try { 149 if (lock.await(5, TimeUnit.SECONDS)) { 150 if (dragEnterException == null) { 151 System.out.println("Test passed."); 152 } else { 153 System.out.println("Test failed."); 154 dragEnterException.printStackTrace(); | 70 private static final DataFlavor DropObjectFlavor; 71 private static final int DELAY = 1000; 72 73 private final DnDPanel panel1 = new DnDPanel(Color.yellow); 74 private final DnDPanel panel2 = new DnDPanel(Color.pink); 75 private final JFrame frame; 76 77 private static final CountDownLatch lock = new CountDownLatch(1); 78 private static volatile Exception dragEnterException = null; 79 80 static { 81 DataFlavor flavor = null; 82 try { 83 flavor = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType); 84 } catch (ClassNotFoundException e) { 85 e.printStackTrace(); 86 } 87 DropObjectFlavor = flavor; 88 } 89 90 private static Point point; 91 92 bug8024061() { 93 frame = new JFrame("DnDWithRobot"); 94 frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 95 96 Dimension d = new Dimension(100, 100); 97 98 panel1.setPreferredSize(d); 99 panel2.setPreferredSize(d); 100 101 Container content = frame.getContentPane(); 102 content.setLayout(new GridLayout(1, 2, 5, 5)); 103 content.add(panel1); 104 content.add(panel2); 105 106 frame.pack(); 107 108 DropObject drop = new DropObject(); 109 drop.place(panel1, new Point(10, 10)); 110 frame.setVisible(true); 111 } 112 113 public static void main(String[] args) throws AWTException, InvocationTargetException, InterruptedException { 114 OSInfo.OSType type = OSInfo.getOSType(); 115 if (type != OSInfo.OSType.LINUX && type != OSInfo.OSType.SOLARIS) { 116 System.out.println("This test is for Linux and Solaris only... " + 117 "skipping!"); 118 return; 119 } 120 121 final bug8024061[] dnd = {null}; 122 SwingUtilities.invokeAndWait(new Runnable() { 123 @Override 124 public void run() { 125 dnd[0] = new bug8024061(); 126 } 127 }); 128 final Robot robot = new Robot(); 129 robot.setAutoDelay(10); 130 robot.waitForIdle(); 131 robot.delay(200); 132 133 JFrame frame = dnd[0].frame; 134 SwingUtilities.invokeAndWait(() -> point = frame.getLocationOnScreen()); 135 Point here = new Point(point.x + 35, point.y + 45); 136 Point there = new Point(point.x + 120, point.y + 45); 137 here.x += 20; 138 robot.mouseMove(here.x, here.y); 139 robot.mousePress(InputEvent.BUTTON1_MASK); 140 while (here.x < there.x) { 141 here.x += 20; 142 robot.mouseMove(here.x, here.y); 143 System.out.println("x = " + here.x); 144 } 145 robot.mouseRelease(InputEvent.BUTTON1_MASK); 146 robot.waitForIdle(); 147 robot.mousePress(InputEvent.BUTTON1_MASK); 148 robot.mouseRelease(InputEvent.BUTTON1_MASK); 149 System.out.println("finished"); 150 151 try { 152 if (lock.await(5, TimeUnit.SECONDS)) { 153 if (dragEnterException == null) { 154 System.out.println("Test passed."); 155 } else { 156 System.out.println("Test failed."); 157 dragEnterException.printStackTrace(); |