B4J Library jDragAndDrop2 - Drag and Drop

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

  • jDragandDrop2.zip
    35.2 KB · Views: 858
Last edited:

alirezahassan

Active Member
Licensed User
thank you dear @stevel05,
I solved my problem. The following code was originally my code.
old code:
Sub DropTarget_Text_DragDropped(e As DragEvent)
    Try
        Dim pathsss As String = File.GetFileParent(e.GetDragboard.GetFiles.Get(0))
        Dim namesss As String = File.GetName(e.GetDragboard.GetFiles.Get(0))
        TXT_Text.Visible = False
        IMG_Text.Visible = True
        Wait For (Codes.Compress(pathsss,namesss)) Complete (Completed As Image)
        IMG_Text.SetImage(Completed)
        Loadings.Loading_Show(MainForm)
-->  uploudFile(File.GetFileParent(e.GetDragboard.GetFiles.Get(0)),File.GetName(e.GetDragboard.GetFiles.Get(0)),"Text")
        e.SetDropCompleted(True)
    Catch
        Log(LastException)
    End Try
End Sub
I changed the above code
New code:
Sub DropTarget_Text_DragDropped(e As DragEvent)
    Try
        Dim pathsss As String = File.GetFileParent(e.GetDragboard.GetFiles.Get(0))
        Dim namesss As String = File.GetName(e.GetDragboard.GetFiles.Get(0))
        TXT_Text.Visible = False
        IMG_Text.Visible = True
        Wait For (Codes.Compress(pathsss,namesss)) Complete (Completed As Image)
        IMG_Text.SetImage(Completed)
        Loadings.Loading_Show(MainForm)
 --> uploudFile(pathsss,namesss,"Text")
        e.SetDropCompleted(True)
    Catch
        Log(LastException)
    End Try
End Sub
I realized that this error occurred after the (Wait For) code. After the (Wait For) code, the variable e was cleared! It is as if the inputs are empty after the (Wait For) code.
I defined two variables. And after the (Wait For) code, its value was not cleared. I think this is a bug @Erel.
Thanks for following up Mr. @stevel05
 
Top