jmri.jmrit.display.layoutEditor
Class LayoutBlock

java.lang.Object
  extended by jmri.implementation.AbstractNamedBean
      extended by jmri.jmrit.display.layoutEditor.LayoutBlock
All Implemented Interfaces:
PropertyChangeListener, Serializable, EventListener, NamedBean

public class LayoutBlock
extends AbstractNamedBean
implements PropertyChangeListener

A LayoutBlock is a group of track segments and turnouts on a LayoutEditor panel corresponding to a 'block'. LayoutBlock is a LayoutEditor specific extension of the JMRI Block object.

LayoutBlocks may have an occupancy Sensor. The getOccupancy method returns the occupancy state of the LayoutBlock - OCCUPIED, EMPTY, or UNKNOWN. If no occupancy sensor is provided, UNKNOWN is returned. The occupancy sensor if there is one, is the same as the occupancy sensor of the corresponding JMRI Block.

The name of each Layout Block is the same as that of the corresponding block as defined in Layout Editor . A corresponding JMRI Block object is created when a LayoutBlock is created. The JMRI Block uses the name of the block defined in Layout Editor as its user name and a unique IBnnn system name. The JMRI Block object and its associated Path objects are useful in tracking a train around the layout. Blocks may be viewed in the Block Table.

A LayoutBlock may have an associated Memory object. This Memory object contains a string representing the current "value" of the corresponding JMRI Block object. If the value contains a train name, for example, displaying Memory objects associated with LayoutBlocks, and displayed near each Layout Block can follow a train around the layout, displaying its name when it is in the . LayoutBlock.

LayoutBlocks are "cross-panel", similar to sensors and turnouts. A LayoutBlock may be used by more than one Layout Editor panel simultaneously. As a consequence, LayoutBlocks are saved with the configuration, not with a panel.

LayoutBlocks are used by TrackSegments, LevelXings, and LayoutTurnouts. LevelXings carry two LayoutBlock designations, which may be the same. LayoutTurnouts carry LayoutBlock designations also, one per turnout, except for double crossovers which can have up to four.

LayoutBlocks carry a use count. The use count counts the number of track segments, layout turnouts, and levelcrossings which use the LayoutBlock. Only LayoutBlocks which have a use count greater than zero are saved when the configuration is saved.

Author:
Dave Duchamp Copyright (c) 2004-2008
See Also:
Serialized Form

Field Summary
 Color blockExtraColor
           
 String blockName
           
 Color blockOccupiedColor
           
 Color blockTrackColor
           
static int EMPTY
           
 boolean enableAddRouteLogging
           
 boolean enableDeleteRouteLogging
           
 boolean enableSearchRouteLogging
           
 boolean enableUpdateRouteLogging
           
 String lbSystemName
           
protected  Vector<PropertyChangeListener> listeners
           
 String memoryName
           
 String occupancySensorName
           
static int OCCUPIED
           
 int occupiedSense
           
static int RESERVED
           
static int UNKNOWN
           
 
Fields inherited from class jmri.implementation.AbstractNamedBean
mSystemName, mUserName
 
Fields inherited from interface jmri.NamedBean
INCONSISTENT
 
Constructor Summary
LayoutBlock(String sName, String uName)
           
 
Method Summary
 void addAllThroughPaths()
           
 void addLayoutEditor(LayoutEditor panel)
          Keeps track of LayoutEditor panels that are using this LayoutBlock
 void addPropertyChangeListener(PropertyChangeListener l)
           
static String colorToString(Color color)
          Utility methods for converting between string and color Note: These names are only used internally, so don't need a resource bundle
 void decrementUse()
           
 void deleteLayoutEditor(LayoutEditor panel)
           
 void disableDeleteRouteLog()
           
protected  void editLayoutBlock(Component callingPane)
          Edit a Layout Block
 void enableDeleteRouteLog()
           
protected  void firePropertyChange(String p, Object old, Object n)
           
 ArrayList<Block> getActiveNextBlocks(Block source)
           
 Block getBlock()
          Get the jmri.Block corresponding to this LayoutBlock
 Color getBlockColor()
          Returns the color for drawing items in this block.
 Color getBlockExtraColor()
           
 int getBlockHopCount(Block destination, Block nextBlock)
          Returns the number of layout blocks to our desintation block going from the next directly connected block.
 Color getBlockOccupiedColor()
           
 Color getBlockTrackColor()
           
 int getConnectedBlockRouteIndex(Block destBlock, int direction)
           
 String getID()
          Accessor methods
 LayoutEditor getMaxConnectedPanel()
          Get the Layout Editor panel with the highest connectivity to this Layout Block
 Memory getMemory()
          Returns Memory
 String getMemoryName()
          Returns Memory name
 Block getNeighbourAtIndex(int i)
          Get the neighbouring block at index i
 int getNeighbourDirection(int i)
          Get the direction of travel to neighbouring block at index i
 int getNeighbourDirection(LayoutBlock neigh)
          Gets the direction of travel to our neighbouring block.
 int getNeighbourMetric(int i)
          Get the metric/cost to neighbouring block at index i
 String getNeighbourPacketFlowAsString(int i)
          Get the flow of traffic to and from neighbouring block at index i RXTX - Means Traffic can flow both ways between the blocks RXONLY - Means we can only recieve traffic from our neighbour, we can not send traffic to it TXONLY - Means we do not recieve traffic from our neighbour, but can send traffic to it.
 int getNextBestBlock(Block previousBlock, Block destBlock, int lastIndex, int routingMethod)
          last index - the index of the last block we returned ie we last returned index 10, so we don't want to return it again.
 Block getNextBlock(Block previousBlock, Block destBlock)
          Used if we already know the block prior to our block, and the destination block.
 Block getNextBlock(Block destBlock, int direction)
           
 int getNextBlockByIndex(Block previousBlock, Block destBlock, int offSet)
           
 int getNextBlockByIndex(Block destBlock, int direction, int offSet)
           
 int getNumberOfNeighbours()
          Get the number of neighbour blocks attached to this block
 int getNumberOfRoutes()
          Get the number of routes that the block has registered.
 int getNumberOfThroughPaths()
          Returns the number of valid through paths on this block.
 int getOccupancy()
          Test block occupancy
 Sensor getOccupancySensor()
          Returns occupancy Sensor
 String getOccupancySensorName()
          Returns occupancy Sensor name
 int getOccupiedSense()
          Get/Set occupied sense
 Block getRouteDestBlockAtIndex(int i)
          Get the destination block at route i
 int getRouteDirectionAtIndex(int i)
          Get the direction of route i.
 int getRouteHopCountAtIndex(int i)
          Get the hop count of route i.
 int getRouteMetric(int i)
          Get the metric/cost at route i
 Block getRouteNextBlockAtIndex(int i)
          Get the next block at route i
 int getRouteState(int i)
          Gets the state (Occupied, unoccupied) of the destination layout block at index i
 String getRouteStateAsString(int i)
          Gets the state of the destination layout block at index i as a string
 boolean getRouteValid(int i)
          Is the route to the destination potentially valid from our block.
 int getState()
          Provide generic access to internal state.
 Block getThroughPathDestination(int i)
          Returns the destination block at index i
 Path getThroughPathDestinationPathAtIndex(int i)
           
 int getThroughPathIndex(Block sourceBlock, Block destinationBlock)
           
 Block getThroughPathSource(int i)
          Returns the source block at index i
 Path getThroughPathSourcePathAtIndex(int i)
           
 int getUseCount()
           
 boolean getUseExtraColor()
           
 void incrementUse()
           
protected  void initializeLayoutBlock()
           
 boolean isActive()
          "active" means that the object is still displayed, and should be stored.
 boolean isNeighbourMutual(int i)
          Is our neighbouring block at index i a mutual neighbour, ie both blocks have each other registered as neighbours and are exchaning information.
 boolean isOnPanel(LayoutEditor panel)
           
 boolean isRouteToDestValid(Block protecting, Block destination)
          Is the route to the destination block, going via our neighbouring block valid.
 Boolean isThroughPathActive(int i)
          Is the through path at index i active
 void printAdjacencies()
          Provides an output to the console of all our neighbouring blocks
 void printRoutes()
          Provides an output to the console of all the remote blocks reachable from our block
 void printRoutes(String blockName)
          Provides an output to the console of how to reach a specific block from our block
 void printValidThroughPaths()
          Provides an output to the console of all the valid paths through this block
 void propertyChange(PropertyChangeEvent e)
           
 void redrawLayoutBlockPanels()
          Redraws panels using this layout block
 void refreshValidRoutes()
           
 void removePropertyChangeListener(PropertyChangeListener l)
          Remove a request for a call-back when a bound property changes.
 void setBlockExtraColor(Color color)
           
 void setBlockMetric(int m)
          Sets a metric cost against a block, this is used in the calculation of a path between two location on the layout, a lower path cost is always preferred For Layout blocks defined as Mainline the default metric is 50.
 void setBlockOccupiedColor(Color color)
           
 void setBlockTrackColor(Color color)
           
 void setMemoryName(String name)
          Add Memory by name
 void setOccupancySensorName(String name)
          Add occupancy sensor by name
 void setOccupiedSense(int sense)
           
 void setState(int i)
          Provide generic access to internal state.
 void setSuppressNameUpdate(boolean set)
          Sets/resets update of memory name when block goes from occupied to unoccupied or vice versa.
 void setUseExtraColor(boolean b)
           
static Color stringToColor(String string)
           
 void updatePaths()
          Check/Update Path objects for the attached jmri.Block If multiple panels are present, Paths are set according to the panel with the highest connectivity (most LayoutConnectivity objects);
 void updatePathsUsingPanel(LayoutEditor panel)
          Check/Update Path objects for the attached jmri.Block using the connectivity in the specified Layout Editor panel.
 boolean useDefaultMetric()
           
 void useDefaultMetric(boolean boo)
           
 Memory validateMemory(String memName, Component openFrame)
          Validates that the memory name corresponds to an existing memory.
 Sensor validateSensor(String sensorName, Component openFrame)
          Validates that the supplied occupancy sensor name corresponds to an existing sensor and is unique among all blocks.
 boolean validThroughPath(Block sourceBlock, Block destinationBlock)
           
 
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, dispose, getComment, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyKeys, getSystemName, getUserName, setComment, setProperty, setUserName, updateListenerRef
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enableAddRouteLogging

public boolean enableAddRouteLogging

enableUpdateRouteLogging

public boolean enableUpdateRouteLogging

enableDeleteRouteLogging

public boolean enableDeleteRouteLogging

enableSearchRouteLogging

public boolean enableSearchRouteLogging

OCCUPIED

public static final int OCCUPIED
See Also:
Constant Field Values

EMPTY

public static final int EMPTY
See Also:
Constant Field Values

UNKNOWN

public static final int UNKNOWN
See Also:
Constant Field Values

blockName

public String blockName

lbSystemName

public String lbSystemName

occupancySensorName

public String occupancySensorName

memoryName

public String memoryName

occupiedSense

public int occupiedSense

blockTrackColor

public Color blockTrackColor

blockOccupiedColor

public Color blockOccupiedColor

blockExtraColor

public Color blockExtraColor

RESERVED

public static final int RESERVED
See Also:
Constant Field Values

listeners

protected Vector<PropertyChangeListener> listeners
Constructor Detail

LayoutBlock

public LayoutBlock(String sName,
                   String uName)
Method Detail

enableDeleteRouteLog

public void enableDeleteRouteLog()

disableDeleteRouteLog

public void disableDeleteRouteLog()

initializeLayoutBlock

protected void initializeLayoutBlock()

getID

public String getID()
Accessor methods


getBlockTrackColor

public Color getBlockTrackColor()

setBlockTrackColor

public void setBlockTrackColor(Color color)

getBlockOccupiedColor

public Color getBlockOccupiedColor()

setBlockOccupiedColor

public void setBlockOccupiedColor(Color color)

getBlockExtraColor

public Color getBlockExtraColor()

setBlockExtraColor

public void setBlockExtraColor(Color color)

getUseExtraColor

public boolean getUseExtraColor()

setUseExtraColor

public void setUseExtraColor(boolean b)

incrementUse

public void incrementUse()

decrementUse

public void decrementUse()

getUseCount

public int getUseCount()

addLayoutEditor

public void addLayoutEditor(LayoutEditor panel)
Keeps track of LayoutEditor panels that are using this LayoutBlock


deleteLayoutEditor

public void deleteLayoutEditor(LayoutEditor panel)

isOnPanel

public boolean isOnPanel(LayoutEditor panel)

redrawLayoutBlockPanels

public void redrawLayoutBlockPanels()
Redraws panels using this layout block


validateSensor

public Sensor validateSensor(String sensorName,
                             Component openFrame)
Validates that the supplied occupancy sensor name corresponds to an existing sensor and is unique among all blocks. If valid, returns the sensor and sets the block sensor name in the block. Else returns null, and does nothing to the block. This method also converts the sensor name to upper case if it is a system name.


validateMemory

public Memory validateMemory(String memName,
                             Component openFrame)
Validates that the memory name corresponds to an existing memory. If valid, returns the memory. Else returns null, and notifies the user. This method also converts the memory name to upper case if it is a system name.


getBlockColor

public Color getBlockColor()
Returns the color for drawing items in this block. Returns color based on block occupancy.


getBlock

public Block getBlock()
Get the jmri.Block corresponding to this LayoutBlock


getMemoryName

public String getMemoryName()
Returns Memory name


getMemory

public Memory getMemory()
Returns Memory


setMemoryName

public void setMemoryName(String name)
Add Memory by name


getOccupancySensorName

public String getOccupancySensorName()
Returns occupancy Sensor name


getOccupancySensor

public Sensor getOccupancySensor()
Returns occupancy Sensor


setOccupancySensorName

public void setOccupancySensorName(String name)
Add occupancy sensor by name


getOccupiedSense

public int getOccupiedSense()
Get/Set occupied sense


setOccupiedSense

public void setOccupiedSense(int sense)

getOccupancy

public int getOccupancy()
Test block occupancy


getState

public int getState()
Description copied from interface: NamedBean
Provide generic access to internal state.

This generally shouldn't be used by Java code; use the class-specific form instead. (E.g. getCommandedState in Turnout) This provided to make Jython script access easier to read.

Specified by:
getState in interface NamedBean

setState

public void setState(int i)
Description copied from interface: NamedBean
Provide generic access to internal state.

This generally shouldn't be used by Java code; use the class-specific form instead. (E.g. setCommandedState in Turnout) This provided to make Jython script access easier to read.

Specified by:
setState in interface NamedBean

getMaxConnectedPanel

public LayoutEditor getMaxConnectedPanel()
Get the Layout Editor panel with the highest connectivity to this Layout Block


updatePaths

public void updatePaths()
Check/Update Path objects for the attached jmri.Block

If multiple panels are present, Paths are set according to the panel with the highest connectivity (most LayoutConnectivity objects);


updatePathsUsingPanel

public void updatePathsUsingPanel(LayoutEditor panel)
Check/Update Path objects for the attached jmri.Block using the connectivity in the specified Layout Editor panel.


setSuppressNameUpdate

public void setSuppressNameUpdate(boolean set)
Sets/resets update of memory name when block goes from occupied to unoccupied or vice versa. If set is true, name update is suppressed. If set is false, name update works normally.


editLayoutBlock

protected void editLayoutBlock(Component callingPane)
Edit a Layout Block


colorToString

public static String colorToString(Color color)
Utility methods for converting between string and color Note: These names are only used internally, so don't need a resource bundle


stringToColor

public static Color stringToColor(String string)

isActive

public boolean isActive()
"active" means that the object is still displayed, and should be stored.


useDefaultMetric

public boolean useDefaultMetric()

useDefaultMetric

public void useDefaultMetric(boolean boo)

setBlockMetric

public void setBlockMetric(int m)
Sets a metric cost against a block, this is used in the calculation of a path between two location on the layout, a lower path cost is always preferred For Layout blocks defined as Mainline the default metric is 50. For Layout blocks defined as a Siding the default metric is 200.


addAllThroughPaths

public void addAllThroughPaths()

getActiveNextBlocks

public ArrayList<Block> getActiveNextBlocks(Block source)

getThroughPathSourcePathAtIndex

public Path getThroughPathSourcePathAtIndex(int i)

getThroughPathDestinationPathAtIndex

public Path getThroughPathDestinationPathAtIndex(int i)

validThroughPath

public boolean validThroughPath(Block sourceBlock,
                                Block destinationBlock)

getThroughPathIndex

public int getThroughPathIndex(Block sourceBlock,
                               Block destinationBlock)

printValidThroughPaths

public void printValidThroughPaths()
Provides an output to the console of all the valid paths through this block


printAdjacencies

public void printAdjacencies()
Provides an output to the console of all our neighbouring blocks


printRoutes

public void printRoutes()
Provides an output to the console of all the remote blocks reachable from our block


printRoutes

public void printRoutes(String blockName)
Provides an output to the console of how to reach a specific block from our block


getNextBlock

public Block getNextBlock(Block destBlock,
                          int direction)
Parameters:
destBlock - - is the destination of the block we are following
direction - - is the direction of travel from the previous block

getNextBlock

public Block getNextBlock(Block previousBlock,
                          Block destBlock)
Used if we already know the block prior to our block, and the destination block. direction, is optional and is used where the previousBlock is equal to our block.


getConnectedBlockRouteIndex

public int getConnectedBlockRouteIndex(Block destBlock,
                                       int direction)

getNextBlockByIndex

public int getNextBlockByIndex(Block destBlock,
                               int direction,
                               int offSet)

getNextBlockByIndex

public int getNextBlockByIndex(Block previousBlock,
                               Block destBlock,
                               int offSet)

getNextBestBlock

public int getNextBestBlock(Block previousBlock,
                            Block destBlock,
                            int lastIndex,
                            int routingMethod)
last index - the index of the last block we returned ie we last returned index 10, so we don't want to return it again. The block returned will have a hopcount or metric equal to or greater than the one of the last block returned. if last index is set to -1 this indicates that this is the first time.


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Specified by:
addPropertyChangeListener in interface NamedBean
Overrides:
addPropertyChangeListener in class AbstractNamedBean

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Description copied from interface: NamedBean
Remove a request for a call-back when a bound property changes.

Specified by:
removePropertyChangeListener in interface NamedBean
Overrides:
removePropertyChangeListener in class AbstractNamedBean

firePropertyChange

protected void firePropertyChange(String p,
                                  Object old,
                                  Object n)
Overrides:
firePropertyChange in class AbstractNamedBean

propertyChange

public void propertyChange(PropertyChangeEvent e)
Specified by:
propertyChange in interface PropertyChangeListener

isRouteToDestValid

public boolean isRouteToDestValid(Block protecting,
                                  Block destination)
Is the route to the destination block, going via our neighbouring block valid. ie Does the block have a route registered via neighbour "protecting" to the destination block.


getNeighbourDirection

public int getNeighbourDirection(LayoutBlock neigh)
Gets the direction of travel to our neighbouring block.


getNumberOfNeighbours

public int getNumberOfNeighbours()
Get the number of neighbour blocks attached to this block


getNeighbourAtIndex

public Block getNeighbourAtIndex(int i)
Get the neighbouring block at index i


getNeighbourDirection

public int getNeighbourDirection(int i)
Get the direction of travel to neighbouring block at index i


getNeighbourMetric

public int getNeighbourMetric(int i)
Get the metric/cost to neighbouring block at index i


getNeighbourPacketFlowAsString

public String getNeighbourPacketFlowAsString(int i)
Get the flow of traffic to and from neighbouring block at index i RXTX - Means Traffic can flow both ways between the blocks RXONLY - Means we can only recieve traffic from our neighbour, we can not send traffic to it TXONLY - Means we do not recieve traffic from our neighbour, but can send traffic to it.


isNeighbourMutual

public boolean isNeighbourMutual(int i)
Is our neighbouring block at index i a mutual neighbour, ie both blocks have each other registered as neighbours and are exchaning information.


getNumberOfRoutes

public int getNumberOfRoutes()
Get the number of routes that the block has registered.


getRouteDirectionAtIndex

public int getRouteDirectionAtIndex(int i)
Get the direction of route i.


getRouteDestBlockAtIndex

public Block getRouteDestBlockAtIndex(int i)
Get the destination block at route i


getRouteNextBlockAtIndex

public Block getRouteNextBlockAtIndex(int i)
Get the next block at route i


getRouteHopCountAtIndex

public int getRouteHopCountAtIndex(int i)
Get the hop count of route i.
The Hop count is the number of other blocks that we traverse to get to the destination


getRouteMetric

public int getRouteMetric(int i)
Get the metric/cost at route i


getRouteState

public int getRouteState(int i)
Gets the state (Occupied, unoccupied) of the destination layout block at index i


getRouteValid

public boolean getRouteValid(int i)
Is the route to the destination potentially valid from our block.


getRouteStateAsString

public String getRouteStateAsString(int i)
Gets the state of the destination layout block at index i as a string


getBlockHopCount

public int getBlockHopCount(Block destination,
                            Block nextBlock)
Returns the number of layout blocks to our desintation block going from the next directly connected block. If the destination block and nextblock are the same and the block is also registered as a neighbour then 1 is returned. If no valid route to the destination block can be found via the next block then -1 is returned. If more than one route exists to the destination then the route with the lowest count is returned.


getNumberOfThroughPaths

public int getNumberOfThroughPaths()
Returns the number of valid through paths on this block.


getThroughPathSource

public Block getThroughPathSource(int i)
Returns the source block at index i


getThroughPathDestination

public Block getThroughPathDestination(int i)
Returns the destination block at index i


isThroughPathActive

public Boolean isThroughPathActive(int i)
Is the through path at index i active


refreshValidRoutes

public void refreshValidRoutes()


Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads