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_maxTrainNameLengthprotected java.util.List<java.lang.String>_shutDownScriptsprotected java.util.List<java.lang.String>_startUpScriptsstatic java.lang.StringLISTLENGTH_CHANGED_PROPERTY(package private) static java.lang.StringNONEstatic java.lang.StringOPEN_FILE_CHANGED_PROPERTYstatic java.lang.StringPRINTPREVIEW_CHANGED_PROPERTYstatic java.lang.StringROW_COLOR_NAME_CHANGED_PROPERTYstatic java.lang.StringRUN_FILE_CHANGED_PROPERTYprotected static java.lang.StringSEVENstatic java.lang.StringTRAIN_ACTION_CHANGED_PROPERTYstatic java.lang.StringTRAINS_BUILT_CHANGED_PROPERTYstatic java.lang.StringTRAINS_SAVED_PROPERTYstatic java.lang.StringTRAINS_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 voidaddShutDownScript(java.lang.String pathname)Add a script to run at shutdownvoidaddStartUpScript(java.lang.String pathname)Add a script to run after trains have been loadedvoidbuildSelectedTrains(java.util.List<Train> trains)TraincopyTrain(Train train, java.lang.String trainName)Makes a copy of an existing train.voiddeleteShutDownScript(java.lang.String pathname)voiddeleteStartUpScript(java.lang.String pathname)voidderegister(Train train)Forget a NamedBean Object created outside the manager.voiddispose()java.util.List<Train>getList()intgetMaxTrainNameLength()intgetNumEntries()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.StringgetRowColorNameForBuildFailed()java.lang.StringgetRowColorNameForBuilt()java.lang.StringgetRowColorNameForReset()java.lang.StringgetRowColorNameForTerminated()java.lang.StringgetRowColorNameForTrainEnRoute()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 loadedTraingetTrainById(java.lang.String id)TraingetTrainByName(java.lang.String name)javax.swing.JComboBox<Train>getTrainComboBox()TraingetTrainForCar(Car car, java.io.PrintWriter buildReport)TraingetTrainForCar(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.StringgetTrainsFrameTrainAction()voidinitialize()Perform any initialization that occurs after this object has been constructed and made available by the InstanceManager.booleanisAnyTrainBuilding()booleanisAnyTrainBuilt()booleanisBuildMessagesEnabled()booleanisBuildReportEnabled()booleanisBuiltRestricted()Used to determine if a train has any restrictions with regard to car built dates.booleanisCabooseRoadRestricted()Used to determine if a train has any restrictions with regard to caboose roads.booleanisCarRoadRestricted()Used to determine if a train has any restrictions with regard to car roads.booleanisLoadRestricted()Used to determine if a train has any restrictions with regard to car loads.booleanisLocoRoadRestricted()Used to determine if a train has any restrictions with regard to Locomotive roads.booleanisOpenFileEnabled()booleanisOwnerRestricted()Used to determine if a train has any restrictions with regard to car owners.booleanisPrintPreviewEnabled()booleanisRowColorManual()booleanisRunFileEnabled()booleanisShowLocationHyphenNameEnabled()When true show entire location name including hyphenvoidload(org.jdom2.Element root)voidloadTrainIcons()Loads train icons if neededTrainnewTrain(java.lang.String name)Finds an existing train or creates a new train if needed.booleanprintSelectedTrains(java.util.List<Train> trains)voidpropertyChange(java.beans.PropertyChangeEvent e)Not currently used.voidregister(Train train)Remember a NamedBean Object created outside the manager.voidreplaceLoad(java.lang.String type, java.lang.String oldLoadName, java.lang.String newLoadName)voidresetBuildFailedTrains()voidrunShutDownScripts()voidrunStartUpScripts()voidsetBuildMessagesEnabled(boolean enable)voidsetBuildReportEnabled(boolean enable)voidsetOpenFileEnabled(boolean enable)voidsetPrintPreviewEnabled(boolean enable)voidsetRowColorNameForBuildFailed(java.lang.String colorName)voidsetRowColorNameForBuilt(java.lang.String colorName)voidsetRowColorNameForReset(java.lang.String colorName)voidsetRowColorNameForTerminated(java.lang.String colorName)voidsetRowColorNameForTrainEnRoute(java.lang.String colorName)voidsetRowColorsManual(boolean manual)voidsetRunFileEnabled(boolean enable)voidsetShowLocationHyphenNameEnabled(boolean enable)voidsetTrainsFrameTrainAction(java.lang.String action)voidsetTrainsModified()Sets all built trains manifests to modified.voidsetTrainsSwitchListStatus(java.lang.String status)Sets the switch list status for all built trains.voidstore(org.jdom2.Element root)Create an XML element to represent this Entry.booleanterminateSelectedTrains(java.util.List<Train> trains)voidupdateTrainComboBox(javax.swing.JComboBox<Train> box)voidupdateTrainComboBox(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:
propertyChangein interfacejava.beans.PropertyChangeListener
-
initialize
public void initialize()
Description copied from interface:InstanceManagerAutoInitializePerform any initialization that occurs after this object has been constructed and made available by the InstanceManager.- Specified by:
initializein interfaceInstanceManagerAutoInitialize
-
-