Search in sources :

Example 6 with CatalogTreeNode

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());
        }
    }
}
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 CatalogTreeNode

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

Example 8 with CatalogTreeNode

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;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) HashMap(java.util.HashMap) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 9 with CatalogTreeNode

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

Example 10 with CatalogTreeNode

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);
    }
}
Also used : CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) Element(org.jdom2.Element) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Aggregations

CatalogTreeNode (jmri.jmrit.catalog.CatalogTreeNode)13 CatalogTreeManager (jmri.CatalogTreeManager)6 NamedIcon (jmri.jmrit.catalog.NamedIcon)6 HashMap (java.util.HashMap)5 CatalogTree (jmri.CatalogTree)5 CatalogTreeLeaf (jmri.jmrit.catalog.CatalogTreeLeaf)4 Element (org.jdom2.Element)4 Entry (java.util.Map.Entry)3 Attribute (org.jdom2.Attribute)2 File (java.io.File)1 JToggleButton (javax.swing.JToggleButton)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 XmlFile (jmri.jmrit.XmlFile)1 Document (org.jdom2.Document)1