Class BrushToolEventHandler

java.lang.Object
qupath.lib.gui.viewer.tools.handlers.BrushToolEventHandler
All Implemented Interfaces:
EventListener, EventHandler<MouseEvent>
Direct Known Subclasses:
WandToolEventHandler

public class BrushToolEventHandler extends Object
Tool for drawing (and subtract from) freehand regions, optionally adapting brush size to magnification.
Author:
Pete Bankhead
  • Constructor Details

    • BrushToolEventHandler

      public BrushToolEventHandler()
  • Method Details

    • preferReturnToMove

      protected boolean preferReturnToMove()
      Returns false.
      Returns:
    • getRequestedCursor

      protected Cursor getRequestedCursor()
    • mouseExited

      public void mouseExited(MouseEvent e)
    • mouseEntered

      public void mouseEntered(MouseEvent e)
    • mouseMoved

      public void mouseMoved(MouseEvent e)
    • mousePressed

      public void mousePressed(MouseEvent e)
    • mouseDragged

      public void mouseDragged(MouseEvent e)
    • isSubtractMode

      protected boolean isSubtractMode(MouseEvent e)
    • mouseReleased

      public void mouseReleased(MouseEvent e)
    • getBrushDiameter

      protected double getBrushDiameter()
    • createShape

      protected Geometry createShape(MouseEvent e, double x, double y, boolean useTiles, Geometry addToShape)
      Create a new Geometry using the specified tool, assuming a user click/drag at the provided x & y coordinates.
      Parameters:
      e -
      x -
      y -
      useTiles - If true, request generating a shape from existing tile objects.
      addToShape - If provided, it can be assumed that any new shape ought to be added to this one. The purpose is that this method may (optionally) use the shape to refine the one it will generate, e.g. to avoid having isolated or jagged boundaries.
      Returns:
    • getGeometryFactory

      protected GeometryFactory getGeometryFactory()
    • createNewROI

      protected ROI createNewROI(MouseEvent e, double x, double y, ImagePlane plane)
      Create a new ROI with the given starting coordinates.
      Parameters:
      e -
      x -
      y -
      plane -
      Returns:
    • createNewAnnotation

      protected PathObject createNewAnnotation(MouseEvent e, double x, double y)
      Create a new annotation and set it in the current viewer.
      Parameters:
      e -
      x -
      y -
      Returns:
    • ensureCursorType

      protected void ensureCursorType(Cursor cursor)
      Ensure that the specified cursor is set in the current viewer.
      Parameters:
      cursor -
    • requestPixelSnapping

      protected boolean requestPixelSnapping()
      Returns true if the tool requests that pixel coordinates be snapped to integer values. Default returns true.
      Returns:
    • getViewer

      protected QuPathViewer getViewer()
    • mouseLocationToImage

      protected Point2D mouseLocationToImage(MouseEvent e, boolean constrainToBounds, boolean snapToPixel)
    • requestParentClipping

      protected boolean requestParentClipping(MouseEvent e)
      Query whether parent clipping should be applied.

      This might depend upon the MouseEvent.

      Parameters:
      e -
      Returns:
    • refineROIByParent

      protected ROI refineROIByParent(ROI currentROI)
      Apply clipping based on the current parent object.

      Returns an empty ROI if this result of the clipping is an empty area.

      Parameters:
      currentROI -
      Returns:
    • refineGeometryByParent

      protected Geometry refineGeometryByParent(Geometry geometry)
    • updatingConstrainingObjects

      protected void updatingConstrainingObjects(QuPathViewer viewer, double xx, double yy, Collection<PathObject> exclusions)
      New annotations can be constrained while they are being drawn, to avoid overlaps with existing annotations or to ensure they are drawn within a parent annotation.

      This method requests that the constraining objects are identified now based upon the specified mouse position. It is useful when starting to draw with a tool that makes use of constraining objects.

      Parameters:
      viewer - the viewer that may contain potential constraining objects
      xx - x-coordinate in the image space of the starting point for the new object
      yy - y-coordinate in the image space of the starting point for the new object
      exclusions - objects not to consider (e.g. the new ROI being created)
    • resetConstrainingObjects

      protected void resetConstrainingObjects()
      Reset the constraining objects. These should be done as soon as they are no longer required, to prevent a memory leak by inadvertently holding on to an object hierarchy too long.
    • getCurrentParent

      protected PathObject getCurrentParent()
    • mouseClicked

      public void mouseClicked(MouseEvent e)
    • handle

      public void handle(MouseEvent event)
      Specified by:
      handle in interface EventHandler<MouseEvent>