Search in sources :

Example 6 with CatalogTreeManager

use of jmri.CatalogTreeManager 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());
        }
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) CatalogTreeManager(jmri.CatalogTreeManager) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode) Entry(java.util.Map.Entry) CatalogTree(jmri.CatalogTree)

Example 7 with CatalogTreeManager

use of jmri.CatalogTreeManager 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);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) CatalogTreeManager(jmri.CatalogTreeManager) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 8 with CatalogTreeManager

use of jmri.CatalogTreeManager in project JMRI by JMRI.

the class ImageIndexEditor method makeIndexPanel.

private JPanel makeIndexPanel() {
    _index = new CatalogPanel("ImageIndex", "selectIndexNode");
    _index.init(true);
    boolean found = false;
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    List<String> sysNames = manager.getSystemNameList();
    for (int i = 0; i < sysNames.size(); i++) {
        String systemName = sysNames.get(i);
        if (systemName.startsWith("IX")) {
            _index.addTree(manager.getBySystemName(systemName));
            found = true;
        }
    }
    if (!found) {
        _index.createNewBranch("IXII", Bundle.getMessage("ImageIndexRoot"), "ImageIndexRoot");
    }
    return _index;
}
Also used : CatalogTreeManager(jmri.CatalogTreeManager)

Example 9 with CatalogTreeManager

use of jmri.CatalogTreeManager in project JMRI by JMRI.

the class CatalogPanel method makeDefaultCatalog.

public static CatalogPanel makeDefaultCatalog() {
    CatalogPanel catalog = new CatalogPanel("catalogs", "selectNode");
    catalog.init(false);
    CatalogTreeManager manager = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
    List<String> sysNames = manager.getSystemNameList();
    for (int i = 0; i < sysNames.size(); i++) {
        String systemName = sysNames.get(i);
        if (systemName.charAt(0) == 'I') {
            catalog.addTree(manager.getBySystemName(systemName));
        }
    }
    catalog.createNewBranch("IFJAR", "Program Directory", "resources");
    FileUtil.createDirectory(FileUtil.getUserFilesPath() + "resources");
    catalog.createNewBranch("IFPREF", "Preferences Directory", FileUtil.getUserFilesPath() + "resources");
    return catalog;
}
Also used : CatalogTreeManager(jmri.CatalogTreeManager) Point(java.awt.Point)

Example 10 with CatalogTreeManager

use of jmri.CatalogTreeManager 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);
    }
}
Also used : CatalogTree(jmri.CatalogTree) Element(org.jdom2.Element) CatalogTreeManager(jmri.CatalogTreeManager)

Aggregations

CatalogTreeManager (jmri.CatalogTreeManager)11 CatalogTree (jmri.CatalogTree)7 CatalogTreeNode (jmri.jmrit.catalog.CatalogTreeNode)6 Element (org.jdom2.Element)3 HashMap (java.util.HashMap)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Point (java.awt.Point)1 File (java.io.File)1 Entry (java.util.Map.Entry)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 XmlFile (jmri.jmrit.XmlFile)1 Attribute (org.jdom2.Attribute)1 Document (org.jdom2.Document)1