use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class PaneSet method loadDecoderFromLoco.
// copied from PaneProgFrame
protected void loadDecoderFromLoco(RosterEntry r) {
// get a DecoderFile from the locomotive xml
String decoderModel = r.getDecoderModel();
String decoderFamily = r.getDecoderFamily();
if (log.isDebugEnabled()) {
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);
if (log.isDebugEnabled()) {
log.debug("found " + l.size() + " matches");
}
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");
}
}
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class EcosLocoToRoster method layoutDecoderSelection.
//@TODO this could do with being re-written so that it reuses the combined loco select tree code
protected JPanel layoutDecoderSelection() {
JPanel pane1a = new JPanel();
pane1a.setLayout(new BoxLayout(pane1a, BoxLayout.X_AXIS));
// create the list of manufacturers; get the list of decoders, and add elements
dRoot = new DefaultMutableTreeNode("Root");
dModel = new DefaultTreeModel(dRoot);
dTree = new JTree(dModel) {
@Override
public String getToolTipText(MouseEvent evt) {
if (getRowForLocation(evt.getX(), evt.getY()) == -1) {
return null;
}
TreePath curPath = getPathForLocation(evt.getX(), evt.getY());
return ((DecoderTreeNode) curPath.getLastPathComponent()).getToolTipText();
}
};
dTree.setToolTipText("");
List<DecoderFile> decoders = DecoderIndexFile.instance().matchingDecoderList(null, null, null, null, null, null);
int len = decoders.size();
DefaultMutableTreeNode mfgElement = null;
DefaultMutableTreeNode familyElement = null;
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());
familyElement = null;
}
String famComment = decoders.get(i).getFamilyComment();
String verString = decoders.get(i).getVersionsAsString();
String hoverText = "";
if (famComment == null || famComment.equals("")) {
if (verString != null && !verString.equals("")) {
hoverText = "CV7=" + verString;
}
} else {
if (verString == null || verString.equals("")) {
hoverText = famComment;
} else {
hoverText = famComment + " CV7=" + verString;
}
}
if (familyElement == null || !family.equals(familyElement.toString())) {
// 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, hoverText, decoders.get(i).titleString());
dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
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, hoverText, decoders.get(i).titleString());
dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
i = i + 1;
continue;
}
}
// insert at the decoder level, except if family name is the same
if (!family.equals(model)) {
dModel.insertNodeInto(new DecoderTreeNode(model, hoverText, decoders.get(i).titleString()), familyElement, familyElement.getChildCount());
}
}
// end of loop over decoders
// build the tree GUI
pane1a.add(new JScrollPane(dTree));
dTree.expandPath(new TreePath(dRoot));
dTree.setRootVisible(false);
dTree.setShowsRootHandles(true);
dTree.setScrollsOnExpand(true);
dTree.setExpandsSelectedPaths(true);
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
// tree listener
dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // can't be just a mfg, has to be at least a family
dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
dTree.getSelectionCount() < 2) {
// decoder selected - reset and disable loco selection
log.debug("Selection event with " + dTree.getSelectionPath().toString());
if (locoBox != null) {
locoBox.setSelectedIndex(0);
}
}
}
});
// Mouselistener for doubleclick activation of proprammer
dTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent me) {
// Clear any status messages and ensure the tree is in single path select mode
//if (_statusLabel != null) _statusLabel.setText("StateIdle");
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
/* check for both double click and that it's a decoder
that is being clicked on. If it's just a Family, the programmer
button is enabled by the TreeSelectionListener, but we don't
want to automatically open a programmer so a user has the opportunity
to select an individual decoder
*/
if (me.getClickCount() == 2) {
if (((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf()) {
okayButton();
}
}
}
});
this.selectDecoder(ecosLoco.getCVAsString(8), ecosLoco.getCVAsString(7));
return pane1a;
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class EcosLocoToRoster method updateForDecoderTypeID.
@SuppressWarnings("unchecked")
void updateForDecoderTypeID(List<DecoderFile> pList) {
// find and select the first item
if (log.isDebugEnabled()) {
//String msg = "Identified "+pList.size()+" matches: ";
StringBuilder buf = new StringBuilder();
buf.append("Identified ");
buf.append(pList.size());
buf.append(" matches: ");
for (int i = 0; i < pList.size(); i++) {
buf.append(pList.get(i).getModel());
buf.append(":");
//msg = msg+pList.get(i).getModel()+":";
}
log.debug(buf.toString());
}
if (pList.size() <= 0) {
log.error("Found empty list in updateForDecoderTypeID, should not happen");
return;
}
dTree.clearSelection();
// and issue a warning instruction in the status bar
if (pList.size() > 1) {
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
} else {
dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
}
// Select the decoder(s) in the tree
for (int i = 0; i < pList.size(); i++) {
DecoderFile f = pList.get(i);
String findMfg = f.getMfg();
String findFamily = f.getFamily();
String findModel = f.getModel();
Enumeration<DefaultMutableTreeNode> e = dRoot.breadthFirstEnumeration();
while (e.hasMoreElements()) {
DefaultMutableTreeNode node = e.nextElement();
// convert path to comparison string
TreeNode[] list = node.getPath();
if (list.length == 3) {
// check for match to mfg, model, model
if (list[1].toString().equals(findMfg) && list[2].toString().equals(findModel)) {
TreePath path = new TreePath(node.getPath());
dTree.expandPath(path);
dTree.addSelectionPath(path);
dTree.scrollPathToVisible(path);
break;
}
} else if (list.length == 4) {
// check for match to mfg, family, model
if (list[1].toString().equals(findMfg) && list[2].toString().equals(findFamily) && list[3].toString().equals(findModel)) {
TreePath path = new TreePath(node.getPath());
dTree.expandPath(path);
dTree.addSelectionPath(path);
dTree.scrollPathToVisible(path);
break;
}
}
}
}
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class EcosLocoToRoster method ecosLocoToRoster.
//Same Name as the constructor need to sort it out!
public void ecosLocoToRoster(String ecosObject) {
frame = new JFrame();
_ecosObject = ecosObject;
_ecosObjectInt = Integer.parseInt(_ecosObject);
ecosManager = adaptermemo.getLocoAddressManager();
ecosLoco = ecosManager.getByEcosObject(ecosObject);
String rosterId = ecosLoco.getEcosDescription();
if (checkDuplicate(rosterId)) {
int count = 0;
String oldrosterId = rosterId;
while (checkDuplicate(rosterId)) {
rosterId = oldrosterId + "_" + count;
count++;
}
}
re = new RosterEntry();
re.setId(rosterId);
List<DecoderFile> decoder = decoderind.matchingDecoderList(null, null, ecosLoco.getCVAsString(8), ecosLoco.getCVAsString(7), null, null);
if (decoder.size() == 1) {
pDecoderFile = decoder.get(0);
SelectedDecoder(pDecoderFile);
} else {
class WindowMaker implements Runnable {
WindowMaker() {
}
@Override
public void run() {
comboPanel();
}
}
WindowMaker t = new WindowMaker();
javax.swing.SwingUtilities.invokeLater(t);
}
}
use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.
the class CombinedLocoSelPane method selectDecoder.
/**
* Identify decoder complete, act on it by setting the GUI This will fire
* "GUI changed" events which will reset the locomotive GUI.
*
* @param mfgID the decoder's manufacturer ID value from CV8
* @param modelID the decoder's model ID value from CV7
* @param productID the decoder's product ID
*/
protected void selectDecoder(int mfgID, int modelID, int productID) {
// raise the button again
iddecoder.setSelected(false);
List<DecoderFile> temp = null;
// if productID present, try with that
if (productID != -1) {
String sz_productID = Integer.toString(productID);
temp = DecoderIndexFile.instance().matchingDecoderList(null, null, Integer.toString(mfgID), Integer.toString(modelID), sz_productID, null);
if (temp.isEmpty()) {
log.debug("selectDecoder found no items with product ID " + productID);
temp = null;
} else {
log.debug("selectDecoder found " + temp.size() + " matches with productID " + productID);
}
}
// try without product ID if needed
if (temp == null) {
// i.e. if no match previously
temp = DecoderIndexFile.instance().matchingDecoderList(null, null, Integer.toString(mfgID), Integer.toString(modelID), null, null);
if (log.isDebugEnabled()) {
log.debug("selectDecoder without productID found " + temp.size() + " matches");
}
}
// remove unwanted matches
// save size of unfiltered list
int tempOriginalSize = temp.size();
String theFamily = "";
String theModel = "";
String lastWasFamily = "";
ListIterator<DecoderFile> it = temp.listIterator();
while (it.hasNext()) {
log.debug("Match List size is currently {}, scanning for unwanted entries", temp.size());
DecoderFile t = it.next();
theFamily = t.getFamily();
theModel = t.getModel();
if (t.getFamily().equals(theModel)) {
log.debug("Match List index={} is family entry '{}'", it.previousIndex(), theFamily);
lastWasFamily = theFamily;
} else if (lastWasFamily.equals(theFamily)) {
log.debug("Match List index={} is first model '{}' in family '{}'", it.previousIndex(), theModel, theFamily);
log.debug("Removing family entry '{}'", theFamily);
t = it.previous();
t = it.previous();
it.remove();
lastWasFamily = "";
} else if ((t.getModelElement().getAttribute("show") != null) && (t.getModelElement().getAttribute("show").getValue().equals("no"))) {
log.debug("Match List index={} is legacy model '{}' in family '{}'", it.previousIndex(), theModel, theFamily);
log.debug("Removing legacy model '{}'", theModel);
t = it.previous();
it.remove();
lastWasFamily = "";
} else {
log.debug("Match List index={} is model '{}' in family '{}'", it.previousIndex(), theModel, theFamily);
lastWasFamily = "";
}
}
log.debug("Final Match List size is {}", temp.size());
// pretend we have no product ID so we get a coarse match
if (tempOriginalSize > 0 && temp.isEmpty()) {
log.debug("Filtering removed all matches so reverting to coarse match with mfgID='{}' & modelID='{}'", Integer.toString(mfgID), Integer.toString(modelID));
temp = DecoderIndexFile.instance().matchingDecoderList(null, null, Integer.toString(mfgID), Integer.toString(modelID), null, null);
log.debug("selectDecoder without productID found {} matches", temp.size());
}
// install all those in the JComboBox in place of the longer, original list
if (temp.size() > 0) {
updateForDecoderTypeID(temp);
} else {
String mfg = DecoderIndexFile.instance().mfgNameFromId(Integer.toString(mfgID));
if (mfg == null) {
updateForDecoderNotID(mfgID, modelID);
} else {
updateForDecoderMfgID(mfg, mfgID, modelID);
}
}
}
Aggregations