java.lang.Object
org.opensourcephysics.cabrillo.tracker.Ruler
Direct Known Subclasses:
AngleRuler, WorldRuler

public abstract class Ruler extends Object
This draws ruled lines and labels for a protractor.
Author:
Douglas Brown
  • Field Details

    • DASHED_LINE

      protected static final float[] DASHED_LINE
    • MAX_RULER_SIZE

      protected static final int MAX_RULER_SIZE
      See Also:
    • DEFAULT_RULER_SIZE

      protected static final int DEFAULT_RULER_SIZE
      See Also:
    • MAX_RULER_LINE_SPACING

      protected static final double MAX_RULER_LINE_SPACING
      See Also:
    • MIN_RULER_LINE_SPACING

      protected static final double MIN_RULER_LINE_SPACING
      See Also:
    • NUMBER_OF_LEVELS

      protected static final int NUMBER_OF_LEVELS
      See Also:
    • MIN_INSET_PER_LEVEL

      protected static final int MIN_INSET_PER_LEVEL
      See Also:
    • DEFAULT_LABEL_GAP

      protected static final int DEFAULT_LABEL_GAP
      See Also:
    • DEFAULT_LINE_GAP

      protected static final int DEFAULT_LINE_GAP
      See Also:
    • track

      protected InputTrack track
    • baseStrokes

      protected BasicStroke[] baseStrokes
    • strokes

      protected BasicStroke[] strokes
    • dashedStroke

      protected BasicStroke dashedStroke
    • colors

      protected Color[] colors
    • alpha

      protected int alpha
    • lines

      protected ArrayList<ArrayList<Line2D>> lines
    • multiShapes

      protected org.opensourcephysics.cabrillo.tracker.MultiShape[] multiShapes
    • labelMarks

      protected ArrayList<org.opensourcephysics.cabrillo.tracker.Ruler.Label> labelMarks
    • handle

      protected org.opensourcephysics.cabrillo.tracker.Ruler.Handle handle
    • utilityPoint

      protected TPoint utilityPoint
    • visible

      protected boolean visible
    • hitShapeVisible

      protected boolean hitShapeVisible
    • rulerSize

      protected double rulerSize
    • rulerLineSpacing

      protected double rulerLineSpacing
    • insetPerLevel

      protected int insetPerLevel
    • labelGap

      protected int labelGap
    • lineGap

      protected int lineGap
    • transform

      protected AffineTransform transform
    • labelTransform

      protected AffineTransform labelTransform
    • format

      protected DecimalFormat format
    • previousDistFromLineEnd

      protected Double previousDistFromLineEnd
    • previousLineSpacing

      protected double previousLineSpacing
    • previousAngle

      protected double previousAngle
    • prevSigFigs

      protected int prevSigFigs
  • Constructor Details

    • Ruler

      public Ruler(InputTrack track)
      Constructor.
      Parameters:
      track - a TapeMeasure or Protractor
  • Method Details

    • getMark

      protected abstract Mark getMark(TrackerPanel trackerPanel, int n)
      Gets the mark to draw for a given frame.
      Parameters:
      trackerPanel - the TrackerPanel to draw on
      n - the frame number
      Returns:
      the Mark
    • findInteractive

      protected Interactive findInteractive(TrackerPanel trackerPanel, Rectangle hitRect)
      Returns the Handle if this Ruler's hit shape intersects the supplied Rectangle.
      Parameters:
      trackerPanel - the TrackerPanel
      hitRect - the Rectangle
      Returns:
      the Handle if hit
    • setHandleXY

      protected void setHandleXY(double x, double y)
      Set the handle position in image units.
      Parameters:
      x -
      y -
    • getHandle

      public org.opensourcephysics.cabrillo.tracker.Ruler.Handle getHandle()
      Gets the handle, used to adjust the ruler size
      Returns:
      the Handle TPoint
    • setHitShapeVisible

      protected void setHitShapeVisible(boolean vis)
      Sets the visibility of the hit shape
      Parameters:
      vis - true to draw the hit shape
    • setStrokeWidth

      public void setStrokeWidth(float width)
      Sets the stroke width.
      Parameters:
      width - the desired width
    • getStrokeWidth

      public float getStrokeWidth()
      Gets the stroke width.
      Returns:
      the width
    • refreshStrokes

      public void refreshStrokes()
      Refreshes the strokes.
    • setRulerSize

      public void setRulerSize(double size)
      Sets the ruler size. May be positive or negative.
      Parameters:
      size - the desired size
    • getRulerSize

      public double getRulerSize()
      Gets the ruler size--width for tapes, radius for protractors.
      Returns:
      the size
    • setLineSpacing

      public void setLineSpacing(double space)
      Sets the ruler line spacing. The line spacing is the minimum allowed screen distance between ruler lines--the actual spacing depends on the scale.
      Parameters:
      space - the desired spacing
    • getLineSpacing

      public double getLineSpacing()
      Gets the ruler line spacing.
      Returns:
      the spacing
    • getColor

      public Color getColor()
      Gets the color.
      Returns:
      the line color
    • setColor

      public void setColor(Color color)
      Sets the color.
      Parameters:
      color - the desired line color
    • getAlpha

      public int getAlpha()
      Gets the alpha.
      Returns:
      the line color alpha
    • setAlpha

      public void setAlpha(int alpha)
      Sets the alpha.
      Parameters:
      alpha - the desired alpha
    • setVisible

      public void setVisible(boolean isVisible)
      Sets the visibility of the ruler.
      Parameters:
      isVisible - true to draw this ruler
    • isVisible

      public boolean isVisible()
      Gets the visibility of the ruler.
      Returns:
      true if visible
    • getFormattedValue

      public String getFormattedValue(double value, double min)
      Formats the specified value.
      Parameters:
      value - the value to format
      min - the smallest value expected, used to determine format pattern
      Returns:
      the formatted value string
    • getScreenDistanceToBase

      protected double getScreenDistanceToBase(Point p)
      Gets the perpendicular screen distance from a Point to the tape or protractor base line.
      Returns:
      the distance in screen pixels
    • isLeft

      protected boolean isLeft(TPoint p, TPoint end1, TPoint end2)
      Determines if a TPoint p is to the left of the line defined by end1 and end2.
      Parameters:
      p - the TPoint to test
      end1 - one end of the line
      end2 - second end of the line
      Returns:
      true if to the left