Class LayoutTrackView

java.lang.Object
jmri.jmrit.display.layoutEditor.LayoutTrackView
All Implemented Interfaces:
InlineLogixNG
Direct Known Subclasses:
LayoutTurnoutView, LayoutTurntableView, LevelXingView, PositionablePointView, TrackSegmentView

public abstract class LayoutTrackView extends 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
  • Field Details

  • Constructor Details

  • Method Details

    • getId

      @Nonnull public final String getId()
    • getName

      @Nonnull public final String getName()
    • getLayoutEditor

    • setIdent

      protected final void setIdent(@Nonnull String ident)
    • getLayoutTrack

    • getCoordsCenter

      Set center coordinates
      Returns:
      The center coordinates
    • 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
    • getDecorations

      Get current decorations
      Returns:
      the decorations
    • setDecorations

      public void setDecorations(@Nonnull 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.
    • getLayoutEditorToolBarPanel

      convenience method for accessing...
      Returns:
      the layout editor's toolbar panel
    • trackEditControlCircleAt

    • trackControlCircleAt

    • trackControlCircleRectAt

    • getColorForTrackBlock

      protected final Color getColorForTrackBlock(@CheckForNull LayoutBlock layoutBlock, boolean forceBlockTrackColor)
    • getColorForTrackBlock

    • setColorForTrackBlock

      protected final Color setColorForTrackBlock(Graphics2D g2, @CheckForNull LayoutBlock layoutBlock, boolean forceBlockTrackColor)
    • setColorForTrackBlock

    • 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)
    • highlightUnconnected

      protected final void highlightUnconnected(Graphics2D g2)
    • 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
    • rotatePoint

      protected final Point2D rotatePoint(@Nonnull Point2D p, double sineRot, double cosineRot)
    • 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
    • findHitPointType

    • findHitPointType

      protected final HitPointType findHitPointType(@Nonnull Point2D p, boolean useRectangles)
    • 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
    • getBounds

      public abstract Rectangle2D getBounds()
      Returns:
      the bounds of this track
    • showPopup

      @Nonnull protected abstract 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 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
    • getNameString

      Description copied from interface: InlineLogixNG
      Get the name of this InlineLogixNG.
      Specified by:
      getNameString in interface InlineLogixNG
      Returns:
      the name
    • getEditorName

      Description copied from interface: InlineLogixNG
      Get the LogixNG of this InlineLogixNG.
      Specified by:
      getEditorName in interface InlineLogixNG
      Returns:
      the LogixNG or null if it has no LogixNG
    • 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
    • getTypeName

      public String getTypeName()
      Description copied from interface: InlineLogixNG
      Get the type of item of this InlineLogixNG.
      Specified by:
      getTypeName in interface InlineLogixNG
      Returns:
      the type
    • setLogixNGPositionableMenu

      Add a menu entry to edit Id of the Positionable item
      Parameters:
      popup - the menu to add the entry to
    • getLogixNG

      public LogixNG getLogixNG()
      Get the LogixNG of this Positionable.
      Specified by:
      getLogixNG in interface InlineLogixNG
      Returns:
      the LogixNG or null if it has no LogixNG
    • 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
    • setLogixNG_SystemName

      public void setLogixNG_SystemName(String systemName)
      Description copied from interface: InlineLogixNG
      Set the system name for the LogixNG of this InlineLogixNG.
      Specified by:
      setLogixNG_SystemName in interface InlineLogixNG
      Parameters:
      systemName - the system name
    • setupLogixNG

      public void setupLogixNG()
      Description copied from interface: InlineLogixNG
      Setup the LogixNG of this InlineLogixNG.
      Specified by:
      setupLogixNG in interface InlineLogixNG
    • 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
    • getLayoutConnectivity

      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

      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 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
    • collectContiguousTracksNamesInBlockNamed

      public abstract void collectContiguousTracksNamesInBlockNamed(@Nonnull String blockName, @Nonnull Set<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)
    • removeInlineLogixNG

      protected boolean removeInlineLogixNG()