public class ItemDropInputMode<T extends IModelItem> extends DropInputMode
DropInputMode
providing a preview of the dragged item.
A dragged IModelItem
is visualized during the drag operation. In addition, this input mode supports snapping of
the dragged IModelItem
via the SnapContext
and highlighting the DropTarget
.
Highlighting is done via a HighlightIndicatorManager
.
DATA_FORMAT_DROP_ID
Modifier | Constructor and Description |
---|---|
protected |
ItemDropInputMode(Class expectedType)
Constructs a new instance of class
DropInputMode for the expected data type. |
Modifier and Type | Method and Description |
---|---|
void |
addItemCreatedListener(IEventHandler<ItemEventArgs<T>> itemCreatedEvent)
Adds the given listener for the
ItemCreated event that occurs when a new item gets created by this input mode. |
protected void |
cleanup()
|
protected void |
cleanupDropTarget()
Cleans up the drop target and its highlighting.
|
protected void |
cleanupPreview()
Cleans up the item preview.
|
protected void |
cleanupSnapContext()
Cleans up the snap context.
|
protected void |
collectSnapResults(Object source,
CollectSnapResultsEventArgs args)
Callback registered on the
SnapContext that collects
SnapResult s for the dragged element. |
protected T |
getDraggedItem()
Gets the currently dragged
IModelItem instance. |
IModelItem |
getDropTarget()
Gets the drop target at
SnappedMousePosition . |
protected IModelItem |
getDropTarget(PointD dragLocation)
Returns the drop target at the specified location.
|
IDropCreationCallback<T> |
getItemCreator()
Gets the callback for item creation.
|
protected IGraph |
getPreviewGraph()
Returns the graph displayed as item preview.
|
SnapContext |
getSnapContext()
The
SnapContext which is used to snap the dragged element during the drag. |
PointD |
getSnappedMousePosition()
Gets the current snapped mouse position during drag operations.
|
protected void |
initializeDropTarget()
Initializes the drop target.
|
protected void |
initializePreview()
Initializes the item preview.
|
protected void |
initializeSnapContext()
Initializes the snapping context.
|
boolean |
isDropTargetHighlightEnabled()
Switches highlighting the drop target on and off.
|
boolean |
isPreviewEnabled()
Determines whether a preview of the dragged element is displayed during the drag.
|
boolean |
isSnappingEnabled()
Switches snapping on and off.
|
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 |
onItemCreated(ItemEventArgs<T> args)
Called whenever a new item is created.
|
protected void |
populatePreviewGraph(IGraph previewGraph)
Subclasses shall fill the specified graph that is used to preview the dragged item.
|
void |
removeItemCreatedListener(IEventHandler<ItemEventArgs<T>> itemCreatedEvent)
Removes the given listener for the
ItemCreated event that occurs when a new item gets created by this input
mode. |
protected void |
setDragLocation(PointD location)
Sets the
drag location and calls updatePreview(IGraph, PointD) to
update the layout of item preview based on the mouse coordinates and the results of the
SnapContext . |
protected void |
setDropTarget(IModelItem newDropTarget)
Gets the drop target at
SnappedMousePosition |
void |
setDropTargetHighlightEnabled(boolean value)
Switches highlighting the drop target on and off.
|
void |
setItemCreator(IDropCreationCallback<T> value)
Sets the callback for item creation.
|
void |
setPreviewEnabled(boolean value)
Determines whether a preview of the dragged element is displayed during the drag.
|
void |
setSnapContext(SnapContext value)
The
SnapContext which is used to snap the dragged element during the drag. |
void |
setSnappingEnabled(boolean value)
Switches snapping on and off.
|
protected void |
updateDropTarget(PointD dragLocation)
|
protected void |
updatePreview(IGraph previewGraph,
PointD dragLocation)
Subclasses shall update the
preview graph so the dragged item is displayed at the specified
dragLocation . |
addDragDroppedListener, addDragEnteredListener, addDragLeftListener, addDragOverListener, adjustTransferMode, cancel, createInputModeEventArgs, getController, getDropData, getDropData, getDropDataMap, getDropLocation, getExpectedType, getInputModeContext, getLastDragEvent, getMousePosition, getPriority, getTransferMode, getValidDropHitTestable, install, isCapturingMouseInputDuringDragEnabled, isEnabled, isExclusive, onCanceled, onConcurrencyControllerActivated, onStopped, removeDragDroppedListener, removeDragEnteredListener, removeDragLeftListener, removeDragOverListener, setCapturingMouseInputDuringDragEnabled, setDropDataMap, setEnabled, setExclusive, setPriority, setTransferMode, setValidDropHitTestable, stop, uninstall
protected ItemDropInputMode(Class expectedType)
DropInputMode
for the expected data type. This constructor only exists for
usage in child class.public final void addItemCreatedListener(IEventHandler<ItemEventArgs<T>> itemCreatedEvent)
ItemCreated
event that occurs when a new item gets created by this input mode.itemCreatedEvent
- The listener to add.removeItemCreatedListener(IEventHandler)
protected void cleanup()
cleanupSnapContext()
, cleanupPreview()
and cleanupDropTarget()
.
This method should be called for cleanup actions after a drag/drop gesture has been finished or canceled.
protected void cleanupDropTarget()
protected void cleanupPreview()
protected void cleanupSnapContext()
protected void collectSnapResults(Object source, CollectSnapResultsEventArgs args)
SnapContext
that collects
SnapResult
s for the dragged element.
The default implementation doesn't collect any snap results.
source
- The SnapContext
this callback is registered at.args
- The arguments describing the movement SnapResult
s shall be collected for.protected T getDraggedItem()
IModelItem
instance.
This implementation simply tries to cast the DropData
to the type of the dragged
items.
public final IModelItem getDropTarget()
SnappedMousePosition
.isDropTargetHighlightEnabled()
,
setDropTarget(IModelItem)
protected IModelItem getDropTarget(PointD dragLocation)
The drop target is highlighted, if DropTargetHighlightEnabled
is enabled. Per
default, null
is returned.
dragLocation
- The location to return the drop target for.null
if no drop target can be found.public final IDropCreationCallback<T> getItemCreator()
Called by method onDragDropped(InputModeEventArgs)
.
setItemCreator(IDropCreationCallback)
protected final IGraph getPreviewGraph()
null
if no preview is displayed at the moment.public final SnapContext getSnapContext()
SnapContext
which is used to snap the dragged element during the drag.
If set to null
(the default) this input mode tries to obtain the SnapContext
from the
IInputModeContext
. To explicitly disable snapping, a SnapContext
implementation
that does nothing has to be set to this instance.
setSnapContext(SnapContext)
public final PointD getSnappedMousePosition()
The position is returned in world coordinates according to the CanvasControl
into which this input mode is
installed. If SnappingEnabled
is false, this value corresponds with
MousePosition
.
protected void initializeDropTarget()
protected void initializePreview()
This method is called by onDragEntered(InputModeEventArgs)
. If a preview
shall be displayed
, the preview graph
is initialized and populatePreviewGraph(IGraph)
is called.
protected void initializeSnapContext()
This method is called by onDragEntered(InputModeEventArgs)
public final boolean isDropTargetHighlightEnabled()
setDropTargetHighlightEnabled(boolean)
public final boolean isPreviewEnabled()
setPreviewEnabled(boolean)
public final boolean isSnappingEnabled()
setSnappingEnabled(boolean)
protected void onConcurrencyControllerDeactivated()
DropInputMode
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.
onConcurrencyControllerDeactivated
in class DropInputMode
protected void onDragDropped(InputModeEventArgs eventArgs)
DropInputMode
onDragDropped
in class DropInputMode
protected void onDragEntered(InputModeEventArgs eventArgs)
Calls initializeSnapContext()
, initializePreview()
and initializeDropTarget()
.
onDragEntered
in class DropInputMode
protected void onDragExited(InputModeEventArgs eventArgs)
DropInputMode
onDragExited
in class DropInputMode
protected void onDraggedOver(InputModeEventArgs eventArgs)
DropInputMode
onDraggedOver
in class DropInputMode
protected void onItemCreated(ItemEventArgs<T> args)
protected void populatePreviewGraph(IGraph previewGraph)
previewGraph
- The preview graph to fill.public final void removeItemCreatedListener(IEventHandler<ItemEventArgs<T>> itemCreatedEvent)
ItemCreated
event that occurs when a new item gets created by this input
mode.itemCreatedEvent
- The listener to remove.addItemCreatedListener(IEventHandler)
protected void setDragLocation(PointD location)
drag location
and calls updatePreview(IGraph, PointD)
to
update the layout of item preview based on the mouse coordinates and the results of the
SnapContext
.setDragLocation
in class DropInputMode
location
- The current location of the mouse in world coordinates.protected final void setDropTarget(IModelItem newDropTarget)
SnappedMousePosition
newDropTarget
- The DropTarget to set.
HighlightDropTarget
getDropTarget()
public final void setDropTargetHighlightEnabled(boolean value)
value
- The DropTargetHighlightEnabled to set.isDropTargetHighlightEnabled()
public final void setItemCreator(IDropCreationCallback<T> value)
Called by method onDragDropped(InputModeEventArgs)
.
value
- The ItemCreator to set.getItemCreator()
public final void setPreviewEnabled(boolean value)
value
- The PreviewEnabled to set.isPreviewEnabled()
public final void setSnapContext(SnapContext value)
SnapContext
which is used to snap the dragged element during the drag.
If set to null
(the default) this input mode tries to obtain the SnapContext
from the
IInputModeContext
. To explicitly disable snapping, a SnapContext
implementation
that does nothing has to be set to this instance.
value
- The SnapContext to set.getSnapContext()
public final void setSnappingEnabled(boolean value)
value
- The SnappingEnabled to set.isSnappingEnabled()
protected void updateDropTarget(PointD dragLocation)
getDropTarget(PointD)
for SnappedMousePosition
and sets the returned
item as DropTarget
.
If DropTargetHighlightEnabled
is enabled, the highlight is updated as well.
dragLocation
- The location to update the drop target for.protected void updatePreview(IGraph previewGraph, PointD dragLocation)
preview graph
so the dragged item is displayed at the specified
dragLocation
.previewGraph
- The preview graph to update.dragLocation
- The current drag location.