Class DecoderIndexFile
This allows a program to navigate to various decoder descriptions without having to manipulate files.
This class doesn't provide tools for defining the index; that's done
by DecoderIndexCreateAction, which
rebuilds it from the decoder files.
Multiple DecoderIndexFile objects don't make sense, so we use an "instance" member to navigate to a single one.
Previous to JMRI 4.19.1, the manufacturer information was kept in the decoderIndex.xml file. Starting with that version it's in the separate nmra_mfg_list.xml file, but still written to decoderIndex.xml when one is created.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class jmri.jmrit.XmlFile
XmlFile.Validate -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected static final Stringprotected List<DecoderFile>(package private) intstatic final String(package private) Stringstatic final Stringstatic final Stringstatic final String(package private) String(package private) Stringstatic final StringFields inherited from class jmri.jmrit.XmlFile
dtdLocation, xsltLocation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckEntry(int i, String mfgName, String family, String mfgID, String decoderVersionID, String decoderProductID, String model, String developerID, String manufacturerID, String productID, String progMode) Check if an entry consistent with specific properties.booleancheckInCommaDelimString(String findString, String inString) Check if target string is in a comma-delimited stringprotected static StringGet the filename for the default decoder index file, including location.fileFromTitle(String title) Get a DecoderFile from a "title" string, typically a selection in a matching ComboBox.static voidForce creation of a new user index without incrementing versionstatic voidforceCreationOfNewIndex(boolean increment) Force creation of a new user index.Get a new JComboBox made with the titles from a list of DecoderFile.static ComboBoxModel<String>Get a new ComboBoxModel made with the titles from a list of DecoderFile.matchingComboBox(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model) Get a JComboBox representing the choices that match basic characteristics.matchingDecoderList(String progMode) Get a List of decoders matching (only) the programming mode.matchingDecoderList(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model) Get a List of decoders matching basic characteristics.matchingDecoderList(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model, String developerID, String manufacturerID, String productID) Get a List of decoders matching basic characteristics + product ID etc.matchingDecoderList(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model, String developerID, String manufacturerID, String productID, String progMode) Get a List of decoders matching basic characteristics + product ID etc. + programming mode.mfgIdFromName(String name) mfgNameFromID(String idNum) int(package private) voidreadFamily(org.jdom2.Element family) (package private) voidreadFamilySection(org.jdom2.Element decoderIndex) (package private) voidRead the contents of a decoderIndex XML file into this object.(package private) voidstatic voidReplace the managed instance with a new instance.static booleanCheck whether the user's version of the decoder index file needs to be updated; if it does, then forces the update.voidwriteFile(String name, DecoderIndexFile oldIndex, String[] files, JOptionPane pane, JProgressBar pb) Build and write the decoder index file, based on a set of decoder files.Methods inherited from class jmri.jmrit.XmlFile
addDefaultInfo, backupFileName, checkFile, createFileNameWithDate, dumpElement, findFile, getBuilder, getDefaultDtdLocation, getDefaultValidate, getDtdLocation, getProcessingInstructionHRef, getProcessingInstructionType, getRoot, getValidate, makeBackupFile, makeBackupFile, newDocument, newDocument, revertBackupFile, rootFromFile, rootFromInputStream, rootFromName, rootFromURL, setDefaultDtdLocation, setDefaultValidate, setDtdLocation, setValidate, userFileChooser, userFileChooser, writeXML, xmlDir
-
Field Details
-
MANUFACTURER
- See Also:
-
MFG_ID
- See Also:
-
DECODER_INDEX
- See Also:
-
VERSION
- See Also:
-
LOW_VERSION_ID
- See Also:
-
HIGH_VERSION_ID
- See Also:
-
decoderList
-
fileVersion
int fileVersion -
_mfgIdFromNameHash
-
_mfgNameFromIdHash
-
mMfgNameList
-
nmraListDate
-
updated
-
lastAdd
-
DECODER_INDEX_FILE_NAME
- See Also:
-
-
Constructor Details
-
DecoderIndexFile
public DecoderIndexFile()
-
-
Method Details
-
numDecoders
-
getMfgNameList
-
mfgIdFromName
-
mfgNameFromID
- Parameters:
idNum- String containing the manufacturer's NMRA manufacturer ID number- Returns:
- String containing the "friendly" name of the manufacturer
-
matchingDecoderList
Get a List of decoders matching (only) the programming mode.- Parameters:
progMode- decoder programming mode as defined in a decoder's programming element- Returns:
- a list, possibly empty, of matching decoders
-
matchingDecoderList
@Nonnull public List<DecoderFile> matchingDecoderList(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model) Get a List of decoders matching basic characteristics.- Parameters:
mfg- decoder manufacturerfamily- decoder familydecoderMfgID- NMRA decoder manufacturer IDdecoderVersionID- decoder version IDdecoderProductID- decoder product IDmodel- decoder model- Returns:
- a list, possibly empty, of matching decoders
-
matchingDecoderList
@Nonnull public List<DecoderFile> matchingDecoderList(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model, String developerID, String manufacturerID, String productID) Get a List of decoders matching basic characteristics + product ID etc.- Parameters:
mfg- decoder manufacturerfamily- decoder familydecoderMfgID- NMRA decoder manufacturer IDdecoderVersionID- decoder version IDdecoderProductID- decoder product IDmodel- decoder modeldeveloperID- developer ID numbermanufacturerID- manufacturerID numberproductID- productID number- Returns:
- a list, possibly empty, of matching decoders
-
matchingDecoderList
@Nonnull public List<DecoderFile> matchingDecoderList(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model, String developerID, String manufacturerID, String productID, String progMode) Get a List of decoders matching basic characteristics + product ID etc. + programming mode.- Parameters:
mfg- decoder manufacturerfamily- decoder familydecoderMfgID- NMRA decoder manufacturer IDdecoderVersionID- decoder version IDdecoderProductID- decoder product IDmodel- decoder modeldeveloperID- developer ID numbermanufacturerID- manufacturerID numberproductID- productID numberprogMode- programming mode as defined in a decoder's programming element- Returns:
- a list, possibly empty, of matching decoders
-
matchingComboBox
public JComboBox<String> matchingComboBox(String mfg, String family, String decoderMfgID, String decoderVersionID, String decoderProductID, String model) Get a JComboBox representing the choices that match basic characteristics.- Parameters:
mfg- decoder manufacturerfamily- decoder familydecoderMfgID- NMRA decoder manufacturer IDdecoderVersionID- decoder version IDdecoderProductID- decoder product IDmodel- decoder model- Returns:
- a combo box populated with matching decoders
-
jComboBoxFromList
Get a new JComboBox made with the titles from a list of DecoderFile.- Parameters:
l- list of decoders- Returns:
- a combo box populated with the list
-
jComboBoxModelFromList
Get a new ComboBoxModel made with the titles from a list of DecoderFile. entries.- Parameters:
l- list of decoders- Returns:
- a combo box model populated with the list
-
fileFromTitle
Get a DecoderFile from a "title" string, typically a selection in a matching ComboBox.- Parameters:
title- the decoder title- Returns:
- the decoder file
-
checkEntry
public boolean checkEntry(int i, String mfgName, String family, String mfgID, String decoderVersionID, String decoderProductID, String model, String developerID, String manufacturerID, String productID, String progMode) Check if an entry consistent with specific properties. A null String entry always matches. Strings are used for convenience in GUI building. Don't bother asking about the model number...- Parameters:
i- index of entrymfgName- decoder manufacturerfamily- decoder familymfgID- NMRA decoder manufacturer IDdecoderVersionID- decoder version IDdecoderProductID- decoder product IDmodel- decoder modeldeveloperID- developer ID numbermanufacturerID- manufacturer ID numberproductID- product ID numberprogMode- programming mode as defined in a decoder's programming element- Returns:
- true if entry at i matches the other parameters; false otherwise
-
resetInstance
Replace the managed instance with a new instance. -
updateIndexIfNeeded
Check whether the user's version of the decoder index file needs to be updated; if it does, then forces the update.- Returns:
- true is the index should be reloaded because it was updated
- Throws:
org.jdom2.JDOMException- if unable to parse decoder indexIOException- if unable to read decoder index
-
forceCreationOfNewIndex
Force creation of a new user index without incrementing version -
forceCreationOfNewIndex
Force creation of a new user index.- Parameters:
increment- true to increment the version of the decoder index
-
readFile
Read the contents of a decoderIndex XML file into this object. Note that this does not clear any existing entries; reset the instance to do that.- Parameters:
name- the name of the decoder index file- Throws:
org.jdom2.JDOMException- if unable to parse to decoder index fileIOException- if unable to read decoder index file
-
readMfgSection
- Throws:
org.jdom2.JDOMExceptionIOException
-
readFamilySection
-
readFamily
-
checkInCommaDelimString
Check if target string is in a comma-delimited stringExample: findString = "47" inString = "1,4,53,97" return value is 'false'
Example: findString = "47" inString = "1,31,47,51" return value is 'true'
Example: findString = "47" inString = "47" return value is true
- Parameters:
findString- string to findinString- comma-delimited string of sub-strings- Returns:
- true if target string is found as sub-string within comma- delimited string
-
writeFile
public void writeFile(String name, DecoderIndexFile oldIndex, String[] files, JOptionPane pane, JProgressBar pb) throws IOException Build and write the decoder index file, based on a set of decoder files.This creates the full DOM object for the decoder index based on reading the supplied decoder xml files. It then saves the decoder index out to a new file.
- Parameters:
name- name of the new index fileoldIndex- old decoder index filefiles- array of files to read for new indexpane- optional JOptionPane to check for cancellationpb- optional JProgressBar to update during operations- Throws:
IOException- for errors writing the decoder index file
-
defaultDecoderIndexFilename
Get the filename for the default decoder index file, including location. This is here to allow easy override in tests.- Returns:
- the complete path to the decoder index
-