Class ALcdGXYNewControllerModel2
- All Implemented Interfaces:
ILcdUndoableSource
- Direct Known Subclasses:
ALcdAPP6AGXYNewControllerModel
,ALcdMS2525bGXYNewControllerModel
,ALcyGXYNewControllerModel
ILcdGXYView
.
Once a defining position is decided upon (e.g. by a mouse click), the method
getGXYLayer
is called to retrieve a relevant layer and a new, uninitialized object is created
using the method create
.
Further initialization steps (e.g. by a mouse click), are executed by the method edit
, which
by default delegates the real work to the ILcdGXYEditor
of the object.
Finally, when the creation finishes, the commit
method ensures that the object is added to a
model and/or layer. From this moment on, visualization of and interaction with the object
is typically handed over to the layer.
While the creation process is ongoing (e.g., the user is moving the mouse), the
objects are not edited all the time, they are just painted in their temporary
state. The method paint
takes care of this. This method is typically
invoked often (e.g. on mouse move) while the creation process is ongoing.
At all times - before an edit, during an edit or after an edit - the correct mouse
cursor is provided by the method mouseCursor
.
This controller model fires undoable events for every edit step by reusing the
undoable events fired by the ILcdGXYEditor
s, or by cloning the object
if the editor does not implement ILcdUndoableSource
.
- Since:
- 9.0
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
A description of the creation status an object is in, used to make decisions on whether a certain input event should trigger editing or other operations.static class
Object representing all needed information about a snap target. -
Constructor Summary
ConstructorDescriptionCreates an new instance, ready to be used with aTLcdGXYNewController2
controller. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addUndoableListener
(ILcdUndoableListener aListener) Adds a listener to this source, so this listener is notified when something undoable has happened.void
cancel
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Cancels creation of the object.void
commit
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Commits the created object.abstract Object
create
(int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Creates an uninitialized model object, ready for editing.protected ILcdUndoable
createCommitUndoable
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Creates a newILcdUndoable
for committing the given object.edit
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Performs an edit operation on the object, given the context parameters.protected void
fireUndoableHappened
(ILcdUndoable aUndoable) Notifies all undoable listeners thataUndoable
has happened.getCreationStatus
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns the creation status of the object being created.abstract ILcdGXYLayer
getGXYLayer
(Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns a suitable layer for creating an object.Returns theILcdStringTranslator
set on this controller model.mouseCursor
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns the desired cursor for the given parameters, ornull
if no specific cursor is needed.void
paint
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Paints the object being created.void
removeUndoableListener
(ILcdUndoableListener aListener) Removes the specified listener so it is no longer notified.void
setStringTranslator
(ILcdStringTranslator aStringTranslator) Sets theILcdStringTranslator
that this controller model should use to translate theStrings
that will be visible in the user interface.boolean
shouldCommit
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Deprecated.This method depends on the kind of input (in this case a mouseEvent).boolean
shouldEdit
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Deprecated.This method depends on the kind of input (in this case a mouseEvent).boolean
shouldUndo
(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Deprecated.This method depends on the kind of input (in this case a mouseEvent).snapTarget
(Object aObjectToSnap, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Tries to retrieve a snap target from the givenaSnappables
.
-
Constructor Details
-
ALcdGXYNewControllerModel2
public ALcdGXYNewControllerModel2()Creates an new instance, ready to be used with aTLcdGXYNewController2
controller.
-
-
Method Details
-
getGXYLayer
public abstract ILcdGXYLayer getGXYLayer(Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns a suitable layer for creating an object. The layer is made available in the other method calls through theILcdGXYContext
object.This method may be called several times during the creation process; upon the first call,
aContext.getGXYLayer
will returnnull
. If the controller model does not support changing the layer during creation (e.g. due to incompatible objects), it should returnaContext.getGXYLayer
when this is notnull
.- Parameters:
aGraphics
- the graphics onto which created objects will be paintedaMouseEvent
- the mouse event causing the edit operation, or null if another input method is used.aSnappables
- the list of potential snap targetsaContext
- the GXY context information- Returns:
- a suitable layer to create an object for
- See Also:
-
create
public abstract Object create(int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Creates an uninitialized model object, ready for editing. The object may be edited and cloned several times before it is added to a model by thecommit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
method.- Parameters:
aEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which created objects will be paintedaMouseEvent
- the mouse event causing the edit operation, or null if another input method is usedaSnappables
- the list of potential snap targetsaContext
- the GXY context information, including the layer to create the object for- Returns:
- an uninitialized model object that may be edited and cloned, or null to cancel the creation process.
- See Also:
-
edit
public Object edit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Performs an edit operation on the object, given the context parameters. The default implementation uses the object's editor, snapping when possible.- Parameters:
aObject
- the object to editaEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which the object is paintedaMouseEvent
- the mouse event causing the edit operation, or null if another input method is usedaSnappables
- the list of potential snap targetsaContext
- the GXY context information- Returns:
- an edited version of aObject, or null if no edit was performed
- See Also:
-
commit
public void commit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Commits the created object. From this moment on, the object is no longer under creation. Hence, no further edit operations are performed, and the object will no longer be painted by this controller model. The default implementation adds the object to the context's layer, taking a write lock on the layer's model. Also, an undoable is created usingcreateCommitUndoable(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
and fired and the object is selected.- Parameters:
aObject
- the object to editaEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which the object is paintedaMouseEvent
- the mouse event causing the edit operation, or null if another input method is used.aSnappables
- the list of potential snap targetsaContext
- the GXY context information- See Also:
-
createCommitUndoable
protected ILcdUndoable createCommitUndoable(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Creates a newILcdUndoable
for committing the given object. The default implementation creates an undoable with display name "Create {0}", translated with the setILcdStringTranslator
and the domain object'stoString
value. The undo operation removes the object from the model. The default redo behavior re-inserts the object into the layer.- Parameters:
aObject
- the object to editaEditCount
- a list of previous versions of the object. These versions are acquired when calling theedit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
operation.aGraphics
- the graphics onto which the object is paintedaMouseEvent
- the mouse event causing the edit operation, or null if another input method is used.aSnappables
- the list of potential snap targetsaContext
- the GXY context information- Returns:
- the undoable for comitting the given object.
- See Also:
-
cancel
public void cancel(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Cancels creation of the object. From this moment on, the object is no longer under creation. Hence, no further edit operations are performed, and the object will no longer be painted by this controller model. The default implementation does nothing.- Parameters:
aObject
- the object to editaEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which the object is paintedaMouseEvent
- the mouse event causing the edit operation, or nullaSnappables
- the list of potential snap targetsaContext
- the GXY context information
-
paint
public void paint(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Paints the object being created. The default implementation paints the object usingILcdGXYPainter.BODY | ILcdGXYPainter.CREATING
as render mode, and adds snaps when necessary.- Parameters:
aObject
- the object being editedaEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which the object is paintedaMouseEvent
- the last relevant mouse event before calling this method, or null if another input method is used.aSnappables
- the list of potential snap targetsaContext
- the GXY context information
-
shouldEdit
public boolean shouldEdit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Deprecated.This method depends on the kind of input (in this case a mouseEvent). To allow using existing controller models for other kinds of input (eg. touchEvents), this method should be moved to the (input specific) controller. The method is deprecated here because the controller should decide when to edit. SeeTLcdGXYNewController2.shouldEdit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.Returns whether the mouse event should trigger an edit of the object, given the context parameters. The default implementation returns true for left and right single clicks, and also for drag operations that have not been preceded by clicks.- 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
- See Also:
-
shouldUndo
public boolean shouldUndo(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Deprecated.This method depends on the kind of input (in this case a mouseEvent). To allow using existing controller models for other kinds of input (eg. touchEvents), this method should be moved to the (input specific) controller. The method is deprecated here because the controller should decide when to undo. SeeTLcdGXYNewController2.shouldUndo(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.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
- See Also:
-
shouldCommit
public boolean shouldCommit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Deprecated.This method depends on the kind of input (in this case a mouseEvent). To allow using existing controller models for other kinds of input (eg. touch events), this method should be moved to the (input specific) controller. The method is deprecated here because the controller should decide when to commit. SeeTLcdGXYNewController2.shouldCommit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.Returns whether the mouse event should trigger a commit of the object, given the context parameters. The default implementation uses thegetCreationStatus(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 left-drag operation is not ongoing
- the object is COMMITTABLE and the mouse event is a right click, a double left click, or the end of a left-drag operation that has not been preceded by a click operation
- 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
- See Also:
-
getCreationStatus
public ALcdGXYNewControllerModel2.CreationStatus getCreationStatus(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns the creation status of the object being created.
After a number of interactions the object might be finished (for example, a circle for instance can be created using two points: the center and one of the points on its outer rim). If that's the case the created domain object can be immediately committed and added to the layer. There are however some objects that can't be finished within a set amount of steps (for example, when creating a polyline, yu can add as many points as you want). For those cases we have theALcdGXYNewControllerModel2.CreationStatus.COMMITTABLE
status. The default implementation compares the edit count with the editor's creation click count.- Parameters:
aObject
- the object being editedaEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which the object is paintedaMouseEvent
- the mouse event that is causing the method call, or null if another input method is used.aSnappables
- the list of potential snap targetsaContext
- the GXY context information- Returns:
UNCOMMITTABLE
if more editing steps are required,COMMITTABLE
if more editing steps are optional,FINISHED
if no more clicks can be accepted.- See Also:
-
snapTarget
protected ALcdGXYNewControllerModel2.SnapTargetInfo snapTarget(Object aObjectToSnap, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Tries to retrieve a snap target from the givenaSnappables
. It does so by invokingsnapTarget
. If the snap target returned by the painter isaccepted
by theILcdGXYEditor
of aObjectToSnap, it is returned. When no snap target can be found this method returnsnull
.- Parameters:
aObjectToSnap
- the object that would like to snap to one of the candidates in aSnappables, so basically the object that is being edited.aEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which the object is paintedaMouseEvent
- the mouse event that is causing the method call, or null if another input method is used.aSnappables
- the list of potential snap targetsaContext
- the GXY context information- Returns:
- The snap info.
-
mouseCursor
public Cursor mouseCursor(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext) Returns the desired cursor for the given parameters, ornull
if no specific cursor is needed. The default implementation returns null.- Parameters:
aObject
- the object under creationaEditCount
- the number of previous edit operationsaGraphics
- the graphics onto which the object is paintedaMouseEvent
- the mouse event causing this method callaSnappables
- the list of potential snap targetsaContext
- the GXY context information- Returns:
- a suitable cursor, or null to use a default cursor
-
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:
aListener
- 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:
aListener
- The listener to remove.
-
fireUndoableHappened
Notifies all undoable listeners thataUndoable
has happened.- Parameters:
aUndoable
- The undoable of which the listeners should be notified.
-
getStringTranslator
Returns the
ILcdStringTranslator
set on this controller model.- Returns:
- The translator set on this controller model. Never
null
.
-
setStringTranslator
Sets the
ILcdStringTranslator
that this controller model should use to translate theStrings
that will be visible in the user interface.The following list of
Strings
are translated by the given instance:- "Creation step"
- "Create {0}". The translated
String
is used as the pattern for aMessageFormat
. - "Undo {0}". The translated
String
is used as the pattern for aMessageFormat
. - "Redo {0}". The translated
String
is used as the pattern for aMessageFormat
.
- Parameters:
aStringTranslator
- TheILcdStringTranslator
that should be used. Must not benull
.
-