Class RubberRadArc

All Implemented Interfaces:
IRubberbandAngleProvider, MouseListener, MouseMotionListener, EventListener

public class RubberRadArc extends AClickRubberband implements IRubberbandAngleProvider
Click-based, three-click radial-arc (pie-wedge) gesture.

Interaction

  1. First click: the arc's center.
  2. Second click: the endpoint of the first leg, which fixes the radius (see scaleToFirstRadius(java.awt.Point)).
  3. Third click (or drag preview before it): the endpoint of the second leg, whose distance from center is rescaled to match the first leg's radius, and whose angle relative to the first leg determines the swept arc.

Sweep tracking

The signed sweep angle between the two legs, in degrees, is recomputed on every mouse move via updateSweepForCurrentPoint(java.awt.Point). Because Math.atan2(double, double) only returns a value in (-180, 180], dragging the second leg all the way around the center would otherwise cause the reported sweep to jump discontinuously at the ±180° boundary. This class instead unwraps the sweep across that boundary, so sweepDeg can exceed ±180° for a drag that goes more than halfway around, and callers (via getRubberbandAngleDeg()) see a continuous value rather than a wrapped one. This unwrapped angle cannot be reconstructed from the gesture's vertices alone, hence IRubberbandAngleProvider.

  • Constructor Details

  • Method Details

    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
      Overrides:
      mousePressed in class ARubberband
    • getRubberbandAngleDeg

      public double getRubberbandAngleDeg()
      Specified by:
      getRubberbandAngleDeg in interface IRubberbandAngleProvider
      Returns:
      signed, unwrapped sweep angle in degrees (may exceed 180 in magnitude)
    • isGestureValid

      public boolean isGestureValid(int minSizePx)
      Description copied from class: ARubberband
      Validity rules depend on the policy; default is area-based (bounds must exceed min size). Click-based policies should override with their own rules.
      Overrides:
      isGestureValid in class ARubberband
      Parameters:
      minSizePx - minimum size in pixels for validity; interpretation depends on policy (e.g. max dimension for polygons).
      Returns:
      true if the current gesture state is valid for completion, false if it should be rejected (e.g. too small).
    • computeVertices

      protected Point[] computeVertices()
      Description copied from class: ARubberband
      Get the vertices of the rubberband shape based on the current state. Used for click-based policies and by toolbars to read results. Default implementation returns the corners of the bounding rectangle, which is suitable for rectangles and ovals but not for lines or polygons. Subclasses should override this if their shape has specific vertex requirements.
      Overrides:
      computeVertices in class ARubberband
      Returns:
      an array of points representing the vertices of the rubberband shape, or null if not applicable.
    • draw

      protected void draw(Graphics2D g)
      Description copied from class: ARubberband
      Draw the rubberband shape based on the current state. Called during dragging or when the toolbar requests a preview update. Subclasses must implement this to define the visual appearance of the rubberband.
      Specified by:
      draw in class ARubberband
      Parameters:
      g -
    • getRubberbandBounds

      public Rectangle getRubberbandBounds()
      Description copied from class: ARubberband
      Get the bounding rectangle of the rubberband shape based on the current state. Used for area-based validity checks and as a default for vertex calculations. Subclasses should override this if their shape is not well-represented by a bounding rectangle (e.g. lines, polygons).
      Specified by:
      getRubberbandBounds in class ARubberband
      Returns:
      the bounding rectangle of the rubberband shape, or null if not applicable.