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 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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.String>
decorations
protected LayoutEditor
layoutEditor
protected static int
NUM_ARROW_TYPES
-
Constructor Summary
Constructors Constructor Description LayoutTrackView(LayoutTrack track, java.awt.geom.Point2D c, LayoutEditor layoutEditor)
constructor methodLayoutTrackView(LayoutTrack track, LayoutEditor layoutEditor)
Constructor method.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addCommonPopupItems(JmriMouseEvent mouseEvent, javax.swing.JPopupMenu popup)
Att items to the popup menu that's common to all implementing classes.abstract boolean
canRemove()
Check for active block boundaries.abstract java.util.List<HitPointType>
checkForFreeConnections()
return a list of the available connections for this layout trackabstract void
checkForNonContiguousBlocks(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 blocksabstract boolean
checkForUnAssignedBlocks()
determine if all the appropriate blocks have been assigned to this trackabstract void
collectContiguousTracksNamesInBlockNamed(java.lang.String blockName, java.util.Set<java.lang.String> TrackNameSet)
recursive routine to check for all contiguous tracks in this blockNamevoid
displayRemoveWarningDialog(java.util.List<java.lang.String> itemList, java.lang.String typeKey)
Display the attached items that prevent removing the layout track item.protected abstract void
draw1(java.awt.Graphics2D g2, boolean isMain, boolean isBlock)
draw one line (Ballast, ties, center or 3rd rail, block lines)protected abstract void
draw2(java.awt.Graphics2D g2, boolean isMain, float railDisplacement)
draw two lines (rails)protected abstract void
drawDecorations(java.awt.Graphics2D g2)
Draw track decorationsprotected abstract void
drawEditControls(java.awt.Graphics2D g2)
draw the edit controlsprotected void
drawHidden(java.awt.Graphics2D g2)
draw hidden trackprotected void
drawLayoutTrackText(java.awt.Graphics2D g)
draw the text for this layout trackprotected abstract void
drawTurnoutControls(java.awt.Graphics2D g2)
Draw the turnout controlsprotected HitPointType
findHitPointType(java.awt.geom.Point2D p)
protected HitPointType
findHitPointType(java.awt.geom.Point2D p, boolean useRectangles)
protected abstract HitPointType
findHitPointType(java.awt.geom.Point2D hitPoint, boolean useRectangles, boolean requireUnconnected)
find the hit (location) type for a pointabstract java.awt.geom.Rectangle2D
getBounds()
protected java.awt.Color
getColorForTrackBlock(LayoutBlock lb)
protected java.awt.Color
getColorForTrackBlock(LayoutBlock layoutBlock, boolean forceBlockTrackColor)
abstract LayoutTrack
getConnection(HitPointType connectionType)
get the LayoutTrack connected at the specified connection typejava.awt.geom.Point2D
getCoordsCenter()
Set center coordinatesabstract java.awt.geom.Point2D
getCoordsForConnectionType(HitPointType connectionType)
return the coordinates for a specified connection type (abstract: should be overridden by ALL subclasses)java.util.Map<java.lang.String,java.lang.String>
getDecorations()
Get current decorationsjava.lang.String
getEditorName()
Get the LogixNG of this InlineLogixNG.java.lang.String
getId()
protected abstract java.util.List<LayoutConnectivity>
getLayoutConnectivity()
get the layout connectivity for this trackLayoutEditor
getLayoutEditor()
LayoutEditorToolBarPanel
getLayoutEditorToolBarPanel()
convenience method for accessing...LayoutTrack
getLayoutTrack()
LogixNG
getLogixNG()
Get the LogixNG of this Positionable.java.lang.String
getName()
java.lang.String
getNameString()
Get the name of this InlineLogixNG.java.lang.String
getTurnoutStateString(int turnoutState)
get turnout state stringjava.lang.String
getTypeName()
Get the type of item of this InlineLogixNG.int
getX()
Get the X position of this InlineLogixNG.int
getY()
Get the Y position of this InlineLogixNG.boolean
hasDecorations()
protected void
highlightUnconnected(java.awt.Graphics2D g2)
protected abstract void
highlightUnconnected(java.awt.Graphics2D g2, HitPointType specificType)
highlight unconnected connectionsboolean
isDisconnected(HitPointType connectionType)
return true if this connection type is disconnectedboolean
isHidden()
Get the hidden state of the track element.javax.swing.JCheckBoxMenuItem
loadArrowImageToJCBItem(int n, javax.swing.JMenu arrowsCountMenu)
Load a file for a specific arrow ending.protected abstract void
reCheckBlockBoundary()
abstract method... subclasses should implement _IF_ they need to recheck their block boundariesprotected boolean
removeInlineLogixNG()
abstract void
rotateCoords(double angleDEG)
rotate this LayoutTrack's coordinates by angleDEG'sprotected java.awt.geom.Point2D
rotatePoint(java.awt.geom.Point2D p, double sineRot, double cosineRot)
abstract void
scaleCoords(double xFactor, double yFactor)
scale this LayoutTrack's coordinates by the x and y factorsabstract void
setAllLayoutBlocks(LayoutBlock layoutBlock)
Assign all the layout blocks in this trackprotected java.awt.Color
setColorForTrackBlock(java.awt.Graphics2D g2, LayoutBlock lb)
protected java.awt.Color
setColorForTrackBlock(java.awt.Graphics2D g2, LayoutBlock layoutBlock, boolean forceBlockTrackColor)
abstract void
setConnection(HitPointType connectionType, LayoutTrack o, HitPointType type)
set the LayoutTrack connected at the specified connection typevoid
setCoordsCenter(java.awt.geom.Point2D p)
Set center coordinates.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.void
setHidden(boolean hide)
protected void
setIdent(java.lang.String ident)
void
setLogixNG(LogixNG logixNG)
Set the LogixNG of this Positionable.void
setLogixNG_SystemName(java.lang.String systemName)
Set the system name for the LogixNG of this InlineLogixNG.void
setLogixNGPositionableMenu(javax.swing.JPopupMenu popup)
Add a menu entry to edit Id of the Positionable itemvoid
setupLogixNG()
Setup the LogixNG of this InlineLogixNG.protected javax.swing.JPopupMenu
showPopup()
show the popup menu for this layout trackprotected javax.swing.JPopupMenu
showPopup(java.awt.geom.Point2D where)
show the popup menu for this layout trackprotected abstract javax.swing.JPopupMenu
showPopup(JmriMouseEvent mouseEvent)
show the popup menu for this layout trackjava.awt.geom.Ellipse2D
trackControlCircleAt(java.awt.geom.Point2D inPoint)
java.awt.geom.Rectangle2D
trackControlCircleRectAt(java.awt.geom.Point2D inPoint)
java.awt.geom.Ellipse2D
trackEditControlCircleAt(java.awt.geom.Point2D inPoint)
abstract void
translateCoords(double xFactor, double yFactor)
translate this LayoutTrack's coordinates by the x and y factors
-
-
-
Field Detail
-
layoutEditor
protected final LayoutEditor layoutEditor
-
decorations
protected java.util.Map<java.lang.String,java.lang.String> decorations
-
NUM_ARROW_TYPES
protected static final int NUM_ARROW_TYPES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LayoutTrackView
public LayoutTrackView(@Nonnull LayoutTrack track, @Nonnull LayoutEditor layoutEditor)
Constructor method.- Parameters:
track
- the layout track to viewlayoutEditor
- the panel in which to place the view
-
LayoutTrackView
public LayoutTrackView(@Nonnull LayoutTrack track, @Nonnull java.awt.geom.Point2D c, @Nonnull LayoutEditor layoutEditor)
constructor method- Parameters:
track
- the track to viewc
- display locationlayoutEditor
- for reference to tools
-
-
Method Detail
-
getLayoutEditor
@Nonnull @CheckReturnValue public LayoutEditor getLayoutEditor()
-
getLayoutTrack
public LayoutTrack getLayoutTrack()
-
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.
-
getLayoutEditorToolBarPanel
@Nonnull public final LayoutEditorToolBarPanel getLayoutEditorToolBarPanel()
convenience method for accessing...- Returns:
- the layout editor's toolbar panel
-
trackEditControlCircleAt
public final java.awt.geom.Ellipse2D trackEditControlCircleAt(@Nonnull java.awt.geom.Point2D inPoint)
-
trackControlCircleAt
public final java.awt.geom.Ellipse2D trackControlCircleAt(@Nonnull java.awt.geom.Point2D inPoint)
-
trackControlCircleRectAt
public final java.awt.geom.Rectangle2D trackControlCircleRectAt(@Nonnull java.awt.geom.Point2D inPoint)
-
getColorForTrackBlock
protected final java.awt.Color getColorForTrackBlock(@CheckForNull LayoutBlock layoutBlock, boolean forceBlockTrackColor)
-
getColorForTrackBlock
protected final java.awt.Color getColorForTrackBlock(@CheckForNull LayoutBlock lb)
-
setColorForTrackBlock
protected final java.awt.Color setColorForTrackBlock(java.awt.Graphics2D g2, @CheckForNull LayoutBlock layoutBlock, boolean forceBlockTrackColor)
-
setColorForTrackBlock
protected final java.awt.Color setColorForTrackBlock(java.awt.Graphics2D g2, @CheckForNull LayoutBlock lb)
-
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 contextisMain
- true if drawing mainlinesisBlock
- 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 contextisMain
- true if drawing mainlinesrailDisplacement
- 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 numberarrowsCountMenu
- 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 contextspecificType
- the specific connection to draw (or NONE for all)
-
highlightUnconnected
protected final void highlightUnconnected(java.awt.Graphics2D g2)
-
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 coordinatesyFactor
- 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 coordinatesyFactor
- 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 pointuseRectangles
- whether to use (larger) rectangles or (smaller) circles for hit testingrequireUnconnected
- whether to only return hit types for free connections- Returns:
- the location type for the point (or NONE)
- Since:
- 7.4.3
-
findHitPointType
protected final HitPointType findHitPointType(@Nonnull java.awt.geom.Point2D p)
-
findHitPointType
protected final HitPointType findHitPointType(@Nonnull java.awt.geom.Point2D p, boolean useRectangles)
-
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 popuppopup
- the popup menu
-
getNameString
public java.lang.String getNameString()
Description copied from interface:InlineLogixNG
Get the name of this InlineLogixNG.- Specified by:
getNameString
in interfaceInlineLogixNG
- Returns:
- the name
-
getEditorName
public java.lang.String getEditorName()
Description copied from interface:InlineLogixNG
Get the LogixNG of this InlineLogixNG.- Specified by:
getEditorName
in interfaceInlineLogixNG
- 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 interfaceInlineLogixNG
- Returns:
- the X position
-
getY
public int getY()
Description copied from interface:InlineLogixNG
Get the Y position of this InlineLogixNG.- Specified by:
getY
in interfaceInlineLogixNG
- Returns:
- the Y position
-
getTypeName
public java.lang.String getTypeName()
Description copied from interface:InlineLogixNG
Get the type of item of this InlineLogixNG.- Specified by:
getTypeName
in interfaceInlineLogixNG
- Returns:
- the type
-
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
-
getLogixNG
public LogixNG getLogixNG()
Get the LogixNG of this Positionable.- Specified by:
getLogixNG
in interfaceInlineLogixNG
- 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 interfaceInlineLogixNG
- Parameters:
logixNG
- the LogixNG or null if remove the LogixNG from the Positionable
-
setLogixNG_SystemName
public void setLogixNG_SystemName(java.lang.String systemName)
Description copied from interface:InlineLogixNG
Set the system name for the LogixNG of this InlineLogixNG.- Specified by:
setLogixNG_SystemName
in interfaceInlineLogixNG
- Parameters:
systemName
- the system name
-
setupLogixNG
public void setupLogixNG()
Description copied from interface:InlineLogixNG
Setup the LogixNG of this InlineLogixNG.- Specified by:
setupLogixNG
in interfaceInlineLogixNG
-
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 connectiono
- the LayoutTrack that is to be connectedtype
- 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<LayoutConnectivity> 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
@Nonnull public abstract java.util.List<HitPointType> 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 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 blocksFor 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 forTrackNameSet
- 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()
-
-