public class TLcdGXYTouchNewController extends ALcdGXYChainableController implements ILcdUndoableSource
create
;
edit steps
;
comitting
of the domain object to a model.
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.configured
.
canUndo()
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.shouldCommit
, shouldEdit
,
and shouldUndo
can be overridden to map mouse events to specific
editing behaviour.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.
ILcdGXYChainableController
,
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 TLcdTouchPoint
s which are not-consumed, and marks the
TLcdTouchPoint
s it uses as consumed, similar to the ALcdGXYTouchChainableController
Constructor and Description |
---|
TLcdGXYTouchNewController(ALcdGXYNewControllerModel2 aNewControllerModel)
Creates a new Controller with the specified new controller model.
|
Modifier and Type | Method and Description |
---|---|
void |
addUndoableListener(ILcdUndoableListener aUndoableListener)
Adds a listener to this source, so this listener is notified when something undoable has
happened.
|
void |
appendGXYController(ILcdGXYChainableController aEnd)
This method will append the passed controller to the end of the chain.
|
boolean |
canCancel()
This method indicates whether or not it's possible to cancel the creation of the current
object.
|
boolean |
canCommit()
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()
If
canCancel() returns true, this method will cancel the creation of the current
object. |
void |
doCommit()
If
canCommit() 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()
When
canRedo() returns true, this method will redo the last creation step that was
undone. |
void |
doUndo()
When
canUndo() returns true, this method will undo the last creation step. |
ILcdAction |
getActionToTriggerAfterCommit()
Returns the
ILcdAction that will be will be triggered just after this controller
component has created a new Object , initialized it and committed it to an
ILcdModel . |
int |
getEditThreshold()
This method returns the edit threshold currently used by this controller.
|
ILcdGXYLayer |
getGXYLayer()
Returns the layer visualizing the object that the controller is creating.
|
int |
getMoveThreshold()
Returns the threshold for move events.
|
ALcdGXYNewControllerModel2 |
getNewControllerModel()
Returns the
ALcdGXYNewControllerModel2 this controller delegates to. |
ILcdGXYChainableController |
getNextGXYController()
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.
|
Object |
getObject()
Returns the object that the controller is creating.
|
ILcdGXYLayerSubsetList |
getSnappables()
Returns the Objects to snap to when initializing a new created Object, or
null
when snapping is disabled. |
void |
handleAWTEvent(AWTEvent aEvent)
This is method is called when the target of the listener has a new AWTEvent available.
|
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.
|
void |
paint(Graphics aGraphics)
Enables the controller to give visual feedback on the current user interactions.
|
protected void |
paintImpl(Graphics aGraphics)
The specific implementation of
paint for this controller. |
void |
removeUndoableListener(ILcdUndoableListener aUndoableListener)
Removes the specified listener so it is no longer notified.
|
void |
setActionToTriggerAfterCommit(ILcdAction aNewActionToTriggerAfterCommit)
Sets the
ILcdAction that will be triggered just after this controller component
has created a new Object and committed it to an ILcdModel . |
void |
setEditThreshold(int aEditThreshold)
Sets the edit threshold.
|
protected void |
setGXYView(ILcdGXYView aGXYView)
Sets the
ILcdGXYView the controller is interacting with. |
void |
setMoveThreshold(int aMoveThreshold)
Sets the threshold for move events.
|
void |
setNewControllerModel(ALcdGXYNewControllerModel2 aControllerModel)
Sets the
ALcdGXYNewControllerModel2 to delegate to. |
void |
setNextGXYController(ILcdGXYChainableController aNext)
This method sets the next controller in the chain for this controller.
|
void |
setSnappables(ILcdGXYLayerSubsetList aSnappables)
Sets the Objects to snap to when initializing a new created Object.
|
void |
setUndoOnSecondTouch(boolean aUndoOnSecondTouch)
A setter to activate of deactivate undo on second touch behaviour.
|
protected boolean |
shouldCommit(Object aObject,
int aEditCount,
Graphics aGraphics,
TLcdTouchPoint aTouchPoint,
ILcdGXYLayerSubsetList aSnappables,
ILcdGXYContext aContext)
This method indicates that the object should be committed.
|
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 ).
|
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.
|
void |
startInteraction(ILcdGXYView aGXYView)
Sets up the controller to receive input through the view passed.
|
protected void |
startInteractionImpl(ILcdGXYView aGXYView)
The specific implementation of
startInteraction for this controller. |
void |
terminateInteraction(ILcdGXYView aGXYView)
Releases a few items.
|
protected void |
terminateInteractionImpl(ILcdGXYView aGXYView)
The specific implementation of
terminateInteraction for this controller. |
addStatusListener, removeStatusListener
asGXYController, fireStatusEvent, getCursor, getGXYView, getIcon, getName, getShortDescription, isTraceOn, registerInstance, retrieveGXYViewXYWorldTransformation, setClassTraceOn, setCursor, setIcon, setName, setShortDescription, setTraceOn, viewRepaint
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCursor, getIcon, getLayered, getName, getShortDescription, viewRepaint
public TLcdGXYTouchNewController(ALcdGXYNewControllerModel2 aNewControllerModel)
aNewControllerModel
- The new controller model that will be used by this controller.public void addUndoableListener(ILcdUndoableListener aUndoableListener)
ILcdUndoableSource
addUndoableListener
in interface ILcdUndoableSource
aUndoableListener
- The listener to be notified when something undoable has happened.public void removeUndoableListener(ILcdUndoableListener aUndoableListener)
ILcdUndoableSource
removeUndoableListener
in interface ILcdUndoableSource
aUndoableListener
- The listener to remove.public void handleAWTEvent(AWTEvent aEvent)
ILcdAWTEventListener
handleAWTEvent
in interface ILcdAWTEventListener
aEvent
- The event to be handled.public void setNewControllerModel(ALcdGXYNewControllerModel2 aControllerModel)
ALcdGXYNewControllerModel2
to delegate to.aControllerModel
- the ALcdGXYNewControllerModel2
to delegate to.getNewControllerModel()
public ALcdGXYNewControllerModel2 getNewControllerModel()
ALcdGXYNewControllerModel2
this controller delegates to.ALcdGXYNewControllerModel2
this controller delegates to.setNewControllerModel(com.luciad.view.gxy.controller.ALcdGXYNewControllerModel2)
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.
aMoveThreshold
- the move thresholdgetMoveThreshold()
public int getMoveThreshold()
Returns the threshold for move events.
setMoveThreshold(int)
public void setSnappables(ILcdGXYLayerSubsetList aSnappables)
Sets the Objects to snap to when initializing a new created Object.
When null
, snapping is disabled.
aSnappables
- the new value for the snappables property, or null
to disable
snappinggetSnappables()
public ILcdGXYLayerSubsetList getSnappables()
null
when snapping is disabled.null
when snapping is disabledsetSnappables(com.luciad.view.gxy.ILcdGXYLayerSubsetList)
public void setActionToTriggerAfterCommit(ILcdAction aNewActionToTriggerAfterCommit)
ILcdAction
that will be triggered just after this controller component
has created a new Object
and committed it to an ILcdModel
. It might
be interesting for example to set an ILcdGXYController
( using a
TLcdGXYSetControllerAction
) that can edit the new Object
, 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.aNewActionToTriggerAfterCommit
- the ILcdAction
to be triggered or
null
if no ILcdAction
has to be
triggered.TLcdGXYSetControllerAction
,
getActionToTriggerAfterCommit()
public ILcdAction getActionToTriggerAfterCommit()
ILcdAction
that will be will be triggered just after this controller
component has created a new Object
, initialized it and committed it to an
ILcdModel
.ILcdAction
to be triggered after creation of a new Object.setActionToTriggerAfterCommit(com.luciad.gui.ILcdAction)
public int getEditThreshold()
setEditThreshold(int)
public void setEditThreshold(int aEditThreshold)
aEditThreshold
- the new edit threshold.getEditThreshold()
,
shouldCommit(java.lang.Object, int, java.awt.Graphics, com.luciad.input.touch.TLcdTouchPoint, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
protected boolean shouldEdit(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
By default it returns true for the first edit operation,
for clicks when the aContext.getDeltaX
or aContext.getDeltaY
is greater than the edit threshold,
and also for drag operations that have not been preceded by clicks.
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.protected boolean shouldUndo(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
shouldEdit
returns false. By default it returns true when
isUndoOnSecondTouch
returns true and the aContext.getDeltaX
and
aContext.getDeltaY
are smaller than the edit threshold.
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 undoneprotected boolean shouldCommit(Object aObject, int aEditCount, Graphics aGraphics, TLcdTouchPoint aTouchPoint, ILcdGXYLayerSubsetList aSnappables, ILcdGXYContext aContext)
ALcdGXYNewControllerModel2.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 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 undoneprotected void startInteractionImpl(ILcdGXYView aGXYView)
ALcdGXYChainableController
startInteraction
for this controller.startInteractionImpl
in class ALcdGXYChainableController
aGXYView
- the view to start interaction with.protected void terminateInteractionImpl(ILcdGXYView aGXYView)
ALcdGXYChainableController
terminateInteraction
for this controller.terminateInteractionImpl
in class ALcdGXYChainableController
aGXYView
- the view to terminate interaction with.protected void paintImpl(Graphics aGraphics)
ALcdGXYChainableController
paint
for this controller.paintImpl
in class ALcdGXYChainableController
aGraphics
- the graphics to be used for painting.public ILcdGXYChainableController getNextGXYController()
ILcdGXYChainableController
getNextGXYController
in interface ILcdGXYChainableController
getNextGXYController
in class ALcdGXYChainableController
ILcdGXYChainableController.setNextGXYController(ILcdGXYChainableController)
public void setNextGXYController(ILcdGXYChainableController aNext)
ILcdGXYChainableController
setNextGXYController
in interface ILcdGXYChainableController
setNextGXYController
in class ALcdGXYChainableController
aNext
- the reference to the controller that will be the next element in the chainILcdGXYChainableController.getNextGXYController()
public void appendGXYController(ILcdGXYChainableController aEnd)
ILcdGXYChainableController
appendGXYController
in interface ILcdGXYChainableController
appendGXYController
in class ALcdGXYChainableController
aEnd
- the controller to be appended to the end of the chain.public void startInteraction(ILcdGXYView aGXYView)
ALcdGXYChainableController
All ILcdGXYView
implementations that support interaction call this method when the controller
has been made active with setGXYController
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
.
This method also calls ALcdGXYChainableController.startInteraction(com.luciad.view.gxy.ILcdGXYView)
on the next controller.
Override ALcdGXYChainableController.startInteractionImpl(com.luciad.view.gxy.ILcdGXYView)
if you want to add your own behavior to this controller.
startInteraction
in interface ILcdGXYController
startInteraction
in class ALcdGXYChainableController
aGXYView
- the ILcdGXYView
this ILcdGXYController
will interact with.ALcdGXYChainableController.startInteractionImpl(com.luciad.view.gxy.ILcdGXYView)
public void terminateInteraction(ILcdGXYView aGXYView)
ALcdGXYChainableController
This method also calls ALcdGXYChainableController.terminateInteraction(com.luciad.view.gxy.ILcdGXYView)
on the next controller.
Override ALcdGXYChainableController.terminateInteractionImpl(com.luciad.view.gxy.ILcdGXYView)
if you want to add your own behavior to this controller.
terminateInteraction
in interface ILcdGXYController
terminateInteraction
in class ALcdGXYChainableController
aGXYView
- the ILcdGXYView
this ILcdGXYController
interacted with.ALcdGXYChainableController.terminateInteractionImpl(com.luciad.view.gxy.ILcdGXYView)
public void paint(Graphics aGraphics)
ALcdGXYChainableController
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.
Override ALcdGXYChainableController.paintImpl(java.awt.Graphics)
if you want to add your own behavior to this controller.
paint
in interface ILcdGXYController
paint
in class ALcdGXYChainableController
aGraphics
- the Graphics on which the view was rendered.ALcdGXYChainableController.paintImpl(java.awt.Graphics)
protected void setGXYView(ILcdGXYView aGXYView)
ALcdGXYController
ILcdGXYView
the controller is interacting with.
This method is called when ILcdGXYView.setGXYController
is used to set an
ILcdGXYController
active on an ILcdGXYView
.
setGXYView
in class ALcdGXYController
aGXYView
- the view the controller is interacting withALcdGXYController.startInteraction(com.luciad.view.gxy.ILcdGXYView)
,
ILcdGXYView.setGXYController(com.luciad.view.gxy.ILcdGXYController)
public boolean canCommit()
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 to ALcdGXYNewControllerModel2.CreationStatus.COMMITTABLE
.public void doCommit()
canCommit()
returns true, this method will commit the object currently under
creation, and trigger the action to trigger after commit if it's available.public boolean canCancel()
public void doCancel()
canCancel()
returns true, this method will cancel the creation of the current
object.canCancel()
public boolean canUndo()
public void doUndo()
canUndo()
returns true, this method will undo the last creation step.public boolean canRedo()
public void doRedo()
canRedo()
returns true, this method will redo the last creation step that was
undone.public boolean isUndoOnSecondTouch()
setUndoOnSecondTouch(boolean)
public void setUndoOnSecondTouch(boolean aUndoOnSecondTouch)
aUndoOnSecondTouch
- the boolean indicating whether or not the undo on second touch
behaviour should be activated.isUndoOnSecondTouch()
,
shouldUndo(java.lang.Object, int, java.awt.Graphics, com.luciad.input.touch.TLcdTouchPoint, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
public Object getObject()
ALcdGXYNewControllerModel2.edit(java.lang.Object, int, java.awt.Graphics, java.awt.event.MouseEvent, com.luciad.view.gxy.ILcdGXYLayerSubsetList, com.luciad.view.gxy.ILcdGXYContext)
.public ILcdGXYLayer getGXYLayer()