java.lang.Object
com.amalgamasimulation.graphicaleditor.views.Ruler
Direct Known Subclasses:
HorizontalRuler, VerticalRuler

public abstract class Ruler extends Object
Provides static utility methods and constants for ruler implementations. Contains shared functionality for:
  • Calculating tick step sizes based on zoom level
  • Defining ruler dimensions and tick lengths
  • Establishing minimum spacing between ticks

Key features:

  • Step Calculation: Dynamically determines optimal tick intervals
  • Standardized Measurements: Defines consistent ruler dimensions
  • Rendering Constants: Provides shared values for tick lengths and margins
See Also:
  • Field Details

    • RULER_SIZE

      public static final double RULER_SIZE
      See Also:
    • VERTICAL_OFFSET

      public static final double VERTICAL_OFFSET
      See Also:
    • MAJOR_TICK_LENGTH

      public static final double MAJOR_TICK_LENGTH
      See Also:
    • MINOR_TICK_LENGTH

      public static final double MINOR_TICK_LENGTH
      See Also:
    • MIN_TICK_DISTANCE

      public static final double MIN_TICK_DISTANCE
      See Also:
    • BACKGROUND_COLOR

      public static final javafx.scene.paint.Color BACKGROUND_COLOR
    • canvas

      protected final javafx.scene.canvas.Canvas canvas
    • infiniteCanvas

      protected final CustomInfiniteCanvas infiniteCanvas
  • Constructor Details

  • Method Details

    • calculateStep

      public static double calculateStep(double zoom, double minPixels)
      Calculates the optimal step size between ruler ticks based on zoom level and minimum pixel distance. The algorithm:
      1. Converts minimum pixel distance to model space
      2. Calculates base-10 exponent of the model distance
      3. Selects step from {1, 2, 5, 10} × 10exponent
      Example: At zoom=2.0 with minPixels=50:
         minStepModel = 50 / 2.0 = 25
         exponent = floor(log10(25)) = 1
         fraction = 25 / 10^1 = 2.5 → step=5
         returns 5 × 10^1 = 50
       
      Parameters:
      zoom - Current zoom level (pixels per model unit)
      minPixels - Minimum allowed pixel distance between major ticks
      Returns:
      Optimal step size in model coordinates
      Throws:
      IllegalArgumentException - if zoom ≤ 0 or minPixels ≤ 0
    • getCanvas

      public javafx.scene.canvas.Canvas getCanvas()
      Returns the Canvas node used for rendering the ruler.
      Returns:
      Renderable Canvas component
    • update

      public abstract void update()
      Updates ruler rendering based on current:
      • Canvas viewport position
      • Zoom level
      • Content dimensions

      Rendering workflow:

      1. Clears existing ruler graphics
      2. Draws baseline along ruler bottom edge
      3. Calculates tick positions using calculateStep(double, double)
      4. Draws major/minor ticks with labels
      5. Applies label collision avoidance

      Coordinate notes:

      • Uses model-space coordinates from parent canvas
      • Accounts for palette offset via adjusted coordinates