Class Ruler
java.lang.Object
com.amalgamasimulation.graphicaleditor.views.Ruler
- Direct Known Subclasses:
HorizontalRuler,VerticalRuler
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final javafx.scene.paint.Colorprotected final javafx.scene.canvas.Canvasprotected final CustomInfiniteCanvasstatic final doublestatic final doublestatic final doublestatic final doublestatic final double -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecalculateStep(double zoom, double minPixels) Calculates the optimal step size between ruler ticks based on zoom level and minimum pixel distance.javafx.scene.canvas.CanvasReturns the Canvas node used for rendering the ruler.abstract voidupdate()Updates ruler rendering based on current: Canvas viewport position Zoom level Content dimensions
-
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
-
-
Constructor Details
-
Ruler
-
-
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:- Converts minimum pixel distance to model space
- Calculates base-10 exponent of the model distance
- Selects step from {1, 2, 5, 10} × 10exponent
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:
- Clears existing ruler graphics
- Draws baseline along ruler bottom edge
- Calculates tick positions using
calculateStep(double, double) - Draws major/minor ticks with labels
- Applies label collision avoidance
Coordinate notes:
- Uses model-space coordinates from parent canvas
- Accounts for palette offset via adjusted coordinates
-