Class BaseToolHandler

java.lang.Object
edu.cnu.mdi.container.BaseToolHandler
All Implemented Interfaces:
IToolHandler
Direct Known Subclasses:
MapToolHandler

public class BaseToolHandler extends Object implements IToolHandler
Default tool handler for BaseContainer. This class provides standard implementations for all tools, which can be used as-is or overridden by subclasses.

Dragging an already-selected item translates every selected item that is draggable and belongs to an unlocked layer. Locked and non-draggable items remain in place. Resize and rotate gestures continue to affect only the item whose handle initiated the gesture.

Author:
heddle
  • Field Details

    • ZOOM_FACTOR

      protected static final double ZOOM_FACTOR
      See Also:
    • base

      protected BufferedImage base
    • buffer

      protected BufferedImage buffer
    • container

      protected final BaseContainer container
    • modifyItem

      protected AItem modifyItem
    • modifyItems

      protected final List<AItem> modifyItems
    • modifying

      protected boolean modifying
    • dragPressPoint

      protected Point dragPressPoint
  • Constructor Details

    • BaseToolHandler

      public BaseToolHandler(BaseContainer container)
      Constructor.
      Parameters:
      container - BaseContainer that owns this tool handler
  • Method Details

    • info

      public void info(GestureContext gc)
      Specified by:
      info in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • hitTest

      public Object hitTest(GestureContext gc, Point p)
      Hit test at the given point on the canvas.
      Specified by:
      hitTest in interface IToolHandler
      Parameters:
      gc - GestureContext providing context for the hit test
      p - Point to hit test
      Returns:
      Object that was hit, or null if nothing was hit
    • pointerClick

      public void pointerClick(GestureContext gc)
      Handle pointer click on an object at the given point.
      Specified by:
      pointerClick in interface IToolHandler
      Parameters:
      gc - GestureContext providing context for the click
    • pointerDoubleClick

      public void pointerDoubleClick(GestureContext gc)
      Handle pointer double click on an object at the given point.
      Specified by:
      pointerDoubleClick in interface IToolHandler
      Parameters:
      gc - GestureContext providing context for the double click
    • pointerRubberbanding

      public void pointerRubberbanding(GestureContext gc, Rectangle bounds)
      Description copied from interface: IToolHandler
      Pointer rubberband feedback (typically multi-select or region selection).
      Specified by:
      pointerRubberbanding in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      bounds - rubberband bounds (non-null)
    • beginDragObject

      public void beginDragObject(GestureContext gc)
      Description copied from interface: IToolHandler
      Begin dragging an object/selection.
      Specified by:
      beginDragObject in interface IToolHandler
      Parameters:
      gc - gesture context (non-null). gc.getTarget() is the drag target.
    • dragObjectBy

      public void dragObjectBy(GestureContext gc, int dx, int dy)
      Description copied from interface: IToolHandler
      Drag the object/selection by a pixel delta.
      Specified by:
      dragObjectBy in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      dx - delta x since last update
      dy - delta y since last update
    • endDragObject

      public void endDragObject(GestureContext gc)
      Description copied from interface: IToolHandler
      End dragging an object/selection.
      Specified by:
      endDragObject in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • boxZoomRubberbanding

      public void boxZoomRubberbanding(GestureContext gc, Rectangle bounds)
      Description copied from interface: IToolHandler
      Box-zoom rubberband completion (or continuous feedback depending on tool).
      Specified by:
      boxZoomRubberbanding in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      bounds - rubberband bounds (non-null)
    • panStartDrag

      public void panStartDrag(GestureContext gc)
      Specified by:
      panStartDrag in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • panUpdateDrag

      public void panUpdateDrag(GestureContext gc)
      Specified by:
      panUpdateDrag in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • panDoneDrag

      public void panDoneDrag(GestureContext gc)
      Specified by:
      panDoneDrag in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • magnifyStartMove

      public void magnifyStartMove(GestureContext gc)
      Specified by:
      magnifyStartMove in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • magnifyUpdateMove

      public void magnifyUpdateMove(GestureContext gc)
      Specified by:
      magnifyUpdateMove in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • magnifyDoneMove

      public void magnifyDoneMove(GestureContext gc)
      Specified by:
      magnifyDoneMove in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • recenter

      public void recenter(GestureContext gc)
      Specified by:
      recenter in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
    • zoomIn

      public void zoomIn(GestureContext gc)
      Specified by:
      zoomIn in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • zoomOut

      public void zoomOut(GestureContext gc)
      Specified by:
      zoomOut in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • undoZoom

      public void undoZoom(GestureContext gc)
      Specified by:
      undoZoom in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • resetZoom

      public void resetZoom(GestureContext gc)
      Specified by:
      resetZoom in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • styleEdit

      public void styleEdit(GestureContext gc)
      Specified by:
      styleEdit in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • delete

      public void delete(GestureContext gc)
      Specified by:
      delete in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • createConnection

      public void createConnection(GestureContext gc, Point start, Point end)
      Description copied from interface: IToolHandler
      Create a connection between two points.
      Specified by:
      createConnection in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      start - start point (non-null)
      end - end point (non-null)
    • approveConnectionPoint

      public boolean approveConnectionPoint(GestureContext gc, Point p)
      Description copied from interface: IToolHandler
      Approve or reject a connection point.
      Specified by:
      approveConnectionPoint in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      p - point to approve/reject (non-null)
      Returns:
      true to approve
    • createRectangle

      public void createRectangle(GestureContext gc, Rectangle bounds)
      Description copied from interface: IToolHandler
      Create a rectangle.
      Specified by:
      createRectangle in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      bounds - rectangle bounds (non-null)
    • createEllipse

      public void createEllipse(GestureContext gc, Rectangle bounds)
      Description copied from interface: IToolHandler
      Create an ellipse.
      Specified by:
      createEllipse in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      bounds - ellipse bounds (non-null)
    • createPolygon

      public void createPolygon(GestureContext gc, Point[] vertices)
      Description copied from interface: IToolHandler
      Create a polygon.
      Specified by:
      createPolygon in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      vertices - polygon vertices (non-null)
    • createPolyline

      public void createPolyline(GestureContext gc, Point[] vertices)
      Description copied from interface: IToolHandler
      Create a polyline.
      Specified by:
      createPolyline in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      vertices - polyline vertices (non-null)
    • createLine

      public void createLine(GestureContext gc, Point start, Point end)
      Description copied from interface: IToolHandler
      Create a line between two points.
      Specified by:
      createLine in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      start - start point
      end - end point
    • createRadArc

      public void createRadArc(GestureContext gc, Point[] pp)
      Description copied from interface: IToolHandler
      Create a radial arc.

      The expected interpretation of vertices is tool-defined; for a typical radial arc gesture:

      • vertices[0] = center
      • vertices[1] = radius leg endpoint
      • vertices[2] = angle-defining point
      Specified by:
      createRadArc in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      pp - gesture vertices (non-null)
    • createTextItem

      public void createTextItem(GestureContext gc, Point location)
      Description copied from interface: IToolHandler
      Create a text item at the given location.
      Specified by:
      createTextItem in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      location - text location (non-null)
    • captureImage

      public void captureImage(GestureContext gc)
      Specified by:
      captureImage in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • print

      public void print(GestureContext gc)
      Specified by:
      print in interface IToolHandler
      Parameters:
      gc - context (non-null)
    • doNotDrag

      public boolean doNotDrag(GestureContext gc)
      Description copied from interface: IToolHandler
      Optional veto before starting a drag.
      Specified by:
      doNotDrag in interface IToolHandler
      Parameters:
      gc - gesture context (non-null)
      Returns:
      true to veto drag start, false to allow