Class TLcdGXYEditController2

All Implemented Interfaces:
ILcdUndoableSource, ILcdAWTEventListener, ILcdStatusSource, ILcdGXYChainableController, ILcdGXYController, KeyListener, MouseListener, MouseMotionListener, Serializable, EventListener

public class TLcdGXYEditController2 extends TLcdGXYSelectController2
Extension of TLcdGXYSelectController2 that adds editing capabilities to it. It allows a user to graphically edit objects on an ILcdGXYView using the mouse.

The selected objects are translated by moving the mouse pointer over them, and dragging them to a new location. Selecting and dragging can be performed as one operation. If the ctrl modifier key is pressed during the drag, the single object that is touched by the mouse pointer is reshaped. Escape can be used to abort the edit operation. Note that the meaning of translating and reshaping is defined by the implementations of the ILcdGXYPainters and ILcdGXYEditors.

Both the objects themselves (bodies) and their labels can be edited. Editing an object requires that an ILcdGXYEditor is available from the layer, editing the labels requires that an ILcdGXYLabelEditor and an ILcdGXYLabelPainter2 (not just ILcdGXYLabelPainter) are available from the layer.

All editing related logic can programmatically be customized by setting a custom TLcdGXYEditControllerModel2, for example to change the behavior of modifier keys, disable editing of labels, influence which objects should be edited, specify which mouse cursor to use, etc. Please refer to TLcdGXYEditControllerModel2 for more information.

This controller can be configured to instantly edit objects and labels, instead of only applying the edit when the mouse is released. See setInstantEditing for more information.

This controller supports undo capabilities, please refer to TLcdGXYEditControllerModel2 for more information.

This controller also has snapping capabilities. A list of candidates for snapping must be set to enable this feature.

Since:
7.0
See Also:
  • Constructor Details

  • Method Details

    • startInteraction

      public void startInteraction(ILcdGXYView aGXYView)
      Description copied from class: ALcdGXYController
      Sets up the controller to receive input through the view passed.

      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.

      Specified by:
      startInteraction in interface ILcdGXYController
      Overrides:
      startInteraction in class TLcdGXYSelectController2
      Parameters:
      aGXYView - the ILcdGXYView this ILcdGXYController will interact with.
      See Also:
    • terminateInteraction

      public void terminateInteraction(ILcdGXYView aGXYView)
      Description copied from class: ALcdGXYController
      Releases a few items. Can be redefined but this 'super' method should be called too.
      Specified by:
      terminateInteraction in interface ILcdGXYController
      Overrides:
      terminateInteraction in class TLcdGXYSelectController2
      Parameters:
      aGXYView - the ILcdGXYView this ILcdGXYController interacted with.
      See Also:
    • getEditControllerModel

      public TLcdGXYEditControllerModel2 getEditControllerModel()
      Returns the edit controller model.
      Returns:
      the edit controller model.
      See Also:
    • setEditControllerModel

      public void setEditControllerModel(TLcdGXYEditControllerModel2 aEditControllerModel)
      Sets the edit controller model. This allows to customize the editing logic, such as the behavior of modifier keys, which objects should be edited, etc. Please refer to TLcdGXYEditControllerModel2 for more information.
      Parameters:
      aEditControllerModel - The edit controller model to set.
    • getSnappables

      public ILcdGXYLayerSubsetList getSnappables()
      Returns the snappables.
      Returns:
      the snappables.
      See Also:
    • setSnappables

      public void setSnappables(ILcdGXYLayerSubsetList aSnappables)
      Sets the set of objects that are used as candidates-to-snap-to while editing other objects. Set to null to disable snapping.

      Please refer to the developer guide for more information about snapping.

      Parameters:
      aSnappables - the list of objects that are candidates to snap to.
      See Also:
    • isInstantEditing

      public boolean isInstantEditing()
      This method indicates whether the object being edited is painted in a temporary state and only changed when the mouse is released, or whether the object is instantly edited while the mouse is dragged.
      Returns:
      true if this controller instantly edits objects, without painting them in a temporary state, false otherwise.
      See Also:
    • setInstantEditing

      public void setInstantEditing(boolean aInstantEditing)
      The method can be used to activate or deactivate instant editing. When instant editing is enabled objects will be edited whenever the mouse is dragged. When it is disabled, objects will be edited only when the mouse button is released, and will be painted in a temporary state. When enabling instant editing, take into account:
      • performance may suffer, the view invalidates the layer that is edited, and as a result this layer has to be repainted.
      • no snap targets will be visible, snapping will still work but with less feedback.
      • when dragging a handle over another handle, it's possible that the second handle is edited instead of the first
      Also note that labels will be sticky while being instant edited. This makes sure that they will only be adapted by the edit controller, and not by the label placer.
      Parameters:
      aInstantEditing - when true instant editing will be enabled, when false disabled.
      See Also:
    • getStickyLabelsLayerFilter

      public ILcdFilter getStickyLabelsLayerFilter()
      This method returns the filter that will determine which layers have sticky labels when hovering over them. These labels will not be moved by a label placer while the mouse hovers over the label. If null is returned sticky labels are disabled for all layers.
      Returns:
      the filter that indicates which layers should have sticky labels.
      See Also:
    • setStickyLabelsLayerFilter

      public void setStickyLabelsLayerFilter(ILcdFilter aStickyLabelsLayerFilter)
      Sets the filter that will indicate which layers should have sticky labels when hovering over them. If a layer has sticky labels, they can't be moved by a label placer when the mouse is hovering over them. The default value is null which means no layers will have sticky labels. This setting is especially useful for real time layers.
      Parameters:
      aStickyLabelsLayerFilter - the filter that will indicate which layers should have sticky labels
      See Also:
    • keyPressed

      public void keyPressed(KeyEvent aKeyEvent)
      Handles key pressed events. For more information on behavior, see the class documentation above.
      Specified by:
      keyPressed in interface KeyListener
      Overrides:
      keyPressed in class ALcdGXYSmartController
      Parameters:
      aKeyEvent - The key event describing the change.
    • keyReleased

      public void keyReleased(KeyEvent aKeyEvent)
      Handles key released events. For more information on behavior, see the class documentation above.
      Specified by:
      keyReleased in interface KeyListener
      Overrides:
      keyReleased in class ALcdGXYSmartController
      Parameters:
      aKeyEvent - The key event describing the change.
    • mouseMoved

      public void mouseMoved(MouseEvent me)
      Handles mouse moved events. For more information on behavior, see the class documentation above.
      Specified by:
      mouseMoved in interface MouseMotionListener
      Overrides:
      mouseMoved in class TLcdGXYDragRectangleController
      Parameters:
      me - The mouse event describing the change.
    • mouseExited

      public void mouseExited(MouseEvent me)
      Description copied from class: ALcdGXYSmartController
      Will perform a pan depending on the values of isDragging, isPanOnMouseDragExit and isPanOnMouseMoveExit properties
      Specified by:
      mouseExited in interface MouseListener
      Overrides:
      mouseExited in class ALcdGXYSmartController
    • editHowMode

      protected int editHowMode(ILcdGXYView aGXYView, ILcdGXYLayerSubsetList aSnappables, Point aFrom, Point aTo, MouseEvent aMouseEvent)
      Returns the edit-how mode. This mode indicates how the edit should behave: should the editing candidates be translated or reshaped? This method should be overridden if a different behaviour is desired.

      By default, it returns TLcdGXYEditControllerModel2.EDIT_HOW_RESHAPING if ctrl is pressed, TLcdGXYEditControllerModel2.EDIT_HOW_TRANSLATING if no modifiers are pressed, and TLcdGXYEditControllerModel2.EDIT_HOW_NO_CHANGE otherwise.

      Please note that the actual meaning of reshaping and translating is defined by the implementation of ILcdGXYPainter/ILcdGXYEditor that is used.

      Parameters:
      aGXYView - The ILcdGXYView, provided as contextual information.
      aSnappables - The list of potential snapping candidates, provided as contextual information.
      aFrom - The point where the edit originated.
      aTo - The point where the edit terminated (so far).
      aMouseEvent - The last mouse event that was involved in the edit process.
      Returns:
      One of the constants in TLcdGXYEditControllerModel2 that start with EDIT_HOW.
    • editWhatMode

      protected int editWhatMode(ILcdGXYView aGXYView, ILcdGXYLayerSubsetList aSnappables, Point aFrom, Point aTo, MouseEvent aMouseEvent, int aEditHow)
      Returns the edit-what mode. This mode indicates what the edit should do: should the labels be edited, or the objects themselves? This method can be overridden if a different behaviour is required.

      If the left mouse button is used, returns TLcdGXYEditControllerModel2.EDIT_WHAT_OBJECTS if the objects are touched for aFrom, and TLcdGXYEditControllerModel2.EDIT_WHAT_LABELS if the labels are touched for aFrom. If the mouse event is a mouse moved event, the test on the mouse button is skipped. So for that case, it returns what would happen if a button would be pressed. In all other cases, TLcdGXYEditControllerModel2.EDIT_WHAT_NO_CHANGE is returned.

      Parameters:
      aGXYView - The ILcdGXYView, provided as contextual information.
      aSnappables - The list of potential snapping candidates, provided as contextual information.
      aFrom - The point where the edit originated.
      aTo - The point where the edit terminated (so far).
      aMouseEvent - The last mouse event that was involved in the edit process.
      aEditHow - The edit-how mode: one of the constants in the class TLcdGXYEditControllerModel2 that start with EDIT_HOW. For example the result of the method editHowMode.
      Returns:
      one of the constants in the class TLcdGXYEditControllerModel2 that start with EDIT_WHAT.
    • mousePressed

      public void mousePressed(MouseEvent me)
      Handles mouse pressed events. For more information on behavior, see the class documentation above.
      Specified by:
      mousePressed in interface MouseListener
      Overrides:
      mousePressed in class TLcdGXYSelectController2
      Parameters:
      me - The mouse event describing the change.
    • mouseDragged

      public void mouseDragged(MouseEvent me)
      Handles mouse dragged events. For more information on behavior, see the class documentation above.
      Specified by:
      mouseDragged in interface MouseMotionListener
      Overrides:
      mouseDragged in class TLcdGXYSelectController2
      Parameters:
      me - The mouse event describing the change.
    • mouseReleased

      public void mouseReleased(MouseEvent me)
      Handles mouse released events. For more information on behavior, see the class documentation above.
      Specified by:
      mouseReleased in interface MouseListener
      Overrides:
      mouseReleased in class TLcdGXYSelectController2
      Parameters:
      me - The mouse event describing the change.
    • repaintGXYView

      protected void repaintGXYView(ILcdGXYView aGXYView)
      Repaints the given ILcdGXYView. Whenever this controller wants the ILcdGXYView to be repainted, this method is invoked.
      Parameters:
      aGXYView - The ILcdGXYView.
    • paint

      public void paint(Graphics aGraphics)
      If an edit is ongoing, this method paints the edited objects in their editing state. If for example the selected objects are being dragged to a new location, this method paints those objects in their translating state (see ILcdGXYPainter.TRANSLATING).

      If no edit is ongoing, painting is delegated to the super class.

      Specified by:
      paint in interface ILcdGXYController
      Overrides:
      paint in class TLcdGXYSelectController2
      Parameters:
      aGraphics - The graphics to draw on.
    • setCursor

      public void setCursor(Cursor aCursor)
      This cursor is only used when there is no specific cursor provided by the controller model.
      Overrides:
      setCursor in class ALcdGXYController
      Parameters:
      aCursor - The cursor to use when no specific cursor is available.