Class TLcdGXYTouchNewController
- All Implemented Interfaces:
ILcdUndoableSource
,ILcdAWTEventListener
,ILcdStatusSource
,ILcdGXYChainableController
,ILcdGXYController
,Serializable
- the object to
create
; - the initialization of the object through a series of
edit steps
; - the
comitting
of the domain object to a model.
Typical use
To interactively create a new object, implement a controller model providing a target layer and an uninitialized new domain object, and configure a corresponding controller on the view:
ALcdGXYNewControllerModel2 controllerModel = new ALcdGXYNewControllerModel2() {
public ILcdGXYLayer getGXYLayer(Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) {
return myLayer;
}
public Object create(int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) {
return new MyDomainObject();
}
};
TLcdGXYTouchNewController controller = new TLcdGXYTouchNewController(controllerModel);
view.setGXYController(controller);
Typically you also want user interface elements to indicate if creation should end (e.g. when creating a polyline).
See samples.gxy.touch.editing.TouchNewController
for an example of this.This controller supports snapping if snapping candidates are
configured
.
Undo behavior
This controller supports undo operations while creating, as well as after the creation has been finalized. The methodscanUndo()
and canRedo()
can be used to check
whether an undo or redo operation is possible at any given time during the creation process. The
methods doUndo()
and doRedo()
will respectively undo the last creation
interaction or redo the last action that was undone.
After creation has finished (the object is committed), all registered ILcdUndoableListeners
are notified with an undoable that will remove the object from the layer.Customizing the editing process
The methodsshouldCommit
, shouldEdit
,
and shouldUndo
can be overridden to map mouse events to specific
editing behaviour.In addition, some actions can be called programmatically. The methods
canUndo()
,
canRedo()
, canCommit()
and canCancel()
indicate whether or not an undo,
redo, commit or cancel action are possible at the moment. The methods doUndo()
,
doRedo()
, doCommit()
and doCancel()
will execute the actions when possible.
See ALcdGXYNewControllerModel2
for a more detailed explanation of the interaction with the controller model.
Use in a controller chain
This controller implementsILcdGXYChainableController
,
which means it can choose to disregard received AWTEvents and pass them on to an other component.
This controller will automatically pass on all events but instances of TLcdTouchEvent
. Even so it will only use one touch at a time. A second
touch while the first isn't lifted will be delegated.
This controller only handles TLcdTouchPoint
s which are not-consumed, and marks the
TLcdTouchPoint
s it uses as consumed, similar to the ALcdGXYTouchChainableController
- Since:
- 10.0
- See Also:
-
Constructor Summary
ConstructorDescriptionTLcdGXYTouchNewController
(ALcdGXYNewControllerModel2 aNewControllerModel) Creates a new Controller with the specified new controller model. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addUndoableListener
(ILcdUndoableListener aUndoableListener) Adds a listener to this source, so this listener is notified when something undoable has happened.void
This method will append the passed controller to the end of the chain.boolean
This method indicates whether or not it's possible to cancel the creation of the current object.boolean
This method indicates whether are not an object is ready to be committed.boolean
canRedo()
This method indicates whether or not an creation step can be redone.boolean
canUndo()
This method indicates whether or not an creation step can be undone.void
doCancel()
IfcanCancel()
returns true, this method will cancel the creation of the current object.void
doCommit()
IfcanCommit()
returns true, this method will commit the object currently under creation, and trigger the action to trigger after commit if it's available.void
doRedo()
WhencanRedo()
returns true, this method will redo the last creation step that was undone.void
doUndo()
WhencanUndo()
returns true, this method will undo the last creation step.Returns theILcdAction
that will be will be triggered just after this controller component has created a newObject
, initialized it and committed it to anILcdModel
.int
This method returns the edit threshold currently used by this controller.Returns the layer visualizing the object that the controller is creating.int
Returns the threshold for move events.Returns theALcdGXYNewControllerModel2
this controller delegates to.Returns a reference to the controller that is located after this one in a chain, or null if this controller is the last element of the chain.Returns the object that the controller is creating.Returns the Objects to snap to when initializing a new created Object, ornull
when snapping is disabled.void
handleAWTEvent
(AWTEvent aEvent) This is method is called when the target of the listener has a new AWTEvent available.boolean
This method indicates whether or not you can undo actions by touching the representation of the last point added in the current object.void
Enables the controller to give visual feedback on the current user interactions.protected void
The specific implementation ofpaint
for this controller.void
removeUndoableListener
(ILcdUndoableListener aUndoableListener) Removes the specified listener so it is no longer notified.void
setActionToTriggerAfterCommit
(ILcdAction aNewActionToTriggerAfterCommit) Sets theILcdAction
that will be triggered just after this controller component has created a newObject
and committed it to anILcdModel
.void
setEditThreshold
(int aEditThreshold) Sets the edit threshold.protected void
setGXYView
(ILcdGXYView aGXYView) Sets theILcdGXYView
the controller is interacting with.void
setMoveThreshold
(int aMoveThreshold) Sets the threshold for move events.void
setNewControllerModel
(ALcdGXYNewControllerModel2 aControllerModel) Sets theALcdGXYNewControllerModel2
to delegate to.void
This method sets the next controller in the chain for this controller.void
setSnappables
(ILcdGXYLayerSubsetList aSnappables) Sets the Objects to snap to when initializing a new created Object.void
setUndoOnSecondTouch
(boolean aUndoOnSecondTouch) A setter to activate of deactivate undo on second touch behaviour.protected boolean
shouldCommit
(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method indicates that the object should be committed.protected boolean
shouldEdit
(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method controls when a edit should take place ( placing a point ).protected boolean
shouldUndo
(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method controls when you should undo instead of edit.void
startInteraction
(ILcdGXYView aGXYView) Sets up the controller to receive input through the view passed.protected void
startInteractionImpl
(ILcdGXYView aGXYView) The specific implementation ofstartInteraction
for this controller.void
terminateInteraction
(ILcdGXYView aGXYView) Releases a few items.protected void
terminateInteractionImpl
(ILcdGXYView aGXYView) The specific implementation ofterminateInteraction
for this controller.Methods inherited from class com.luciad.view.gxy.controller.ALcdGXYChainableController
addStatusListener, removeStatusListener
Methods inherited from class com.luciad.view.gxy.controller.ALcdGXYController
asGXYController, fireStatusEvent, getCursor, getGXYView, getIcon, getName, getShortDescription, isTraceOn, registerInstance, retrieveGXYViewXYWorldTransformation, setClassTraceOn, setCursor, setIcon, setName, setShortDescription, setTraceOn, viewRepaint
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.view.gxy.ILcdGXYController
getCursor, getIcon, getLayered, getName, getShortDescription, viewRepaint
-
Constructor Details
-
TLcdGXYTouchNewController
Creates a new Controller with the specified new controller model.- Parameters:
aNewControllerModel
- The new controller model that will be used by this controller.
-
-
Method Details
-
addUndoableListener
Description copied from interface:ILcdUndoableSource
Adds a listener to this source, so this listener is notified when something undoable has happened.- Specified by:
addUndoableListener
in interfaceILcdUndoableSource
- Parameters:
aUndoableListener
- The listener to be notified when something undoable has happened.
-
removeUndoableListener
Description copied from interface:ILcdUndoableSource
Removes the specified listener so it is no longer notified.- Specified by:
removeUndoableListener
in interfaceILcdUndoableSource
- Parameters:
aUndoableListener
- The listener to remove.
-
handleAWTEvent
Description copied from interface:ILcdAWTEventListener
This is method is called when the target of the listener has a new AWTEvent available.- Specified by:
handleAWTEvent
in interfaceILcdAWTEventListener
- Parameters:
aEvent
- The event to be handled.
-
setNewControllerModel
Sets theALcdGXYNewControllerModel2
to delegate to.- Parameters:
aControllerModel
- theALcdGXYNewControllerModel2
to delegate to.- See Also:
-
getNewControllerModel
Returns theALcdGXYNewControllerModel2
this controller delegates to.- Returns:
- the
ALcdGXYNewControllerModel2
this controller delegates to. - See Also:
-
setMoveThreshold
public void setMoveThreshold(int aMoveThreshold) Sets the threshold for move events.
A move event will only be handled if the move exceeds the threshold in either the x or y direction.
- Parameters:
aMoveThreshold
- the move threshold- See Also:
-
getMoveThreshold
public int getMoveThreshold()Returns the threshold for move events.
- Returns:
- the threshold for move events
- See Also:
-
setSnappables
Sets the Objects to snap to when initializing a new created Object.
When
null
, snapping is disabled.- Parameters:
aSnappables
- the new value for the snappables property, ornull
to disable snapping- See Also:
-
getSnappables
Returns the Objects to snap to when initializing a new created Object, ornull
when snapping is disabled.- Returns:
- the Objects to snap to when initializing a new created Object, or
null
when snapping is disabled - See Also:
-
setActionToTriggerAfterCommit
Sets theILcdAction
that will be triggered just after this controller component has created a newObject
and committed it to anILcdModel
. It might be interesting for example to set anILcdGXYController
( using aTLcdGXYSetControllerAction
) that can edit the newObject
, just after this one has been created and initialized. When no action is set, the new controller model will be requested for an object and a layer when creation has been finished or has been canceled.- Parameters:
aNewActionToTriggerAfterCommit
- theILcdAction
to be triggered ornull
if noILcdAction
has to be triggered.- See Also:
-
getActionToTriggerAfterCommit
Returns theILcdAction
that will be will be triggered just after this controller component has created a newObject
, initialized it and committed it to anILcdModel
.- Returns:
- the
ILcdAction
to be triggered after creation of a new Object. - See Also:
-
getEditThreshold
public int getEditThreshold()This method returns the edit threshold currently used by this controller.- Returns:
- the edit threshold
- See Also:
-
setEditThreshold
public void setEditThreshold(int aEditThreshold) Sets the edit threshold. This value controls when an edit will take place. The distance between an edit and a previous edit must be at larger than the value set here for the second edit to have effect.- Parameters:
aEditThreshold
- the new edit threshold.- See Also:
-
shouldEdit
protected boolean shouldEdit(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method controls when a edit should take place ( placing a point ). It is called before a new point is added to the object under construction.By default it returns true for the first edit operation, for clicks when the
aContext.getDeltaX
oraContext.getDeltaY
is greater than the edit threshold, and also for drag operations that have not been preceded by clicks.- Parameters:
aObject
- the object currently created.aEditCount
- the number of editsaGraphics
- the graphics the object is painted onaTouchPoint
- the touchPoint descriptor triggering this callaSnappables
- the snappablesaContext
- the context @return a boolean indicating whether or not a point should be added to the object under construction.- Returns:
- when true the new controller will edit ( add a point to the object under creation ).
-
shouldUndo
protected boolean shouldUndo(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method controls when you should undo instead of edit. It is called whenshouldEdit
returns false.By default it returns true when
isUndoOnSecondTouch
returns true and theaContext.getDeltaX
andaContext.getDeltaY
are smaller than the edit threshold.- Parameters:
aObject
- the object currently created.aEditCount
- the number of previous editsaGraphics
- the graphics the object is painted onaTouchPoint
- touchPoint descriptor triggering this callaSnappables
- the snappablesaContext
- the context @return a boolean indicating whether or not the last edit should be undone- Returns:
- when true the controller will undo the last edit action.
-
shouldCommit
protected boolean shouldCommit(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method indicates that the object should be committed. It is called after attempting to edit/undo. The default implementation uses theALcdGXYNewControllerModel2.getCreationStatus(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
method and returns true in any of the following cases:- the object is FINISHED and a drag operation is not ongoing
- the object is COMMITTABLE and the touch event is the end of a drag operation that has not been preceded by a click operation
- Parameters:
aObject
- the object currently created.aEditCount
- the number of previous editsaGraphics
- the graphics the object is painted onaTouchPoint
- touchPoint descriptor triggering this callaSnappables
- the snappablesaContext
- the context @return a boolean indicating whether or not the last edit should be undone- Returns:
- when true the controller will commit the current object.
-
startInteractionImpl
Description copied from class:ALcdGXYChainableController
The specific implementation ofstartInteraction
for this controller.- Overrides:
startInteractionImpl
in classALcdGXYChainableController
- Parameters:
aGXYView
- the view to start interaction with.
-
terminateInteractionImpl
Description copied from class:ALcdGXYChainableController
The specific implementation ofterminateInteraction
for this controller.- Overrides:
terminateInteractionImpl
in classALcdGXYChainableController
- Parameters:
aGXYView
- the view to terminate interaction with.
-
paintImpl
Description copied from class:ALcdGXYChainableController
The specific implementation ofpaint
for this controller.- Overrides:
paintImpl
in classALcdGXYChainableController
- Parameters:
aGraphics
- the graphics to be used for painting.
-
getNextGXYController
Description copied from interface:ILcdGXYChainableController
Returns a reference to the controller that is located after this one in a chain, or null if this controller is the last element of the chain.- Specified by:
getNextGXYController
in interfaceILcdGXYChainableController
- Overrides:
getNextGXYController
in classALcdGXYChainableController
- Returns:
- a reference to the next controller.
- See Also:
-
setNextGXYController
Description copied from interface:ILcdGXYChainableController
This method sets the next controller in the chain for this controller. You can set null if you want the chain to end. This method does not start or terminate any interaction. If you need to replace a controller while it's being used you are responsible for properly terminating and starting it yourself.- Specified by:
setNextGXYController
in interfaceILcdGXYChainableController
- Overrides:
setNextGXYController
in classALcdGXYChainableController
- Parameters:
aNext
- the reference to the controller that will be the next element in the chain- See Also:
-
appendGXYController
Description copied from interface:ILcdGXYChainableController
This method will append the passed controller to the end of the chain. The controller will be the stored as the next controller in the last element of the current chain.- Specified by:
appendGXYController
in interfaceILcdGXYChainableController
- Overrides:
appendGXYController
in classALcdGXYChainableController
- Parameters:
aEnd
- the controller to be appended to the end of the chain.
-
startInteraction
Description copied from class:ALcdGXYChainableController
Sets up the controller to receive input through the view passed.All
ILcdGXYView
implementations that support interaction call this method when the controller has been made active withsetGXYController
on the view, so this method shouldn't normally be called directly. Note that most view implementations add the controller as listener if appropriate before calling this method.Sets the cursor on the view and sets the view for which this controller is now active. Sends out a status event based on the
short description
.This method also calls
ALcdGXYChainableController.startInteraction(com.luciad.view.gxy.ILcdGXYView)
on the next controller. OverrideALcdGXYChainableController.startInteractionImpl(com.luciad.view.gxy.ILcdGXYView)
if you want to add your own behavior to this controller.- Specified by:
startInteraction
in interfaceILcdGXYController
- Overrides:
startInteraction
in classALcdGXYChainableController
- Parameters:
aGXYView
- theILcdGXYView
thisILcdGXYController
will interact with.- See Also:
-
terminateInteraction
Description copied from class:ALcdGXYChainableController
Releases a few items. Can be redefined but this 'super' method should be called too.This method also calls
ALcdGXYChainableController.terminateInteraction(com.luciad.view.gxy.ILcdGXYView)
on the next controller. OverrideALcdGXYChainableController.terminateInteractionImpl(com.luciad.view.gxy.ILcdGXYView)
if you want to add your own behavior to this controller.- Specified by:
terminateInteraction
in interfaceILcdGXYController
- Overrides:
terminateInteraction
in classALcdGXYChainableController
- Parameters:
aGXYView
- theILcdGXYView
thisILcdGXYController
interacted with.- See Also:
-
paint
Description copied from class:ALcdGXYChainableController
Enables the controller to give visual feedback on the current user interactions. Note that the controller is responsible for repainting the view.Empty implementation. Redefine this method to render on the Graphics on which the view is rendered.
This method also calls
ALcdGXYChainableController.paint(java.awt.Graphics)
on the next controller. OverrideALcdGXYChainableController.paintImpl(java.awt.Graphics)
if you want to add your own behavior to this controller.- Specified by:
paint
in interfaceILcdGXYController
- Overrides:
paint
in classALcdGXYChainableController
- Parameters:
aGraphics
- the Graphics on which the view was rendered.- See Also:
-
setGXYView
Description copied from class:ALcdGXYController
Sets theILcdGXYView
the controller is interacting with.This method is called when
ILcdGXYView.setGXYController
is used to set anILcdGXYController
active on anILcdGXYView
.- Overrides:
setGXYView
in classALcdGXYController
- Parameters:
aGXYView
- the view the controller is interacting with- See Also:
-
canCommit
public boolean canCommit()This method indicates whether are not an object is ready to be committed. It will return true when the controller is interacting with a view, a creation process is ongoing and the creation status returned by the new controller model (ALcdGXYNewControllerModel2.getCreationStatus(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
) is equal toALcdGXYNewControllerModel2.CreationStatus.COMMITTABLE
.- Returns:
- A boolean indicating whether are not the object under creation is ready to be committed.
-
doCommit
public void doCommit()IfcanCommit()
returns true, this method will commit the object currently under creation, and trigger the action to trigger after commit if it's available.- See Also:
-
canCancel
public boolean canCancel()This method indicates whether or not it's possible to cancel the creation of the current object. It will return true when this controller is interacting with a view and when a creation process is ongoing.- Returns:
- a boolean indicating if the creation of the current object can be cancelled.
-
doCancel
public void doCancel()IfcanCancel()
returns true, this method will cancel the creation of the current object.- See Also:
-
canUndo
public boolean canUndo()This method indicates whether or not an creation step can be undone. It will return true when this controller is interacting with a view, when a creation process is in progress, and when an undoable is available, meaning there has to have been at least one creation interaction.- Returns:
- a boolean indicating whether or not a undo operation is possible.
-
doUndo
public void doUndo()WhencanUndo()
returns true, this method will undo the last creation step. -
canRedo
public boolean canRedo()This method indicates whether or not an creation step can be redone. It will return true when this controller is interacting with a view, when a creation process is in progress, and when an redoable is available, meaning that at least one creation step has been undone.- Returns:
- a boolean indicating whether or not a redo operation is possible.
-
doRedo
public void doRedo()WhencanRedo()
returns true, this method will redo the last creation step that was undone. -
isUndoOnSecondTouch
public boolean isUndoOnSecondTouch()This method indicates whether or not you can undo actions by touching the representation of the last point added in the current object.- Returns:
- true when the undo on second touch behaviour is active, false otherwise.
- See Also:
-
setUndoOnSecondTouch
public void setUndoOnSecondTouch(boolean aUndoOnSecondTouch) A setter to activate of deactivate undo on second touch behaviour. When activated, you can undo actions by touching the representation of the last point added in the current object. The default value is false.- Parameters:
aUndoOnSecondTouch
- the boolean indicating whether or not the undo on second touch behaviour should be activated.- See Also:
-
getObject
Returns the object that the controller is creating. Note that this object can be replaced during the creation, for example, when callingALcdGXYNewControllerModel2.edit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.- Returns:
- the object that the controller is creating, or null if no object is being created
-
getGXYLayer
Returns the layer visualizing the object that the controller is creating.- Returns:
- the layer visualizing the object that the controller is creating, or null if no object is being created
-