jmri.jmrit.operations.trains
Class TrainManager

java.lang.Object
  extended by jmri.jmrit.operations.trains.TrainManager
All Implemented Interfaces:
PropertyChangeListener, EventListener

public class TrainManager
extends Object
implements PropertyChangeListener

Manages trains.

Author:
Bob Jacobsen Copyright (C) 2003, Daniel Boudreau Copyright (C) 2008, 2009, 2010

Field Summary
protected  List<String> _shutDownScripts
           
protected  List<String> _startUpScripts
           
static String ACTIVE_TRAIN_SCHEDULE_ID
           
static String LISTLENGTH_CHANGED_PROPERTY
           
static String PRINTPREVIEW_CHANGED_PROPERTY
           
static String TRAIN_ACTION_CHANGED_PROPERTY
           
 
Constructor Summary
TrainManager()
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
           
 void addShutDownScript(String pathname)
          Add a script to run at shutdown
 void addStartUpScript(String pathname)
          Add a script to run after trains have been loaded
 void deleteShutDownScript(String pathname)
           
 void deleteStartUpScript(String pathname)
           
 void deregister(Train train)
          Forget a NamedBean Object created outside the manager.
 void dispose()
           
 boolean getAnyTrainBuilt()
           
 JComboBox getComboBox()
           
 List<String> getShutDownScripts()
          Gets a list of pathnames to run at shutdown
 List<String> getStartUpScripts()
          Gets a list of pathnames to run after trains have been loaded
 Train getTrainById(String id)
           
 Train getTrainByName(String name)
           
 Train getTrainForCar(Car car)
           
 List<String> getTrainsByDepartureList()
          Sort by train departure name
 List<String> getTrainsByIdList()
          Sort by train id
 List<String> getTrainsByNameList()
          Sort by train name
 List<String> getTrainsByRouteList()
          Sort by train route name
 List<String> getTrainsByStatusList()
          Sort by train route name
 List<String> getTrainsByTerminatesList()
          Sort by train termination name
 List<String> getTrainsByTimeList()
          Sort by train departure time
 String getTrainScheduleActiveId()
           
 int[] getTrainScheduleFrameTableColumnWidths()
           
 String getTrainsFrameSortBy()
           
 int[] getTrainsFrameTableColumnWidths()
           
 String getTrainsFrameTrainAction()
           
static TrainManager instance()
           
 boolean isBuildMessagesEnabled()
           
 boolean isBuildReportEnabled()
           
 boolean isPrintPreviewEnabled()
           
 Train newTrain(String name)
          Finds an existing train or creates a new train if needed requires train's name creates a unique id for this train
 int numEntries()
           
 void options(Element values)
           
 void propertyChange(PropertyChangeEvent e)
          Check for car type and road name replacements.
 void register(Train train)
          Remember a NamedBean Object created outside the manager.
 void removePropertyChangeListener(PropertyChangeListener l)
           
 void replaceLoad(String oldLoadName, String newLoadName)
           
 void runShutDownScripts()
           
 void runStartUpScripts()
           
 void save()
          Save all xml files that a train can modify.
 void setBuildMessagesEnabled(boolean enable)
           
 void setBuildReportEnabled(boolean enable)
           
 void setFilesDirty()
          Report that the train, car and engine databases are dirty.
 void setPrintPreviewEnabled(boolean enable)
           
 void setTrainScheduleFrameTableColumnWidths(int[] tableColumnWidths)
           
 void setTrainSecheduleActiveId(String id)
          Sets the selected schedule id
 void setTrainsFrameSortBy(String sortBy)
           
 void setTrainsFrameTableColumnWidths(int[] tableColumnWidths)
           
 void setTrainsFrameTrainAction(String action)
           
 Element store()
          Create an XML element to represent this Entry.
 void updateComboBox(JComboBox box)
           
 void updateComboBox(JComboBox box, Car car)
          Update combo box with trains that will service this car
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_startUpScripts

protected List<String> _startUpScripts

_shutDownScripts

protected List<String> _shutDownScripts

LISTLENGTH_CHANGED_PROPERTY

public static final String LISTLENGTH_CHANGED_PROPERTY
See Also:
Constant Field Values

PRINTPREVIEW_CHANGED_PROPERTY

public static final String PRINTPREVIEW_CHANGED_PROPERTY
See Also:
Constant Field Values

TRAIN_ACTION_CHANGED_PROPERTY

public static final String TRAIN_ACTION_CHANGED_PROPERTY
See Also:
Constant Field Values

ACTIVE_TRAIN_SCHEDULE_ID

public static final String ACTIVE_TRAIN_SCHEDULE_ID
See Also:
Constant Field Values
Constructor Detail

TrainManager

public TrainManager()
Method Detail

instance

public static TrainManager instance()

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)

isPrintPreviewEnabled

public boolean isPrintPreviewEnabled()
Returns:
true if print preview is enabled

setPrintPreviewEnabled

public void setPrintPreviewEnabled(boolean enable)

getTrainsFrameSortBy

public String getTrainsFrameSortBy()

setTrainsFrameSortBy

public void setTrainsFrameSortBy(String sortBy)

getTrainsFrameTrainAction

public String getTrainsFrameTrainAction()

setTrainsFrameTrainAction

public void setTrainsFrameTrainAction(String action)

getTrainsFrameTableColumnWidths

public int[] getTrainsFrameTableColumnWidths()
Returns:
get an array of table column widths for the trains frame

setTrainsFrameTableColumnWidths

public void setTrainsFrameTableColumnWidths(int[] tableColumnWidths)

getTrainScheduleFrameTableColumnWidths

public int[] getTrainScheduleFrameTableColumnWidths()

setTrainScheduleFrameTableColumnWidths

public void setTrainScheduleFrameTableColumnWidths(int[] tableColumnWidths)

setTrainSecheduleActiveId

public void setTrainSecheduleActiveId(String id)
Sets the selected schedule id

Parameters:
id - Selected schedule id

getTrainScheduleActiveId

public String getTrainScheduleActiveId()

addStartUpScript

public void addStartUpScript(String pathname)
Add a script to run after trains have been loaded

Parameters:
pathname - The script's pathname

deleteStartUpScript

public void deleteStartUpScript(String pathname)

getStartUpScripts

public List<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(String pathname)
Add a script to run at shutdown

Parameters:
pathname - The script's pathname

deleteShutDownScript

public void deleteShutDownScript(String pathname)

getShutDownScripts

public List<String> getShutDownScripts()
Gets a list of pathnames to run at shutdown

Returns:
A list of pathnames to run at shutdown

runShutDownScripts

public void runShutDownScripts()

dispose

public void dispose()

getTrainByName

public Train getTrainByName(String name)
Returns:
requested Train object or null if none exists

getTrainById

public Train getTrainById(String id)

newTrain

public Train newTrain(String name)
Finds an existing train or creates a new train if needed requires train's name creates a unique id for this train

Parameters:
name -
Returns:
new train or existing train

register

public void register(Train train)
Remember a NamedBean Object created outside the manager.


deregister

public void deregister(Train train)
Forget a NamedBean Object created outside the manager.


replaceLoad

public void replaceLoad(String oldLoadName,
                        String newLoadName)

getAnyTrainBuilt

public boolean getAnyTrainBuilt()
Returns:
true if there are any trains built

getTrainForCar

public Train getTrainForCar(Car car)
Parameters:
car -
Returns:
Train that can service car from its current location to the its destination.

getTrainsByNameList

public List<String> getTrainsByNameList()
Sort by train name

Returns:
list of train ids ordered by name

getTrainsByTimeList

public List<String> getTrainsByTimeList()
Sort by train departure time

Returns:
list of train ids ordered by departure time

getTrainsByDepartureList

public List<String> getTrainsByDepartureList()
Sort by train departure name

Returns:
list of train ids ordered by departure name

getTrainsByTerminatesList

public List<String> getTrainsByTerminatesList()
Sort by train termination name

Returns:
list of train ids ordered by termination name

getTrainsByRouteList

public List<String> getTrainsByRouteList()
Sort by train route name

Returns:
list of train ids ordered by route name

getTrainsByStatusList

public List<String> getTrainsByStatusList()
Sort by train route name

Returns:
list of train ids ordered by route name

getTrainsByIdList

public List<String> getTrainsByIdList()
Sort by train id

Returns:
list of train ids ordered by id

getComboBox

public JComboBox getComboBox()

updateComboBox

public void updateComboBox(JComboBox box)

updateComboBox

public void updateComboBox(JComboBox box,
                           Car car)
Update combo box with trains that will service this car

Parameters:
box - the combo box to update
car - the car to be serviced

setFilesDirty

public void setFilesDirty()
Report that the train, car and engine databases are dirty.


save

public void save()
Save all xml files that a train can modify.


numEntries

public int numEntries()
Returns:
Number of trains

options

public void options(Element values)

store

public Element store()
Create an XML element to represent this Entry. This member has to remain synchronized with the detailed DTD in operations-trains.dtd.

Returns:
Contents in a JDOM Element

propertyChange

public void propertyChange(PropertyChangeEvent e)
Check for car type and road name replacements. Also check for engine type replacement.

Specified by:
propertyChange in interface PropertyChangeListener

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)


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