jmri.jmrit.roster
Class RosterEntry

Show UML class diagram
java.lang.Object
  extended by jmri.jmrit.roster.RosterEntry
All Implemented Interfaces:
BasicRosterEntry

public class RosterEntry
extends Object
implements BasicRosterEntry

RosterEntry represents a single element in a locomotive roster, including information on how to locate it from decoder information.

The RosterEntry is the central place to find information about a locomotive's configuration, including CV and "programming variable" information. RosterEntry handles persistency through the LocoFile class. Creating a RosterEntry does not necessarily read the corresponding file (which might not even exist), please see readFile(), writeFile() member functions.

All the data attributes have a content, not null. FileName, however, is special. A null value for it indicates that no physical file is (yet) associated with this entry.

When the filePath attribute is non-null, the user has decided to organize the roster into directories.

Each entry can have one or more "Attributes" associated with it. These are (key, value) pairs. The key has to be unique, and currently both objects have to be Strings.

All properties, including the "Attributes", are bound.

See Also:
LocoFile

Field Summary
protected  String _comment
           
protected  String _dateUpdated
           
protected  String _dccAddress
           
protected  String _decoderComment
           
protected  String _decoderFamily
           
protected  String _decoderModel
           
protected  String _fileName
           
protected  String _iconFilePath
           
protected  String _id
           
protected  String _imageFilePath
           
protected  String _isShuntingOn
           
protected  int _maxSpeedPCT
           
protected  String _mfg
           
protected  String _model
           
protected  String _owner
           
protected  LocoAddress.Protocol _protocol
           
protected  String _roadName
           
protected  String _roadNumber
           
protected  RosterSpeedProfile _sp
           
protected  String _URL
           
(package private)  TreeMap<String,String> attributePairs
           
protected  String[] functionImages
           
protected  String[] functionLabels
           
protected  boolean[] functionLockables
           
protected  String[] functionSelectedImages
           
(package private)  String indent
           
(package private)  int indentWidth
           
(package private)  boolean loadedOnce
           
(package private) static org.slf4j.Logger log
           
(package private) static int MAXFNNUM
           
(package private)  String newLine
           
(package private)  int openCounter
           
(package private)  PropertyChangeSupport pcs
           
 
Constructor Summary
RosterEntry()
          Construct a blank object.
RosterEntry(org.jdom.Element e)
          Construct this Entry from XML.
RosterEntry(RosterEntry pEntry, String pID)
           
RosterEntry(String fileName)
           
 
Method Summary
 void addPropertyChangeListener(PropertyChangeListener l)
           
 void changeDateUpdated()
          Mark the date updated, e.g. from storing this roster entry
 void deleteAttribute(String key)
           
 void ensureFilenameExists()
          Ensure the entry has a valid filename.
protected  void firePropertyChange(String p, Object old, Object n)
           
 String getAttribute(String key)
           
 String[] getAttributeList()
           
 Set<String> getAttributes()
          Provide access to the set of attributes.
 String getComment()
           
 String getDateUpdated()
           
 String getDccAddress()
           
 DccLocoAddress getDccLocoAddress()
           
 String getDecoderComment()
           
 String getDecoderFamily()
           
 String getDecoderModel()
           
static String getDefaultOwner()
           
 String getFileName()
           
 String getFunctionImage(int fn)
           
 String getFunctionLabel(int fn)
          If a label has been defined for a specific function, return it, otherwise return null.
 boolean getFunctionLockable(int fn)
          Return the lockable state of a specific function.
 String getFunctionSelectedImage(int fn)
           
 String getIconPath()
           
 String getId()
           
 String getImagePath()
           
 int getMAXFNNUM()
           
 int getMaxSpeedPCT()
           
 String getMfg()
           
 String getModel()
           
 String getOwner()
           
 String getPathName()
           
 LocoAddress.Protocol getProtocol()
           
 String getProtocolAsString()
           
 String getRoadName()
           
 String getRoadNumber()
           
 String getShuntingFunction()
           
 RosterSpeedProfile getSpeedProfile()
           
 String getURL()
           
 boolean isLongAddress()
           
 boolean isOpen()
           
 void loadAttributes(org.jdom.Element e3)
          Loads attribute key/value pairs from a JDOM element.
 void loadCvModel(CvTableModel cvModel, IndexedCvTableModel iCvModel)
          Load a pre-existing CvTableModel object with the CV contents of this entry
 void loadFunctions(org.jdom.Element e3)
          Loads function names from a JDOM element.
 void printEntry(HardcopyWriter w)
           
 void printEntryDetails(Writer w)
          Prints the roster information.
 void putAttribute(String key, String value)
           
 void readFile()
          Read a file containing the contents of this RosterEntry.
 void removePropertyChangeListener(PropertyChangeListener l)
           
 void setComment(String s)
           
 void setDateUpdated(String s)
           
 void setDccAddress(String s)
           
 void setDecoderComment(String s)
           
 void setDecoderFamily(String s)
           
 void setDecoderModel(String s)
           
static void setDefaultOwner(String n)
           
 void setFileName(String s)
           
 void setFunctionImage(int fn, String s)
           
 void setFunctionLabel(int fn, String label)
          Define label for a specific function
 void setFunctionLockable(int fn, boolean lockable)
          Define whether a specific function is lockable.
 void setFunctionSelectedImage(int fn, String s)
           
 void setIconPath(String s)
           
 void setId(String s)
           
 void setImagePath(String s)
           
 void setLongAddress(boolean b)
           
 void setMaxSpeedPCT(int maxSpeedPCT)
           
 void setMfg(String s)
           
 void setModel(String s)
           
 void setOpen(boolean boo)
           
 void setOwner(String s)
           
 void setProtocol(LocoAddress.Protocol protocol)
           
 void setRoadName(String s)
           
 void setRoadNumber(String s)
           
 void setShuntingFunction(String fn)
           
 void setSpeedProfile(RosterSpeedProfile sp)
           
 void setURL(String s)
           
 org.jdom.Element store()
          Create an XML element to represent this Entry.
 String titleString()
           
 String toString()
           
 void updateFile()
          Write the contents of this RosterEntry back to a file, preserving all existing decoder CV content.
protected  void warnShortLong(String id)
          Warn user that the roster entry needs to be resaved.
 Vector<String> wrapComment(String comment, int textSpace)
          Take a String comment field and perform line wrapping on it.
 void writeFile(CvTableModel cvModel, IndexedCvTableModel iCvModel, VariableTableModel variableModel)
          Write the contents of this RosterEntry to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_fileName

protected String _fileName

_id

protected String _id

_roadName

protected String _roadName

_roadNumber

protected String _roadNumber

_mfg

protected String _mfg

_owner

protected String _owner

_model

protected String _model

_dccAddress

protected String _dccAddress

_protocol

protected LocoAddress.Protocol _protocol

_comment

protected String _comment

_decoderModel

protected String _decoderModel

_decoderFamily

protected String _decoderFamily

_decoderComment

protected String _decoderComment

_dateUpdated

protected String _dateUpdated

_maxSpeedPCT

protected int _maxSpeedPCT

MAXFNNUM

static final int MAXFNNUM
See Also:
Constant Field Values

functionLabels

protected String[] functionLabels

functionSelectedImages

protected String[] functionSelectedImages

functionImages

protected String[] functionImages

functionLockables

protected boolean[] functionLockables

_isShuntingOn

protected String _isShuntingOn

attributePairs

TreeMap<String,String> attributePairs

_imageFilePath

protected String _imageFilePath

_iconFilePath

protected String _iconFilePath

_URL

protected String _URL

_sp

protected RosterSpeedProfile _sp

openCounter

int openCounter

loadedOnce

boolean loadedOnce

indent

String indent

indentWidth

int indentWidth

newLine

String newLine

pcs

PropertyChangeSupport pcs

log

static org.slf4j.Logger log
Constructor Detail

RosterEntry

public RosterEntry()
Construct a blank object.


RosterEntry

public RosterEntry(String fileName)

RosterEntry

public RosterEntry(RosterEntry pEntry,
                   String pID)

RosterEntry

public RosterEntry(org.jdom.Element e)
Construct this Entry from XML. This member has to remain synchronized with the detailed DTD in roster-config.xml

Parameters:
e - Locomotive XML element
Method Detail

getDefaultOwner

public static String getDefaultOwner()

setDefaultOwner

public static void setDefaultOwner(String n)

getMAXFNNUM

public int getMAXFNNUM()

setId

public void setId(String s)

getId

public String getId()
Specified by:
getId in interface BasicRosterEntry

setFileName

public void setFileName(String s)

getFileName

public String getFileName()

getPathName

public String getPathName()

ensureFilenameExists

public void ensureFilenameExists()
Ensure the entry has a valid filename. If none exists, create one based on the ID string. Does _not_ enforce any particular naming; you have to check separately for "<.none>." or whatever your convention is for indicating an invalid name. Does replace the space, period, colon, slash and backslash characters so that the filename will be generally usable.


setRoadName

public void setRoadName(String s)

getRoadName

public String getRoadName()

setRoadNumber

public void setRoadNumber(String s)

getRoadNumber

public String getRoadNumber()

setMfg

public void setMfg(String s)

getMfg

public String getMfg()

setModel

public void setModel(String s)

getModel

public String getModel()

setOwner

public void setOwner(String s)

getOwner

public String getOwner()

setDccAddress

public void setDccAddress(String s)

getDccAddress

public String getDccAddress()
Specified by:
getDccAddress in interface BasicRosterEntry

setLongAddress

public void setLongAddress(boolean b)

getSpeedProfile

public RosterSpeedProfile getSpeedProfile()

setSpeedProfile

public void setSpeedProfile(RosterSpeedProfile sp)

isLongAddress

public boolean isLongAddress()
Specified by:
isLongAddress in interface BasicRosterEntry

setProtocol

public void setProtocol(LocoAddress.Protocol protocol)

getProtocol

public LocoAddress.Protocol getProtocol()

getProtocolAsString

public String getProtocolAsString()

setComment

public void setComment(String s)

getComment

public String getComment()

setDecoderModel

public void setDecoderModel(String s)

getDecoderModel

public String getDecoderModel()

setDecoderFamily

public void setDecoderFamily(String s)

getDecoderFamily

public String getDecoderFamily()

setDecoderComment

public void setDecoderComment(String s)

getDecoderComment

public String getDecoderComment()

getDccLocoAddress

public DccLocoAddress getDccLocoAddress()
Specified by:
getDccLocoAddress in interface BasicRosterEntry

setImagePath

public void setImagePath(String s)

getImagePath

public String getImagePath()

setIconPath

public void setIconPath(String s)

getIconPath

public String getIconPath()

setShuntingFunction

public void setShuntingFunction(String fn)

getShuntingFunction

public String getShuntingFunction()
Specified by:
getShuntingFunction in interface BasicRosterEntry

setURL

public void setURL(String s)

getURL

public String getURL()

setDateUpdated

public void setDateUpdated(String s)

getDateUpdated

public String getDateUpdated()

setOpen

public void setOpen(boolean boo)
Specified by:
setOpen in interface BasicRosterEntry

isOpen

public boolean isOpen()
Specified by:
isOpen in interface BasicRosterEntry

loadFunctions

public void loadFunctions(org.jdom.Element e3)
Loads function names from a JDOM element. Does not change values that are already present!


loadAttributes

public void loadAttributes(org.jdom.Element e3)
Loads attribute key/value pairs from a JDOM element.


setFunctionLabel

public void setFunctionLabel(int fn,
                             String label)
Define label for a specific function

Parameters:
fn - function number, starting with 0

getFunctionLabel

public String getFunctionLabel(int fn)
If a label has been defined for a specific function, return it, otherwise return null.

Parameters:
fn - function number, starting with 0

setFunctionImage

public void setFunctionImage(int fn,
                             String s)

getFunctionImage

public String getFunctionImage(int fn)

setFunctionSelectedImage

public void setFunctionSelectedImage(int fn,
                                     String s)

getFunctionSelectedImage

public String getFunctionSelectedImage(int fn)

setFunctionLockable

public void setFunctionLockable(int fn,
                                boolean lockable)
Define whether a specific function is lockable.

Parameters:
fn - function number, starting with 0

getFunctionLockable

public boolean getFunctionLockable(int fn)
Return the lockable state of a specific function. Defaults to true.

Parameters:
fn - function number, starting with 0

putAttribute

public void putAttribute(String key,
                         String value)
Specified by:
putAttribute in interface BasicRosterEntry

getAttribute

public String getAttribute(String key)
Specified by:
getAttribute in interface BasicRosterEntry

deleteAttribute

public void deleteAttribute(String key)
Specified by:
deleteAttribute in interface BasicRosterEntry

getAttributes

public Set<String> getAttributes()
Provide access to the set of attributes. This is directly backed access, so e.g. removing an item from this Set removes it from the RosterEntry too.


getAttributeList

public String[] getAttributeList()
Specified by:
getAttributeList in interface BasicRosterEntry

getMaxSpeedPCT

public int getMaxSpeedPCT()
Specified by:
getMaxSpeedPCT in interface BasicRosterEntry

setMaxSpeedPCT

public void setMaxSpeedPCT(int maxSpeedPCT)

warnShortLong

protected void warnShortLong(String id)
Warn user that the roster entry needs to be resaved.


store

public org.jdom.Element store()
Create an XML element to represent this Entry. This member has to remain synchronized with the detailed DTD in roster-config.xml.

Specified by:
store in interface BasicRosterEntry
Returns:
Contents in a JDOM Element

titleString

public String titleString()
Specified by:
titleString in interface BasicRosterEntry

toString

public String toString()
Specified by:
toString in interface BasicRosterEntry
Overrides:
toString in class Object

updateFile

public void updateFile()
Write the contents of this RosterEntry back to a file, preserving all existing decoder CV content.

This writes the file back in place, with the same decoder-specific content.


writeFile

public void writeFile(CvTableModel cvModel,
                      IndexedCvTableModel iCvModel,
                      VariableTableModel variableModel)
Write the contents of this RosterEntry to a file. Information on the contents is passed through the parameters, as the actual XML creation is done in the LocoFile class.

Parameters:
cvModel - CV contents to include in file
variableModel - Variable contents to include in file

changeDateUpdated

public void changeDateUpdated()
Mark the date updated, e.g. from storing this roster entry


loadCvModel

public void loadCvModel(CvTableModel cvModel,
                        IndexedCvTableModel iCvModel)
Load a pre-existing CvTableModel object with the CV contents of this entry

Parameters:
cvModel - Model to load, must exist

printEntry

public void printEntry(HardcopyWriter w)

printEntryDetails

public void printEntryDetails(Writer w)
Prints the roster information. Updated to allow for multiline comment and decoder comment fields. Created separate write statements for text and line feeds to work around the HardcopyWriter bug that misplaces borders


wrapComment

public Vector<String> wrapComment(String comment,
                                  int textSpace)
Take a String comment field and perform line wrapping on it. String must be non-null and may or may not have \n characters embedded. textSpace is the width of the space to print for wrapping purposes. The comment is wrapped on a word wrap basis


readFile

public void readFile()
Read a file containing the contents of this RosterEntry. This has to be done before a call to loadCvModel, for example.


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener l)
Specified by:
addPropertyChangeListener in interface BasicRosterEntry

firePropertyChange

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

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener l)
Specified by:
removePropertyChangeListener in interface BasicRosterEntry


Copyright © 1997-2013 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