-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDragAndDrop.bas
255 lines (228 loc) · 11.1 KB
/
DragAndDrop.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
Type=Class
Version=4.7
ModulesStructureVersion=1
B4J=true
@EndOfDesignText@
#IgnoreWarnings: 2
#Event: DragDetected(e As MouseEvent)
#Event: DragDone(e As DragEvent)
#Event: DragEntered(e As DragEvent)
#Event: DragExited(e As DragEvent)
#Event: DragOver(e As DragEvent)
#Event: DragDropped(e As DragEvent)
Sub Class_Globals
Private fx As JFX
Private Mode As Object
Private DataID() As String
Private DataObject() As Object
Private DragboardImg As Image
Private DragboardImgOffsetX,DragboardImgOffsetY As Double
Private StartDrag As Boolean
Private CallBack As Object
Private sEventName,tEventName As String
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(vCallBack As Object)
CallBack = vCallBack
TransferMode.Initialize
End Sub
'Makes the specified node a drag source by adding the DragDetected And DragDone events To it.
'The DragDetected event Sub receives a MouseEvent object. A DragEvent object is passed to the DragDone event.
'The DragDetected event Sub should call SetDragModeAndData if it wants to start a drag and drop operation.
'
'DragId Is a string identifying the Type of data being dragged.
'DragObject Is the data To be transferred which must be a serializable object.
'TransferMode can be one of
'COPY Indicates copying of data Is supported Or intended.
'LINK Indicates linking of data Is supported Or intended.
'MOVE Indicates moving of data Is supported Or intended.
'
'Once the drag And drop operation Is complete the DragDone event Is Is sent To the gesture source
'To inform the source about how the gesture finished. In the DragDone event handler, obtain the
'transfer Mode by calling the GetTransferMode method on the event. If the transfer Mode Is Null that
'means the data transfer did Not happen. If the Mode Is MOVE, Then clear the data on the gesture source.
Public Sub MakeDragSource(pNode As Node, vEventName As String)
sEventName = vEventName
If SubExists(CallBack,sEventName & "_DragDetected") Then
Dim Event As Object = AsJO(pNode).CreateEvent("javafx.event.EventHandler","DragDetected",Null)
AsJO(pNode).RunMethod("setOnDragDetected",Array(Event))
End If
If SubExists(CallBack,sEventName & "_DragDone") Then
Dim Event As Object = AsJO(pNode).CreateEvent("javafx.event.EventHandler","DragDone",Null)
AsJO(pNode).RunMethod("setOnDragDone",Array(Event))
End If
End Sub
#Region Source field event handlers
Private Sub DragDetected_Event(MethodName As String,Args() As Object) As Object
CallSub2(CallBack,sEventName & "_DragDetected",AsMouseEvent(Args(0)))
If StartDrag Then
Dim DataFormat As JavaObject
DataFormat.InitializeStatic("javafx.scene.input.DataFormat")
Dim DB As Dragboard
DB.Initialize
DB.SetObject(AsJO(Args(0)).RunMethodJO("getSource",Null).RunMethod("startDragAndDrop",Array(Mode)))
For i = 0 To DataID.Length - 1
Dim LDF As JavaObject = DataFormat.RunMethod("lookupMimeType",Array(DataID(i)))
If LDF.IsInitialized = False Then LDF.InitializeNewInstance("javafx.scene.input.DataFormat",Array(Array As String(DataID(i))))
If DragboardImg.IsInitialized Then DB.SetDragView(DragboardImg, DragboardImgOffsetX, DragboardImgOffsetY)
Dim ClipboardContent As JavaObject
ClipboardContent.InitializeNewInstance("javafx.scene.input.ClipboardContent",Null)
If DataObject(i) Is Image Then
ClipboardContent.RunMethod("putImage",Array(DataObject(i)))
Else
ClipboardContent.RunMethod("put",Array(LDF,DataObject(i)))
End If
DB.setContent(ClipboardContent)
Next
End If
End Sub
Private Sub DragDone_Event(MethodName As String,Args() As Object) As Object
Dim DE As DragEvent
DE.Initialize
DE.SetObject(Args(0))
CallSub2(CallBack,sEventName & "_DragDone",DE)
End Sub
#End Region Source field event handlers
'Set the drag And drop operation parameters.
'
'TransferMode can be one of
'COPY Indicates copying of data Is supported Or intended.
'LINK Indicates linking of data Is supported Or intended.
'MOVE Indicates moving of data Is supported Or intended.
'DataIDs is an array that identifies the type of data to be dropped in this process.
'This could be a mime type if drag/dropping data to/from outside a B4j application, or an arbitrary string to
'identify the data as specific to this app.
'There may be more than one version of the data on the clipboard, an application could pass a plaintext version('text/plain') and an html version('text/html')
'you can choose which version you want to use by calling e.GetDataObjectForId(DataId) specifying the appropriate DataId.
'
'DataObjects Is the array of objects (relating to the DataID's that will be dragged And dropped.
Public Sub SetDragModeAndData(tMode As Object,DataIDs() As String,DataObjects() As Object)
Mode = tMode
DataID = DataIDs
DataObject = DataObjects
StartDrag = True
DragboardImg = Null
DragboardImgOffsetX = 0
DragboardImgOffsetY = 0
End Sub
'Set the drag And drop operation parameters.
'
'TransferMode can be one of
'COPY Indicates copying of data Is supported Or intended.
'LINK Indicates linking of data Is supported Or intended.
'MOVE Indicates moving of data Is supported Or intended.
'DataIDs is an array that identifies the type of data to be dropped in this process.
'This could be a mime type if drag/dropping data to/from outside a B4j application, or an arbitrary string to
'identify the data as specific to this app.
'There may be more than one version of the data on the clipboard, an application could pass a plaintext version('text/plain') and an html version('text/html')
'you can choose which version you want to use by calling e.GetDataObjectForId(DataId) specifying the appropriate DataId.
'
'DataObjects Is the array of objects (relating to the DataID's that will be dragged And dropped.
'DragboardImage will be displayed with the mouse cursor while the drag is taking place, pass Null for no Image.
'If you attach an image, an additional DataID and Object is automatically added to the Dragboard contents.
Public Sub SetDragModeAndData2(tMode As Object,DataIDs() As String,DataObjects() As Object,DragboardImage As Image)
Mode = tMode
DataID = DataIDs
DataObject = DataObjects
StartDrag = True
DragboardImg = DragboardImage
DragboardImgOffsetX = 0
DragboardImgOffsetY = 0
End Sub
'Set the drag And drop operation parameters.
'
'TransferMode can be one of
'COPY Indicates copying of data Is supported Or intended.
'LINK Indicates linking of data Is supported Or intended.
'MOVE Indicates moving of data Is supported Or intended.
'DataIDs is an array that identifies the type of data to be dropped in this process.
'This could be a mime type if drag/dropping data to/from outside a B4j application, or an arbitrary string to
'identify the data as specific to this app.
'There may be more than one version of the data on the clipboard, an application could pass a plaintext version('text/plain') and an html version('text/html')
'you can choose which version you want to use by calling e.GetDataObjectForId(DataId) specifying the appropriate DataId.
'
'DataObjects : the array of objects (relating to the DataID's that will be dragged And dropped.
'DragboardImage : will be displayed with the mouse cursor while the drag is taking place, pass Null for no Image.
'If you attach an image, an additional DataID and Object is automatically added to the Dragboard contents.
'ImageOffsetX : The Xoffset for the image
'ImageOffsetY : The Yoffset for the image
Public Sub SetDragModeAndData3(tMode As Object,DataIDs() As String,DataObjects() As Object,DragboardImage As Image,ImageOffsetX As Double,ImageOffsetY As Double)
Mode = tMode
DataID = DataIDs
DataObject = DataObjects
StartDrag = True
DragboardImg = DragboardImage
DragboardImgOffsetX = ImageOffsetX
DragboardImgOffsetY = ImageOffsetY
End Sub
'Makes the specified node a drag target by adding the DragEntered, DragExited, DragOver And DragDrop events To it.
'
'After the drag-And-drop gesture Is started, any node Or scene that the mouse Is dragged over Is a potential target
'To drop the data. You specify which object accepts the data by implementing the DragOver event handler.
'
'For a successful drag-And-drop operation, you must implement the DragOver event handler, which calls the
'AcceptTransferModes(TransferMode) method of the event, passing the transfer modes that the target intends To
'accept. If none of the passed transfer modes are supported by the gesture source, the potential target does Not fit
'the given drag-And-drop gesture.
'
'When the mouse button Is released on the gesture target, which accepted previous DragOver events with a transfer Mode
'supported by the gesture source, Then the DragDropped event Is sent To the gesture target.
'
'In the DragDropped event handler, you must complete the drag-And-drop gesture by calling the SetDropCompleted(Boolean)
'method on the event otherwise the gesture Is considered unsuccessful.
'
'When the drag gesture enters the boundaries of a potential gesture target, the target receives a DragEntered event.
'When the drag gesture leaves the potential targets boundaries, the target receives a DragExited event.
'You can use the DragEntered And DragExited event handlers To change the targets appearance in order To provide visual
'feedback To the user. You should verify the DataID of the object And only change appearance If it Is an appropriate DataID.
Public Sub MakeDragTarget(pNode As Node, vEventName As String)
tEventName = vEventName
If SubExists(CallBack,tEventName & "_DragOver") Then
Dim Event As Object = AsJO(pNode).CreateEvent("javafx.event.EventHandler","DragOver",Null)
AsJO(pNode).RunMethod("setOnDragOver",Array(Event))
End If
If SubExists(CallBack,tEventName & "_DragEntered") Then
Dim Event As Object = AsJO(pNode).CreateEvent("javafx.event.EventHandler","DragEntered",Null)
AsJO(pNode).RunMethod("setOnDragEntered",Array(Event))
End If
If SubExists(CallBack,tEventName & "_DragExited") Then
Dim Event As Object = AsJO(pNode).CreateEvent("javafx.event.EventHandler","DragExited",Null)
AsJO(pNode).RunMethod("setOnDragExited",Array(Event))
End If
If SubExists(CallBack,tEventName & "_DragDropped") Then
Dim Event As Object = AsJO(pNode).CreateEvent("javafx.event.EventHandler","DragDropped",Null)
AsJO(pNode).RunMethod("setOnDragDropped",Array(Event))
End If
End Sub
#Region Target field event handlers
Private Sub DragOver_Event(MethodName As String,Args() As Object) As Object
Dim DE As DragEvent
DE.Initialize
DE.SetObject(Args(0))
CallSub2(CallBack,tEventName & "_DragOver",DE)
End Sub
Private Sub DragEntered_Event(MethodName As String,Args() As Object) As Object
Dim DE As DragEvent
DE.Initialize
DE.SetObject(Args(0))
CallSub2(CallBack,tEventName & "_DragEntered",DE)
End Sub
Private Sub DragExited_Event(MethodName As String,Args() As Object) As Object
Dim DE As DragEvent
DE.Initialize
DE.SetObject(Args(0))
CallSub2(CallBack,tEventName & "_DragExited",DE)
End Sub
Private Sub DragDropped_Event(MethodName As String,Args() As Object) As Object
Dim DE As DragEvent
DE.Initialize
DE.SetObject(Args(0))
CallSub2(CallBack,tEventName & "_DragDropped",DE)
End Sub
#End Region Target field event handlers
Private Sub AsMouseEvent(M As MouseEvent) As MouseEvent
Return M
End Sub
Private Sub AsJO(JO As JavaObject) As JavaObject
Return JO
End Sub