use of jmri.CatalogTree in project JMRI by JMRI.
the class IconAdder method updateCatalogTree.
/**
* If icons are changed, update global tree
*/
private void updateCatalogTree() {
CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
// unfiltered, xml-stored, default icon tree
CatalogTree tree = manager.getBySystemName("NXDI");
if (tree == null) {
// build a new Default Icons tree
tree = manager.newCatalogTree("NXDI", "Default Icons");
}
CatalogTreeNode root = tree.getRoot();
Enumeration<CatalogTreeNode> e = root.children();
String name = _defaultIcons.toString();
while (e.hasMoreElements()) {
CatalogTreeNode nChild = e.nextElement();
if (name.equals(nChild.toString())) {
if (log.isDebugEnabled()) {
log.debug("Remove node " + nChild);
}
root.remove(nChild);
break;
}
}
root.add(_defaultIcons);
ImageIndexEditor.indexChanged(true);
}
use of jmri.CatalogTree in project JMRI by JMRI.
the class CatalogPanel method getCorespondingModel.
/**
* Find the corresponding CatalogTreeManager tree to the displayed branch
*/
private CatalogTree getCorespondingModel(CatalogTreeNode node) {
TreeNode[] nodes = node.getPath();
CatalogTree model = null;
for (int i = 0; i < _branchModel.size(); i++) {
model = _branchModel.get(i);
CatalogTreeNode cRoot = model.getRoot();
if (match(cRoot, nodes, 1) != null) {
break;
}
}
return model;
}
use of jmri.CatalogTree in project JMRI by JMRI.
the class DefaultCatalogTreeManager method getBySystemName.
@Override
public CatalogTree getBySystemName(String key) {
String name = key.toUpperCase();
if (log.isDebugEnabled()) {
log.debug("getBySystemName: systemName= " + name);
CatalogTree tree = (CatalogTree) _tsys.get(name);
if (tree != null) {
CatalogTreeNode root = tree.getRoot();
log.debug("root= " + root.toString() + ", has " + root.getChildCount() + " children");
}
}
return (CatalogTree) _tsys.get(name);
}
use of jmri.CatalogTree in project JMRI by JMRI.
the class DefaultCatalogTreeManagerXml method store.
/**
* Default implementation for storing the contents of a CatalogTreeManager
*
* @param cat Element to load with contents
* @param trees List of contents
*/
public void store(Element cat, List<String> trees) {
CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
cat.setAttribute("class", "jmri.jmrit.catalog.DefaultCatalogTreeManagerConfigXML");
Iterator<String> iter = trees.iterator();
while (iter.hasNext()) {
String sname = iter.next();
if (sname == null) {
log.error("System name null during store");
continue;
}
if (log.isDebugEnabled()) {
log.debug("system name is " + sname);
}
if (sname.charAt(1) != CatalogTree.XML) {
continue;
}
CatalogTree ct = manager.getBySystemName(sname);
Element elem = new Element("catalogTree");
elem.setAttribute("systemName", sname);
String uname = ct.getUserName();
if (uname != null) {
elem.setAttribute("userName", uname);
}
storeNode(elem, ct.getRoot());
if (log.isDebugEnabled()) {
log.debug("store CatalogTree " + sname);
}
cat.addContent(elem);
}
}
use of jmri.CatalogTree in project JMRI by JMRI.
the class ItemPalette method loadSavedIcons.
static boolean loadSavedIcons(Editor ed) {
CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
CatalogTree tree = manager.getBySystemName("NXPI");
if (tree != null) {
CatalogTreeNode root = tree.getRoot();
// root.children() is still unchecked in JDOM2
@SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> e = root.children();
while (e.hasMoreElements()) {
CatalogTreeNode node = e.nextElement();
String typeName = (String) node.getUserObject();
// not very elegant (i.e. extensible), but maybe all that's needed.
if (typeName.equals("IndicatorTO")) {
HashMap<String, HashMap<String, HashMap<String, NamedIcon>>> familyTOMap = loadIndicatorFamilyMap(node, ed);
if (log.isDebugEnabled()) {
log.debug("Add " + familyTOMap.size() + " indicatorTO families to item type " + typeName + " to _indicatorTOMaps.");
}
_indicatorTOMaps.put(typeName, familyTOMap);
} else {
HashMap<String, HashMap<String, NamedIcon>> familyMap = loadFamilyMap(node, ed);
_iconMaps.put(typeName, familyMap);
if (log.isDebugEnabled()) {
log.debug("Add item type " + typeName + " to _iconMaps.");
}
}
}
if (log.isDebugEnabled()) {
log.debug("Icon Map has " + _iconMaps.size() + " members");
}
return true;
}
return false;
}
Aggregations