use of jmri.jmrit.symbolicprog.VariableTableModel in project JMRI by JMRI.
the class PaneProgDp3Action method setUpRosterPanel.
synchronized void setUpRosterPanel() {
re = null;
if (rosterPanel == null) {
rosterPanel = new JPanel();
rosterPanel.setLayout(new BorderLayout());
JPanel p = new JPanel();
// NOI18N
p.add(new JLabel(Bundle.getMessage("RosterId")));
p.add(rosterIdField);
rosterPanel.add(p, BorderLayout.NORTH);
// NOI18N
rosterIdField.setText(SymbolicProgBundle.getMessage("LabelNewDecoder"));
// NOI18N
saveBasicRoster = new JButton(Bundle.getMessage("Save"));
saveBasicRoster.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
try {
log.debug("saveBasicRoster button pressed, calls saveRosterEntry");
saveRosterEntry();
} catch (JmriException ex) {
return;
}
}
});
TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
// NOI18N
border.setTitle(Bundle.getMessage("CreateBasicRosterEntry"));
rosterPanel.setBorder(border);
rosterPanel.setVisible(false);
f.getContentPane().add(rosterPanel, BorderLayout.EAST);
} else {
// NOI18N
rosterIdField.setText(SymbolicProgBundle.getMessage("LabelNewDecoder"));
}
if (progPane != null) {
progPane.dispose();
rosterPanel.remove(progPane);
progPane = null;
rosterPanel.revalidate();
f.getContentPane().repaint();
f.repaint();
f.pack();
}
if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null && jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).isGlobalProgrammerAvailable()) {
this.mProgrammer = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
}
cvModel = new CvTableModel(statusLabel, mProgrammer);
iCvModel = new IndexedCvTableModel(statusLabel, mProgrammer);
variableModel = new VariableTableModel(statusLabel, new String[] { "Name", "Value" }, cvModel, iCvModel);
if (decoderFile != null) {
Element decoderRoot = null;
try {
decoderRoot = decoderFile.rootFromName(DecoderFile.fileLocation + decoderFile.getFilename());
} catch (JDOMException | IOException e) {
log.error("Exception while loading decoder XML file: " + decoderFile.getFilename(), e);
return;
}
// NOI18N
modelElem = decoderFile.getModelElement();
// NOI18N
decoderFile.loadVariableModel(decoderRoot.getChild("decoder"), variableModel);
rosterPanel.setVisible(true);
} else {
rosterPanel.setVisible(false);
return;
}
Element programmerRoot;
XmlFile pf = new XmlFile() {
};
// XmlFile is abstract
java.beans.PropertyChangeListener dccNews = new java.beans.PropertyChangeListener() {
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
updateDccAddress();
}
};
// NOI18N
primaryAddr = variableModel.findVar("Short Address");
if (primaryAddr == null) {
// NOI18N
log.debug("DCC Address monitor didnt find a Short Address variable");
} else {
primaryAddr.addPropertyChangeListener(dccNews);
}
// NOI18N
extendAddr = variableModel.findVar("Long Address");
if (extendAddr == null) {
// NOI18N
log.debug("DCC Address monitor didnt find an Long Address variable");
} else {
extendAddr.addPropertyChangeListener(dccNews);
}
// NOI18N
addMode = (EnumVariableValue) variableModel.findVar("Address Format");
if (addMode == null) {
// NOI18N
log.debug("DCC Address monitor didnt find an Address Format variable");
} else {
addMode.addPropertyChangeListener(dccNews);
}
try {
// NOI18N
programmerRoot = pf.rootFromName("programmers" + File.separator + "Basic.xml");
Element base;
if ((base = programmerRoot.getChild("programmer")) == null) {
// NOI18N
// NOI18N
log.error("xml file top element is not programmer");
return;
}
// for all "pane" elements in the programmer
// NOI18N
List<Element> paneList = base.getChildren("pane");
// NOI18N
log.debug("will process {} pane definitions", paneList.size());
String name = jmri.util.jdom.LocaleSelector.getAttribute(paneList.get(0), "name");
progPane = new ThisProgPane(this, name, paneList.get(0), cvModel, iCvModel, variableModel, modelElem);
// NOI18N
progPane.setVariableValue("Short Address", cv1);
// NOI18N
progPane.setVariableValue("Long Address", longAddress);
// NOI18N
progPane.setCVValue("29", cv29);
// NOI18N
progPane.setCVValue("19", cv19);
rosterPanel.add(progPane, BorderLayout.CENTER);
rosterPanel.revalidate();
rosterPanel.setVisible(true);
f.getContentPane().repaint();
f.repaint();
f.pack();
return;
} catch (JDOMException | IOException e) {
// NOI18N
log.error("exception reading programmer file: ", e);
}
}
use of jmri.jmrit.symbolicprog.VariableTableModel in project JMRI by JMRI.
the class VSDConfigDialog method storeFile.
/**
* Write roster settings to the Roster file
*/
protected boolean storeFile(RosterEntry _rosterEntry) {
log.debug("storeFile starts");
// We need to create a programmer, a cvTableModel, an iCvTableModel, and a variableTableModel.
// Doesn't matter which, so we'll use the Global programmer.
Programmer p = InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
CvTableModel cvModel = new CvTableModel(null, p);
IndexedCvTableModel iCvModel = new IndexedCvTableModel(null, p);
VariableTableModel variableModel = new VariableTableModel(null, new String[] { "Name", "Value" }, cvModel, iCvModel);
// Now, in theory we can call _rosterEntry.writeFile...
if (_rosterEntry.getFileName() != null) {
// set the loco file name in the roster entry
// read, but don't yet process
_rosterEntry.readFile();
_rosterEntry.loadCvModel(variableModel, cvModel, iCvModel);
}
// id has to be set!
if (_rosterEntry.getId().equals("")) {
log.debug("storeFile without a filename; issued dialog");
return false;
}
// if there isn't a filename, store using the id
_rosterEntry.ensureFilenameExists();
// create the RosterEntry to its file
// where to get the models???
_rosterEntry.writeFile(cvModel, iCvModel, variableModel);
// mark this as a success
variableModel.setFileDirty(false);
// and store an updated roster file
Roster.getDefault().writeRoster();
return true;
}
use of jmri.jmrit.symbolicprog.VariableTableModel in project JMRI by JMRI.
the class VSDConfigPanel method storeFile.
protected boolean storeFile(RosterEntry _rosterEntry) {
log.debug("storeFile starts");
// We need to create a programmer, a cvTableModel, an iCvTableModel, and a variableTableModel.
// Doesn't matter which, so we'll use the Global programmer.
Programmer p = InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
CvTableModel cvModel = new CvTableModel(null, p);
IndexedCvTableModel iCvModel = new IndexedCvTableModel(null, p);
VariableTableModel variableModel = new VariableTableModel(null, new String[] { "Name", "Value" }, cvModel, iCvModel);
// Now, in theory we can call _rosterEntry.writeFile...
if (_rosterEntry.getFileName() != null) {
// set the loco file name in the roster entry
// read, but don't yet process
_rosterEntry.readFile();
_rosterEntry.loadCvModel(variableModel, cvModel, iCvModel);
}
// id has to be set!
if (_rosterEntry.getId().equals("")) {
log.debug("storeFile without a filename; issued dialog");
return false;
}
// if there isn't a filename, store using the id
_rosterEntry.ensureFilenameExists();
// create the RosterEntry to its file
// where to get the models???
_rosterEntry.writeFile(cvModel, iCvModel, variableModel);
// mark this as a success
variableModel.setFileDirty(false);
// and store an updated roster file
Roster.getDefault().writeRoster();
return true;
}
use of jmri.jmrit.symbolicprog.VariableTableModel in project JMRI by JMRI.
the class DecoderFileTest method testMinFn.
public void testMinFn() {
setupDecoder();
// this test should probably be done in terms of a test class instead of the real one...
JLabel progStatus = new JLabel(" OK ");
CvTableModel cvModel = new CvTableModel(progStatus, p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
VariableTableModel variableModel = new VariableTableModel(progStatus, new String[] { "Name", "Value" }, cvModel, icvModel);
DecoderFile d = new DecoderFile("mfg", "mfgID", "model", "23", "24", "family", "filename", 3, 16, null);
d.loadVariableModel(decoder, variableModel);
Assert.assertEquals("read rows ", 2, variableModel.getRowCount());
}
use of jmri.jmrit.symbolicprog.VariableTableModel in project JMRI by JMRI.
the class DecoderFileTest method testLoadTable.
public void testLoadTable() {
setupDecoder();
// this test should probably be done in terms of a test class instead of the real one...
JLabel progStatus = new JLabel(" OK ");
CvTableModel cvModel = new CvTableModel(progStatus, p);
IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
VariableTableModel variableModel = new VariableTableModel(progStatus, new String[] { "Name", "Value" }, cvModel, icvModel);
DecoderFile d = new DecoderFile("mfg", "mfgID", "model", "23", "24", "family", "filename", 16, 16, null);
d.loadVariableModel(decoder, variableModel);
Assert.assertEquals("read rows ", 3, variableModel.getRowCount());
Assert.assertEquals("first row name ", "Address", variableModel.getLabel(0));
Assert.assertEquals("third row name ", "Normal direction of motion", variableModel.getLabel(2));
}
Aggregations