use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class CombinedLocoSelTreePane method createDecoderTypeContents.
/**
* Reads the available decoders and loads them into the dModel tree model.
*/
void createDecoderTypeContents() {
List<DecoderFile> decoders = DecoderIndexFile.instance().matchingDecoderList(null, null, null, null, null, null);
int len = decoders.size();
DecoderTreeNode mfgElement = null;
DecoderTreeNode familyElement = null;
HashMap<String, DecoderTreeNode> familyNameNode = new HashMap<String, DecoderTreeNode>();
for (int i = 0; i < len; i++) {
DecoderFile decoder = decoders.get(i);
String mfg = decoder.getMfg();
String family = decoder.getFamily();
String model = decoder.getModel();
log.debug(" process " + mfg + "/" + family + "/" + model + " on nodes " + (mfgElement == null ? "<null>" : mfgElement.toString() + "(" + mfgElement.getChildCount() + ")") + "/" + (familyElement == null ? "<null>" : familyElement.toString() + "(" + familyElement.getChildCount() + ")"));
// build elements
if (mfgElement == null || !mfg.equals(mfgElement.toString())) {
// need new mfg node
mfgElement = new DecoderTreeNode(mfg, "CV8 = " + DecoderIndexFile.instance().mfgIdFromName(mfg), "");
dModel.insertNodeInto(mfgElement, dRoot, dRoot.getChildCount());
familyNameNode = new HashMap<String, DecoderTreeNode>();
familyElement = null;
}
String famComment = decoders.get(i).getFamilyComment();
String verString = decoders.get(i).getVersionsAsString();
if (familyElement == null || (!family.equals(familyElement.toString()) && !familyNameNode.containsKey(family))) {
// appears to have decoder names separate from the family name
if ((i + 2 >= len) || decoders.get(i + 2).getFamily().equals(family) || !decoders.get(i + 1).getModel().equals(family)) {
// normal here; insert the new family element & exit
log.debug("normal family update case: " + family);
familyElement = new DecoderTreeNode(family, getHoverText(verString, famComment), decoders.get(i).titleString());
dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
familyNameNode.put(family, familyElement);
continue;
} else {
// this is short case; insert decoder entry (next) here
log.debug("short case, i=" + i + " family=" + family + " next " + decoders.get(i + 1).getModel());
if (i + 1 > len) {
log.error("Unexpected single entry for family: " + family);
}
family = decoders.get(i + 1).getModel();
familyElement = new DecoderTreeNode(family, getHoverText(verString, famComment), decoders.get(i).titleString());
dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
familyNameNode.put(family, familyElement);
i = i + 1;
continue;
}
}
// insert at the decoder level, except if family name is the same
if (!family.equals(model)) {
if (familyNameNode.containsKey(family)) {
familyElement = familyNameNode.get(family);
}
String modelComment = decoders.get(i).getModelComment();
DecoderTreeNode decoderNameNode = new DecoderTreeNode(model, getHoverText(verString, modelComment), decoders.get(i).titleString());
decoderNameNode.setShowable(decoder.getShowable());
dModel.insertNodeInto(decoderNameNode, familyElement, familyElement.getChildCount());
}
}
// end of loop over decoders
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class PaneNewProgAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (log.isDebugEnabled()) {
log.debug("New roster entry programmer requested");
}
// create the initial frame that steers
final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameNewEntrySetup"));
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
// add the Roster menu
JMenuBar menuBar = new JMenuBar();
// menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
menuBar.add(j);
menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
f.setJMenuBar(menuBar);
// new Loco on programming track
JPanel pane1 = new LocoSelTreePane(null, null) {
@Override
protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
String title = SymbolicProgBundle.getMessage("FrameNewEntryTitle");
JFrame p = new PaneProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", null, false) {
@Override
protected JPanel getModePane() {
return null;
}
};
p.pack();
p.setVisible(true);
}
};
// load primary frame
pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
f.getContentPane().add(pane1);
f.pack();
if (log.isDebugEnabled()) {
log.debug("Tab-Programmer setup created");
}
f.setVisible(true);
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class SymbolicProgFrame method readAndParseConfigFile.
void readAndParseConfigFile(File file) {
try {
DecoderFile xf = new DecoderFile() {
};
// XmlFile is abstract
Element root = xf.rootFromFile(file);
// decode type, invoke proper processing routine if a decoder file
if (root.getChild("decoder") != null) {
log.debug("Attempt to open as decoder file");
processDecoderFile(root.getChild("decoder"), xf);
log.debug("succeeded");
} else {
// try again as a loco file
log.debug("Attempt to open as loco file");
if (root.getChild("locomotive") != null) {
processLocoFile(root.getChild("locomotive"));
} else {
log.error("Unrecognized config file contents");
}
}
} catch (org.jdom2.JDOMException | java.io.IOException e) {
log.warn("readAndParseDecoderConfig: readAndParseDecoderConfig exception: " + e);
}
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class AutoSpeedAction method actionPerformed.
@Override
public void actionPerformed(ActionEvent e) {
if (log.isInfoEnabled()) {
log.debug("auto speed tool requested");
}
// create the initial frame that steers
final JFrame f = new JFrame("Auto-speed Tool Setup");
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
// add the Roster menu
JMenuBar menuBar = new JMenuBar();
// menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
menuBar.add(new jmri.jmrit.roster.swing.RosterMenu("Roster", jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
f.setJMenuBar(menuBar);
// known loco on main track
JPanel pane1 = new // no ident in ops mode yet
KnownLocoSelPane(// no ident in ops mode yet
false) {
@Override
protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
String title = "Set speed info for " + re.getId() + " on main track";
// find the ops-mode programmer
int address = Integer.parseInt(re.getDccAddress());
boolean longAddr = true;
if (address < 100) {
longAddr = false;
}
Programmer programmer = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(longAddr, address);
// and created the frame
JFrame p = new PaneOpsProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", programmer);
p.pack();
p.setVisible(true);
f.setVisible(false);
f.dispose();
}
};
// load primary frame
pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
f.getContentPane().add(pane1);
f.pack();
if (log.isInfoEnabled()) {
log.debug("setup created");
}
f.setVisible(true);
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class PaneProgFrame method loadDecoderFromLoco.
protected void loadDecoderFromLoco(RosterEntry r) {
// get a DecoderFile from the locomotive xml
String decoderModel = r.getDecoderModel();
String decoderFamily = r.getDecoderFamily();
log.debug("selected loco uses decoder {} {}", decoderFamily, decoderModel);
// locate a decoder like that.
List<DecoderFile> l = DecoderIndexFile.instance().matchingDecoderList(null, decoderFamily, null, null, null, decoderModel);
log.debug("found {} matches", l.size());
if (l.size() == 0) {
log.debug("Loco uses " + decoderFamily + " " + decoderModel + " decoder, but no such decoder defined");
// fall back to use just the decoder name, not family
l = DecoderIndexFile.instance().matchingDecoderList(null, null, null, null, null, decoderModel);
if (log.isDebugEnabled()) {
log.debug("found " + l.size() + " matches without family key");
}
}
if (l.size() > 0) {
DecoderFile d = l.get(0);
loadDecoderFile(d, r);
} else {
if (decoderModel.equals("")) {
log.debug("blank decoderModel requested, so nothing loaded");
} else {
log.warn("no matching \"" + decoderModel + "\" decoder found for loco, no decoder info loaded");
}
}
}
Aggregations