Package jmri.jmrit.operations.trains
Class TrainManager
- java.lang.Object
-
- jmri.beans.PropertyChangeSupport
-
- jmri.jmrit.operations.trains.TrainManager
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener
,java.util.EventListener
,PropertyChangeFirer
,PropertyChangeProvider
,InstanceManagerAutoDefault
,InstanceManagerAutoInitialize
public class TrainManager extends PropertyChangeSupport implements InstanceManagerAutoDefault, InstanceManagerAutoInitialize, java.beans.PropertyChangeListener
Manages trains.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) int
_maxTrainNameLength
protected java.util.List<java.lang.String>
_shutDownScripts
protected java.util.List<java.lang.String>
_startUpScripts
static java.lang.String
LISTLENGTH_CHANGED_PROPERTY
(package private) static java.lang.String
NONE
static java.lang.String
OPEN_FILE_CHANGED_PROPERTY
static java.lang.String
PRINTPREVIEW_CHANGED_PROPERTY
static java.lang.String
ROW_COLOR_NAME_CHANGED_PROPERTY
static java.lang.String
RUN_FILE_CHANGED_PROPERTY
protected static java.lang.String
SEVEN
static java.lang.String
TRAIN_ACTION_CHANGED_PROPERTY
static java.lang.String
TRAINS_BUILT_CHANGED_PROPERTY
static java.lang.String
TRAINS_SAVED_PROPERTY
static java.lang.String
TRAINS_SHOW_FULL_NAME_PROPERTY
-
Fields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupport
-
-
Constructor Summary
Constructors Constructor Description TrainManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addShutDownScript(java.lang.String pathname)
Add a script to run at shutdownvoid
addStartUpScript(java.lang.String pathname)
Add a script to run after trains have been loadedvoid
buildSelectedTrains(java.util.List<Train> trains)
Train
copyTrain(Train train, java.lang.String trainName)
Makes a copy of an existing train.void
deleteShutDownScript(java.lang.String pathname)
void
deleteStartUpScript(java.lang.String pathname)
void
deregister(Train train)
Forget a NamedBean Object created outside the manager.void
dispose()
int
getMaxTrainNameLength()
int
getNumEntries()
Get the number of items in the rosterjavax.swing.JComboBox<java.lang.String>
getRowColorComboBox()
JColorChooser is not a replacement for getRowColorComboBox as it doesn't support no color as a selection.java.lang.String
getRowColorNameForBuildFailed()
java.lang.String
getRowColorNameForBuilt()
java.lang.String
getRowColorNameForReset()
java.lang.String
getRowColorNameForTerminated()
java.lang.String
getRowColorNameForTrainEnRoute()
java.util.List<java.lang.String>
getShutDownScripts()
Gets a list of pathnames to run at shutdownjava.util.List<java.lang.String>
getStartUpScripts()
Gets a list of pathnames to run after trains have been loadedTrain
getTrainById(java.lang.String id)
Train
getTrainByName(java.lang.String name)
javax.swing.JComboBox<Train>
getTrainComboBox()
Train
getTrainForCar(Car car, java.io.PrintWriter buildReport)
Train
getTrainForCar(Car car, java.util.List<Train> excludeTrains, java.io.PrintWriter buildReport)
java.util.List<Train>
getTrainsArrivingThisLocationList(Location location)
Provides a list of trains ordered by arrival time to a locationjava.util.List<Train>
getTrainsByDepartureList()
Sort by train departure location namejava.util.List<Train>
getTrainsByDescriptionList()
Sort by train descriptionjava.util.List<Train>
getTrainsByIdList()
Sort by train idjava.util.List<Train>
getTrainsByNameList()
Sort by train namejava.util.List<Train>
getTrainsByRouteList()
Sort by train route namejava.util.List<Train>
getTrainsByStatusList()
Sort by train statusjava.util.List<Train>
getTrainsByTerminatesList()
Sort by train termination location namejava.util.List<Train>
getTrainsByTimeList()
Sort by train departure timejava.lang.String
getTrainsFrameTrainAction()
void
initialize()
Perform any initialization that occurs after this object has been constructed and made available by the InstanceManager.boolean
isAnyTrainBuilding()
boolean
isAnyTrainBuilt()
boolean
isBuildMessagesEnabled()
boolean
isBuildReportEnabled()
boolean
isBuiltRestricted()
Used to determine if a train has any restrictions with regard to car built dates.boolean
isCabooseRoadRestricted()
Used to determine if a train has any restrictions with regard to caboose roads.boolean
isCarRoadRestricted()
Used to determine if a train has any restrictions with regard to car roads.boolean
isLoadRestricted()
Used to determine if a train has any restrictions with regard to car loads.boolean
isLocoRoadRestricted()
Used to determine if a train has any restrictions with regard to Locomotive roads.boolean
isOpenFileEnabled()
boolean
isOwnerRestricted()
Used to determine if a train has any restrictions with regard to car owners.boolean
isPrintPreviewEnabled()
boolean
isRowColorManual()
boolean
isRunFileEnabled()
boolean
isShowLocationHyphenNameEnabled()
When true show entire location name including hyphenvoid
load(org.jdom2.Element root)
void
loadTrainIcons()
Loads train icons if neededTrain
newTrain(java.lang.String name)
Finds an existing train or creates a new train if needed.boolean
printSelectedTrains(java.util.List<Train> trains)
void
propertyChange(java.beans.PropertyChangeEvent e)
Not currently used.void
register(Train train)
Remember a NamedBean Object created outside the manager.void
replaceLoad(java.lang.String type, java.lang.String oldLoadName, java.lang.String newLoadName)
void
resetBuildFailedTrains()
void
runShutDownScripts()
void
runStartUpScripts()
void
setBuildMessagesEnabled(boolean enable)
void
setBuildReportEnabled(boolean enable)
void
setOpenFileEnabled(boolean enable)
void
setPrintPreviewEnabled(boolean enable)
void
setRowColorNameForBuildFailed(java.lang.String colorName)
void
setRowColorNameForBuilt(java.lang.String colorName)
void
setRowColorNameForReset(java.lang.String colorName)
void
setRowColorNameForTerminated(java.lang.String colorName)
void
setRowColorNameForTrainEnRoute(java.lang.String colorName)
void
setRowColorsManual(boolean manual)
void
setRunFileEnabled(boolean enable)
void
setShowLocationHyphenNameEnabled(boolean enable)
void
setTrainsFrameTrainAction(java.lang.String action)
void
setTrainsModified()
Sets all built trains manifests to modified.void
setTrainsSwitchListStatus(java.lang.String status)
Sets the switch list status for all built trains.void
store(org.jdom2.Element root)
Create an XML element to represent this Entry.boolean
terminateSelectedTrains(java.util.List<Train> trains)
void
updateTrainComboBox(javax.swing.JComboBox<Train> box)
void
updateTrainComboBox(javax.swing.JComboBox<Train> box, Car car)
Update combo box with trains that will service this car-
Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
NONE
static final java.lang.String NONE
- See Also:
- Constant Field Values
-
_startUpScripts
protected java.util.List<java.lang.String> _startUpScripts
-
_shutDownScripts
protected java.util.List<java.lang.String> _shutDownScripts
-
LISTLENGTH_CHANGED_PROPERTY
public static final java.lang.String LISTLENGTH_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
PRINTPREVIEW_CHANGED_PROPERTY
public static final java.lang.String PRINTPREVIEW_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
OPEN_FILE_CHANGED_PROPERTY
public static final java.lang.String OPEN_FILE_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
RUN_FILE_CHANGED_PROPERTY
public static final java.lang.String RUN_FILE_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
TRAIN_ACTION_CHANGED_PROPERTY
public static final java.lang.String TRAIN_ACTION_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
ROW_COLOR_NAME_CHANGED_PROPERTY
public static final java.lang.String ROW_COLOR_NAME_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
TRAINS_BUILT_CHANGED_PROPERTY
public static final java.lang.String TRAINS_BUILT_CHANGED_PROPERTY
- See Also:
- Constant Field Values
-
TRAINS_SHOW_FULL_NAME_PROPERTY
public static final java.lang.String TRAINS_SHOW_FULL_NAME_PROPERTY
- See Also:
- Constant Field Values
-
TRAINS_SAVED_PROPERTY
public static final java.lang.String TRAINS_SAVED_PROPERTY
- See Also:
- Constant Field Values
-
SEVEN
protected static final java.lang.String SEVEN
- See Also:
- Constant Field Values
-
_maxTrainNameLength
int _maxTrainNameLength
-
-
Constructor Detail
-
TrainManager
public TrainManager()
-
-
Method Detail
-
getNumEntries
public int getNumEntries()
Get the number of items in the roster- Returns:
- Number of trains in the roster
-
isBuildMessagesEnabled
public boolean isBuildMessagesEnabled()
- Returns:
- true if build messages are enabled
-
setBuildMessagesEnabled
public void setBuildMessagesEnabled(boolean enable)
-
isBuildReportEnabled
public boolean isBuildReportEnabled()
- Returns:
- true if build reports are enabled
-
setBuildReportEnabled
public void setBuildReportEnabled(boolean enable)
-
isOpenFileEnabled
public boolean isOpenFileEnabled()
- Returns:
- true if open file is enabled
-
setOpenFileEnabled
public void setOpenFileEnabled(boolean enable)
-
isRunFileEnabled
public boolean isRunFileEnabled()
- Returns:
- true if open file is enabled
-
setRunFileEnabled
public void setRunFileEnabled(boolean enable)
-
isPrintPreviewEnabled
public boolean isPrintPreviewEnabled()
- Returns:
- true if print preview is enabled
-
setPrintPreviewEnabled
public void setPrintPreviewEnabled(boolean enable)
-
isShowLocationHyphenNameEnabled
public boolean isShowLocationHyphenNameEnabled()
When true show entire location name including hyphen- Returns:
- true when showing entire location name
-
setShowLocationHyphenNameEnabled
public void setShowLocationHyphenNameEnabled(boolean enable)
-
getTrainsFrameTrainAction
public java.lang.String getTrainsFrameTrainAction()
-
setTrainsFrameTrainAction
public void setTrainsFrameTrainAction(java.lang.String action)
-
addStartUpScript
public void addStartUpScript(java.lang.String pathname)
Add a script to run after trains have been loaded- Parameters:
pathname
- The script's pathname
-
deleteStartUpScript
public void deleteStartUpScript(java.lang.String pathname)
-
getStartUpScripts
public java.util.List<java.lang.String> getStartUpScripts()
Gets a list of pathnames to run after trains have been loaded- Returns:
- A list of pathnames to run after trains have been loaded
-
runStartUpScripts
public void runStartUpScripts()
-
addShutDownScript
public void addShutDownScript(java.lang.String pathname)
Add a script to run at shutdown- Parameters:
pathname
- The script's pathname
-
deleteShutDownScript
public void deleteShutDownScript(java.lang.String pathname)
-
getShutDownScripts
public java.util.List<java.lang.String> getShutDownScripts()
Gets a list of pathnames to run at shutdown- Returns:
- A list of pathnames to run at shutdown
-
runShutDownScripts
public void runShutDownScripts()
-
isBuiltRestricted
public boolean isBuiltRestricted()
Used to determine if a train has any restrictions with regard to car built dates.- Returns:
- true if there's a restriction
-
isLoadRestricted
public boolean isLoadRestricted()
Used to determine if a train has any restrictions with regard to car loads.- Returns:
- true if there's a restriction
-
isCarRoadRestricted
public boolean isCarRoadRestricted()
Used to determine if a train has any restrictions with regard to car roads.- Returns:
- true if there's a restriction
-
isCabooseRoadRestricted
public boolean isCabooseRoadRestricted()
Used to determine if a train has any restrictions with regard to caboose roads.- Returns:
- true if there's a restriction
-
isLocoRoadRestricted
public boolean isLocoRoadRestricted()
Used to determine if a train has any restrictions with regard to Locomotive roads.- Returns:
- true if there's a restriction
-
isOwnerRestricted
public boolean isOwnerRestricted()
Used to determine if a train has any restrictions with regard to car owners.- Returns:
- true if there's a restriction
-
dispose
public void dispose()
-
getTrainByName
public Train getTrainByName(java.lang.String name)
- Parameters:
name
- The train's name.- Returns:
- requested Train object or null if none exists
-
getTrainById
public Train getTrainById(java.lang.String id)
-
newTrain
public Train newTrain(java.lang.String name)
Finds an existing train or creates a new train if needed. Requires train's name and creates a unique id for a new train- Parameters:
name
- The train's name.- Returns:
- new train or existing train
-
register
public void register(Train train)
Remember a NamedBean Object created outside the manager.- Parameters:
train
- The Train to be added.
-
deregister
public void deregister(Train train)
Forget a NamedBean Object created outside the manager.- Parameters:
train
- The Train to delete.
-
replaceLoad
public void replaceLoad(java.lang.String type, java.lang.String oldLoadName, java.lang.String newLoadName)
-
isAnyTrainBuilt
public boolean isAnyTrainBuilt()
- Returns:
- true if there's a built train
-
isAnyTrainBuilding
public boolean isAnyTrainBuilding()
- Returns:
- true if there's a train being built
-
getTrainForCar
public Train getTrainForCar(Car car, java.io.PrintWriter buildReport)
- Parameters:
car
- The car looking for a train.buildReport
- The optional build report for logging.- Returns:
- Train that can service car from its current location to the its destination.
-
getTrainForCar
public Train getTrainForCar(Car car, java.util.List<Train> excludeTrains, java.io.PrintWriter buildReport)
- Parameters:
car
- The car looking for a train.excludeTrains
- The trains not to try.buildReport
- The optional build report for logging.- Returns:
- Train that can service car from its current location to the its destination.
-
getTrainsByNameList
public java.util.List<Train> getTrainsByNameList()
Sort by train name- Returns:
- list of trains ordered by name
-
getTrainsByTimeList
public java.util.List<Train> getTrainsByTimeList()
Sort by train departure time- Returns:
- list of trains ordered by departure time
-
getTrainsByDepartureList
public java.util.List<Train> getTrainsByDepartureList()
Sort by train departure location name- Returns:
- list of trains ordered by departure name
-
getTrainsByTerminatesList
public java.util.List<Train> getTrainsByTerminatesList()
Sort by train termination location name- Returns:
- list of trains ordered by termination name
-
getTrainsByRouteList
public java.util.List<Train> getTrainsByRouteList()
Sort by train route name- Returns:
- list of trains ordered by route name
-
getTrainsByStatusList
public java.util.List<Train> getTrainsByStatusList()
Sort by train status- Returns:
- list of trains ordered by status
-
getTrainsByDescriptionList
public java.util.List<Train> getTrainsByDescriptionList()
Sort by train description- Returns:
- list of trains ordered by train description
-
getTrainsByIdList
public java.util.List<Train> getTrainsByIdList()
Sort by train id- Returns:
- list of trains ordered by id
-
getTrainComboBox
public javax.swing.JComboBox<Train> getTrainComboBox()
-
updateTrainComboBox
public void updateTrainComboBox(javax.swing.JComboBox<Train> box)
-
updateTrainComboBox
public void updateTrainComboBox(javax.swing.JComboBox<Train> box, Car car)
Update combo box with trains that will service this car- Parameters:
box
- the combo box to updatecar
- the car to be serviced
-
isRowColorManual
public boolean isRowColorManual()
-
setRowColorsManual
public void setRowColorsManual(boolean manual)
-
getRowColorNameForBuilt
public java.lang.String getRowColorNameForBuilt()
-
setRowColorNameForBuilt
public void setRowColorNameForBuilt(java.lang.String colorName)
-
getRowColorNameForBuildFailed
public java.lang.String getRowColorNameForBuildFailed()
-
setRowColorNameForBuildFailed
public void setRowColorNameForBuildFailed(java.lang.String colorName)
-
getRowColorNameForTrainEnRoute
public java.lang.String getRowColorNameForTrainEnRoute()
-
setRowColorNameForTrainEnRoute
public void setRowColorNameForTrainEnRoute(java.lang.String colorName)
-
getRowColorNameForTerminated
public java.lang.String getRowColorNameForTerminated()
-
setRowColorNameForTerminated
public void setRowColorNameForTerminated(java.lang.String colorName)
-
getRowColorNameForReset
public java.lang.String getRowColorNameForReset()
-
setRowColorNameForReset
public void setRowColorNameForReset(java.lang.String colorName)
-
getRowColorComboBox
public javax.swing.JComboBox<java.lang.String> getRowColorComboBox()
JColorChooser is not a replacement for getRowColorComboBox as it doesn't support no color as a selection.- Returns:
- the available colors used highlighting table rows including no color.
-
copyTrain
public Train copyTrain(Train train, java.lang.String trainName)
Makes a copy of an existing train.- Parameters:
train
- the train to copytrainName
- the name of the new train- Returns:
- a copy of train
-
getTrainsArrivingThisLocationList
public java.util.List<Train> getTrainsArrivingThisLocationList(Location location)
Provides a list of trains ordered by arrival time to a location- Parameters:
location
- The location- Returns:
- A list of trains ordered by arrival time.
-
loadTrainIcons
public void loadTrainIcons()
Loads train icons if needed
-
setTrainsSwitchListStatus
public void setTrainsSwitchListStatus(java.lang.String status)
Sets the switch list status for all built trains. Used for switch lists in consolidated mode.- Parameters:
status
- Train.PRINTED, Train.UNKNOWN
-
setTrainsModified
public void setTrainsModified()
Sets all built trains manifests to modified. This causes the train's manifest to be recreated.
-
buildSelectedTrains
public void buildSelectedTrains(java.util.List<Train> trains)
-
printSelectedTrains
public boolean printSelectedTrains(java.util.List<Train> trains)
-
terminateSelectedTrains
public boolean terminateSelectedTrains(java.util.List<Train> trains)
-
resetBuildFailedTrains
public void resetBuildFailedTrains()
-
getMaxTrainNameLength
public int getMaxTrainNameLength()
-
load
public void load(org.jdom2.Element root)
-
store
public void store(org.jdom2.Element root)
Create an XML element to represent this Entry. This member has to remain synchronized with the detailed DTD in operations-trains.dtd.- Parameters:
root
- common Element for operations-trains.dtd.
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
Not currently used.- Specified by:
propertyChange
in interfacejava.beans.PropertyChangeListener
-
initialize
public void initialize()
Description copied from interface:InstanceManagerAutoInitialize
Perform any initialization that occurs after this object has been constructed and made available by the InstanceManager.- Specified by:
initialize
in interfaceInstanceManagerAutoInitialize
-
-