Class BoardStackPane

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.layout.Pane
javafx.scene.layout.StackPane
edu.ntnu.idi.idatt.view.common.BoardStackPane
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget
Direct Known Subclasses:
LadderGameBoardStackPane, LudoGameBoardStackPane

public abstract class BoardStackPane extends javafx.scene.layout.StackPane
BoardStackPane.

Abstract JavaFX StackPane that serves as the base for displaying game boards. It manages a background image, a grid overlay, and a pane for draggable/interactive TileActionComponents (like ladders or slides), if enabled.

This class handles the visual representation of the board, mapping grid cells to coordinates, and managing the placement and removal of board components. Subclasses are responsible for specific implementations of grid creation, component loading, and visual updates.

See Also:
  • 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
    Modifier and Type
    Field
    Description
    protected final javafx.scene.image.ImageView
     
    protected Board
     
    protected double[]
     
    protected final Map<javafx.scene.shape.Rectangle,TileCoordinates>
     
     
    protected final javafx.scene.layout.Pane
     
    protected final javafx.scene.layout.VBox
     
    protected static final org.slf4j.Logger
     
    Consumer for handling events when a component is dropped onto the board.
    protected Runnable
    Runnable action for removing components that are placed outside the valid grid area.

    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
    Constructs a BoardStackPane, initializing its internal maps and visual layers (background, grid, components pane).
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    addComponent(String componentIdentifier, TileCoordinates coordinates)
    Adds a new TileActionComponent to the board at the specified coordinates.
    abstract void
    Applies a specific visual pattern or layout to the board's grid cells.
    abstract javafx.scene.layout.StackPane
    createRowCell(double cellWidth, double cellHeight, int row, int col)
    Creates a single cell (typically a StackPane containing a Rectangle) for the board grid at the specified row and column.
    protected javafx.scene.shape.Rectangle
    Finds and returns the visual grid cell (Rectangle) that corresponds to the given TileCoordinates.
    javafx.scene.image.ImageView
    Gets the ImageView used to display the board's background.
    Gets the underlying Board model associated with this display.
    double[]
    Gets the current dimensions (width, height) of the board area in pixels.
    Map<javafx.scene.shape.Rectangle,TileCoordinates>
    Gets the map that links visual grid cells (Rectangle) to their TileCoordinates.
    Gets the map of placed TileActionComponents, keyed by their TileCoordinates.
    javafx.scene.layout.Pane
    Gets the Pane used as a layer for displaying TileActionComponents.
    javafx.scene.layout.VBox
    Gets the VBox container that holds the grid rows.
    protected abstract String
    getImagePath(String componentIdentifier)
    Retrieves the image path for a given component identifier.
    void
    initialize(Board board, String backgroundImagePath)
    Initializes the BoardStackPane with a specific Board model and a background image.
    protected abstract void
    Loads visual components (e.g., ladders, slides) onto the board based on the current board model.
    void
    Removes a TileActionComponent from the board at the specified coordinates.
    protected void
    Resets the BoardStackPane by clearing all internal maps (cells, components) and removing children from the grid and components panes.
    void
    setBackground(String backgroundImagePath)
    Sets the background image for the board.
    void
    setBoard(Board board)
    Sets the Board model for this display.
    void
    setBoardDimensions(double[] boardDimensions)
    Sets the pixel dimensions (width, height) for the board display area.
    protected void
    Sets up listeners, particularly for changes in the backgroundImageView layout bounds, to update boardDimensions and trigger updateBoardVisuals().
    void
    Sets a callback Consumer to be executed when a component is dropped onto the board.
    void
    setOnRemoveComponentsOutsideGrid(Runnable onRemoveComponentsOutsideGrid)
    Sets a Runnable action to be executed when components placed outside the grid need to be removed.
    abstract void
    Updates all visual aspects of the board, including the grid and component placements.
    abstract void
    Updates or recreates the grid display based on the current board dimensions and configuration.

    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
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • cellToCoordinatesMap

      protected final Map<javafx.scene.shape.Rectangle,TileCoordinates> cellToCoordinatesMap
    • components

      protected final Map<TileCoordinates,TileActionComponent> components
    • boardDimensions

      protected double[] boardDimensions
    • board

      protected Board board
    • backgroundImageView

      protected final javafx.scene.image.ImageView backgroundImageView
    • gridContainer

      protected final javafx.scene.layout.VBox gridContainer
    • componentsPane

      protected final javafx.scene.layout.Pane componentsPane
    • onComponentDropped

      protected Consumer<ComponentDropEventData> onComponentDropped
      Consumer for handling events when a component is dropped onto the board.
    • onRemoveComponentsOutsideGrid

      protected Runnable onRemoveComponentsOutsideGrid
      Runnable action for removing components that are placed outside the valid grid area.
  • Constructor Details

    • BoardStackPane

      public BoardStackPane()
      Constructs a BoardStackPane, initializing its internal maps and visual layers (background, grid, components pane).
  • Method Details

    • loadComponents

      protected abstract void loadComponents()
      Loads visual components (e.g., ladders, slides) onto the board based on the current board model. Subclasses must implement this to populate the componentsPane with TileActionComponents.
    • getImagePath

      protected abstract String getImagePath(String componentIdentifier)
      Retrieves the image path for a given component identifier. This is used to find the visual asset for a TileActionComponent.
      Parameters:
      componentIdentifier - The unique identifier of the component (e.g., "ladder_1R_2U").
      Returns:
      The file path to the component's image.
    • addComponent

      public abstract void addComponent(String componentIdentifier, TileCoordinates coordinates)
      Adds a new TileActionComponent to the board at the specified coordinates. Subclasses must implement the logic for creating and placing the component visually.
      Parameters:
      componentIdentifier - The identifier for the type of component to add.
      coordinates - The TileCoordinates where the component should be placed.
    • updateBoardVisuals

      public abstract void updateBoardVisuals()
      Updates all visual aspects of the board, including the grid and component placements. This is often called after changes to board dimensions or component configurations.
    • applyPattern

      public abstract void applyPattern()
      Applies a specific visual pattern or layout to the board's grid cells. Subclasses define what a "pattern" means in their context (e.g., alternating colors, numbering).
    • updateGrid

      public abstract void updateGrid()
      Updates or recreates the grid display based on the current board dimensions and configuration.
    • createRowCell

      public abstract javafx.scene.layout.StackPane createRowCell(double cellWidth, double cellHeight, int row, int col)
      Creates a single cell (typically a StackPane containing a Rectangle) for the board grid at the specified row and column.
      Parameters:
      cellWidth - The calculated width for the cell.
      cellHeight - The calculated height for the cell.
      row - The row index of the cell.
      col - The column index of the cell.
      Returns:
      The created StackPane representing the grid cell.
    • initialize

      public void initialize(Board board, String backgroundImagePath)
      Initializes the BoardStackPane with a specific Board model and a background image. This involves resetting the pane, setting the board, and applying the background.
      Parameters:
      board - The game Board model to display.
      backgroundImagePath - The file path to the background image.
    • getCellToCoordinatesMap

      public Map<javafx.scene.shape.Rectangle,TileCoordinates> getCellToCoordinatesMap()
      Gets the map that links visual grid cells (Rectangle) to their TileCoordinates.
      Returns:
      The cell-to-coordinates map.
    • getComponents

      public Map<TileCoordinates,TileActionComponent> getComponents()
      Gets the map of placed TileActionComponents, keyed by their TileCoordinates.
      Returns:
      The map of components.
    • getBoardDimensions

      public double[] getBoardDimensions()
      Gets the current dimensions (width, height) of the board area in pixels.
      Returns:
      An array containing [width, height].
    • getBoard

      public Board getBoard()
      Gets the underlying Board model associated with this display.
      Returns:
      The board model.
    • getBackgroundImageView

      public javafx.scene.image.ImageView getBackgroundImageView()
      Gets the ImageView used to display the board's background.
      Returns:
      The background image view.
    • getComponentsPane

      public javafx.scene.layout.Pane getComponentsPane()
      Gets the Pane used as a layer for displaying TileActionComponents.
      Returns:
      The components pane.
    • getGridContainer

      public javafx.scene.layout.VBox getGridContainer()
      Gets the VBox container that holds the grid rows.
      Returns:
      The grid container.
    • setBackground

      public void setBackground(String backgroundImagePath)
      Sets the background image for the board. Updates both the model's background property and the backgroundImageView.
      Parameters:
      backgroundImagePath - The file path to the background image.
    • setBoard

      public void setBoard(Board board)
      Sets the Board model for this display.
      Parameters:
      board - The board model to use.
    • setBoardDimensions

      public void setBoardDimensions(double[] boardDimensions)
      Sets the pixel dimensions (width, height) for the board display area.
      Parameters:
      boardDimensions - An array containing [width, height].
    • setOnComponentDropped

      public void setOnComponentDropped(Consumer<ComponentDropEventData> onComponentDropped)
      Sets a callback Consumer to be executed when a component is dropped onto the board. The consumer receives ComponentDropEventData with details about the drop.
      Parameters:
      onComponentDropped - The consumer to handle component drop events.
    • setOnRemoveComponentsOutsideGrid

      public void setOnRemoveComponentsOutsideGrid(Runnable onRemoveComponentsOutsideGrid)
      Sets a Runnable action to be executed when components placed outside the grid need to be removed.
      Parameters:
      onRemoveComponentsOutsideGrid - The runnable action.
    • setNodeListeners

      protected void setNodeListeners()
      Sets up listeners, particularly for changes in the backgroundImageView layout bounds, to update boardDimensions and trigger updateBoardVisuals().
    • reset

      protected void reset()
      Resets the BoardStackPane by clearing all internal maps (cells, components) and removing children from the grid and components panes.
    • removeComponent

      public void removeComponent(TileCoordinates coordinates)
      Removes a TileActionComponent from the board at the specified coordinates. Updates the visual display after removal.
      Parameters:
      coordinates - The TileCoordinates of the component to remove.
    • findCellByCoordinates

      protected javafx.scene.shape.Rectangle findCellByCoordinates(TileCoordinates coordinates)
      Finds and returns the visual grid cell (Rectangle) that corresponds to the given TileCoordinates.
      Parameters:
      coordinates - The coordinates to search for.
      Returns:
      The matching Rectangle cell, or null if not found.