Class LayoutTrackView

  • All Implemented Interfaces:
    InlineLogixNG
    Direct Known Subclasses:
    LayoutTurnoutView, LayoutTurntableView, LevelXingView, PositionablePointView, TrackSegmentView

    public abstract class LayoutTrackView
    extends java.lang.Object
    implements InlineLogixNG
    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

      • getCoordsCenter

        public java.awt.geom.Point2D getCoordsCenter()
        Set center coordinates
        Returns:
        The center coordinates
      • setCoordsCenter

        public void setCoordsCenter​(@Nonnull
                                    java.awt.geom.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
      • getDecorations

        public java.util.Map<java.lang.String,​java.lang.String> getDecorations()
        Get current decorations
        Returns:
        the decorations
      • setDecorations

        public void setDecorations​(java.util.Map<java.lang.String,​java.lang.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​(java.awt.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​(java.awt.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​(java.awt.Graphics2D g2)
        draw hidden track
        Parameters:
        g2 - the graphics context
      • drawLayoutTrackText

        protected final void drawLayoutTrackText​(java.awt.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 javax.swing.JCheckBoxMenuItem loadArrowImageToJCBItem​(int n,
                                                                     javax.swing.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​(java.awt.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​(java.awt.Graphics2D g2)
        draw the edit controls
        Parameters:
        g2 - the graphics context
      • drawTurnoutControls

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

        protected abstract void drawDecorations​(java.awt.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 java.lang.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​(java.util.List<java.lang.String> itemList,
                                                     java.lang.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
      • rotatePoint

        protected final java.awt.geom.Point2D rotatePoint​(@Nonnull
                                                          java.awt.geom.Point2D p,
                                                          double sineRot,
                                                          double cosineRot)
      • findHitPointType

        protected abstract HitPointType findHitPointType​(@Nonnull
                                                         java.awt.geom.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 java.awt.geom.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
      • getBounds

        public abstract java.awt.geom.Rectangle2D getBounds()
        Returns:
        the bounds of this track
      • showPopup

        @Nonnull
        protected abstract javax.swing.JPopupMenu showPopup​(@Nonnull
                                                            JmriMouseEvent 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
      • addCommonPopupItems

        protected void addCommonPopupItems​(@Nonnull
                                           JmriMouseEvent mouseEvent,
                                           @Nonnull
                                           javax.swing.JPopupMenu popup)
        Att items to the popup menu that's common to all implementing classes.
        Parameters:
        mouseEvent - the mouse down event that triggered this popup
        popup - the popup menu
      • getX

        public int getX()
        Description copied from interface: InlineLogixNG
        Get the X position of this InlineLogixNG.
        Specified by:
        getX in interface InlineLogixNG
        Returns:
        the X position
      • getY

        public int getY()
        Description copied from interface: InlineLogixNG
        Get the Y position of this InlineLogixNG.
        Specified by:
        getY in interface InlineLogixNG
        Returns:
        the Y position
      • setLogixNGPositionableMenu

        public void setLogixNGPositionableMenu​(javax.swing.JPopupMenu popup)
        Add a menu entry to edit Id of the Positionable item
        Parameters:
        popup - the menu to add the entry to
      • setLogixNG

        public void setLogixNG​(LogixNG logixNG)
        Set the LogixNG of this Positionable.
        Specified by:
        setLogixNG in interface InlineLogixNG
        Parameters:
        logixNG - the LogixNG or null if remove the LogixNG from the Positionable
      • showPopup

        @Nonnull
        protected final javax.swing.JPopupMenu showPopup​(java.awt.geom.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 javax.swing.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
      • getLayoutConnectivity

        protected abstract java.util.List<LayoutConnectivitygetLayoutConnectivity()
        get the layout connectivity for this track
        Returns:
        the list of Layout Connectivity objects
      • 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
      • checkForFreeConnections

        @Nonnull
        public abstract java.util.List<HitPointTypecheckForFreeConnections()
        return a list of the available connections for this layout track
        Returns:
        the list of available connections
      • 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
                                                         java.util.HashMap<java.lang.String,​java.util.List<java.util.Set<java.lang.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
      • collectContiguousTracksNamesInBlockNamed

        public abstract void collectContiguousTracksNamesInBlockNamed​(@Nonnull
                                                                      java.lang.String blockName,
                                                                      @Nonnull
                                                                      java.util.Set<java.lang.String> TrackNameSet)
        recursive routine to check for all contiguous tracks in this blockName
        Parameters:
        blockName - the block that we're checking for
        TrackNameSet - the set of track names in this block
      • 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)