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
comittingof 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 TLcdTouchPoints which are not-consumed, and marks the
TLcdTouchPoints it uses as consumed, similar to the ALcdGXYTouchChainableController
- Since:
- 10.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTLcdGXYTouchNewController(ALcdGXYNewControllerModel2 aNewControllerModel) Creates a new Controller with the specified new controller model. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddUndoableListener(ILcdUndoableListener aUndoableListener) Adds a listener to this source, so this listener is notified when something undoable has happened.voidThis method will append the passed controller to the end of the chain.booleanThis method indicates whether or not it's possible to cancel the creation of the current object.booleanThis method indicates whether are not an object is ready to be committed.booleancanRedo()This method indicates whether or not an creation step can be redone.booleancanUndo()This method indicates whether or not an creation step can be undone.voiddoCancel()IfcanCancel()returns true, this method will cancel the creation of the current object.voiddoCommit()IfcanCommit()returns true, this method will commit the object currently under creation, and trigger the action to trigger after commit if it's available.voiddoRedo()WhencanRedo()returns true, this method will redo the last creation step that was undone.voiddoUndo()WhencanUndo()returns true, this method will undo the last creation step.Returns theILcdActionthat will be will be triggered just after this controller component has created a newObject, initialized it and committed it to anILcdModel.intThis method returns the edit threshold currently used by this controller.Returns the layer visualizing the object that the controller is creating.intReturns the threshold for move events.Returns theALcdGXYNewControllerModel2this 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, ornullwhen snapping is disabled.voidhandleAWTEvent(AWTEvent aEvent) This is method is called when the target of the listener has a new AWTEvent available.booleanThis method indicates whether or not you can undo actions by touching the representation of the last point added in the current object.voidEnables the controller to give visual feedback on the current user interactions.protected voidThe specific implementation ofpaintfor this controller.voidremoveUndoableListener(ILcdUndoableListener aUndoableListener) Removes the specified listener so it is no longer notified.voidsetActionToTriggerAfterCommit(ILcdAction aNewActionToTriggerAfterCommit) Sets theILcdActionthat will be triggered just after this controller component has created a newObjectand committed it to anILcdModel.voidsetEditThreshold(int aEditThreshold) Sets the edit threshold.protected voidsetGXYView(ILcdGXYView aGXYView) Sets theILcdGXYViewthe controller is interacting with.voidsetMoveThreshold(int aMoveThreshold) Sets the threshold for move events.voidsetNewControllerModel(ALcdGXYNewControllerModel2 aControllerModel) Sets theALcdGXYNewControllerModel2to delegate to.voidThis method sets the next controller in the chain for this controller.voidsetSnappables(ILcdGXYLayerSubsetList aSnappables) Sets the Objects to snap to when initializing a new created Object.voidsetUndoOnSecondTouch(boolean aUndoOnSecondTouch) A setter to activate of deactivate undo on second touch behaviour.protected booleanshouldCommit(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method indicates that the object should be committed.protected booleanshouldEdit(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 booleanshouldUndo(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) This method controls when you should undo instead of edit.voidstartInteraction(ILcdGXYView aGXYView) Sets up the controller to receive input through the view passed.protected voidstartInteractionImpl(ILcdGXYView aGXYView) The specific implementation ofstartInteractionfor this controller.voidterminateInteraction(ILcdGXYView aGXYView) Releases a few items.protected voidterminateInteractionImpl(ILcdGXYView aGXYView) The specific implementation ofterminateInteractionfor this controller.Methods inherited from class com.luciad.view.gxy.controller.ALcdGXYChainableController
addStatusListener, removeStatusListenerMethods 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, viewRepaintMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:ILcdUndoableSourceAdds a listener to this source, so this listener is notified when something undoable has happened.- Specified by:
addUndoableListenerin interfaceILcdUndoableSource- Parameters:
aUndoableListener- The listener to be notified when something undoable has happened.
-
removeUndoableListener
Description copied from interface:ILcdUndoableSourceRemoves the specified listener so it is no longer notified.- Specified by:
removeUndoableListenerin interfaceILcdUndoableSource- Parameters:
aUndoableListener- The listener to remove.
-
handleAWTEvent
Description copied from interface:ILcdAWTEventListenerThis is method is called when the target of the listener has a new AWTEvent available.- Specified by:
handleAWTEventin interfaceILcdAWTEventListener- Parameters:
aEvent- The event to be handled.
-
setNewControllerModel
Sets theALcdGXYNewControllerModel2to delegate to.- Parameters:
aControllerModel- theALcdGXYNewControllerModel2to delegate to.- See Also:
-
getNewControllerModel
Returns theALcdGXYNewControllerModel2this controller delegates to.- Returns:
- the
ALcdGXYNewControllerModel2this 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, ornullto disable snapping- See Also:
-
getSnappables
Returns the Objects to snap to when initializing a new created Object, ornullwhen snapping is disabled.- Returns:
- the Objects to snap to when initializing a new created Object, or
nullwhen snapping is disabled - See Also:
-
setActionToTriggerAfterCommit
Sets theILcdActionthat will be triggered just after this controller component has created a newObjectand 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- theILcdActionto be triggered ornullif noILcdActionhas to be triggered.- See Also:
-
getActionToTriggerAfterCommit
Returns theILcdActionthat will be will be triggered just after this controller component has created a newObject, initialized it and committed it to anILcdModel.- Returns:
- the
ILcdActionto 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.getDeltaXoraContext.getDeltaYis 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 whenshouldEditreturns false.By default it returns true when
isUndoOnSecondTouchreturns true and theaContext.getDeltaXandaContext.getDeltaYare 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:ALcdGXYChainableControllerThe specific implementation ofstartInteractionfor this controller.- Overrides:
startInteractionImplin classALcdGXYChainableController- Parameters:
aGXYView- the view to start interaction with.
-
terminateInteractionImpl
Description copied from class:ALcdGXYChainableControllerThe specific implementation ofterminateInteractionfor this controller.- Overrides:
terminateInteractionImplin classALcdGXYChainableController- Parameters:
aGXYView- the view to terminate interaction with.
-
paintImpl
Description copied from class:ALcdGXYChainableControllerThe specific implementation ofpaintfor this controller.- Overrides:
paintImplin classALcdGXYChainableController- Parameters:
aGraphics- the graphics to be used for painting.
-
getNextGXYController
Description copied from interface:ILcdGXYChainableControllerReturns 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:
getNextGXYControllerin interfaceILcdGXYChainableController- Overrides:
getNextGXYControllerin classALcdGXYChainableController- Returns:
- a reference to the next controller.
- See Also:
-
setNextGXYController
Description copied from interface:ILcdGXYChainableControllerThis 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:
setNextGXYControllerin interfaceILcdGXYChainableController- Overrides:
setNextGXYControllerin classALcdGXYChainableController- Parameters:
aNext- the reference to the controller that will be the next element in the chain- See Also:
-
appendGXYController
Description copied from interface:ILcdGXYChainableControllerThis 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:
appendGXYControllerin interfaceILcdGXYChainableController- Overrides:
appendGXYControllerin classALcdGXYChainableController- Parameters:
aEnd- the controller to be appended to the end of the chain.
-
startInteraction
Description copied from class:ALcdGXYChainableControllerSets up the controller to receive input through the view passed.All
ILcdGXYViewimplementations that support interaction call this method when the controller has been made active withsetGXYControlleron 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:
startInteractionin interfaceILcdGXYController- Overrides:
startInteractionin classALcdGXYChainableController- Parameters:
aGXYView- theILcdGXYViewthisILcdGXYControllerwill interact with.- See Also:
-
terminateInteraction
Description copied from class:ALcdGXYChainableControllerReleases 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:
terminateInteractionin interfaceILcdGXYController- Overrides:
terminateInteractionin classALcdGXYChainableController- Parameters:
aGXYView- theILcdGXYViewthisILcdGXYControllerinteracted with.- See Also:
-
paint
Description copied from class:ALcdGXYChainableControllerEnables 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:
paintin interfaceILcdGXYController- Overrides:
paintin classALcdGXYChainableController- Parameters:
aGraphics- the Graphics on which the view was rendered.- See Also:
-
setGXYView
Description copied from class:ALcdGXYControllerSets theILcdGXYViewthe controller is interacting with.This method is called when
ILcdGXYView.setGXYControlleris used to set anILcdGXYControlleractive on anILcdGXYView.- Overrides:
setGXYViewin 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
-