Class LayoutTurntableView
- java.lang.Object
-
- jmri.jmrit.display.layoutEditor.LayoutTrackView
-
- jmri.jmrit.display.layoutEditor.LayoutTurntableView
-
- All Implemented Interfaces:
InlineLogixNG
public class LayoutTurntableView extends LayoutTrackView
MVC View component for the LayoutTurntable class.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
LayoutTurntableView.RayTrackVisuals
-
Field Summary
Fields Modifier and Type Field Description java.lang.String
tLayoutBlockName
-
Fields inherited from class jmri.jmrit.display.layoutEditor.LayoutTrackView
decorations, layoutEditor, NUM_ARROW_TYPES
-
-
Constructor Summary
Constructors Constructor Description LayoutTurntableView(LayoutTurntable turntable, java.awt.geom.Point2D c, LayoutEditor layoutEditor)
Constructor method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LayoutTurntable.RayTrack
addRay(double angle)
Add a ray at the specified angle.boolean
canRemove()
Check for active block boundaries.java.util.List<HitPointType>
checkForFreeConnections()
return a list of the available connections for this layout trackvoid
checkForNonContiguousBlocks(java.util.HashMap<java.lang.String,java.util.List<java.util.Set<java.lang.String>>> blockNamesToTrackNameSetsMap)
check this track and its neighbors for non-contiguous blocksboolean
checkForUnAssignedBlocks()
determine if all the appropriate blocks have been assigned to this trackvoid
collectContiguousTracksNamesInBlockNamed(java.lang.String blockName, java.util.Set<java.lang.String> TrackNameSet)
recursive routine to check for all contiguous tracks in this blockNamevoid
deleteRay(LayoutTurntable.RayTrack rayTrack)
Delete this ray track.void
dispose()
Clean up when this object is no longer needed.protected void
draw1(java.awt.Graphics2D g2, boolean isMain, boolean isBlock)
draw one line (Ballast, ties, center or 3rd rail, block lines)protected void
draw2(java.awt.Graphics2D g2, boolean isMain, float railDisplacement)
draw two lines (rails)protected void
drawDecorations(java.awt.Graphics2D g2)
Draw track decorations.protected void
drawEditControls(java.awt.Graphics2D g2)
Draw this turntable's edit controls.protected void
drawTurnoutControls(java.awt.Graphics2D g2)
Draw this turntable's controls.protected HitPointType
findHitPointType(java.awt.geom.Point2D hitPoint, boolean useRectangles, boolean requireUnconnected)
find the hit (location) type for a pointjava.lang.String
getBlockName()
java.awt.geom.Rectangle2D
getBounds()
LayoutTrack
getConnection(HitPointType connectionType)
get the LayoutTrack connected at the specified connection typejava.awt.geom.Point2D
getCoordsForConnectionType(HitPointType connectionType)
Get the coordinates for a specified connection type.LayoutBlock
getLayoutBlock()
protected java.util.List<LayoutConnectivity>
getLayoutConnectivity()
get the layout connectivity for this trackint
getNumberRays()
Get the number of rays on turntable.int
getPosition()
Get the turntable position.double
getRadius()
Get the radius for this turntable.double
getRayAngle(int i)
Get the angle for the ray at this position in the rayTrackList.TrackSegment
getRayConnectIndexed(int index)
Get the connection for the ray with this index.TrackSegment
getRayConnectOrdered(int i)
Get the connection for the ray at the index in the rayTrackList.java.awt.geom.Point2D
getRayCoordsIndexed(int index)
Get the coordinates for the ray with this index.java.awt.geom.Point2D
getRayCoordsOrdered(int i)
Get the coordinates for the ray at this index.int
getRayIndex(int i)
Get the index for the ray at this position in the rayTrackList.java.util.List<LayoutTurntable.RayTrack>
getRayTrackList()
Turnout
getRayTurnout(int i)
Get the turnout for the ray at this index.java.lang.String
getRayTurnoutName(int i)
Get the name of the turnout for the ray at this index.int
getRayTurnoutState(int i)
Get the state of the turnout for the ray at this index.LayoutTurntable
getTurntable()
protected void
highlightUnconnected(java.awt.Graphics2D g2, HitPointType specificType)
highlight unconnected connectionsboolean
isActive()
boolean
isMainlineIndexed(int index)
Test if ray with this index is a mainline track or not.boolean
isMainlineOrdered(int i)
Test if ray at this index is a mainline track or not.boolean
isRayDisabled(int i)
Get if the ray at this index is disabled.boolean
isRayDisabledWhenOccupied(int i)
Get the disabled when occupied state of the ray at this index.boolean
isTurnoutControlled()
Is this turntable turnout controlled?protected void
reCheckBlockBoundary()
abstract method... subclasses should implement _IF_ they need to recheck their block boundariesvoid
remove()
Remove this object from display and persistance.void
rotateCoords(double angleDEG)
rotate this LayoutTrack's coordinates by angleDEG'svoid
scaleCoords(double xFactor, double yFactor)
Scale this LayoutTrack's coordinates by the x and y factors.void
setAllLayoutBlocks(LayoutBlock layoutBlock)
Assign all the layout blocks in this trackvoid
setConnection(HitPointType connectionType, LayoutTrack o, HitPointType type)
set the LayoutTrack connected at the specified connection typevoid
setLayoutBlock(LayoutBlock newLayoutBlock)
Set up a LayoutBlock for this LayoutTurntable.void
setLayoutBlockByName(java.lang.String name)
Set up a LayoutBlock for this LayoutTurntable.void
setPosition(int index)
Set turntable position to the ray with this index.void
setRadius(double r)
Set the radius for this turntable.void
setRayConnect(TrackSegment ts, int index)
Set the connection for the ray at the index in the rayTrackList.void
setRayCoordsIndexed(double x, double y, int index)
Set the coordinates for the ray at this index.void
setRayCoordsIndexed(java.awt.geom.Point2D point, int index)
Set the coordinates for the ray at this index.void
setRayDisabled(int i, boolean boo)
Set the disabled state of the ray at this index.void
setRayDisabledWhenOccupied(int i, boolean boo)
Set the disabled when occupied state of the ray at this index.void
setRayTurnout(int index, java.lang.String turnoutName, int state)
Set the turnout and state for the ray with this index.void
setTurnoutControlled(boolean boo)
Set if this turntable is turnout controlled.protected javax.swing.JPopupMenu
showPopup(JmriMouseEvent mouseEvent)
show the popup menu for this layout trackprotected void
showRayPopUp(JmriMouseEvent e, int index)
java.lang.String
toString()
Get a string that represents this object.void
translateCoords(double xFactor, double yFactor)
Translate (2D move) this LayoutTrack's coordinates by the x and y factors.-
Methods inherited from class jmri.jmrit.display.layoutEditor.LayoutTrackView
addCommonPopupItems, displayRemoveWarningDialog, drawHidden, drawLayoutTrackText, findHitPointType, findHitPointType, getColorForTrackBlock, getColorForTrackBlock, getCoordsCenter, getDecorations, getEditorName, getId, getLayoutEditor, getLayoutEditorToolBarPanel, getLayoutTrack, getLogixNG, getName, getNameString, getTurnoutStateString, getTypeName, getX, getY, hasDecorations, highlightUnconnected, isDisconnected, isHidden, loadArrowImageToJCBItem, removeInlineLogixNG, rotatePoint, setColorForTrackBlock, setColorForTrackBlock, setCoordsCenter, setDecorations, setHidden, setIdent, setLogixNG, setLogixNG_SystemName, setLogixNGPositionableMenu, setupLogixNG, showPopup, showPopup, trackControlCircleAt, trackControlCircleRectAt, trackEditControlCircleAt
-
-
-
-
Field Detail
-
tLayoutBlockName
public java.lang.String tLayoutBlockName
-
-
Constructor Detail
-
LayoutTurntableView
public LayoutTurntableView(@Nonnull LayoutTurntable turntable, @Nonnull java.awt.geom.Point2D c, @Nonnull LayoutEditor layoutEditor)
Constructor method.- Parameters:
turntable
- the layout turntable to create view for.c
- where to put itlayoutEditor
- what layout editor panel to put it in
-
-
Method Detail
-
getTurntable
public final LayoutTurntable getTurntable()
-
toString
public java.lang.String toString()
Get a string that represents this object. This should only be used for debugging.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the string
-
getRadius
public double getRadius()
Get the radius for this turntable.- Returns:
- the radius for this turntable
-
setRadius
public void setRadius(double r)
Set the radius for this turntable.- Parameters:
r
- the radius for this turntable
-
getBlockName
@Nonnull public java.lang.String getBlockName()
- Returns:
- the layout block name
-
getLayoutBlock
public LayoutBlock getLayoutBlock()
- Returns:
- the layout block
-
setLayoutBlock
public void setLayoutBlock(@CheckForNull LayoutBlock newLayoutBlock)
Set up a LayoutBlock for this LayoutTurntable.- Parameters:
newLayoutBlock
- the LayoutBlock to set
-
setLayoutBlockByName
public void setLayoutBlockByName(@CheckForNull java.lang.String name)
Set up a LayoutBlock for this LayoutTurntable.- Parameters:
name
- the name of the new LayoutBlock
-
getBounds
public java.awt.geom.Rectangle2D getBounds()
- Specified by:
getBounds
in classLayoutTrackView
- Returns:
- the bounds of this turntable.
-
addRay
public LayoutTurntable.RayTrack addRay(double angle)
Add a ray at the specified angle.- Parameters:
angle
- the angle- Returns:
- the RayTrack
-
getRayConnectIndexed
public TrackSegment getRayConnectIndexed(int index)
Get the connection for the ray with this index.- Parameters:
index
- the index- Returns:
- the connection for the ray with this value of getConnectionIndex
-
getRayConnectOrdered
public TrackSegment getRayConnectOrdered(int i)
Get the connection for the ray at the index in the rayTrackList.- Parameters:
i
- the index in the rayTrackList- Returns:
- the connection for the ray at that index in the rayTrackList or null
-
setRayConnect
public void setRayConnect(TrackSegment ts, int index)
Set the connection for the ray at the index in the rayTrackList.- Parameters:
ts
- the connectionindex
- the index in the rayTrackList
-
getRayTrackList
public java.util.List<LayoutTurntable.RayTrack> getRayTrackList()
-
getNumberRays
public int getNumberRays()
Get the number of rays on turntable.- Returns:
- the number of rays
-
getRayIndex
public int getRayIndex(int i)
Get the index for the ray at this position in the rayTrackList.- Parameters:
i
- the position in the rayTrackList- Returns:
- the index
-
getRayAngle
public double getRayAngle(int i)
Get the angle for the ray at this position in the rayTrackList.- Parameters:
i
- the position in the rayTrackList- Returns:
- the angle
-
setRayTurnout
public void setRayTurnout(int index, java.lang.String turnoutName, int state)
Set the turnout and state for the ray with this index.- Parameters:
index
- the indexturnoutName
- the turnout namestate
- the state
-
getRayTurnoutName
public java.lang.String getRayTurnoutName(int i)
Get the name of the turnout for the ray at this index.- Parameters:
i
- the index- Returns:
- name of the turnout for the ray at this index
-
getRayTurnout
public Turnout getRayTurnout(int i)
Get the turnout for the ray at this index.- Parameters:
i
- the index- Returns:
- the turnout for the ray at this index
-
getRayTurnoutState
public int getRayTurnoutState(int i)
Get the state of the turnout for the ray at this index.- Parameters:
i
- the index- Returns:
- state of the turnout for the ray at this index
-
isRayDisabled
public boolean isRayDisabled(int i)
Get if the ray at this index is disabled.- Parameters:
i
- the index- Returns:
- true if disabled
-
setRayDisabled
public void setRayDisabled(int i, boolean boo)
Set the disabled state of the ray at this index.- Parameters:
i
- the indexboo
- the state
-
isRayDisabledWhenOccupied
public boolean isRayDisabledWhenOccupied(int i)
Get the disabled when occupied state of the ray at this index.- Parameters:
i
- the index- Returns:
- the state
-
setRayDisabledWhenOccupied
public void setRayDisabledWhenOccupied(int i, boolean boo)
Set the disabled when occupied state of the ray at this index.- Parameters:
i
- the indexboo
- the state
-
getRayCoordsIndexed
public java.awt.geom.Point2D getRayCoordsIndexed(int index)
Get the coordinates for the ray with this index.- Parameters:
index
- the index- Returns:
- the coordinates
-
getRayCoordsOrdered
public java.awt.geom.Point2D getRayCoordsOrdered(int i)
Get the coordinates for the ray at this index.- Parameters:
i
- the index; zero point returned if this is out of range- Returns:
- the coordinates
-
setRayCoordsIndexed
public void setRayCoordsIndexed(double x, double y, int index)
Set the coordinates for the ray at this index.- Parameters:
x
- the x coordinatesy
- the y coordinatesindex
- the index
-
setRayCoordsIndexed
public void setRayCoordsIndexed(java.awt.geom.Point2D point, int index)
Set the coordinates for the ray at this index.- Parameters:
point
- the new coordinatesindex
- the index
-
getCoordsForConnectionType
public java.awt.geom.Point2D getCoordsForConnectionType(HitPointType connectionType)
Get the coordinates for a specified connection type.- Specified by:
getCoordsForConnectionType
in classLayoutTrackView
- Parameters:
connectionType
- the connection type- Returns:
- the coordinates
-
getConnection
public LayoutTrack getConnection(HitPointType connectionType) throws JmriException
get the LayoutTrack connected at the specified connection type- Specified by:
getConnection
in classLayoutTrackView
- 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 void setConnection(HitPointType connectionType, LayoutTrack o, HitPointType type) throws JmriException
set the LayoutTrack connected at the specified connection type- Specified by:
setConnection
in classLayoutTrackView
- 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
-
isMainlineIndexed
public boolean isMainlineIndexed(int index)
Test if ray with this index is a mainline track or not.Defaults to false (not mainline) if connecting track segment is missing.
- Parameters:
index
- the index- Returns:
- true if connecting track segment is mainline
-
isMainlineOrdered
public boolean isMainlineOrdered(int i)
Test if ray at this index is a mainline track or not.Defaults to false (not mainline) if connecting track segment is missing
- Parameters:
i
- the index- Returns:
- true if connecting track segment is mainline
-
scaleCoords
public void scaleCoords(double xFactor, double yFactor)
Scale this LayoutTrack's coordinates by the x and y factors.- Specified by:
scaleCoords
in classLayoutTrackView
- Parameters:
xFactor
- the amount to scale X coordinatesyFactor
- the amount to scale Y coordinates
-
translateCoords
public void translateCoords(double xFactor, double yFactor)
Translate (2D move) this LayoutTrack's coordinates by the x and y factors.- Specified by:
translateCoords
in classLayoutTrackView
- Parameters:
xFactor
- the amount to translate X coordinatesyFactor
- the amount to translate Y coordinates
-
rotateCoords
public void rotateCoords(double angleDEG)
rotate this LayoutTrack's coordinates by angleDEG's- Specified by:
rotateCoords
in classLayoutTrackView
- Parameters:
angleDEG
- the amount to rotate in degrees
-
findHitPointType
protected HitPointType findHitPointType(java.awt.geom.Point2D hitPoint, boolean useRectangles, boolean requireUnconnected)
find the hit (location) type for a point- Specified by:
findHitPointType
in classLayoutTrackView
- 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)
-
isTurnoutControlled
public boolean isTurnoutControlled()
Is this turntable turnout controlled?- Returns:
- true if so
-
setTurnoutControlled
public void setTurnoutControlled(boolean boo)
Set if this turntable is turnout controlled.- Parameters:
boo
- set true if so
-
showPopup
@Nonnull protected javax.swing.JPopupMenu showPopup(@Nonnull JmriMouseEvent mouseEvent)
show the popup menu for this layout track- Specified by:
showPopup
in classLayoutTrackView
- Parameters:
mouseEvent
- the mouse down event that triggered this popup- Returns:
- the popup menu for this layout track
-
showRayPopUp
protected void showRayPopUp(JmriMouseEvent e, int index)
-
setPosition
public void setPosition(int index)
Set turntable position to the ray with this index.- Parameters:
index
- the index
-
getPosition
public int getPosition()
Get the turntable position.- Returns:
- the turntable position
-
deleteRay
public void deleteRay(LayoutTurntable.RayTrack rayTrack)
Delete this ray track.- Parameters:
rayTrack
- the ray track
-
dispose
public void dispose()
Clean up when this object is no longer needed. Should not be called while the object is still displayed; see remove().
-
remove
public void remove()
Remove this object from display and persistance.
-
isActive
public boolean isActive()
- Returns:
- "active" true means that the object is still displayed, and should be stored.
-
drawDecorations
protected void drawDecorations(java.awt.Graphics2D g2)
Draw track decorations. This type of track has none, so this method is empty.- Specified by:
drawDecorations
in classLayoutTrackView
- Parameters:
g2
- the graphics context
-
draw1
protected void draw1(java.awt.Graphics2D g2, boolean isMain, boolean isBlock)
draw one line (Ballast, ties, center or 3rd rail, block lines)- Specified by:
draw1
in classLayoutTrackView
- Parameters:
g2
- the graphics contextisMain
- true if drawing mainlinesisBlock
- true if drawing block lines
-
draw2
protected void draw2(java.awt.Graphics2D g2, boolean isMain, float railDisplacement)
draw two lines (rails)- Specified by:
draw2
in classLayoutTrackView
- Parameters:
g2
- the graphics contextisMain
- true if drawing mainlinesrailDisplacement
- the offset from center to draw the lines
-
highlightUnconnected
protected void highlightUnconnected(java.awt.Graphics2D g2, HitPointType specificType)
highlight unconnected connections- Specified by:
highlightUnconnected
in classLayoutTrackView
- Parameters:
g2
- the graphics contextspecificType
- the specific connection to draw (or NONE for all)
-
drawTurnoutControls
protected void drawTurnoutControls(java.awt.Graphics2D g2)
Draw this turntable's controls.- Specified by:
drawTurnoutControls
in classLayoutTrackView
- Parameters:
g2
- the graphics port to draw to
-
drawEditControls
protected void drawEditControls(java.awt.Graphics2D g2)
Draw this turntable's edit controls.- Specified by:
drawEditControls
in classLayoutTrackView
- Parameters:
g2
- the graphics port to draw to
-
reCheckBlockBoundary
protected void reCheckBlockBoundary()
abstract method... subclasses should implement _IF_ they need to recheck their block boundaries- Specified by:
reCheckBlockBoundary
in classLayoutTrackView
-
getLayoutConnectivity
protected java.util.List<LayoutConnectivity> getLayoutConnectivity()
get the layout connectivity for this track- Specified by:
getLayoutConnectivity
in classLayoutTrackView
- Returns:
- the list of Layout Connectivity objects
-
checkForFreeConnections
public java.util.List<HitPointType> checkForFreeConnections()
return a list of the available connections for this layout track- Specified by:
checkForFreeConnections
in classLayoutTrackView
- Returns:
- the list of available connections
-
checkForUnAssignedBlocks
public boolean checkForUnAssignedBlocks()
determine if all the appropriate blocks have been assigned to this track- Specified by:
checkForUnAssignedBlocks
in classLayoutTrackView
- Returns:
- true if all appropriate blocks have been assigned
-
checkForNonContiguousBlocks
public void checkForNonContiguousBlocks(@Nonnull java.util.HashMap<java.lang.String,java.util.List<java.util.Set<java.lang.String>>> blockNamesToTrackNameSetsMap)
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)
- Specified by:
checkForNonContiguousBlocks
in classLayoutTrackView
- Parameters:
blockNamesToTrackNameSetsMap
- hashmap of key:block names to lists of track name sets for those blocks
-
collectContiguousTracksNamesInBlockNamed
public 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- Specified by:
collectContiguousTracksNamesInBlockNamed
in classLayoutTrackView
- Parameters:
blockName
- the block that we're checking forTrackNameSet
- the set of track names in this block
-
setAllLayoutBlocks
public void setAllLayoutBlocks(LayoutBlock layoutBlock)
Assign all the layout blocks in this track- Specified by:
setAllLayoutBlocks
in classLayoutTrackView
- Parameters:
layoutBlock
- to this layout block (used by the Tools menu's "Assign block to selection" item)
-
canRemove
public 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.
- Specified by:
canRemove
in classLayoutTrackView
- Returns:
- true if the layout track object can be deleted.
-
-