public abstract class ALcdGXYNewControllerModel2 extends Object implements ILcdUndoableSource
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
.
TLcdGXYNewController2
Modifier and Type | Class and Description |
---|---|
static class |
ALcdGXYNewControllerModel2.CreationStatus
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 |
ALcdGXYNewControllerModel2.SnapTargetInfo
Object representing all needed information about a snap target.
|
Constructor and Description |
---|
ALcdGXYNewControllerModel2()
Creates an new instance, ready to be used with a
TLcdGXYNewController2 controller. |
Modifier and Type | Method and Description |
---|---|
void |
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 new
ILcdUndoable for committing the given object. |
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 that
aUndoable has happened. |
ALcdGXYNewControllerModel2.CreationStatus |
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.
|
ILcdStringTranslator |
getStringTranslator()
Returns the
ILcdStringTranslator set on this controller model. |
Cursor |
mouseCursor(Object aObject,
int aEditCount,
Graphics aGraphics,
MouseEvent aMouseEvent,
ILcdGXYLayerSubsetList aSnappables,
ILcdGXYContext aContext)
Returns the desired cursor for the given parameters, or
null if no specific
cursor is needed.
The default implementation returns null. |
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 the
ILcdStringTranslator that this controller model should use to translate
the Strings 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). 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. See
TLcdGXYNewController2.shouldCommit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext) . |
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. See
TLcdGXYNewController2.shouldEdit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext) . |
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. See
TLcdGXYNewController2.shouldUndo(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext) . |
protected ALcdGXYNewControllerModel2.SnapTargetInfo |
snapTarget(Object aObjectToSnap,
int aEditCount,
Graphics aGraphics,
MouseEvent aMouseEvent,
ILcdGXYLayerSubsetList aSnappables,
ILcdGXYContext aContext)
Tries to retrieve a snap target from the given
aSnappables . |
public ALcdGXYNewControllerModel2()
TLcdGXYNewController2
controller.public abstract ILcdGXYLayer getGXYLayer(Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
ILcdGXYContext
object.
This method may be called several times during the creation process; upon
the first call, aContext.getGXYLayer
will return null
.
If the controller model does not support changing the layer during creation (e.g. due to incompatible objects),
it should return aContext.getGXYLayer
when this is not null
.
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 informationcreate(int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public abstract Object create(int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
commit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
method.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 foredit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
,
getGXYLayer(java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
,
commit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public Object edit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
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 informationcreate(int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
,
shouldEdit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
,
commit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public void commit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
createCommitUndoable(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.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 informationshouldCommit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
protected ILcdUndoable createCommitUndoable(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
ILcdUndoable
for committing the given object.
The default implementation creates an undoable with display name "Create {0}",
translated with the set ILcdStringTranslator
and the domain object's toString
value.
The undo operation removes the object from the model. The default redo behavior re-inserts the
object into the layer.aObject
- the object to editaEditCount
- a list of previous versions of the object. These versions are acquired when
calling the edit(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 informationcommit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public void cancel(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
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 informationpublic void paint(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
ILcdGXYPainter.BODY | ILcdGXYPainter.CREATING
as render mode, and adds snaps when necessary.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 informationpublic boolean shouldEdit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
TLcdGXYNewController2.shouldEdit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.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 informationgetCreationStatus(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
,
edit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public boolean shouldUndo(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
TLcdGXYNewController2.shouldUndo(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.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 informationedit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public boolean shouldCommit(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
TLcdGXYNewController2.shouldCommit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.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:
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 informationgetCreationStatus(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
,
commit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public ALcdGXYNewControllerModel2.CreationStatus getCreationStatus(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
ALcdGXYNewControllerModel2.CreationStatus.COMMITTABLE
status.
The default implementation compares the edit count with the editor's creation click count.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 informationUNCOMMITTABLE
if more editing steps are required,
COMMITTABLE
if more editing steps are optional, FINISHED
if no more clicks can be accepted.ALcdGXYNewControllerModel2.CreationStatus
,
ILcdGXYEditor.getCreationClickCount()
protected ALcdGXYNewControllerModel2.SnapTargetInfo snapTarget(Object aObjectToSnap, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
aSnappables
.
It does so by invoking snapTarget
.
If the snap target returned by the painter is accepted
by the ILcdGXYEditor
of aObjectToSnap, it is returned.
When no snap target can be found this method returns null
.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 informationpublic Cursor mouseCursor(Object aObject, int aEditCount, Graphics aGraphics, MouseEvent aMouseEvent, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
null
if no specific
cursor is needed.
The default implementation returns null.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 informationpublic void addUndoableListener(ILcdUndoableListener aListener)
ILcdUndoableSource
addUndoableListener
in interface ILcdUndoableSource
aListener
- The listener to be notified when something undoable has happened.public void removeUndoableListener(ILcdUndoableListener aListener)
ILcdUndoableSource
removeUndoableListener
in interface ILcdUndoableSource
aListener
- The listener to remove.protected void fireUndoableHappened(ILcdUndoable aUndoable)
aUndoable
has happened.aUndoable
- The undoable of which the listeners should be notified.public ILcdStringTranslator getStringTranslator()
Returns the ILcdStringTranslator
set on this controller model.
null
.public void setStringTranslator(ILcdStringTranslator aStringTranslator)
Sets the ILcdStringTranslator
that this controller model should use to translate
the Strings
that will be visible in the user interface.
The following list of Strings
are translated by the given instance:
String
is used as the pattern for a MessageFormat
.String
is used as the pattern for a MessageFormat
.String
is used as the pattern for a MessageFormat
.aStringTranslator
- The ILcdStringTranslator
that should be used. Must not
be null
.