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

Mac: [dnd] onDragDropped is not called, when DnD is from native, mac only

    Details

      Description

      Run attached code:

      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.input.*;
      import javafx.scene.paint.Color;
      import javafx.scene.text.Text;
      import javafx.stage.Stage;

      public class dndIssue extends Application {

          @Override public void start(Stage stage) {
              stage.setTitle("Hello Drag And Drop");

              Group root = new Group();
              Scene scene = new Scene(root, 400, 200);
              scene.setFill(Color.LIGHTGREEN);

              final Text target = new Text(300, 100, "DROP HERE");
              target.setScaleX(2.0);
              target.setScaleY(2.0);

              target.setOnDragOver(new EventHandler <DragEvent>() {
                  @Override
                  public void handle(DragEvent event) {
                      /* data is dragged over the target */
                      System.out.println("onDragOver");
                      
                      /* accept it only if it is not dragged from the same node
                       * and if it has a string data */
                      if (event.getGestureSource() != target &&
                              event.getDragboard().hasString()) {
                          /* allow for both copying and moving, whatever user chooses */
                          event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                      }
                      
                      event.consume();
                  }
              });

              target.setOnDragEntered(new EventHandler <DragEvent>() {
                  @Override
                  public void handle(DragEvent event) {
                      /* the drag-and-drop gesture entered the target */
                      System.out.println("onDragEntered");
                      /* show to the user that it is an actual gesture target */
                      if (event.getGestureSource() != target &&
                              event.getDragboard().hasString()) {
                          target.setFill(Color.GREEN);
                      }
                      
                      event.consume();
                  }
              });

              target.setOnDragExited(new EventHandler <DragEvent>() {
                  @Override
                  public void handle(DragEvent event) {
                      /* mouse moved away, remove the graphical cues */
                      target.setFill(Color.BLACK);
                      
                      event.consume();
                  }
              });
              
              target.setOnDragDropped(new EventHandler <DragEvent>() {
                  @Override
                  public void handle(DragEvent event) {
                      /* data dropped */
                      System.out.println("onDragDropped");
                      /* if there is a string data on dragboard, read it and use it */
                      Dragboard db = event.getDragboard();
                      boolean success = false;
                      if (db.hasString()) {
                          target.setText(db.getString());
                          success = true;
                      }
                      /* let the source know whether the string was successfully
                       * transferred and used */
                      event.setDropCompleted(success);
                      
                      event.consume();
                  }
              });

              root.getChildren().add(target);
              stage.setScene(scene);
              stage.show();
          }

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


      Open any web-site with image on it. (I used safari)

      Try to DnD image from site to the Text Node.

      For windows I see output:
      onDragOver
      ....
      onDragOver
      OnDragDropped.

      For mac Isee output:
      onDragOver
      ...
      OnDragOver

      That's it. Event onDragDropped is not called.

        Attachments

          Activity

            People

            • Assignee:
              snorthov Steve Northover (Inactive)
              Reporter:
              akirov Alexander Kirov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: