com.dlsc.flexgantt.swing.layer.system

## Class DragLayer

- java.lang.Object
- - com.dlsc.flexgantt.swing.layer.AbstractLayer
  - - com.dlsc.flexgantt.swing.layer.system.AbstractSystemLayer
    - - com.dlsc.flexgantt.swing.layer.system.DragLayer

- All Implemented Interfaces:
    DragGestureListener, DragSourceListener, DropTargetListener, MouseMotionListener, EventListener

      public class DragLayer
      extends AbstractSystemLayer
      implements DragGestureListener, DragSourceListener, DropTargetListener, MouseMotionListener

  The drag layer is responsible for handling drag and drop events that are used to move timeline objects.
  Since:
    1.0
  Author:
    Dirk Lemmermann

- - ### Field Summary

    - ### Fields inherited from class com.dlsc.flexgantt.swing.layer.AbstractLayer

      `alpha, changeSupport, ganttChart, layerContainer, PROPERTY_ALPHA, PROPERTY_VISIBLE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DragLayer(LayerContainer lc)` Constructs a new drag layer.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addDragLayerListener(IDragLayerListener l)` Adds a drag layer listener to the drag layer.
    `protected Image` | `createDragImage(ObjectBounds bounds)` Creates an image that will be shown in combination with the drag cursor during drag & drop operations.
    `protected Cursor` | `createEditModeCursor(IEditModeController.EditMode mode)` Factory method for the cursors of the various edit modes.
    `protected Cursor` | `createEditModeCustomCursors(IEditModeController.EditMode mode)` Factory method for the cursors of the various edit modes.
    `protected Cursor` | `createEditModeDefaultCursors(IEditModeController.EditMode mode)` Factory method for the cursors of the various edit modes.
    `void` | `dragDropEnd(DragSourceDropEvent dsde)`
    `void` | `dragEnter(DragSourceDragEvent dsde)`
    `void` | `dragEnter(DropTargetDragEvent dtde)`
    `void` | `dragExit(DragSourceEvent dse)`
    `void` | `dragExit(DropTargetEvent dte)`
    `void` | `dragGestureRecognized(DragGestureEvent dge)`
    `void` | `dragOver(DragSourceDragEvent dsde)`
    `void` | `dragOver(DropTargetDragEvent dtde)`
    `void` | `drop(DropTargetDropEvent dtde)`
    `void` | `dropActionChanged(DragSourceDragEvent dsde)`
    `void` | `dropActionChanged(DropTargetDragEvent dtde)`
    `protected void` | `fireDragLayerEvent(DragLayerEvent evt)` Sends the given event object to all drag layer listeners that are currently observing the drag layer.
    `IDragInfoRenderer` | `getDragInfoRenderer(Class cl)` Returns a drag info renderer for a given timeline object type.
    `IDragRowRenderer` | `getDragRowRenderer(Class cl)` Returns a drag row renderer for a given tree / hierarchy node.
    `DropTarget` | `getDropTarget()` Returns the drop target object associated with the drag layer / the layer container.
    `IEditModeController.EditMode` | `getEditMode()` Returns the active edit mode.
    `IEditModeController` | `getEditModeController(Class cl)` Returns an edit mode controller for a given timeline object type.
    `MouseEvent` | `getTriggerEvent()` Returns the mouse event, which triggered the last drag gesture.
    `boolean` | `isDragging()` Determines whether the user is currently dragging an object.
    `boolean` | `isDragInfoVisible()` Determines whether the drag information is shown during a drag & drop operation.
    `boolean` | `isShowingDefaultCursors()` Determines whether the `#createEditModeCursor(EditMode)` method delegates to `#createEditModeDefaultCursors(EditMode)` or `#createEditModeCustomCursors(EditMode)`.
    `void` | `mouseDragged(MouseEvent e)`
    `void` | `mouseMoved(MouseEvent e)`
    `protected void` | `paintDragRowRenderers(Graphics g)` Paints the drag row renderers during a drag operation.
    `protected void` | `paintLayer(Graphics g)`
    `void` | `removeDragLayerListener(IDragLayerListener l)` Removes a drag layer listener from the drag layer.
    `void` | `setDragInfoRenderer(Class objectType, IDragInfoRenderer renderer)` Maps the implementation of a drag info renderer to a timeline object type.
    `void` | `setDragInfoVisible(boolean visible)` Specifies whether the drag information is shown during a drag & drop operation.
    `void` | `setDragRowRenderer(Class objectType, IDragRowRenderer renderer)` Maps the implementation of a drag row renderer to a tree node type.
    `void` | `setEditModeController(Class objectType, IEditModeController controller)` Maps the implementation of an edit mode controller to a timeline object type.
    `void` | `setShowingDefaultCursors(boolean show)` Specifies whether the `#createEditModeCursor(EditMode)` method delegates to `#createEditModeDefaultCursors(EditMode)` or `#createEditModeCustomCursors(EditMode)`.

    - ### Methods inherited from class com.dlsc.flexgantt.swing.layer.AbstractLayer

      `addPropertyChangeListener, getAlpha, getDateline, getEventline, getGanttChart, getHeight, getLayerContainer, getLayerPolicyProvider, getModel, getName, getStartRow, getTimeAt, getTimeline, getTimeLocation, getTimeSpanUsed, getToolTipText, getTreeTable, getTreeTablePolicyProvider, getWidth, isVisible, removePropertyChangeListener, repaint, repaint, repaint, setAlpha, setVisible, tearDown`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DragLayer

          public DragLayer(LayerContainer lc)

      Constructs a new drag layer.
      Parameters:
        `lc` - the layer container to which the drag layer belongs
      Since:
        1.0

  - ### Method Detail

    - #### isDragging

          public boolean isDragging()

      Determines whether the user is currently dragging an object.
      Returns:
        TRUE if an object is currently being dragged
      Since:
        1.0

    - #### paintLayer

          protected void paintLayer(Graphics g)

      Overrides:
        `paintLayer` in class `AbstractLayer`

    - #### paintDragRowRenderers

          protected void paintDragRowRenderers(Graphics g)

      Paints the drag row renderers during a drag operation. The method will look up an appropriate `IDragRowRenderer` implementation for each row in the layer container. The renderer can then visualize information relevant for the drag operation (for example: "drop here not allowed" causes the row to be grayed out).
      Parameters:
        `g` - the graphics context into which to draw
      Since:
        1.0
      See Also:
        `setDragRowRenderer(Class, IDragRowRenderer)`

    - #### setDragInfoRenderer

          public void setDragInfoRenderer(Class objectType,
                                          IDragInfoRenderer renderer)

      Maps the implementation of a drag info renderer to a timeline object type.
      Parameters:
        `objectType` - the type of the timeline object for which the info will be rendered with the given renderer
        `renderer` - a renderer implementation that will be used to renderer instances of the given timeline object type
      Since:
        1.0
      See Also:
        `DefaultDragInfoRenderer`

    - #### getDragInfoRenderer

          public IDragInfoRenderer getDragInfoRenderer(Class cl)

      Returns a drag info renderer for a given timeline object type.
      Parameters:
        `cl` - the timeline object type in need of rendering
      Returns:
        a matching drag info renderer implementation
      Since:
        1.0
      See Also:
        `setDragInfoRenderer(Class, IDragInfoRenderer)`, `DefaultDragInfoRenderer`

    - #### isDragInfoVisible

          public boolean isDragInfoVisible()

      Determines whether the drag information is shown during a drag & drop operation. The drag information is usually a small floating window that displays the time span that would be assigned to the currently dragged timeline object when the drop finishes.
      Returns:
        TRUE if the drag information is shown
      Since:
        1.0
      See Also:
        `IDragInfoPolicy`, `IDragInfoRenderer`, `setDragInfoRenderer(Class, IDragInfoRenderer)`

    - #### setDragInfoVisible

          public void setDragInfoVisible(boolean visible)

      Specifies whether the drag information is shown during a drag & drop operation. The drag information is usually a small floating window that displays the time span that would be assigned to the currently dragged timeline object when the drop finishes.
      Parameters:
        `visible` - if TRUE the drag info will be shown
      Since:
        1.0
      See Also:
        `IDragInfoPolicy`, `IDragInfoRenderer`, `setDragInfoRenderer(Class, IDragInfoRenderer)`

    - #### setDragRowRenderer

          public void setDragRowRenderer(Class objectType,
                                         IDragRowRenderer renderer)

      Maps the implementation of a drag row renderer to a tree node type.
      Parameters:
        `objectType` - the type of the tree node for which the row will be rendered with the given renderer
        `renderer` - a renderer implementation that will be used to renderer the row with drag and drop information
      Since:
        1.0
      See Also:
        `DefaultDragRowRenderer`

    - #### getDragRowRenderer

          public IDragRowRenderer getDragRowRenderer(Class cl)

      Returns a drag row renderer for a given tree / hierarchy node.
      Parameters:
        `cl` - the object type of the tree node
      Returns:
        a matching row renderer implementation
      Since:
        1.0
      See Also:
        `setDragRowRenderer(Class, IDragRowRenderer)`, `DefaultDragRowRenderer`

    - #### mouseMoved

          public void mouseMoved(MouseEvent e)

      Specified by:
        `mouseMoved` in interface `MouseMotionListener`

    - #### mouseDragged

          public void mouseDragged(MouseEvent e)

      Specified by:
        `mouseDragged` in interface `MouseMotionListener`

    - #### dragGestureRecognized

          public void dragGestureRecognized(DragGestureEvent dge)

      Specified by:
        `dragGestureRecognized` in interface `DragGestureListener`

    - #### createDragImage

          protected Image createDragImage(ObjectBounds bounds)

      Creates an image that will be shown in combination with the drag cursor during drag & drop operations. A drag image is not supported on all operating systems (e.g. MacOS X supports it, Windows XP does not).
      Parameters:
        `bounds` - the object bounds for which to create an image
      Returns:
        a drag image
      Since:
        1.0

    - #### dragDropEnd

          public void dragDropEnd(DragSourceDropEvent dsde)

      Specified by:
        `dragDropEnd` in interface `DragSourceListener`

    - #### dragEnter

          public void dragEnter(DragSourceDragEvent dsde)

      Specified by:
        `dragEnter` in interface `DragSourceListener`

    - #### dragExit

          public void dragExit(DragSourceEvent dse)

      Specified by:
        `dragExit` in interface `DragSourceListener`

    - #### dragOver

          public void dragOver(DragSourceDragEvent dsde)

      Specified by:
        `dragOver` in interface `DragSourceListener`

    - #### dropActionChanged

          public void dropActionChanged(DragSourceDragEvent dsde)

      Specified by:
        `dropActionChanged` in interface `DragSourceListener`

    - #### dragEnter

          public void dragEnter(DropTargetDragEvent dtde)

      Specified by:
        `dragEnter` in interface `DropTargetListener`

    - #### dragExit

          public void dragExit(DropTargetEvent dte)

      Specified by:
        `dragExit` in interface `DropTargetListener`

    - #### dragOver

          public void dragOver(DropTargetDragEvent dtde)

      Specified by:
        `dragOver` in interface `DropTargetListener`

    - #### drop

          public void drop(DropTargetDropEvent dtde)

      Specified by:
        `drop` in interface `DropTargetListener`

    - #### dropActionChanged

          public void dropActionChanged(DropTargetDragEvent dtde)

      Specified by:
        `dropActionChanged` in interface `DropTargetListener`

    - #### addDragLayerListener

          public void addDragLayerListener(IDragLayerListener l)

      Adds a drag layer listener to the drag layer. The listener will be notified about drag and resize operations that take place in the layer.
      Parameters:
        `l` - the drag layer listener
      Since:
        1.0

    - #### removeDragLayerListener

          public void removeDragLayerListener(IDragLayerListener l)

      Removes a drag layer listener from the drag layer.
      Parameters:
        `l` - the drag layer listener
      Since:
        1.0

    - #### fireDragLayerEvent

          protected void fireDragLayerEvent(DragLayerEvent evt)

      Sends the given event object to all drag layer listeners that are currently observing the drag layer.
      Parameters:
        `evt` - the drag layer event that will be sent to all listeners
      Since:
        1.0

    - #### setEditModeController

          public void setEditModeController(Class objectType,
                                            IEditModeController controller)

      Maps the implementation of an edit mode controller to a timeline object type.
      Parameters:
        `objectType` - the type of the timeline object for which the edit mode will be calculated by the given controller
        `controller` - an edit mode controller implementation that will make the actual decision on the edit mode that will be used when the mouse cursor hovers over a timeline object of the given type
      Since:
        1.0
      See Also:
        `DefaultEditModeController`

    - #### getEditModeController

          public IEditModeController getEditModeController(Class cl)

      Returns an edit mode controller for a given timeline object type.
      Parameters:
        `cl` - the timeline object type in need of rendering
      Returns:
        a matching drag info renderer implementation
      Since:
        1.0
      See Also:
        `setDragInfoRenderer(Class, IDragInfoRenderer)`, `DefaultDragInfoRenderer`

    - #### setShowingDefaultCursors

          public void setShowingDefaultCursors(boolean show)

      Specifies whether the `#createEditModeCursor(EditMode)` method delegates to `#createEditModeDefaultCursors(EditMode)` or `#createEditModeCustomCursors(EditMode)`.
      Parameters:
        `show` - if TRUE the layer will display the default cursors while dragging
      Since:
        2.0

    - #### isShowingDefaultCursors

          public boolean isShowingDefaultCursors()

      Determines whether the `#createEditModeCursor(EditMode)` method delegates to `#createEditModeDefaultCursors(EditMode)` or `#createEditModeCustomCursors(EditMode)`.
      Returns:
        TRUE if the layer is using the default cursors
      Since:
        2.0

    - #### createEditModeCursor

          protected Cursor createEditModeCursor(IEditModeController.EditMode mode)

      Factory method for the cursors of the various edit modes. Depending on the return value of `isShowingDefaultCursors()` the method delegates to `#createEditModeDefaultCursors(EditMode)` or `#createEditModeCustomCursors(EditMode)`.
      Parameters:
        `mode` - the edit mode for which to create a cursor
      Returns:
        a cursor for the given edit mode
      Since:
        1.0

    - #### createEditModeCustomCursors

          protected Cursor createEditModeCustomCursors(IEditModeController.EditMode mode)

      Factory method for the cursors of the various edit modes. The method looks up the cursors from the `IconRegistry` via the following identifiers:
      - `IconId.CURSOR_EDIT_CAPACITY`
      - `IconId.CURSOR_EDIT_PERCENTAGE`
      - `IconId.CURSOR_CHANGE_START_TIME`
      - `IconId.CURSOR_CHANGE_END_TIME`
      - `IconId.CURSOR_MOVE_HORIZONTAL`
      - `IconId.CURSOR_MOVE_VERTICAL`
      - `IconId.CURSOR_MOVE`
      The hotspot for the cursors is always (16, 16) except for the percentage complete cursor (31, 15).
      Parameters:
        `mode` - the edit mode for which to create a cursor
      Returns:
        a cursor for the given edit mode
      Since:
        1.0

    - #### createEditModeDefaultCursors

          protected Cursor createEditModeDefaultCursors(IEditModeController.EditMode mode)

      Factory method for the cursors of the various edit modes. The method uses the default cursors such as DEFAULT, N_RESIZE_CURSOR, W_RESIZE_CURSOR and E_RESIZE_CURSOR. Additionally it looks up the percentage complete cursor from the `IconRegistry` via the following identifiers:
      - `IconId.CURSOR_EDIT_PERCENTAGE`
      The hotspot for the percentage complete cursor located at (31, 15).
      Parameters:
        `mode` - the edit mode for which to create a cursor
      Returns:
        a cursor for the given edit mode
      Since:
        1.0

    - #### getEditMode

          public IEditModeController.EditMode getEditMode()

      Returns the active edit mode.
      Returns:
        the active edit mode
      Since:
        1.0

    - #### getDropTarget

          public DropTarget getDropTarget()

      Returns the drop target object associated with the drag layer / the layer container. This drop target supports multiple drop target listeners.
      Returns:
        the drop target
      Since:
        1.0
      See Also:
        `MultiDropTarget`

    - #### getTriggerEvent

          public MouseEvent getTriggerEvent()

      Returns the mouse event, which triggered the last drag gesture.
      Returns:
        the drag gesture trigger event
      Since:
        1.0
      See Also:
        `DragGestureEvent.getTriggerEvent()`

Copyright © 2006–2020 Dirk Lemmermann Software & Consulting. All rights reserved.