Class ALspEditor

java.lang.Object
com.luciad.view.lightspeed.editor.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

public abstract class ALspEditor extends Object implements ILspEditor
Abstract base class for implementations of 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:
  1. Override the canEdit method to indicate which objects can be edited/created by your editor (do not forget to call super.canEdit).
  2. 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 incoming AWT events into high level edit operations.
  3. Implement the getCreateHandle method to return a single handle that can be used to create the object. Typically, this handle is an extension of ALspCreateHandle.
  4. Implement the editImpl method that performs the necessary actions to modify the object. This method is called from the edit method, after performing the necessary tasks to manage undo behavior and lock the model being edited.
  5. Extend the canCopyGeometry and copyGeometrySFCT methods to handle your custom domain object (do not forget to call super.canCopyGeometry and super.copyGeometrySFCT for other objects).
  6. 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:
  1. Derive your implementation from ALspEditHandle or, even more conveniently, from ALsp3StepEditHandle or from one of the provided subclasses.
  2. Implement handleAWTEvent method or (in case of 3-step handles) the necessary canActivate, onActivate, etc. methods to filter and respond to the correct input events.
  3. 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).
  4. 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 provided VisualComponentType.
  5. Set the priority of the handle using setPriority to make sure it gets the correct priority over other handles.
  6. 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 the ILcdUndoableSource 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 Details

    • ALspEditor

      protected ALspEditor()
      Creates a new editor, with undo support and automatic model locking while performing edit operations.
  • Method Details

    • canEdit

      public boolean canEdit(TLspEditContext aContext)
      Determines whether or not the geometry 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 interface ILspEditor
      Parameters:
      aContext - provides context information to the editor
      Returns:
      true if the editor knows how to modify the object.
    • fireUndoableHappened

      protected void fireUndoableHappened(ILcdUndoable aUndoable)
      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 interface ILspEditor
      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 status
      aContext - the edit context @return the result of the edit operation
      Returns:
      information about the result of the operation
      See Also:
    • canPerformOperation

      public boolean canPerformOperation(TLspEditOperation aOperation, TLspEditContext aContext)
      Determines whether or not the editor knows how to apply the given edit operation to the supplied geometry.

      By default this method returns true if the model reference of the edit operation is equal to that of the edited object.

      Specified by:
      canPerformOperation in interface ILspEditor
      Parameters:
      aOperation - the operation to be applied
      aContext - the edit context
      Returns:
      true if the model reference of the edit operation is equal to that of the edited object
    • copyGeometrySFCT

      public void copyGeometrySFCT(Object aSourceGeometry, Object aDestinationGeometrySFCT)

      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

      public boolean canCopyGeometry(Object aSourceGeometry, Object aDestinationGeometry)
      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 from
      aDestinationGeometry - 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 the edit method to edit the given object based on the given edit operation.

      Note that this method does not need to lock the model of the object, this already happens in the edit method.

      Parameters:
      aOperation - the event that contains the information on how to edit the object
      aInteractionStatus - the interaction status
      aContext - 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.