Class ALspEditor
- All Implemented Interfaces:
ILspEditor
- Direct Known Subclasses:
TLsp2DEditableShapeEditor
,TLsp2DPointListEditor
,TLsp3DArcBandEditor
,TLsp3DPointListEditor
,TLspArcBandEditor
,TLspArcBy3PointsEditor
,TLspArcByBulgeEditor
,TLspArcByCenterEditor
,TLspArcEditor
,TLspBoundsEditor
,TLspCircleBy3PointsEditor
,TLspCircleEditor
,TLspComplexPolygonEditor
,TLspCompositeCurveEditor
,TLspDomeEditor
,TLspEllipseEditor
,TLspExtrudedShapeEditor
,TLspGeoBufferEditor
,TLspPointEditor
,TLspShapeListEditor
,TLspSphereEditor
,TLspSurfaceEditor
,TLspTextEditor
,TLspVariableGeoBufferEditor
ILspEditor
.
An ALspEditor
provides a base for most editors.
This base class adds functionality to automatically support undo behavior while editing. The
only precondition is that the object has to be ILcdCloneable
for this to work. Apart from this functionality, the editor will also automatically lock
the model, while an object is being edited.
Implementing a Custom Editor
It is recommended to use this base class for all your editor implementations. Following steps should be performed when implementing a custom editor:- Override the
canEdit
method to indicate which objects can be edited/created by your editor (do not forget to callsuper.canEdit
). - Implement the
getEditHandles
method to return a collection of handles suitable to edit the given object. As an example:TLsp2DPointListEditor
returns a collection of point handles to move the vertices of the point list as well as a handle to translate the point list. The handles should be capable of transforming incomingAWT events
intohigh level edit operations
. - Implement the
getCreateHandle
method to return a single handle that can be used to create the object. Typically, this handle is an extension ofALspCreateHandle
. - Implement the
editImpl
method that performs the necessary actions to modify the object. This method is called from theedit
method, after performing the necessary tasks to manage undo behavior and lock the model being edited. - Extend the
canCopyGeometry
andcopyGeometrySFCT
methods to handle your custom domain object (do not forget to callsuper.canCopyGeometry
andsuper.copyGeometrySFCT
for other objects). - Extend the
canPerformOperation
method to allow any controller to see what operations this class supports.
Implementing Custom Handles
Occasionally, when implementing a custom editor, custom edit handles are required. Following steps should be followed to correctly implement a custom edit handle:- Derive your implementation from
ALspEditHandle
or, even more conveniently, fromALsp3StepEditHandle
or from one of the provided subclasses. - Implement
handleAWTEvent
method or (in case of 3-step handles) the necessarycanActivate
,onActivate
, etc. methods to filter and respond to the correct input events. - Make sure the edit operation provided
in the
edit
method has the correct interaction status in order for undo/redo support to work correctly (see also below). - Implement the
getStyleTargetProvider
method to return a set of domain objects that constitute the visual representation of the handle and that can be painted for the providedVisualComponentType
. - Set the priority of the handle using
setPriority
to make sure it gets the correct priority over other handles. - Override
requestsFocus
to make sure the handle gets focus when it is highlighted.
Adding Undo/Redo Support
This base class automatically supports undo/redo of operations via theILcdUndoableSource
interface. An undoable is created after each event
with interaction status FINISHED
. The handles in the Lightspeed API fire such an event when appropriate. For
example, TLspPointTranslationHandle
will generate such an edit operation when releasing the mouse after a drag
operation.- Since:
- 2012.0
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new editor, with undo support and automatic model locking while performing edit operations. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canCopyGeometry
(Object aSourceGeometry, Object aDestinationGeometry) Tests whether this editor can apply the properties of a template source object to the given target object.boolean
canEdit
(TLspEditContext aContext) Determines whether or not thegeometry inside the given context
can be edited by this editor.boolean
canPerformOperation
(TLspEditOperation aOperation, TLspEditContext aContext) Determines whether or not the editor knows how to apply the given edit operation to the supplied geometry.void
copyGeometrySFCT
(Object aSourceGeometry, Object aDestinationGeometrySFCT) Method that takes the given source object and applies all geometry to the destination object.edit
(TLspEditOperation aOperation, ELspInteractionStatus aInteractionStatus, TLspEditContext aContext) Applies an interaction obtained from a handle to the object being edited.protected abstract TLspEditOperationResult
editImpl
(TLspEditOperation aOperation, ELspInteractionStatus aInteractionStatus, TLspEditContext aContext) Called by theedit
method to edit the given object based on the givenedit operation
.protected void
fireUndoableHappened
(ILcdUndoable aUndoable) Notifies the registered listeners that an undoable has happened.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.lightspeed.editor.ILspEditor
getCreateHandle, getEditHandles
-
Constructor Details
-
ALspEditor
protected ALspEditor()Creates a new editor, with undo support and automatic model locking while performing edit operations.
-
-
Method Details
-
canEdit
Determines whether or not thegeometry inside the given context
can be edited by this editor. Override this method to provide a custom implementation. The default implementation determines whether the given object is cloneable. This editor can only edit cloneable objects.- Specified by:
canEdit
in interfaceILspEditor
- Parameters:
aContext
- provides context information to the editor- Returns:
- true if the editor knows how to modify the object.
-
fireUndoableHappened
Notifies the registered listeners that an undoable has happened.- Parameters:
aUndoable
- the undoable that has happened
-
edit
public TLspEditOperationResult edit(TLspEditOperation aOperation, ELspInteractionStatus aInteractionStatus, TLspEditContext aContext) Applies an interaction obtained from a handle to the object being edited.Note: Only override this method if you want to bypass the undo/redo support provided by this abstract class. For most use cases, it is preferred to override
editImpl
instead.- Specified by:
edit
in interfaceILspEditor
- Parameters:
aOperation
- describes the edit that should occur. This is usually generated by the handles. It is up to the concrete editor to determine how to handle this event.aInteractionStatus
- the interaction statusaContext
- the edit context @return the result of the edit operation- Returns:
- information about the result of the operation
- See Also:
-
canPerformOperation
Determines whether or not the editor knows how to apply the given edit operation to the supplied geometry. By default this method returnstrue
if the model reference of the edit operation is equal to that of the edited object.- Specified by:
canPerformOperation
in interfaceILspEditor
- Parameters:
aOperation
- the operation to be appliedaContext
- the edit context- Returns:
- true if the model reference of the edit operation is equal to that of the edited object
-
copyGeometrySFCT
Method that takes the given source object and applies all geometry to the destination object.
This method is called when performing an undo or redo operation. Before editing an object, a clone is created from the geometry. When performing e.g. an undo operation, the state of the clone is applied on the geometry object using this method. Something similar happens for a redo operation.
By default, this method supports all default (editable) shapes in LuciadLightspeed. Custom editors should override this method to allow this editor to apply changes to the original object given a modified instance of it.
- Parameters:
aSourceGeometry
- A template source object to copy the geometry from.aDestinationGeometrySFCT
- A destination object to copy the geometry to.
-
canCopyGeometry
Tests whether this editor can apply the properties of a template source object to the given target object. This method is not allowed to modify the parameters of the given objects.- Parameters:
aSourceGeometry
- a template source object from which the geometry will be copied fromaDestinationGeometry
- a destination object to which the geometry will be copied to- Returns:
- true if a call to
copyGeometrySFCT
would succeed, false otherwise. - See Also:
-
editImpl
protected abstract TLspEditOperationResult editImpl(TLspEditOperation aOperation, ELspInteractionStatus aInteractionStatus, TLspEditContext aContext) Called by theedit
method to edit the given object based on the givenedit operation
. Note that this method does not need to lock the model of the object, this already happens in theedit
method.- Parameters:
aOperation
- the event that contains the information on how to edit the objectaInteractionStatus
- the interaction statusaContext
- the edit context- Returns:
- The result of the operation: Whether or not there was success, and whether or not the current handles of the object should be invalidated.
-