public class CreateBendInputMode extends Object implements IInputMode
IInputMode
used for recognizing the gesture of creating IBend
s in an IGraph
.
This mode is used by GraphEditorInputMode
but can be used stand-alone, too. Client code should register with the
BendCreated
event to perform additional actions after the bend has
been created.
This mode is Exclusive
by default.
Constructor and Description |
---|
CreateBendInputMode()
Creates a new instance that will use the
IGraph from the InputModeContext to
create bends in. |
Modifier and Type | Method and Description |
---|---|
void |
addBendCreatedListener(IEventHandler<BendEventArgs> bendCreatedEvent)
Adds the given listener for the
BendCreated event that occurs once a bend creation gesture has been recognized. |
void |
addDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
Adds the given listener for the
DragCanceled event that occurs when the drag has been canceled. |
void |
addDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Adds the given listener for the
Dragged event that occurs at the end of every drag. |
void |
addDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Adds the given listener for the
Dragging event that occurs at the start of every drag. |
protected void |
arm()
Called when a bend creation gesture can be started at the current mouse pointer location.
|
void |
cancel()
Cancels the editing of this mode.
|
protected IBend |
createBend(IEdge edge,
PointD location)
Creates the bend.
|
protected IInputModeContext |
createInputModeContext()
Creates an
IInputModeContext for use with the upcoming IBendCreator.createBend(IInputModeContext, IGraph, IEdge, PointD)
call in createBend(IEdge, PointD) . |
protected void |
disarm()
Called when a bend creation gesture can no longer be started at the current mouse pointer location.
|
protected void |
dragSegment(IEdge edge,
PointD dragLocation)
Updates the
OrthogonalSegmentSplittingEnabled property and then delegates
to createBend(IEdge, PointD) . |
Cursor |
getArmedCursor()
Gets the cursor to use when this mode is in "armed" state.
|
IHitTestable |
getBeginHitTestable()
Gets the
IHitTestable that determines where bends may be created. |
protected ConcurrencyController |
getController()
Returns the installed
Controller . |
IEventRecognizer |
getDraggedRecognizer()
Gets the "dragged" recognizer.
|
protected IEdge |
getEdge(PointD location)
Finds the edge at the given coordinate.
|
IGraph |
getGraph()
Gets the Graph this mode is acting upon.
|
IInputModeContext |
getInputModeContext()
Returns the context instance this mode is currently installed in or
null if this instance is not installed. |
PointD |
getLocation()
Gets the location where the bend creation gesture was initialized.
|
IEventRecognizer |
getMovedRecognizerTouch()
Gets the "moved" state recognizer specifically for touch input.
|
IEventRecognizer |
getPrepareRecognizerTouch()
Gets the "pressed" state recognizer specifically for touch input.
|
IEventRecognizer |
getPressedRecognizer()
Gets the "pressed" state recognizer.
|
int |
getPriority()
The priority of this input mode.
|
IEventRecognizer |
getReleasedRecognizer()
Gets the "released" recognizer.
|
IEventRecognizer |
getReleasedRecognizerTouch()
Gets the "released" state recognizer specifically for touch input.
|
IEventRecognizer |
getSplitOrthogonalSegmentRecognizer()
Gets the event recognizer that determines whether the bend creation should be treated as a split segment operation.
|
void |
install(IInputModeContext context,
ConcurrencyController controller)
Installs this mode into the given context that is provided by the canvas.
|
boolean |
isBendReusingEnabled()
Gets a property that determines whether this mode should use an existing bend in
createBend(IEdge, PointD) if
there is one found at the given location. |
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.
|
boolean |
isOrthogonalSegmentSplittingEnabled()
Gets a value indicating whether an orthogonal segment should be split by the last bend creation.
|
protected boolean |
isValidBegin(Object source,
IEventArgs args)
Determines whether the current location is valid to begin a bend creation gesture.
|
protected void |
onBendCreated(BendEventArgs args)
Triggers the
BendCreated event. |
protected void |
onCanceled()
Called after
cancel() has been called. |
protected void |
onConcurrencyControllerActivated()
|
protected void |
onConcurrencyControllerDeactivated()
|
protected void |
onDragCanceled(InputModeEventArgs inputModeEventArgs)
Triggers the
DragCanceled event. |
protected void |
onDragged(InputModeEventArgs inputModeEventArgs)
Callback triggered at the end of each drag.
|
protected void |
onDragging(InputModeEventArgs inputModeEventArgs)
Callback triggered at the start of each drag.
|
protected void |
onStopped()
Called after
stop() has been called. |
void |
removeBendCreatedListener(IEventHandler<BendEventArgs> bendCreatedEvent)
Removes the given listener for the
BendCreated event that occurs once a bend creation gesture has been
recognized. |
void |
removeDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
Removes the given listener for the
DragCanceled event that occurs when the drag has been canceled. |
void |
removeDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Removes the given listener for the
Dragged event that occurs at the end of every drag. |
void |
removeDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Removes the given listener for the
Dragging event that occurs at the start of every drag. |
void |
setArmedCursor(Cursor value)
Sets the cursor to use when this mode is in "armed" state.
|
void |
setBeginHitTestable(IHitTestable value)
Sets the
IHitTestable that determines where bends may be created. |
void |
setBendReusingEnabled(boolean value)
Sets a property that determines whether this mode should use an existing bend in
createBend(IEdge, PointD) if
there is one found at the given location. |
void |
setDraggedRecognizer(IEventRecognizer value)
Sets the "dragged" recognizer.
|
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 |
setMovedRecognizerTouch(IEventRecognizer value)
Sets the "moved" state recognizer specifically for touch input.
|
protected void |
setOrthogonalSegmentSplittingEnabled(boolean value)
Sets a value indicating whether an orthogonal segment should be split by the last bend creation.
|
void |
setPrepareRecognizerTouch(IEventRecognizer value)
Sets the "pressed" state recognizer specifically for touch input.
|
void |
setPressedRecognizer(IEventRecognizer value)
Sets the "pressed" state recognizer.
|
void |
setPriority(int value)
The priority of this input mode.
|
void |
setReleasedRecognizer(IEventRecognizer value)
Sets the "released" recognizer.
|
void |
setReleasedRecognizerTouch(IEventRecognizer value)
Sets the "released" state recognizer specifically for touch input.
|
void |
setSplitOrthogonalSegmentRecognizer(IEventRecognizer value)
Sets the event recognizer that determines whether the bend creation should be treated as a split segment operation.
|
boolean |
stop()
Called by the client in order to stop a current editing progress.
|
void |
uninstall(IInputModeContext context)
Uninstalls this mode from the given context.
|
public CreateBendInputMode()
IGraph
from the InputModeContext
to
create bends in.getGraph()
public final void addBendCreatedListener(IEventHandler<BendEventArgs> bendCreatedEvent)
BendCreated
event that occurs once a bend creation gesture has been recognized.bendCreatedEvent
- The listener to add.removeBendCreatedListener(IEventHandler)
public final void addDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
DragCanceled
event that occurs when the drag has been canceled.dragCanceledEvent
- The listener to add.removeDragCanceledListener(IEventHandler)
public final void addDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Dragged
event that occurs at the end of every drag.draggedEvent
- The listener to add.removeDraggedListener(IEventHandler)
public final void addDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Dragging
event that occurs at the start of every drag.draggingEvent
- The listener to add.removeDraggingListener(IEventHandler)
protected void arm()
This implementation sets the PreferredCursor
to
ArmedCursor
.
public void cancel()
This implementation releases
the mutex if it is currently owned by this
instance and calls onCanceled()
.
cancel
in interface IInputMode
onCanceled()
protected IBend createBend(IEdge edge, PointD location)
The bend is created using the hit edge's IBendCreator
implementation, as obtained from the edge's
ILookup.lookup(Class)
.
edge
- The hit edge.location
- The coordinates of the hit.null
.createInputModeContext()
protected IInputModeContext createInputModeContext()
IInputModeContext
for use with the upcoming IBendCreator.createBend(IInputModeContext, IGraph, IEdge, PointD)
call in createBend(IEdge, PointD)
.IInputModeContext
.protected void disarm()
This implementation sets the PreferredCursor
back to null
.
protected void dragSegment(IEdge edge, PointD dragLocation)
OrthogonalSegmentSplittingEnabled
property and then delegates
to createBend(IEdge, PointD)
.
This method triggers the BendCreated
event if a bend is created.
edge
- The edge to create a bend for.dragLocation
- The location at which the user initiated the gesture.public final Cursor getArmedCursor()
setArmedCursor(Cursor)
public final IHitTestable getBeginHitTestable()
IHitTestable
that determines where bends may be created.setBeginHitTestable(IHitTestable)
protected final ConcurrencyController getController()
Controller
.public final IEventRecognizer getDraggedRecognizer()
This recognizer instance determines when the user is moving the selection
setDraggedRecognizer(IEventRecognizer)
protected IEdge getEdge(PointD location)
location
- The coordinates.public final IGraph getGraph()
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 PointD getLocation()
public final IEventRecognizer getMovedRecognizerTouch()
This recognizer instance will be used to determine when the user begins actually moves the selection. The default value
is TouchEventRecognizers.TOUCH_MOVED_PRIMARY
.
setMovedRecognizerTouch(IEventRecognizer)
public final IEventRecognizer getPrepareRecognizerTouch()
This recognizer instance will be used to determine when the user begins to move the selection. The default value is
TouchEventRecognizers.TOUCH_LONG_PRESSED_PRIMARY
.
setPrepareRecognizerTouch(IEventRecognizer)
public final IEventRecognizer getPressedRecognizer()
This recognizer instance will be used to determine when the user begins to move the selection.
setPressedRecognizer(IEventRecognizer)
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 IEventRecognizer getReleasedRecognizer()
This instance determines when the user has finished the move.
setReleasedRecognizer(IEventRecognizer)
public final IEventRecognizer getReleasedRecognizerTouch()
This recognizer instance will be used to determine when the finalized the gesture. The default value is
TouchEventRecognizers.TOUCH_UP_PRIMARY
.
setReleasedRecognizerTouch(IEventRecognizer)
public final IEventRecognizer getSplitOrthogonalSegmentRecognizer()
setSplitOrthogonalSegmentRecognizer(IEventRecognizer)
public void install(IInputModeContext context, ConcurrencyController controller)
In general a mode can only be installed into a single canvas at all times.
This method is called to initialize this instance. Subclasses should override this method to register the corresponding event handler delegates for the various input events they need to register with.
Overriding implementations should call the base implementation, first.
install
in interface IInputMode
context
- The context that this instance shall be installed into. The same instance will be passed to this instance during
IInputMode.uninstall(IInputModeContext)
. A reference to the context may be kept and queried during the time
the mode is installed.controller
- The Controller
for this mode.IInputMode.uninstall(IInputModeContext)
public final boolean isBendReusingEnabled()
createBend(IEdge, PointD)
if
there is one found at the given location.
The default is true
setBendReusingEnabled(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)
public final boolean isOrthogonalSegmentSplittingEnabled()
This property can be read by implementations of IBendCreator
if they retrieve this instance from their
ParentInputMode
. If this property is
true
, implementation are advised to treat the bend creation as a gesture that splits the segment into two.
getSplitOrthogonalSegmentRecognizer()
,
setOrthogonalSegmentSplittingEnabled(boolean)
protected boolean isValidBegin(Object source, IEventArgs args)
protected void onBendCreated(BendEventArgs args)
BendCreated
event.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 onDragCanceled(InputModeEventArgs inputModeEventArgs)
DragCanceled
event.inputModeEventArgs
- The event argument that contains context information.protected void onDragged(InputModeEventArgs inputModeEventArgs)
This method triggers the Dragged
event.
inputModeEventArgs
- The event argument that contains context information.protected void onDragging(InputModeEventArgs inputModeEventArgs)
This method triggers the Dragging
event.
inputModeEventArgs
- The event argument that contains context information.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 removeBendCreatedListener(IEventHandler<BendEventArgs> bendCreatedEvent)
BendCreated
event that occurs once a bend creation gesture has been
recognized.bendCreatedEvent
- The listener to remove.addBendCreatedListener(IEventHandler)
public final void removeDragCanceledListener(IEventHandler<InputModeEventArgs> dragCanceledEvent)
DragCanceled
event that occurs when the drag has been canceled.dragCanceledEvent
- The listener to remove.addDragCanceledListener(IEventHandler)
public final void removeDraggedListener(IEventHandler<InputModeEventArgs> draggedEvent)
Dragged
event that occurs at the end of every drag.draggedEvent
- The listener to remove.addDraggedListener(IEventHandler)
public final void removeDraggingListener(IEventHandler<InputModeEventArgs> draggingEvent)
Dragging
event that occurs at the start of every drag.draggingEvent
- The listener to remove.addDraggingListener(IEventHandler)
public final void setArmedCursor(Cursor value)
value
- The ArmedCursor to set.getArmedCursor()
public final void setBeginHitTestable(IHitTestable value)
IHitTestable
that determines where bends may be created.value
- The BeginHitTestable to set.getBeginHitTestable()
public final void setBendReusingEnabled(boolean value)
createBend(IEdge, PointD)
if
there is one found at the given location.
The default is true
value
- The BendReusingEnabled to set.isBendReusingEnabled()
public final void setDraggedRecognizer(IEventRecognizer value)
This recognizer instance determines when the user is moving the selection
value
- The "dragged" recognizer.getDraggedRecognizer()
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 setMovedRecognizerTouch(IEventRecognizer value)
This recognizer instance will be used to determine when the user begins actually moves the selection. The default value
is TouchEventRecognizers.TOUCH_MOVED_PRIMARY
.
value
- The touch move recognizer.getMovedRecognizerTouch()
protected final void setOrthogonalSegmentSplittingEnabled(boolean value)
This property can be read by implementations of IBendCreator
if they retrieve this instance from their
ParentInputMode
. If this property is
true
, implementation are advised to treat the bend creation as a gesture that splits the segment into two.
value
- The OrthogonalSegmentSplittingEnabled to set.getSplitOrthogonalSegmentRecognizer()
,
isOrthogonalSegmentSplittingEnabled()
public final void setPrepareRecognizerTouch(IEventRecognizer value)
This recognizer instance will be used to determine when the user begins to move the selection. The default value is
TouchEventRecognizers.TOUCH_LONG_PRESSED_PRIMARY
.
value
- The "pressed" recognizer.getPrepareRecognizerTouch()
public final void setPressedRecognizer(IEventRecognizer value)
This recognizer instance will be used to determine when the user begins to move the selection.
value
- The "pressed" recognizer.getPressedRecognizer()
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 setReleasedRecognizer(IEventRecognizer value)
This instance determines when the user has finished the move.
value
- The "released" recognizer.getReleasedRecognizer()
public final void setReleasedRecognizerTouch(IEventRecognizer value)
This recognizer instance will be used to determine when the finalized the gesture. The default value is
TouchEventRecognizers.TOUCH_UP_PRIMARY
.
value
- The touch released recognizer.getReleasedRecognizerTouch()
public final void setSplitOrthogonalSegmentRecognizer(IEventRecognizer value)
value
- The event recognizer that determines whether orthogonal edge segments should be split during the bend creation.getSplitOrthogonalSegmentRecognizer()
public boolean stop()
IInputMode
This should stop the current edit, if one is in progress and possibly commit all of the changes. If stopping is not
possible, this method can return false
stop
in interface IInputMode
true
if and only if the editing has been stopped or there was no edit in progressIInputMode.cancel()
public void uninstall(IInputModeContext context)
This code should clean up all changes made to the canvas in the IInputMode.install(IInputModeContext, ConcurrencyController)
method. After a mode has been uninstalled it can be installed again into the same or another canvas.
Overriding implementations should call the base implementation after their own code.
uninstall
in interface IInputMode
context
- The context to deregister from. This is the same instance that had been passed to IInputMode.install(IInputModeContext, ConcurrencyController)
during installation.