This discussion is archived
4 Replies Latest reply: Dec 17, 2012 2:36 PM by 950907 RSS

Simple questions about drag-release gestures.

950907 Newbie
Currently Being Moderated
Hi,

I searched a while but I was not able to understand everything I need.

Simply put, I want to have a very simple Drag and Drop.
I dont want to move data, I just want to have a node (source) to interact with another node (target). Every funky stuff like changing colors or change mouse cursors when I go over potential targets are not important for now.
I just want a "drag start", a "drop" and a "dragdone".
Realised is the drag start and the drop part.

I used the setOnDragDetected function, which works fine and decided to startFullDrag() since the API seemed to me, that this is the right way.
this.setOnDragDetected(new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent p_Event)
            {
                System.out.println("DragDetect");
                startFullDrag(); 
                p_Event.consume();
Since that seems to enable or maybe switch the DragEvents to MouseDragEvents - I used setOnMouseDragReleased to sucessfully enable a reaction on a "drop" (or a "drag release").
this.setOnMouseDragReleased(new EventHandler<MouseDragEvent>()
        {
            @Override
            public void handle(MouseDragEvent p_MDEvent)
            {
                System.out.println("DragRelease");
                p_MDEvent.consume();
                
            }
        });
But I want to change something about the source while I have the drag (color it greyish, maybe) and need to find out, when the Drag is over.
For the DataDrags there is a possibility with "OnDragDone" which seems to be activated for the source. Exactly what I want, as it seems.
It is not working in any way for my nodes.

They Interact with nodes form the same basic class, so each would catch any event, that would be activated, but no node gave me an output. I tried each event catcher that seemed remotely appropriate.
I dont want to have any Drags "half-alive" or anything. I would really love to be able to react to the end of a drag.

I would be really grateful if you can help me with that problem.

tl;dr:
The drag-release from one node to another works, but I cant get an event, that informs the node, that the drag is over. So I maybe cant remove interface-changes I did to make the source clear as the "source".

Edited by: Anro on 12.11.2012 04:43
  • 1. Re: Simple questions about drag-release gestures.
    950907 Newbie
    Currently Being Moderated
    I there are any Questions I am glad to answer them.

    I was still not able to find a fitting tutorial, that could provide me with the information about "How to implement drag and drop in javafx2 for nodes that just want to interact with each other".
  • 2. Re: Simple questions about drag-release gestures.
    950907 Newbie
    Currently Being Moderated
    Ok, I was able to implement the drag and drop part AS LONG AS the Drop is on the right spot.

    I can mark the dragged Element, BUT I can not unmark it.

    No event seems to be able to be delivered to it.
    Like "You beeing dragged has been ended".

    Maybe I could try to get the toplayer to catch the event, since it should end on it.
    But what happens if the drag leaves the window?

    I cant believe that there is no answer to that?
    Maybe i need to implement some kind of listener? extend MouseDragEvent to my own class, so I can create a self made listener?

    Everything feels too much like a work around, doesnt it?
  • 3. Re: Simple questions about drag-release gestures.
    James_D Guru
    Currently Being Moderated
    Does this tutorial cover what you need: http://docs.oracle.com/javafx/2/drag_drop/jfxpub-drag_drop.htm

    For your "drag done" not being fired on the source, I think you have to invoke
    setDropCompleted(true)
    on the drag event for that to happen.

    So you want something like
    target.setOnDragDropped(new EventHandler<DragEvent>() {
      public void handle(DragEvent event) {
        // process end of drag on target
        ...
        // Now inform the drag event that everything's complete:
        event.setDropCompleted(true);
      }
    };
    
    source.setOnDragDone(...);
  • 4. Re: Simple questions about drag-release gestures.
    950907 Newbie
    Currently Being Moderated
    Hi, thanks a lot for your post.

    I went in the meantime another way.
    Everytime I enter a new node, the whole tree is forced to redo its markup.

    That leads to more unneccessary workload, but it works.

    Sadly I work with MouseDragEvents, that not have the setDropCompleted() function.
    I figured from the api that the DragEvents are more for Date and not for dataless drags as mine are (I let node 1 interact with node 2)

    But maybe I misread. I am content with your answer but will open an other problem now that gives me a lot of headaches right now.

    MouseDrag Entered (reactivate after a children blocked)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points