Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8118592

Win: Glass robot mouseMove() issue

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P2 P2
    • 8
    • 7u6
    • javafx
    • None
    • Win 7, b21

      mouseMove() does not work after calling of Dragboard.setContent(). Sample to reproduce:

      import com.sun.glass.ui.Robot;
      import java.util.concurrent.CountDownLatch;
      import java.util.logging.Level;
      import java.util.logging.Logger;
      import javafx.application.Application;
      import javafx.application.Platform;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.input.ClipboardContent;
      import javafx.scene.input.Dragboard;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.input.TransferMode;
      import javafx.stage.Stage;

      public class ImitateDrag extends Application {

          public static void main(String[] args) {
              launch(args);
          }

          public static final int BEFORE_DRAG_TIMEOUT = 500;
          public static final int BEFORE_DROP_TIMEOUT = 500;
          public static final int IN_DRAG_TIMEOUT = 20;
          public static final int DND_POINTS = 10;

          public void dnd(int x1, int y1, int x2, int y2) throws InterruptedException {
              final Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
              robot.mouseMove(x1, y1);
              robot.mousePress(1);
              Thread.sleep(BEFORE_DRAG_TIMEOUT);
              int xDistance = x2 - x1;
              int yDistance = y2 - y1;
              for (int i = 0; i < DND_POINTS + 1; i++) {
                  final int x = x1 + xDistance * i / DND_POINTS;
                  final int y = y1 + yDistance * i / DND_POINTS;
                  final CountDownLatch l = new CountDownLatch(1);
                  Platform.runLater(new Runnable() {
                      public void run() {
                          robot.mouseMove(x, y);
                          l.countDown();
                      }
                  });
                  l.await();
                  Thread.sleep(IN_DRAG_TIMEOUT);
              }
              robot.mouseMove(x2, y2);
              Thread.sleep(BEFORE_DROP_TIMEOUT);
              robot.mouseRelease(1);
          }

          @Override
          public void start(final Stage stage) {
              final Label l = new Label("label");
              l.setOnDragDetected(new EventHandler<MouseEvent>() {

                  public void handle(MouseEvent event) {
                      final Dragboard db = l.startDragAndDrop(TransferMode.ANY);
                      final ClipboardContent content = new ClipboardContent();
                      content.putString(l.getClass().getSimpleName());
                      db.setContent(content);
                      event.consume();
                  }
              });
              final Scene scene = new Scene(new Group(l), 300, 300);
              stage.setScene(scene);
              stage.show();

              new Thread() {

                  @Override
                  public void run() {
                      try {
                          dnd((int) stage.getX() + 30, (int) stage.getY() + 40, (int) stage.getX() + 230, (int) stage.getY() + 240);
                      } catch (InterruptedException ex) {
                          Logger.getLogger(ImitateDrag.class.getName()).log(Level.SEVERE, null, ex);
                      }
                  }
              }.start();
          }
      }

            anthony Anthony Petrov (Inactive)
            ogb Oleg Barbashov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: