jmri.jmrix.nce.consist
Class NceConsistRoster

java.lang.Object
  extended by jmri.jmrit.XmlFile
      extended by jmri.jmrix.nce.consist.NceConsistRoster

public class NceConsistRoster
extends XmlFile

NCE Consist Roster manages and manipulates a roster of consists.

It works with the "consist-roster-config" XML DTD to load and store its information.

This is an in-memory representation of the roster xml file (see below for constants defining name and location). As such, this class is also responsible for the "dirty bit" handling to ensure it gets written. As a temporary reliability enhancement, all changes to this structure are now being written to a backup file, and a copy is made when the file is opened.

Multiple Roster objects don't make sense, so we use an "instance" member to navigate to a single one.

This predates the "XmlFile" base class, so doesn't use it. Not sure whether it should...

The only bound property is the list of s; a PropertyChangedEvent is fired every time that changes.

The entries are stored in an ArrayList, sorted alphabetically. That sort is done manually each time an entry is added.

Author:
Bob Jacobsen Copyright (C) 2001; Dennis Miller Copyright 2004, Daniel Boudreau (C) 2008
See Also:
NceConsistRosterEntry

Field Summary
protected  List<NceConsistRosterEntry> _list
          List of contained RosterEntry elements.
 
Fields inherited from class jmri.jmrit.XmlFile
dtdLocation, xsltLocation
 
Constructor Summary
NceConsistRoster()
           
 
Method Summary
 void addEntry(NceConsistRosterEntry e)
          Add a RosterEntry object to the in-memory Roster.
 void addPropertyChangeListener(PropertyChangeListener l)
           
 boolean checkEntry(int i, String roadName, String roadNumber, String consistNumber, String loco1Address, String loco2Address, String loco3Address, String loco4Address, String loco5Address, String loco6Address, String id)
          Check if an entry consistent with specific properties.
static String defaultNceConsistRosterFilename()
          Return the filename String for the default ConsistRoster file, including location.
 void dispose()
           
 NceConsistRosterEntry entryFromTitle(String title)
          Return RosterEntry from a "title" string, ala selection in matchingComboBox
 void entryIdChanged(NceConsistRosterEntry r)
          Notify that the ID of an entry has changed.
protected  void firePropertyChange(String p, Object old, Object n)
           
 JComboBox fullRosterComboBox()
          Return a combo box containing the entire ConsistRoster.
static NceConsistRoster instance()
          Locate the single instance of Roster, loading it if need be
 JComboBox matchingComboBox(String roadName, String roadNumber, String consistNumber, String eng1Address, String eng2Address, String eng3Address, String eng4Address, String eng5Address, String eng6Address, String id)
          Get a JComboBox representing the choices that match.
 List<NceConsistRosterEntry> matchingList(String roadName, String roadNumber, String consistNumber, String eng1Address, String eng2Address, String eng3Address, String eng4Address, String eng5Address, String eng6Address, String id)
          Get a List of entries matching some information.
 int numEntries()
           
 void reloadRosterFile()
          update the in-memory Roster to be consistent with the current roster file.
 void removeEntry(NceConsistRosterEntry e)
          Remove a RosterEntry object from the in-memory Roster.
 void removePropertyChangeListener(PropertyChangeListener l)
           
static void resetInstance()
           
static void setNceConsistRosterFileName(String name)
           
 void updateComboBox(JComboBox box)
           
static void writeRosterFile()
          Store the roster in the default place, including making a backup if needed
 
Methods inherited from class jmri.jmrit.XmlFile
addDefaultInfo, backupFileName, checkFile, createFileNameWithDate, dumpElement, ensurePrefsPresent, findFile, getBuilder, getRootViaURI, getVerify, makeBackupFile, makeBackupFile, newDocument, newDocument, prefsDir, reportError1, reportError2, resourcesDir, revertBackupFile, rootFromFile, rootFromName, rootFromURL, scriptsDir, setScriptsFileLocationDefault, setUserFileLocationDefault, setVerify, userFileChooser, userFileChooser, userFileChooser, userFileChooser, userFileLocationDefault, writeXML, xmlDir
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_list

protected List<NceConsistRosterEntry> _list
List of contained RosterEntry elements.

Constructor Detail

NceConsistRoster

public NceConsistRoster()
Method Detail

resetInstance

public static void resetInstance()

instance

public static NceConsistRoster instance()
Locate the single instance of Roster, loading it if need be

Returns:
The valid Roster object

addEntry

public void addEntry(NceConsistRosterEntry e)
Add a RosterEntry object to the in-memory Roster.

Parameters:
e - Entry to add

removeEntry

public void removeEntry(NceConsistRosterEntry e)
Remove a RosterEntry object from the in-memory Roster. This does not delete the file for the RosterEntry!

Parameters:
e - Entry to remove

numEntries

public int numEntries()
Returns:
Number of entries in the Roster

fullRosterComboBox

public JComboBox fullRosterComboBox()
Return a combo box containing the entire ConsistRoster.

This is based on a single model, so it can be updated when the ConsistRoster changes.


matchingComboBox

public JComboBox matchingComboBox(String roadName,
                                  String roadNumber,
                                  String consistNumber,
                                  String eng1Address,
                                  String eng2Address,
                                  String eng3Address,
                                  String eng4Address,
                                  String eng5Address,
                                  String eng6Address,
                                  String id)
Get a JComboBox representing the choices that match. There's 10 elements.


updateComboBox

public void updateComboBox(JComboBox box)

entryFromTitle

public NceConsistRosterEntry entryFromTitle(String title)
Return RosterEntry from a "title" string, ala selection in matchingComboBox


matchingList

public List<NceConsistRosterEntry> matchingList(String roadName,
                                                String roadNumber,
                                                String consistNumber,
                                                String eng1Address,
                                                String eng2Address,
                                                String eng3Address,
                                                String eng4Address,
                                                String eng5Address,
                                                String eng6Address,
                                                String id)
Get a List of entries matching some information. The list may have null contents.


checkEntry

public boolean checkEntry(int i,
                          String roadName,
                          String roadNumber,
                          String consistNumber,
                          String loco1Address,
                          String loco2Address,
                          String loco3Address,
                          String loco4Address,
                          String loco5Address,
                          String loco6Address,
                          String id)
Check if an entry consistent with specific properties. A null String entry always matches. Strings are used for convenience in GUI building.


dispose

public void dispose()

writeRosterFile

public static void writeRosterFile()
Store the roster in the default place, including making a backup if needed


reloadRosterFile

public void reloadRosterFile()
update the in-memory Roster to be consistent with the current roster file. This removes the existing roster entries!


defaultNceConsistRosterFilename

public static String defaultNceConsistRosterFilename()
Return the filename String for the default ConsistRoster file, including location.


setNceConsistRosterFileName

public static void setNceConsistRosterFileName(String name)

addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)

firePropertyChange

protected void firePropertyChange(String p,
                                  Object old,
                                  Object n)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)

entryIdChanged

public void entryIdChanged(NceConsistRosterEntry r)
Notify that the ID of an entry has changed. This doesn't actually change the ConsistRoster per se, but triggers recreation.



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