use of jmri.jmrit.catalog.CatalogTreeNode in project JMRI by JMRI.
the class ItemPalette method storeIcons.
/**
* Store palette icons in preferences file catalogTrees.xml
*/
public static void storeIcons() {
if (_iconMaps == null) {
// never loaded
return;
}
if (!jmri.util.ThreadingUtil.isGUIThread())
log.error("Not on GUI thread", new Exception("traceback"));
CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
// unfiltered, xml-stored, item palate icon tree
CatalogTree tree = manager.getBySystemName("NXPI");
// discard old version
if (tree != null) {
manager.deregister(tree);
}
tree = manager.newCatalogTree("NXPI", "Item Palette");
CatalogTreeNode root = tree.getRoot();
Iterator<Entry<String, HashMap<String, HashMap<String, NamedIcon>>>> it = _iconMaps.entrySet().iterator();
while (it.hasNext()) {
Entry<String, HashMap<String, HashMap<String, NamedIcon>>> entry = it.next();
root.add(store3levelMap(entry.getKey(), entry.getValue()));
if (log.isDebugEnabled()) {
log.debug("Add type node " + entry.getKey());
}
}
Iterator<Entry<String, HashMap<String, HashMap<String, HashMap<String, NamedIcon>>>>> its = _indicatorTOMaps.entrySet().iterator();
while (its.hasNext()) {
Entry<String, HashMap<String, HashMap<String, HashMap<String, NamedIcon>>>> entry = its.next();
CatalogTreeNode typeNode = new CatalogTreeNode(entry.getKey());
Iterator<Entry<String, HashMap<String, HashMap<String, NamedIcon>>>> iter = entry.getValue().entrySet().iterator();
while (iter.hasNext()) {
Entry<String, HashMap<String, HashMap<String, NamedIcon>>> ent = iter.next();
typeNode.add(store3levelMap(ent.getKey(), ent.getValue()));
if (log.isDebugEnabled()) {
log.debug("Add IndicatorTO node " + ent.getKey());
}
}
root.add(typeNode);
if (log.isDebugEnabled()) {
log.debug("Add IndicatorTO node " + entry.getKey());
}
}
}
use of jmri.jmrit.catalog.CatalogTreeNode in project JMRI by JMRI.
the class ItemPalette method store3levelMap.
static CatalogTreeNode store3levelMap(String type, HashMap<String, HashMap<String, NamedIcon>> familyMap) {
CatalogTreeNode typeNode = new CatalogTreeNode(type);
Iterator<Entry<String, HashMap<String, NamedIcon>>> iter = familyMap.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, HashMap<String, NamedIcon>> ent = iter.next();
String family = ent.getKey();
CatalogTreeNode familyNode = new CatalogTreeNode(family);
HashMap<String, NamedIcon> iconMap = ent.getValue();
Iterator<Entry<String, NamedIcon>> iterat = iconMap.entrySet().iterator();
while (iterat.hasNext()) {
Entry<String, NamedIcon> e = iterat.next();
String state = e.getKey();
String path = e.getValue().getURL();
familyNode.addLeaf(state, path);
}
typeNode.add(familyNode);
if (log.isDebugEnabled()) {
log.debug("Add familyNode " + familyNode);
}
}
return typeNode;
}
use of jmri.jmrit.catalog.CatalogTreeNode in project JMRI by JMRI.
the class ItemPalette method loadFamilyMap.
static HashMap<String, HashMap<String, NamedIcon>> loadFamilyMap(CatalogTreeNode node, Editor ed) {
HashMap<String, HashMap<String, NamedIcon>> familyMap = new HashMap<String, HashMap<String, NamedIcon>>();
// node.children() is still unchecked in JDOM2
@SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> ee = node.children();
while (ee.hasMoreElements()) {
CatalogTreeNode famNode = ee.nextElement();
String familyName = (String) famNode.getUserObject();
HashMap<String, NamedIcon> iconMap = new HashMap<String, NamedIcon>();
List<CatalogTreeLeaf> list = famNode.getLeaves();
for (int i = 0; i < list.size(); i++) {
String iconName = list.get(i).getName();
CatalogTreeLeaf leaf = list.get(i);
String path = leaf.getPath();
NamedIcon icon = NamedIcon.getIconByName(path);
if (icon == null) {
icon = ed.loadFailed(iconName, path);
if (icon == null) {
log.info(iconName + " removed for url= " + path);
} else {
ImageIndexEditor.indexChanged(true);
}
}
if (icon != null) {
iconMap.put(iconName, icon);
if (log.isDebugEnabled()) {
log.debug("Add " + iconName + " icon to family " + familyName);
}
}
Thread.yield();
}
familyMap.put(familyName, iconMap);
}
return familyMap;
}
use of jmri.jmrit.catalog.CatalogTreeNode in project JMRI by JMRI.
the class DefaultCatalogTreeManagerXml method loadCatalogTrees.
/**
* Utility method to load the individual CatalogTree objects.
*
* @param catalogTrees element containing trees
*/
public void loadCatalogTrees(Element catalogTrees) {
List<Element> catList = catalogTrees.getChildren("catalogTree");
if (log.isDebugEnabled()) {
log.debug("loadCatalogTrees: found " + catList.size() + " CatalogTree objects");
}
CatalogTreeManager mgr = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
for (int i = 0; i < catList.size(); i++) {
Element elem = catList.get(i);
Attribute attr = elem.getAttribute("systemName");
if (attr == null) {
log.warn("unexpected null systemName. elem= " + elem + ", attrs= " + elem.getAttributes());
continue;
}
String sysName = attr.getValue();
String userName;
attr = elem.getAttribute("userName");
if (attr == null) {
log.warn("unexpected null userName. attrs= " + elem.getAttributes());
continue;
} else {
userName = attr.getValue();
}
DefaultTreeModel ct = (DefaultTreeModel) mgr.getBySystemName(sysName);
if (ct != null) {
// tree already registered
continue;
}
ct = (DefaultTreeModel) mgr.newCatalogTree(sysName, userName);
if (log.isDebugEnabled()) {
log.debug("CatalogTree: sysName= " + sysName + ", userName= " + userName);
}
CatalogTreeNode root = (CatalogTreeNode) ct.getRoot();
elem = elem.getChild("node");
loadNode(elem, root, ct);
}
}
use of jmri.jmrit.catalog.CatalogTreeNode in project JMRI by JMRI.
the class DefaultCatalogTreeManagerXml method storeNode.
/**
* Recursively store a CatalogTree.
*
* @param parent the element to store node in
* @param node the root node of the tree
*/
public void storeNode(Element parent, CatalogTreeNode node) {
if (log.isDebugEnabled()) {
log.debug("storeNode " + node.toString() + ", has " + node.getLeaves().size() + " leaves.");
}
Element element = new Element("node");
element.setAttribute("nodeName", node.toString());
List<CatalogTreeLeaf> leaves = node.getLeaves();
for (int i = 0; i < leaves.size(); i++) {
Element el = new Element("leaf");
CatalogTreeLeaf leaf = leaves.get(i);
el.setAttribute("name", leaf.getName());
el.setAttribute("path", leaf.getPath());
element.addContent(el);
}
parent.addContent(element);
// is node.children actually of <Element> type?
@SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> e = node.children();
while (e.hasMoreElements()) {
CatalogTreeNode n = e.nextElement();
storeNode(element, n);
}
}
Aggregations