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
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();
}
};
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
ConstructorDescriptionConstructs 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 TypeMethodDescriptionvoid
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 thisILcdGXYController
has created a newObject
, initialized it and committed it to anILcdModel
.Returns the layer for which the controller is creating.Returns theILcdGXYNewControllerModel
thisTLcdGXYNewController
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.int
This method returns the sensitivity that will be used for snapping.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.void
mouseDragged
(MouseEvent aMouseEvent) void
mouseExited
(MouseEvent aMouseEvent) Only pans the view when an object is actively being created.void
mouseMoved
(MouseEvent aMouseEvent) void
mousePressed
(MouseEvent aMouseEvent) void
mouseReleased
(MouseEvent aMouseEvent) void
Enables the controller to give visual feedback on the current user interactions.void
setActionToTriggerAfterCommit
(ILcdAction aNewActionToTriggerAfterCommit) Sets theILcdAction
that will be triggered just after thisILcdGXYController
has created a newObject
and committed it to anILcdModel
.void
This cursor is only used when there is no specific cursor provided by the controller model.void
setNewControllerModel
(ALcdGXYNewControllerModel2 aControllerModel) Sets theILcdGXYNewControllerModel
to delegate to.void
This method sets the next controller in the chain for this controller.void
setSensitivity
(int aSensitivity) This method sets the sensitivity that should be used by painters/editors for snapping purposes.void
setSnappables
(ILcdGXYLayerSubsetList aSnappables) Sets the Objects to snap to when initializing a new created Object.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.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.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.void
startInteraction
(ILcdGXYView aGXYView) Sets up the controller to receive input through the view passed.void
terminateInteraction
(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, updateViewLocationAfterZoomSFCT
Methods 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, 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
-
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:ALcdGXYController
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
.- Specified by:
startInteraction
in interfaceILcdGXYController
- Overrides:
startInteraction
in classALcdGXYSmartController
- Parameters:
aGXYView
- theILcdGXYView
thisILcdGXYController
will interact with.- See Also:
-
terminateInteraction
Description copied from class:ALcdGXYController
Releases a few items. Can be redefined but this 'super' method should be called too.- Specified by:
terminateInteraction
in interfaceILcdGXYController
- Overrides:
terminateInteraction
in classALcdGXYSmartController
- Parameters:
aGXYView
- theILcdGXYView
thisILcdGXYController
interacted with.- See Also:
-
paint
Description copied from class:ALcdGXYController
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.
- Specified by:
paint
in interfaceILcdGXYController
- Overrides:
paint
in 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:
setCursor
in 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:
mousePressed
in interfaceMouseListener
- Overrides:
mousePressed
in classALcdGXYSmartController
-
mouseDragged
- Specified by:
mouseDragged
in interfaceMouseMotionListener
- Overrides:
mouseDragged
in classALcdGXYSmartController
-
mouseMoved
- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Overrides:
mouseMoved
in classALcdGXYSmartController
-
mouseReleased
- Specified by:
mouseReleased
in interfaceMouseListener
- Overrides:
mouseReleased
in classALcdGXYSmartController
-
mouseExited
Only pans the view when an object is actively being created.- Specified by:
mouseExited
in interfaceMouseListener
- Overrides:
mouseExited
in classALcdGXYSmartController
- Parameters:
aMouseEvent
- the mouse event indicating that the mouse has left the view.- See Also:
-
setNewControllerModel
Sets theILcdGXYNewControllerModel
to delegate to.- Parameters:
aControllerModel
- theILcdGXYNewControllerModel
to delegate to.- See Also:
-
getNewControllerModel
Returns theILcdGXYNewControllerModel
thisTLcdGXYNewController
delegates to.- Returns:
- the
ILcdGXYNewControllerModel
thisTLcdGXYNewController
delegates to. - See Also:
-
setActionToTriggerAfterCommit
Sets theILcdAction
that will be triggered just after thisILcdGXYController
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 thisILcdGXYController
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:
-
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, 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:
-
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 ofTLcdGXYContext
passed 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: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
- 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
- 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
- Parameters:
aEnd
- the controller to be appended to the end of the chain.
-
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.
-