use of jmri.jmrit.catalog.CatalogTreeLeaf in project JMRI by JMRI.
the class DefaultCatalogTreeManagerXml method addLeaves.
private void addLeaves(Element element, CatalogTreeNode node) {
List<Element> leafList = element.getChildren("leaf");
for (int i = 0; i < leafList.size(); i++) {
Element elem = leafList.get(i);
Attribute attr = elem.getAttribute("name");
if (attr == null) {
log.error("unexpected null leaf name. elem= " + elem + ", attrs= " + elem.getAttributes());
continue;
}
String name = attr.getValue();
attr = elem.getAttribute("path");
if (attr == null) {
log.error("unexpected null leaf path. elem= " + elem + ", attrs= " + elem.getAttributes());
continue;
}
String path = attr.getValue();
// use the method that maintains the same order
node.addLeaf(new CatalogTreeLeaf(name, path, 0));
}
}
use of jmri.jmrit.catalog.CatalogTreeLeaf in project JMRI by JMRI.
the class IconAdder method makeIconMap.
void makeIconMap(NamedBean bean) {
if (bean != null && _type != null && _type.equals("SignalHead")) {
_order = new ArrayList<>();
_iconMap = new HashMap<>(12);
int k = 0;
ArrayList<CatalogTreeLeaf> list = _defaultIcons.getLeaves();
String[] states = ((SignalHead) bean).getValidStateNames();
for (int i = 0; i < list.size(); i++) {
CatalogTreeLeaf leaf = list.get(i);
String name = leaf.getName();
try {
name = Bundle.getMessage(leaf.getName());
} catch (java.util.MissingResourceException mre) {
}
if (log.isDebugEnabled()) {
log.debug("makeIconMap: leafName= " + leaf.getName() + ", name= " + name);
}
for (String state : states) {
if (name.equals(state) || leaf.getName().equals(Bundle.getMessage("SignalHeadStateDark")) || leaf.getName().equals(Bundle.getMessage("SignalHeadStateHeld"))) {
String path = leaf.getPath();
this.setIcon(k++, leaf.getName(), new NamedIcon(path, path));
break;
}
}
}
} else {
makeIcons(_defaultIcons);
}
if (log.isDebugEnabled()) {
log.debug("makeIconMap: _iconMap.size()= " + _iconMap.size());
}
}
use of jmri.jmrit.catalog.CatalogTreeLeaf in project JMRI by JMRI.
the class IconAdder method getDefaultIconNode.
public CatalogTreeNode getDefaultIconNode() {
if (log.isDebugEnabled()) {
log.debug("getDefaultIconNode for node= " + _type);
}
CatalogTreeNode defaultIcons = new CatalogTreeNode(_type);
ArrayList<CatalogTreeLeaf> list = _defaultIcons.getLeaves();
for (int i = 0; i < list.size(); i++) {
CatalogTreeLeaf leaf = list.get(i);
defaultIcons.addLeaf(new CatalogTreeLeaf(leaf.getName(), leaf.getPath(), i));
}
return defaultIcons;
}
use of jmri.jmrit.catalog.CatalogTreeLeaf 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.CatalogTreeLeaf 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