Class CanvasPanel

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.layout.Pane
javafx.scene.layout.StackPane
com.digitizer.ui.CanvasPanel
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget

public class CanvasPanel extends javafx.scene.layout.StackPane
Canvas panel for displaying the image and data points and handling pointer-based interactions (calibration, point placement, and auto-trace).

The CanvasPanel owns the JavaFX Canvas that renders images and points. Important coordinate-system notes:

  • The CoordinateTransformer maps between numeric data values and the image's natural pixel coordinates (image pixels).
  • The CanvasPanel renders the image at a scaled size using displayScale and an (optional) offsetX/offsetY. Therefore the UI must convert between image-pixel coordinates and canvas coordinates when drawing or interpreting mouse events. Helper methods imageToCanvas(Point2D) and canvasToImage(Point2D) perform that conversion.
  • Calibration anchors are stored in image-pixel coordinates in CalibrationState. This makes transforms independent of the current zoom or viewport offsets.

This class exposes operations used by ControlPanel and MainWindow including:

  • Property Summary

    Properties inherited from class javafx.scene.layout.StackPane

    alignment

    Properties inherited from class javafx.scene.layout.Region

    background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width

    Properties inherited from class javafx.scene.Parent

    needsLayout

    Properties inherited from class javafx.scene.Node

    accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
  • Field Summary

    Fields inherited from class javafx.scene.layout.Region

    USE_COMPUTED_SIZE, USE_PREF_SIZE

    Fields inherited from class javafx.scene.Node

    BASELINE_OFFSET_SAME_AS_HEIGHT
  • Constructor Summary

    Constructors
    Constructor
    Description
    CanvasPanel(CalibrationState calibration, List<Dataset> datasets, UndoManager undoManager)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    confirmCalibration(double dataXMin, double dataXMax, double dataYMin, double dataYMax, boolean xLog, boolean yLog, Double dataY2Min, Double dataY2Max, Boolean y2Log)
    Applies the collected calibration anchor points and numeric ranges.
    void
    Enters calibration mode for recording anchor points.
    void
    fitToViewport(double viewportWidth, double viewportHeight)
    Compute and apply a zoom that fits the canvas into the provided viewport size.
    double
    Gets the current point size.
    javafx.scene.paint.Color
     
     
    Exposes the Snapper so other UI components (e.g.
    double
    Current zoom factor.
    boolean
     
    boolean
    Gets whether shape variation is enabled.
    void
    Loads an image from a file.
    void
    Performs auto-trace on the active dataset.
    void
    Redraws the canvas.
    void
    Sets which dataset index is considered "active" for point additions and auto-trace.
    void
    setPointSize(double size)
    Sets the point size for rendering data points.
    void
    setSnapLineColor(javafx.scene.paint.Color color)
     
    void
     
    void
    setSnapLinesVisible(boolean visible)
    Set whether snap lines are visible (does not clear snap list).
    void
    setUseShapeVariation(boolean useShapes)
    Sets whether to use shape variation for different datasets.
    void
    setZoom(double z)
    Set the node-level zoom (scale) for the canvas.

    Methods inherited from class javafx.scene.layout.StackPane

    alignmentProperty, clearConstraints, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, getAlignment, getAlignment, getClassCssMetaData, getContentBias, getCssMetaData, getMargin, layoutChildren, requestLayout, setAlignment, setAlignment, setMargin

    Methods inherited from class javafx.scene.layout.Pane

    getChildren

    Methods inherited from class javafx.scene.layout.Region

    backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, computeMaxHeight, computeMaxWidth, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getUserAgentStylesheet, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isResizable, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty

    Methods inherited from class javafx.scene.Parent

    getBaselineOffset, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, queryAccessibleAttribute, requestParentLayout, setNeedsLayout, updateBounds

    Methods inherited from class javafx.scene.Node

    accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, executeAccessibleAction, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInitialFocusTraversable, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.css.Styleable

    getStyleableNode
  • Constructor Details

  • Method Details

    • setZoom

      public void setZoom(double z)
      Set the node-level zoom (scale) for the canvas. This uses node scaling so the canvas content does not need to be redrawn at a different resolution.
      Parameters:
      z - scale factor (1.0 = 100%)
    • setActiveDatasetIndex

      public void setActiveDatasetIndex(int idx)
      Sets which dataset index is considered "active" for point additions and auto-trace. This is intended to be driven by the dataset selector in ControlPanel.
      Parameters:
      idx - 0-based dataset index
    • getZoom

      public double getZoom()
      Current zoom factor.
    • fitToViewport

      public void fitToViewport(double viewportWidth, double viewportHeight)
      Compute and apply a zoom that fits the canvas into the provided viewport size. If image/canvas is smaller than viewport this may return a value > 1.0.
    • getSnapper

      public Snapper getSnapper()
      Exposes the Snapper so other UI components (e.g. ControlPanel) can configure the snap X values and tolerance.
      Returns:
      the Snapper instance used by this canvas
    • setSnapLinesVisible

      public void setSnapLinesVisible(boolean visible)
      Set whether snap lines are visible (does not clear snap list).
    • isSnapLinesVisible

      public boolean isSnapLinesVisible()
    • setSnapLineColor

      public void setSnapLineColor(javafx.scene.paint.Color color)
    • getSnapLineColor

      public javafx.scene.paint.Color getSnapLineColor()
    • setSnapLineStyle

      public void setSnapLineStyle(String style)
    • getSnapLineStyle

      public String getSnapLineStyle()
    • setPointSize

      public void setPointSize(double size)
      Sets the point size for rendering data points.
      Parameters:
      size - the point size in pixels
    • getPointSize

      public double getPointSize()
      Gets the current point size.
      Returns:
      the point size in pixels
    • setUseShapeVariation

      public void setUseShapeVariation(boolean useShapes)
      Sets whether to use shape variation for different datasets.
      Parameters:
      useShapes - true to use different shapes per dataset
    • isUseShapeVariation

      public boolean isUseShapeVariation()
      Gets whether shape variation is enabled.
      Returns:
      true if using shape variation
    • loadImage

      public void loadImage(File file) throws Exception
      Loads an image from a file.
      Parameters:
      file - the image file
      Throws:
      Exception
    • enterCalibrationMode

      public void enterCalibrationMode()
      Enters calibration mode for recording anchor points.
    • performAutoTrace

      public void performAutoTrace()
      Performs auto-trace on the active dataset.
    • redraw

      public void redraw()
      Redraws the canvas.
    • confirmCalibration

      public boolean confirmCalibration(double dataXMin, double dataXMax, double dataYMin, double dataYMax, boolean xLog, boolean yLog, Double dataY2Min, Double dataY2Max, Boolean y2Log)
      Applies the collected calibration anchor points and numeric ranges. This method is intended to be invoked by a UI control (e.g., ControlPanel Apply button) so calibration isn't applied automatically.
      Parameters:
      dataXMin - numeric X minimum provided by the user
      dataXMax - numeric X maximum provided by the user
      dataYMin - numeric Y minimum provided by the user (primary)
      dataYMax - numeric Y maximum provided by the user (primary)
      xLog - whether X axis should be logarithmic
      yLog - whether primary Y axis should be logarithmic
      dataY2Min - optional secondary Y minimum (nullable)
      dataY2Max - optional secondary Y maximum (nullable)
      y2Log - optional secondary Y log flag (nullable)
      Returns:
      true if calibration applied, false if insufficient anchor points