Package com.luciad.view.gxy.controller
Class TLcdGXYNewController2
java.lang.Object
com.luciad.view.gxy.controller.ALcdGXYController
com.luciad.view.gxy.controller.ALcdGXYSmartController
com.luciad.view.gxy.controller.TLcdGXYNewController2
- All Implemented Interfaces:
ILcdUndoableSource,ILcdAWTEventListener,ILcdStatusSource,ILcdGXYChainableController,ILcdGXYController,KeyListener,MouseListener,MouseMotionListener,Serializable,EventListener
public class TLcdGXYNewController2
extends ALcdGXYSmartController
implements ILcdGXYChainableController
Controller to interactively create and initialize domain objects using mouse clicks or mouse drags.
This controller needs a controller model that determines the following:
The controller responds to the backspace and escape keys, going back one step and cancelling the creation respectively.
In addition, some actions can be called programmatically. The methods
- 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();
}
};
TLcdGXYNewController2 controller = new TLcdGXYNewController2(controllerModel);
view.setGXYController(controller);
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.The controller responds to the backspace and escape keys, going back one step and cancelling the creation respectively.
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.
- Since:
- 9.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a controller to create and initialize new objects via mouse interaction.TLcdGXYNewController2(ALcdGXYNewControllerModel2 aControllerModel) Constructs a controller to create and initialize new objects via mouse interaction. -
Method Summary
Modifier and TypeMethodDescriptionvoidThis 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 thisILcdGXYControllerhas created a newObject, initialized it and committed it to anILcdModel.Returns the layer for which the controller is creating.Returns theILcdGXYNewControllerModelthisTLcdGXYNewControllerdelegates 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.intThis method returns the sensitivity that will be used for snapping.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.voidmouseDragged(MouseEvent aMouseEvent) voidmouseExited(MouseEvent aMouseEvent) Only pans the view when an object is actively being created.voidmouseMoved(MouseEvent aMouseEvent) voidmousePressed(MouseEvent aMouseEvent) voidmouseReleased(MouseEvent aMouseEvent) voidEnables the controller to give visual feedback on the current user interactions.voidsetActionToTriggerAfterCommit(ILcdAction aNewActionToTriggerAfterCommit) Sets theILcdActionthat will be triggered just after thisILcdGXYControllerhas created a newObjectand committed it to anILcdModel.voidThis cursor is only used when there is no specific cursor provided by the controller model.voidsetNewControllerModel(ALcdGXYNewControllerModel2 aControllerModel) Sets theILcdGXYNewControllerModelto delegate to.voidThis method sets the next controller in the chain for this controller.voidsetSensitivity(int aSensitivity) This method sets the sensitivity that should be used by painters/editors for snapping purposes.voidsetSnappables(ILcdGXYLayerSubsetList aSnappables) Sets the Objects to snap to when initializing a new created Object.protected booleanshouldCommit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns whether the mouse event should trigger a commit of the object, given the context parameters.protected booleanshouldEdit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns whether the mouse event should trigger an edit of the object, given the context parameters.protected booleanshouldUndo(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns whether the mouse event should undo the last edit operation, given the context parameters.voidstartInteraction(ILcdGXYView aGXYView) Sets up the controller to receive input through the view passed.voidterminateInteraction(ILcdGXYView aGXYView) Releases a few items.Methods inherited from class com.luciad.view.gxy.controller.ALcdGXYSmartController
addUndoableListener, doPanGXYView, doZoomGXYView, fireUndoableEvent, getDownPanChars, getDownPanCodes, getLeftPanChars, getLeftPanCodes, getPanAbsDelta, getPanAbsDelta, getRightPanChars, getRightPanCodes, getUndoableListenerCount, getUpPanChars, getUpPanCodes, getZoomInChars, getZoomInCodes, getZoomOutChars, getZoomOutCodes, isDragging, isPanOnMouseDragExit, isPanOnMouseMoveExit, isPanUndoable, isRequestFocusOnMouseEntered, isRequestFocusOnMousePressed, isTraceOn, isZoomUndoable, keyPressed, keyReleased, keyTyped, mouseClicked, mouseEntered, removeUndoableListener, setDownPanChars, setDownPanCodes, setIsDragging, setLeftPanChars, setLeftPanCodes, setPanAbsDelta, setPanOnMouseDragExit, setPanOnMouseMoveExit, setPanUndoable, setRequestFocusOnMouseEntered, setRequestFocusOnMousePressed, setRightPanChars, setRightPanCodes, setTraceOn, setUpPanChars, setUpPanCodes, setZoomInChars, setZoomInCodes, setZoomOutChars, setZoomOutCodes, setZoomUndoable, updateViewLocationAfterZoomSFCTMethods inherited from class com.luciad.view.gxy.controller.ALcdGXYController
addStatusListener, asGXYController, fireStatusEvent, getCursor, getGXYView, getIcon, getName, getShortDescription, registerInstance, removeStatusListener, retrieveGXYViewXYWorldTransformation, setClassTraceOn, setGXYView, setIcon, setName, setShortDescription, 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
-
TLcdGXYNewController2
public TLcdGXYNewController2()Constructs a controller to create and initialize new objects via mouse interaction. Note that a controller model has to be set before this controller can be used on a view.- See Also:
-
TLcdGXYNewController2
Constructs a controller to create and initialize new objects via mouse interaction.- Parameters:
aControllerModel- the model that defines what type of object will be created and how they are edited and added to the view.
-
-
Method Details
-
startInteraction
Description copied from class:ALcdGXYControllerSets 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.- Specified by:
startInteractionin interfaceILcdGXYController- Overrides:
startInteractionin classALcdGXYSmartController- Parameters:
aGXYView- theILcdGXYViewthisILcdGXYControllerwill interact with.- See Also:
-
terminateInteraction
Description copied from class:ALcdGXYControllerReleases a few items. Can be redefined but this 'super' method should be called too.- Specified by:
terminateInteractionin interfaceILcdGXYController- Overrides:
terminateInteractionin classALcdGXYSmartController- Parameters:
aGXYView- theILcdGXYViewthisILcdGXYControllerinteracted with.- See Also:
-
paint
Description copied from class:ALcdGXYControllerEnables 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.
- Specified by:
paintin interfaceILcdGXYController- Overrides:
paintin classALcdGXYController- Parameters:
aGraphics- the Graphics on which the view was rendered.
-
setCursor
This cursor is only used when there is no specific cursor provided by the controller model.- Overrides:
setCursorin classALcdGXYController- Parameters:
aCursor- The cursor to use when no specific cursor is available.
-
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. -
mousePressed
- Specified by:
mousePressedin interfaceMouseListener- Overrides:
mousePressedin classALcdGXYSmartController
-
mouseDragged
- Specified by:
mouseDraggedin interfaceMouseMotionListener- Overrides:
mouseDraggedin classALcdGXYSmartController
-
mouseMoved
- Specified by:
mouseMovedin interfaceMouseMotionListener- Overrides:
mouseMovedin classALcdGXYSmartController
-
mouseReleased
- Specified by:
mouseReleasedin interfaceMouseListener- Overrides:
mouseReleasedin classALcdGXYSmartController
-
mouseExited
Only pans the view when an object is actively being created.- Specified by:
mouseExitedin interfaceMouseListener- Overrides:
mouseExitedin classALcdGXYSmartController- Parameters:
aMouseEvent- the mouse event indicating that the mouse has left the view.- See Also:
-
setNewControllerModel
Sets theILcdGXYNewControllerModelto delegate to.- Parameters:
aControllerModel- theILcdGXYNewControllerModelto delegate to.- See Also:
-
getNewControllerModel
Returns theILcdGXYNewControllerModelthisTLcdGXYNewControllerdelegates to.- Returns:
- the
ILcdGXYNewControllerModelthisTLcdGXYNewControllerdelegates to. - See Also:
-
setActionToTriggerAfterCommit
Sets theILcdActionthat will be triggered just after thisILcdGXYControllerhas 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 thisILcdGXYControllerhas created a newObject, initialized it and committed it to anILcdModel.- Returns:
- the
ILcdActionto be triggered after creation of a new Object. - See Also:
-
setSnappables
Sets the Objects to snap to when initializing a new created Object. Whennull, 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:
-
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 for which the controller is creating. Normally, the controller retrieves the layer at the beginning of the creation process, before callingALcdGXYNewControllerModel2.create(int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext).- Returns:
- the layer for which the controller is creating, or null if no creation is ongoing
-
getSensitivity
public int getSensitivity()This method returns the sensitivity that will be used for snapping. It indicates how far (in screen coordinates) the input location (mouse cursor, etc...) can be from the visual representation of an object on the screen and still interact with it. This value will be passed to all created instances ofTLcdGXYContextpassed to the painters/editors.- Returns:
- the sensitivity to be used for snapping.
- See Also:
-
setSensitivity
public void setSensitivity(int aSensitivity) This method sets the sensitivity that should be used by painters/editors for snapping purposes.- Parameters:
aSensitivity- the sensitivity that will be used for snapping.- See Also:
-
shouldEdit
protected boolean shouldEdit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns whether the mouse event should trigger an edit of the object, given the context parameters. The default implementation delegates to theALcdGXYNewControllerModel2.shouldEdit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)method.- Parameters:
aObject- the object that may be editedaEditCount- the number of previous edit operationsaGraphics- the graphics onto which the object is paintedaMouseEvent- the mouse event that is eligible for causing an edit operationaSnappables- the list of potential snap targetsaContext- the GXY context information- Returns:
- true if the object should be edited
-
shouldUndo
protected boolean shouldUndo(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns whether the mouse event should undo the last edit operation, given the context parameters. The default implementation always returns false.- Parameters:
aObject- the object that may be revertedaEditCount- the number of previous edit operationsaGraphics- the graphics onto which the object is paintedaMouseEvent- the mouse event that is eligible for causing a revert operationaSnappables- the list of potential snap targetsaContext- the GXY context information- Returns:
- true if the object should be committed
-
shouldCommit
protected boolean shouldCommit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns whether the mouse event should trigger a commit of the object, given the context parameters. The default implementation delegates to theALcdGXYNewControllerModel2.shouldCommit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)method.- Parameters:
aObject- the object that may be committedaEditCount- the number of previous edit operationsaGraphics- the graphics onto which the object is paintedaMouseEvent- the mouse event that is eligible for causing a commit operationaSnappables- the list of potential snap targetsaContext- the GXY context information- Returns:
- true if the object should be committed
-
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- 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- 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- Parameters:
aEnd- the controller to be appended to the end of the chain.
-
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.
-