Skip to content
Permalink
Browse files

cleanup, debug, force read before print

  • Loading branch information...
bobjacobsen committed May 25, 2019
1 parent a58d909 commit c047adfa9450628e991ea90481a5335ed0ef6a07
Showing with 23 additions and 18 deletions.
  1. +23 −18 java/src/jmri/jmrit/roster/PrintRosterEntry.java
@@ -50,24 +50,24 @@
*
* @param rosterEntry Roster item, either as a selection or object
* @param parent window over which this dialog will be centered
* @param filename xml file name for programmer used in printing.
* @param programmerFilename xml file name for programmer used in printing.
*/
public PrintRosterEntry(RosterEntry rosterEntry, JmriJFrame parent, String filename) {
public PrintRosterEntry(RosterEntry rosterEntry, JmriJFrame parent, String programmerFilename) {
_rosterEntry = rosterEntry;
_flPane = new FunctionLabelPane(rosterEntry);
_rMPane = new RosterMediaPane(rosterEntry);
_parent = parent;
JLabel progStatus = new JLabel(Bundle.getMessage("StateIdle"));
ResetTableModel resetModel = new ResetTableModel(progStatus, null); // no programmer

log.debug("Try PrintRosterEntry {} from file {}", _rosterEntry.getDisplayName(), filename);
log.debug("Try PrintRosterEntry {} from file {}", _rosterEntry.getDisplayName(), programmerFilename);
XmlFile pf = new XmlFile() {
};
Element base = null;
Element base = null; // base of programmer file
try {
Element root = pf.rootFromName(filename);
Element root = pf.rootFromName(programmerFilename);
if (root == null) {
log.error("Programmer file name incorrect {}", filename);
log.error("Programmer file name incorrect {}", programmerFilename);
return;
}
if ((base = root.getChild("programmer")) == null) {
@@ -76,14 +76,14 @@ public PrintRosterEntry(RosterEntry rosterEntry, JmriJFrame parent, String filen
}
log.debug("Success: xml file top element is 'programmer'");
} catch (JDOMException | java.io.IOException e) {
log.error("exception reading programmer file {}", filename, e);
log.error("exception reading programmer file {}", programmerFilename, e);
return;
}

CvTableModel cvModel = new CvTableModel(progStatus, null); // no programmer

VariableTableModel variableModel = new VariableTableModel(progStatus, new String[]{"Name", "Value"}, cvModel); // NOI18N

String decoderModel = _rosterEntry.getDecoderModel();
String decoderFamily = _rosterEntry.getDecoderFamily();

@@ -97,9 +97,9 @@ public PrintRosterEntry(RosterEntry rosterEntry, JmriJFrame parent, String filen
l = InstanceManager.getDefault(DecoderIndexFile.class).matchingDecoderList(null, null, null, null, null, decoderModel);
log.debug("found {} matches without family key", l.size());
}
DecoderFile d = null;
DecoderFile decoderFile = null;
if (l.size() > 0) {
d = l.get(0);
decoderFile = l.get(0);
} else {
if (decoderModel.equals("")) {
log.debug("blank decoderModel requested, so nothing loaded");
@@ -108,24 +108,30 @@ public PrintRosterEntry(RosterEntry rosterEntry, JmriJFrame parent, String filen
}
}

if (d == null) {
if (decoderFile == null) {
log.warn("no decoder file found for this loco");
return;
}
Element decoderRoot;
log.debug("Try to read decoder root from {} {}", DecoderFile.fileLocation, decoderFile.getFileName());
try {
decoderRoot = d.rootFromName(DecoderFile.fileLocation + d.getFileName());
decoderRoot = decoderFile.rootFromName(DecoderFile.fileLocation + decoderFile.getFileName());

} catch (org.jdom2.JDOMException exj) {
log.error("could not parse " + d.getFileName() + ": " + exj.getMessage());
log.error("could not parse " + decoderFile.getFileName() + ": " + exj.getMessage());
return;
} catch (java.io.IOException exj) {
log.error("could not read " + d.getFileName() + ": " + exj.getMessage());
log.error("could not read " + decoderFile.getFileName() + ": " + exj.getMessage());
return;
}

d.loadVariableModel(decoderRoot.getChild("decoder"), variableModel);
d.loadResetModel(decoderRoot.getChild("decoder"), resetModel);
// load defaults
decoderFile.loadVariableModel(decoderRoot.getChild("decoder"), variableModel);
decoderFile.loadResetModel(decoderRoot.getChild("decoder"), resetModel);

// load the specific contents for this entry
rosterEntry.readFile();
rosterEntry.loadCvModel(variableModel, cvModel);

List<Element> rawPaneList = base.getChildren("pane");
log.debug("rawPaneList size = {}", rawPaneList.size());
@@ -141,7 +147,7 @@ public PrintRosterEntry(RosterEntry rosterEntry, JmriJFrame parent, String filen
} else {
log.debug("Did not find name element in pane");
}
PaneProgPane p = new PaneProgPane(this, name, elPane, cvModel, variableModel, d.getModelElement(), _rosterEntry);
PaneProgPane p = new PaneProgPane(this, name, elPane, cvModel, variableModel, decoderFile.getModelElement(), _rosterEntry);
// Tab names _paneList.get(i).getName() show up when PrintRosterEntry is called from RosterFrame (entered here, applied in line 278)
_paneList.add(p);
log.debug("_paneList size = {}", _paneList.size());
@@ -193,7 +199,6 @@ public PrintRosterEntry(RosterEntry rosterEntry, List<JPanel> paneList, Function
* @param preview true if output sould got to the Preview panel, false to output to a printer
*/
public void doPrintPanes(boolean preview) {
//choosePrintItems();
HardcopyWriter w = null;
try {
w = new HardcopyWriter(_parent, _rosterEntry.getId(), 10, .8, .5, .5, .5, preview);

0 comments on commit c047adf

Please sign in to comment.
You can’t perform that action at this time.