B4J Library jDragAndDrop2 - Drag and Drop

stevel05

Expert
Licensed User
This library is an update to Andrews jDragandDrop to take advantage of the DragBorad.DragView available in JavaFX8. This allows displaying a graphic next to or behind the mouse cursor while dragging items.

It's not quite a drop in replacement, but I tried to make it as close as possible.

The differences are:
  1. The DragAndDrop class needs to be initialized with the Callback module.
  2. The Transfer Mode does not support strings, it needs to be a TransferMode array, which are available as variables from the TransferMode static class.
  3. The e.AcceptTransferMode call has changed to e.AcceptTransferModes.
  4. There are two additional SetDragModeAndData methods to cater for setting the DragView.
  5. I have exposed most of the Dragboard methods which make it easier to select the data you want to accept, and get the results from the dragboard, and most of the DragEvent methods. Existing code should work as is.
  6. If you use sender to get the current EventSource (as opposed to the GestureSource) you will need to change it from sender to e.GetEventSource
The demo shows drag and drop from within the app, and from outside it for text and images.

Issues:
The only issue I found, and it may be a 'feature'. Is that if an image is being dragged, a copy of that image is used in place of whatever is set in the dragview. I would have preferred to be able to set a thumbnail, but it doesn't appear to work like that.​

It's written as 4 code modules, you can compile it to a library if you prefer.
Please let me know if you find any problems with it.

For a b4xlib, see Erel's implementation in post #3

Enjoy.
 

Attachments

Last edited:

moster67

Expert
Licensed User
Only saw this one now...it could have saved me time.
Thanks Steve.
 

LucaMs

Expert
Licensed User
I still think that we "need" a B4X forum; I found this very useful B4Xlib... "casually".

Also, I would change its name to B4XDragAndDrop (or B4XDragDrop).
 
Last edited:

LucaMs

Expert
Licensed User
Such posts only add clutter. -Your comment has nothing to do with this thread.
I don't think anyone who reads my post loses orientation.

Also note that this is a B4J only library.
I was referring to your b4xlib in this thread; then it also creates clutter, since it is in a thread for B4J libraries (no, I don't think this that creates clutter but only that whoever finds this thread will be content to read the first post without knowing that there is also your version b4xlib).

However, it is certainly true that I have to train myself not to write O.T.
 

Erel

Administrator
Staff member
Licensed User
I was referring to your b4xlib in this thread; then it also creates clutter, since it is in a thread for B4J libraries
That's wrong. b4xlibs can be cross platform. It doesn't mean that all b4xlibs are cross platform.
If you try to add this library to B4A or B4i it will show an error message because the "Supported Platforms" field is set to B4J.
 

LucaMs

Expert
Licensed User
This is an old thread, I know, but what I'm about to write is so useless 😁 that I can write it here too.

In a very small test project, just to drag text lines from a Windows sw to a B4J TextArea, I used the Erel's B4Xlib and it works perfectly, so I made the changes to the project I am developing and... the dropped event does not fire.

So I jumped through hoops to understand the reason and couldn't find it.
After many studies and attempts I have even taken the few parts that make up the test project and I have inserted them so as they are in the main project; nothing, they don't work in my "main project".

At that point I thought there was something strange in the Main Form of the main project, which opens a dialog form and in this second the dragging should work but I didn't see any oddities.

After hours of going crazy, even comparing the generated Java code (of the Main form) I wanted to do one last test: exclude the B4Xlib and directly import Steve's 4 classes. Here, now it works.

I don't know if the 4 classes in the B4Xlib have been changed; if so, that would be the cause, otherwise... I just don't understand.

Anyway, problem solved (but I'll have to remember it, which is not easy)
 

LucaMs

Expert
Licensed User
Are you running in debug mode?
Yes.

Anyway, changing the Erel's manifest from:
B4X:
Version=1.00
Supported Platforms=B4J
DependsOn=JavaObject
to:
B4X:
Version=1.00
Supported Platforms=B4J
B4JDependsOn=JavaObject
the B4Xlib works both on the test project and the "main one" (still in debug mode).
 

LucaMs

Expert
Licensed User
Anyway, changing the Erel's manifest from:
No, that wasn't the problem; both manifest work.

Maybe it works now, even with the Erel's manifest, because I've made a copy of the entire project folder (I haven't changed anything in the project).

I need to read your tip, Steve.
 

LucaMs

Expert
Licensed User
I'm going crazy to find that problem!

Now the main project works, with the b4xlib unmodified and in debug mode, that is exactly as tried for hours previously.

Perhaps the only different thing (Perhaps, because after so many attempts, I got lost) the problem was the "meta" file, but it seems strange to me.

Well, solved, anyway.
 
Top