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
canEditmethod to indicate which objects can be edited/created by your editor (do not forget to callsuper.canEdit). - Implement the
getEditHandlesmethod to return a collection of handles suitable to edit the given object. As an example:TLsp2DPointListEditorreturns 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 eventsintohigh level edit operations. - Implement the
getCreateHandlemethod to return a single handle that can be used to create the object. Typically, this handle is an extension ofALspCreateHandle. - Implement the
editImplmethod that performs the necessary actions to modify the object. This method is called from theeditmethod, after performing the necessary tasks to manage undo behavior and lock the model being edited. - Extend the
canCopyGeometryandcopyGeometrySFCTmethods to handle your custom domain object (do not forget to callsuper.canCopyGeometryandsuper.copyGeometrySFCTfor other objects). - Extend the
canPerformOperationmethod 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
ALspEditHandleor, even more conveniently, fromALsp3StepEditHandleor from one of the provided subclasses. - Implement
handleAWTEventmethod 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
editmethod has the correct interaction status in order for undo/redo support to work correctly (see also below). - Implement the
getStyleTargetProvidermethod 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
setPriorityto make sure it gets the correct priority over other handles. - Override
requestsFocusto 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
ConstructorsModifierConstructorDescriptionprotectedCreates a new editor, with undo support and automatic model locking while performing edit operations. -
Method Summary
Modifier and TypeMethodDescriptionbooleancanCopyGeometry(Object aSourceGeometry, Object aDestinationGeometry) Tests whether this editor can apply the properties of a template source object to the given target object.booleancanEdit(TLspEditContext aContext) Determines whether or not thegeometry inside the given contextcan be edited by this editor.booleancanPerformOperation(TLspEditOperation aOperation, TLspEditContext aContext) Determines whether or not the editor knows how to apply the given edit operation to the supplied geometry.voidcopyGeometrySFCT(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 TLspEditOperationResulteditImpl(TLspEditOperation aOperation, ELspInteractionStatus aInteractionStatus, TLspEditContext aContext) Called by theeditmethod to edit the given object based on the givenedit operation.protected voidfireUndoableHappened(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, waitMethods 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 contextcan 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:
canEditin 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
editImplinstead.- Specified by:
editin 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 returnstrueif the model reference of the edit operation is equal to that of the edited object.- Specified by:
canPerformOperationin 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
copyGeometrySFCTwould succeed, false otherwise. - See Also:
-
editImpl
protected abstract TLspEditOperationResult editImpl(TLspEditOperation aOperation, ELspInteractionStatus aInteractionStatus, TLspEditContext aContext) Called by theeditmethod 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 theeditmethod.- 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.
-