Class LayoutTrackView

  • Direct Known Subclasses:
    LayoutTurnoutView, LayoutTurntableView, LevelXingView, PositionablePointView, TrackSegmentView

    public abstract class LayoutTrackView
    extends Object
    MVC View component abstract base for the LayoutTrack hierarchy.

    This contains the display information, including screen geometry, for a LayoutEditor panel. The geometry/connectivity information is held in LayoutTrack subclasses.

    • Position(s) of the screen icons and its parts, typically the center; scaling and translation; size and bounds
    • Line colors
    • Flipped status; drawing details like bezier curve points
    • Various decorations: arrows, tunnels, bridges
    • Hidden status
    • Method Detail

      • setCoordsCenter

        public void setCoordsCenter​(@Nonnull
                                    Point2D p)
        Set center coordinates.

        Some subtypes may reimplement this is "center" is a more complicated idea, i.e. for Bezier curves

        Parameters:
        p - the coordinates to set
      • hasDecorations

        public boolean hasDecorations()
        Returns:
        true if this track segment has decorations
      • setDecorations

        public void setDecorations​(Map<String,​String> decorations)
        Set new decorations This is a complete replacement of the decorations, not an appending.
        Parameters:
        decorations - A map from strings ("arrow", "bridge", "bumper",..) to specific value strings ("single", "entry;right", ), perhaps including multiple values separated by semicolons.
      • draw1

        protected abstract void draw1​(Graphics2D g2,
                                      boolean isMain,
                                      boolean isBlock)
        draw one line (Ballast, ties, center or 3rd rail, block lines)
        Parameters:
        g2 - the graphics context
        isMain - true if drawing mainlines
        isBlock - true if drawing block lines
      • draw2

        protected abstract void draw2​(Graphics2D g2,
                                      boolean isMain,
                                      float railDisplacement)
        draw two lines (rails)
        Parameters:
        g2 - the graphics context
        isMain - true if drawing mainlines
        railDisplacement - the offset from center to draw the lines
      • drawHidden

        protected final void drawHidden​(Graphics2D g2)
        draw hidden track
        Parameters:
        g2 - the graphics context
      • drawLayoutTrackText

        protected final void drawLayoutTrackText​(Graphics2D g)
        draw the text for this layout track
        Parameters:
        g - note: currently can't override (final); change this if you need to
      • loadArrowImageToJCBItem

        public JCheckBoxMenuItem loadArrowImageToJCBItem​(int n,
                                                         JMenu arrowsCountMenu)
        Load a file for a specific arrow ending.
        Parameters:
        n - The arrow type as a number
        arrowsCountMenu - menu containing the arrows to set visible selection
        Returns:
        An item for the arrow menu
      • highlightUnconnected

        protected abstract void highlightUnconnected​(Graphics2D g2,
                                                     HitPointType specificType)
        highlight unconnected connections
        Parameters:
        g2 - the graphics context
        specificType - the specific connection to draw (or NONE for all)
      • drawEditControls

        protected abstract void drawEditControls​(Graphics2D g2)
        draw the edit controls
        Parameters:
        g2 - the graphics context
      • drawTurnoutControls

        protected abstract void drawTurnoutControls​(Graphics2D g2)
        Draw the turnout controls
        Parameters:
        g2 - the graphics context
      • drawDecorations

        protected abstract void drawDecorations​(Graphics2D g2)
        Draw track decorations
        Parameters:
        g2 - the graphics context
      • isHidden

        public final boolean isHidden()
        Get the hidden state of the track element.
        Returns:
        true if hidden; false otherwise
      • setHidden

        public final void setHidden​(boolean hide)
      • getTurnoutStateString

        public final String getTurnoutStateString​(int turnoutState)
        get turnout state string
        Parameters:
        turnoutState - of the turnout
        Returns:
        the turnout state string
      • canRemove

        public abstract boolean canRemove()
        Check for active block boundaries.

        If any connection point of a layout track object has attached objects, such as signal masts, signal heads or NX sensors, the layout track object cannot be deleted.

        Returns:
        true if the layout track object can be deleted.
      • displayRemoveWarningDialog

        public final void displayRemoveWarningDialog​(List<String> itemList,
                                                     String typeKey)
        Display the attached items that prevent removing the layout track item.
        Parameters:
        itemList - A list of the attached heads, masts and/or sensors.
        typeKey - The object type such as Turnout, Level Crossing, etc.
      • scaleCoords

        public abstract void scaleCoords​(double xFactor,
                                         double yFactor)
        scale this LayoutTrack's coordinates by the x and y factors
        Parameters:
        xFactor - the amount to scale X coordinates
        yFactor - the amount to scale Y coordinates
      • translateCoords

        public abstract void translateCoords​(double xFactor,
                                             double yFactor)
        translate this LayoutTrack's coordinates by the x and y factors
        Parameters:
        xFactor - the amount to translate X coordinates
        yFactor - the amount to translate Y coordinates
      • rotateCoords

        public abstract void rotateCoords​(double angleDEG)
        rotate this LayoutTrack's coordinates by angleDEG's
        Parameters:
        angleDEG - the amount to rotate in degrees
      • findHitPointType

        protected abstract HitPointType findHitPointType​(@Nonnull
                                                         Point2D hitPoint,
                                                         boolean useRectangles,
                                                         boolean requireUnconnected)
        find the hit (location) type for a point
        Parameters:
        hitPoint - the point
        useRectangles - whether to use (larger) rectangles or (smaller) circles for hit testing
        requireUnconnected - whether to only return hit types for free connections
        Returns:
        the location type for the point (or NONE)
        Since:
        7.4.3
      • getCoordsForConnectionType

        public abstract Point2D getCoordsForConnectionType​(HitPointType connectionType)
        return the coordinates for a specified connection type (abstract: should be overridden by ALL subclasses)
        Parameters:
        connectionType - the connection type
        Returns:
        the coordinates for the specified connection type
      • showPopup

        @Nonnull
        protected abstract JPopupMenu showPopup​(@Nonnull
                                                MouseEvent mouseEvent)
        show the popup menu for this layout track
        Parameters:
        mouseEvent - the mouse down event that triggered this popup
        Returns:
        the popup menu for this layout track
      • showPopup

        @Nonnull
        protected final JPopupMenu showPopup​(Point2D where)
        show the popup menu for this layout track
        Parameters:
        where - to show the popup
        Returns:
        the popup menu for this layout track
      • showPopup

        @Nonnull
        protected final JPopupMenu showPopup()
        show the popup menu for this layout track
        Returns:
        the popup menu for this layout track
      • getConnection

        public abstract LayoutTrack getConnection​(HitPointType connectionType)
                                           throws JmriException
        get the LayoutTrack connected at the specified connection type
        Parameters:
        connectionType - where on us to get the connection
        Returns:
        the LayoutTrack connected at the specified connection type
        Throws:
        JmriException - - if the connectionType is invalid
      • setConnection

        public abstract void setConnection​(HitPointType connectionType,
                                           LayoutTrack o,
                                           HitPointType type)
                                    throws JmriException
        set the LayoutTrack connected at the specified connection type
        Parameters:
        connectionType - where on us to set the connection
        o - the LayoutTrack that is to be connected
        type - where on the LayoutTrack we are connected
        Throws:
        JmriException - - if connectionType or type are invalid
      • reCheckBlockBoundary

        protected abstract void reCheckBlockBoundary()
        abstract method... subclasses should implement _IF_ they need to recheck their block boundaries
      • isDisconnected

        public boolean isDisconnected​(HitPointType connectionType)
        return true if this connection type is disconnected
        Parameters:
        connectionType - the connection type to test
        Returns:
        true if the connection for this connection type is free
      • checkForUnAssignedBlocks

        public abstract boolean checkForUnAssignedBlocks()
        determine if all the appropriate blocks have been assigned to this track
        Returns:
        true if all appropriate blocks have been assigned
      • checkForNonContiguousBlocks

        public abstract void checkForNonContiguousBlocks​(@Nonnull
                                                         HashMap<String,​List<Set<String>>> blockNamesToTrackNameSetMaps)
        check this track and its neighbors for non-contiguous blocks

        For each (non-null) blocks of this track do: #1) If it's got an entry in the blockNamesToTrackNameSetMap then #2) If this track is not in one of the TrackNameSets for this block #3) add a new set (with this block/track) to blockNamesToTrackNameSetMap and #4) check all the connections in this block (by calling the 2nd method below)

        Basically, we're maintaining contiguous track sets for each block found (in blockNamesToTrackNameSetMap)

        Parameters:
        blockNamesToTrackNameSetMaps - hashmap of key:block names to lists of track name sets for those blocks
      • setAllLayoutBlocks

        public abstract void setAllLayoutBlocks​(LayoutBlock layoutBlock)
        Assign all the layout blocks in this track
        Parameters:
        layoutBlock - to this layout block (used by the Tools menu's "Assign block to selection" item)