use of jmri.jmrit.catalog.CatalogTreeNode in project JMRI by JMRI.
the class DefaultCatalogTreeManagerXml method writeCatalogTrees.
/*
* Writes out tree values to a file in the user's preferences directory
*/
public void writeCatalogTrees() throws java.io.IOException {
if (log.isDebugEnabled()) {
log.debug("entered writeCatalogTreeValues");
}
CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
List<String> trees = manager.getSystemNameList();
boolean found = false;
Iterator<String> iter = manager.getSystemNameList().iterator();
while (iter.hasNext()) {
String sname = iter.next();
CatalogTree tree = manager.getBySystemName(sname);
if (log.isDebugEnabled()) {
log.debug("Tree: sysName= " + sname + ", userName= " + tree.getUserName());
CatalogTreeNode root = tree.getRoot();
log.debug("enumerateTree called for root= " + root.toString() + ", has " + root.getChildCount() + " children");
// root.depthFirstEnumeration isn't fully typed in JDOM2
@SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> e = root.depthFirstEnumeration();
while (e.hasMoreElements()) {
CatalogTreeNode n = e.nextElement();
log.debug("nodeName= " + n.getUserObject() + " has " + n.getLeaves().size() + " leaves and " + n.getChildCount() + " subnodes.");
}
}
if (sname != null && sname.charAt(1) == CatalogTree.XML) {
found = true;
break;
}
}
if (found) {
// there are trees defined, create root element
Element root = new Element("catalogTrees");
Document doc = newDocument(root, dtdLocation + "catalogTree.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/tree-values.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "panelfile.xsl");
org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
store(root, trees);
try {
if (!checkFile(DEFAULT_FILE_NAME)) {
// file does not exist, create it
File file = new File(DEFAULT_FILE_NAME);
if (!file.createNewFile()) {
log.error("createNewFile failed");
}
}
// write content to file
writeXML(findFile(DEFAULT_FILE_NAME), doc);
// memory consistent with file
jmri.jmrit.catalog.ImageIndexEditor.indexChanged(false);
} catch (java.io.IOException ioe) {
log.error("IO Exception " + ioe);
throw (ioe);
}
}
}
use of jmri.jmrit.catalog.CatalogTreeNode in project JMRI by JMRI.
the class IconAdder method initDefaultIcons.
public void initDefaultIcons() {
CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
CatalogTree tree = manager.getBySystemName("NXDI");
if (tree != null) {
CatalogTreeNode node = tree.getRoot();
Enumeration<CatalogTreeNode> e = node.children();
while (e.hasMoreElements()) {
CatalogTreeNode nChild = e.nextElement();
if (_type.equals(nChild.toString())) {
_defaultIcons = nChild;
_userDefaults = true;
}
}
}
if (log.isDebugEnabled()) {
log.debug("initDefaultIcons: type= " + _type + ", defaultIcons= " + _defaultIcons);
}
}
use of jmri.jmrit.catalog.CatalogTreeNode 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.jmrit.catalog.CatalogTreeNode 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.CatalogTreeNode in project JMRI by JMRI.
the class DefaultCatalogTreeManagerXml method loadNode.
/**
* Recursively load a CatalogTree.
*
* @param element element containing the node to load
* @param parent the parent node of the node in element
* @param model the tree model containing the tree to add the node to
*/
public void loadNode(Element element, CatalogTreeNode parent, DefaultTreeModel model) {
List<Element> nodeList = element.getChildren("node");
if (log.isDebugEnabled()) {
log.debug("Found " + nodeList.size() + " CatalogTreeNode objects");
}
for (int i = 0; i < nodeList.size(); i++) {
Element elem = nodeList.get(i);
Attribute attr = elem.getAttribute("nodeName");
if (attr == null) {
log.warn("unexpected null nodeName. elem= " + elem + ", attrs= " + elem.getAttributes());
continue;
}
String nodeName = attr.getValue();
CatalogTreeNode n = new CatalogTreeNode(nodeName);
addLeaves(elem, n);
model.insertNodeInto(n, parent, parent.getChildCount());
loadNode(elem, n, model);
}
}
Aggregations