public class DropInputMode extends Object implements IInputMode
CanvasControl
.
An instance of DropInputMode
is initialized for an expected data format in the constructor. There are four
events raised by an instance of this class.
DragEntered
is raised, if a drag operation enters the
CanvasControl
.
DragOver
is raised, if a drag operation moves over the CanvasControl
after having entered it.
DragDropped
is raised, if a drag is dropped onto the
CanvasControl
.
DragLeft
is raised, if a drag is operation leaves the
CanvasControl
.
Clients can query the current MousePosition
which is updated while a drag is in progress.
Clients get the data from the drag operation by calling DropData
from an event handler registered
for any of these events.
This mode is Exclusive
by default.
Modifier and Type | Field and Description |
---|---|
static DataFormat |
DATA_FORMAT_DROP_ID |
Constructor and Description |
---|
DropInputMode(Class expectedType)
Constructs a new instance of class
DropInputMode for the expected type of data. |
Modifier and Type | Method and Description |
---|---|
void |
addDragDroppedListener(IEventHandler<InputModeEventArgs> dragDroppedEvent)
Adds the given listener for the
DragDropped event that occurs when a drag operation is dropped onto the CanvasControl
into which this instance is installed. |
void |
addDragEnteredListener(IEventHandler<InputModeEventArgs> dragEnteredEvent)
Adds the given listener for the
DragEntered event that occurs when a drag operation enters the CanvasControl
into which this instance is installed. |
void |
addDragLeftListener(IEventHandler<InputModeEventArgs> dragLeftEvent)
Adds the given listener for the
DragLeft event that occurs when a drag operation leaves the CanvasControl
into which this instance is installed. |
void |
addDragOverListener(IEventHandler<InputModeEventArgs> dragOverEvent)
Adds the given listener for the
DragOver event that occurs when a drag operation drags over the CanvasControl
into which this instance is installed. |
protected boolean |
adjustTransferMode(DragEvent e)
Callback that adjusts the transfer mode accordingly.
|
void |
cancel()
Cleanly cancels this mode.
|
protected InputModeEventArgs |
createInputModeEventArgs()
Helper method that yields a suitably configured
InputModeEventArgs for this input mode. |
protected ConcurrencyController |
getController()
Returns the installed
Controller . |
Object |
getDropData()
Gets the data carried by a drag operation.
|
protected Object |
getDropData(Dragboard dragboard)
Gets the data carried by the drag operation.
|
Map |
getDropDataMap()
Returns the map that maps a drop id to in instance of the type this
DropInputMode was created for. |
PointD |
getDropLocation()
Gets the mouse position after dropping an item.
|
protected Class |
getExpectedType()
Returns the type of data this
DropInputMode instance can handle. |
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
DragEvent |
getLastDragEvent()
Gets the last processed drag event argument.
|
IPoint |
getMousePosition()
Gets the current mouse position during drag operations.
|
int |
getPriority()
The priority of this input mode.
|
TransferMode[] |
getTransferMode()
Gets the
TransferMode that will be used for drags on the canvas. |
IHitTestable |
getValidDropHitTestable()
Gets the
IHitTestable that determines whether the given location is a valid drop location. |
void |
install(IInputModeContext context,
ConcurrencyController controller)
Installs this mode into the given canvas.
|
boolean |
isCapturingMouseInputDuringDragEnabled()
Gets a value indicating whether to capture mouse input during drag operations.
|
boolean |
isEnabled()
Gets the enabled state of this input mode.
|
boolean |
isExclusive()
Gets a value indicating whether this mode will be the only one running when it has the mutex.
|
protected void |
onCanceled()
Called after
cancel() has been called. |
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onDragDropped(InputModeEventArgs eventArgs)
Called once a drag has been dropped on the canvas.
|
protected void |
onDragEntered(InputModeEventArgs eventArgs)
Called once a drag has entered the canvas.
|
protected void |
onDragExited(InputModeEventArgs eventArgs)
Called once a drag has left the canvas.
|
protected void |
onDraggedOver(InputModeEventArgs eventArgs)
Called whenever a drag is over the canvas.
|
protected void |
onStopped()
Called after
stop() has been called. |
void |
removeDragDroppedListener(IEventHandler<InputModeEventArgs> dragDroppedEvent)
Removes the given listener for the
DragDropped event that occurs when a drag operation is dropped onto the CanvasControl
into which this instance is installed. |
void |
removeDragEnteredListener(IEventHandler<InputModeEventArgs> dragEnteredEvent)
Removes the given listener for the
DragEntered event that occurs when a drag operation enters the CanvasControl
into which this instance is installed. |
void |
removeDragLeftListener(IEventHandler<InputModeEventArgs> dragLeftEvent)
Removes the given listener for the
DragLeft event that occurs when a drag operation leaves the CanvasControl
into which this instance is installed. |
void |
removeDragOverListener(IEventHandler<InputModeEventArgs> dragOverEvent)
Removes the given listener for the
DragOver event that occurs when a drag operation drags over the CanvasControl
into which this instance is installed. |
void |
setCapturingMouseInputDuringDragEnabled(boolean value)
Sets a value indicating whether to capture mouse input during drag operations.
|
protected void |
setDragLocation(PointD location)
This method updates the
MousePosition according to the coordinates passed in. |
void |
setDropDataMap(Map dropDataMap)
Sets the map that maps a drop id to in instance of the type this
DropInputMode was created for. |
void |
setEnabled(boolean value)
Sets the enabled state of this input mode.
|
void |
setExclusive(boolean value)
Sets a value indicating whether this mode will be the only one running when it has the mutex.
|
void |
setPriority(int value)
The priority of this input mode.
|
void |
setTransferMode(TransferMode... value)
Sets the
TransferMode that will be used for drags on the canvas. |
void |
setValidDropHitTestable(IHitTestable value)
Sets the
IHitTestable that determines whether the given location is a valid drop location. |
boolean |
stop()
Overridden to only return
true if this instance does not currently
have the input mutex . |
void |
uninstall(IInputModeContext context)
Uninstalls this mode from the canvas.
|
public static final DataFormat DATA_FORMAT_DROP_ID
public DropInputMode(Class expectedType)
DropInputMode
for the expected type of data.
The input mode fires events (see DragEntered
and
DragDropped
) only if a drag operation carries data conforming to the
given type.
expectedType
- This is a type which can be given to DragDropData#getData(Class)
.public final void addDragDroppedListener(IEventHandler<InputModeEventArgs> dragDroppedEvent)
DragDropped
event that occurs when a drag operation is dropped onto the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragDroppedEvent
- The listener to add.removeDragDroppedListener(IEventHandler)
public final void addDragEnteredListener(IEventHandler<InputModeEventArgs> dragEnteredEvent)
DragEntered
event that occurs when a drag operation enters the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragEnteredEvent
- The listener to add.removeDragEnteredListener(IEventHandler)
public final void addDragLeftListener(IEventHandler<InputModeEventArgs> dragLeftEvent)
DragLeft
event that occurs when a drag operation leaves the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragLeftEvent
- The listener to add.removeDragLeftListener(IEventHandler)
public final void addDragOverListener(IEventHandler<InputModeEventArgs> dragOverEvent)
DragOver
event that occurs when a drag operation drags over the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragOverEvent
- The listener to add.removeDragOverListener(IEventHandler)
protected boolean adjustTransferMode(DragEvent e)
e
- public void cancel()
cancel
in interface IInputMode
protected InputModeEventArgs createInputModeEventArgs()
InputModeEventArgs
for this input mode.protected final ConcurrencyController getController()
Controller
.public Object getDropData()
This is only valid, if a drag entered the CanvasControl
first.
protected Object getDropData(Dragboard dragboard)
getDropData()
with the current Dragboard
as argument. The dragboard is set after
a DragEvent.DRAG_ENTERED
event on the CanvasControl occurs and updated for a
DragEvent.DRAG_DROPPED
event that follows if an transfermode
is set.dragboard
- the dragboard that may contain the object that represents the drop data. This argument may be null.public Map getDropDataMap()
DropInputMode
was created for.public final PointD getDropLocation()
The position is returned in world coordinates according to the CanvasControl
into which this input mode is
installed.
protected final Class getExpectedType()
DropInputMode
instance can handle.public final IInputModeContext getInputModeContext()
IInputMode
null
if this instance is not installed.
Note that this instance should not be passed down to subordinate modes or instances. Instead a corresponding context
that has this instance set as the ParentInputMode
should be used.
getInputModeContext
in interface IInputMode
public final DragEvent getLastDragEvent()
public final IPoint getMousePosition()
The position is returned in world coordinates according to the CanvasControl
into which this input mode is
installed.
public final int getPriority()
IInputMode
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
getPriority
in interface IInputMode
public final TransferMode[] getTransferMode()
TransferMode
that will be used for drags on the canvas.setTransferMode(javafx.scene.input.TransferMode...)
public final IHitTestable getValidDropHitTestable()
IHitTestable
that determines whether the given location is a valid drop location.true
for valid drop locations.setValidDropHitTestable(IHitTestable)
public void install(IInputModeContext context, ConcurrencyController controller)
Clients should not call this method as this is handled by the framework.
install
in interface IInputMode
context
- the context to install this mode intocontroller
- The Controller
for this mode.CanvasControl
public final boolean isCapturingMouseInputDuringDragEnabled()
The default is true
and thus prevents mouse events from being processed by visuals in the canvas.
true
if mouse input should be captured during the drag; false
otherwise.setCapturingMouseInputDuringDragEnabled(boolean)
public boolean isEnabled()
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
setEnabled(boolean)
public final boolean isExclusive()
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
setExclusive(boolean)
protected void onCanceled()
cancel()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been canceled.
This implementation does nothing.
protected void onConcurrencyControllerActivated()
Active
property of the installed ConcurrencyController
has been set to true
.
Can be overridden in subclasses to perform additional actions after the mode has been activated.
Overriding implementations should call the base implementation.
protected void onConcurrencyControllerDeactivated()
Active
property of the installed ConcurrencyController
has been set to false
.
Can be overridden in subclasses to perform additional actions after the mode has been deactivated.
Overriding implementations should call the base implementation.
protected void onDragDropped(InputModeEventArgs eventArgs)
protected void onDragEntered(InputModeEventArgs eventArgs)
protected void onDragExited(InputModeEventArgs eventArgs)
protected void onDraggedOver(InputModeEventArgs eventArgs)
protected void onStopped()
stop()
has been called.
Can be overridden in subclasses to perform additional actions after the mode has been stopped.
This implementation does nothing.
public final void removeDragDroppedListener(IEventHandler<InputModeEventArgs> dragDroppedEvent)
DragDropped
event that occurs when a drag operation is dropped onto the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragDroppedEvent
- The listener to remove.addDragDroppedListener(IEventHandler)
public final void removeDragEnteredListener(IEventHandler<InputModeEventArgs> dragEnteredEvent)
DragEntered
event that occurs when a drag operation enters the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragEnteredEvent
- The listener to remove.addDragEnteredListener(IEventHandler)
public final void removeDragLeftListener(IEventHandler<InputModeEventArgs> dragLeftEvent)
DragLeft
event that occurs when a drag operation leaves the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragLeftEvent
- The listener to remove.addDragLeftListener(IEventHandler)
public final void removeDragOverListener(IEventHandler<InputModeEventArgs> dragOverEvent)
DragOver
event that occurs when a drag operation drags over the CanvasControl
into which this instance is installed.
No event is raised
Enabled
,
To get additional data for the event, clients should use the sender which is set to the sending DropInputMode
.
The IEventArgs
provide no useful data.
dragOverEvent
- The listener to remove.addDragOverListener(IEventHandler)
public final void setCapturingMouseInputDuringDragEnabled(boolean value)
The default is true
and thus prevents mouse events from being processed by visuals in the canvas.
value
- true
if mouse input should be captured during the drag; false
otherwise.isCapturingMouseInputDuringDragEnabled()
protected void setDragLocation(PointD location)
MousePosition
according to the coordinates passed in.
It is called prior to the onDragEntered(InputModeEventArgs)
, onDraggedOver(InputModeEventArgs)
, onDragDropped(InputModeEventArgs)
and onDragExited(InputModeEventArgs)
methods.
location
- The current location of the mouse in world coordinates.public void setDropDataMap(Map dropDataMap)
DropInputMode
was created for.dropDataMap
- The mapping between drop ids and drop data instances.public void setEnabled(boolean value)
Clients can use this property to disable or reenable this instance. This will set the Enabled
property of the installed Controller
so a disabled instance should never try to acquire the
input mutex.
value
- The Enabled to set.isEnabled()
public final void setExclusive(boolean value)
The value of this property will be delegated to the Exclusive
property of
the Controller
.
If this mode is marked as exclusive and has the mutex, all other modes added
to the same MultiplexingInputMode
will be deactivated. Otherwise it will always run
concurrently with all other modes.
value
- The Exclusive to set.isExclusive()
public final void setPriority(int value)
The priority will influence the order in which the modes will be installed
into the canvas control. The lower the priority value, the earlier it will be installed. If two modes are installed
using the same priority value, the first one will be installed earlier.
value
- The Priority to set.getPriority()
public final void setTransferMode(TransferMode... value)
TransferMode
that will be used for drags on the canvas.value
- The TransferMode to set.getTransferMode()
public final void setValidDropHitTestable(IHitTestable value)
IHitTestable
that determines whether the given location is a valid drop location.value
- The hit testable that yields true
for valid drop locations.getValidDropHitTestable()
public boolean stop()
true
if this instance does not currently
have the input mutex
.stop
in interface IInputMode
true
iff this instance does not own the mutex
.IInputMode.cancel()
public void uninstall(IInputModeContext context)
Clients should not call this method as this is handled by the framework.
uninstall
in interface IInputMode
context
- the context