Search in sources :

Example 6 with CatalogTreeLeaf

use of jmri.jmrit.catalog.CatalogTreeLeaf in project JMRI by JMRI.

the class IconAdder method makeIcons.

/**
     * Build iconMap and orderArray from user's choice of defaults.
     *
     * @param n the root in a catalog from which icons are made
     */
protected void makeIcons(CatalogTreeNode n) {
    if (log.isDebugEnabled()) {
        log.debug("makeIcons from node= {}, numChildren= {}, NumLeaves= {}", n.toString(), n.getChildCount(), n.getNumLeaves());
    }
    _iconMap = new HashMap<>(10);
    _order = new ArrayList<>();
    ArrayList<CatalogTreeLeaf> list = n.getLeaves();
    // adjust order of icons
    int k = list.size() - 1;
    for (int i = list.size() - 1; i >= 0; i--) {
        CatalogTreeLeaf leaf = list.get(i);
        String name = leaf.getName();
        String path = leaf.getPath();
        switch(name) {
            case "BeanStateInconsistent":
                this.setIcon(0, name, new NamedIcon(path, path));
                break;
            case "BeanStateUnknown":
                this.setIcon(1, name, new NamedIcon(path, path));
                break;
            default:
                this.setIcon(k, name, new NamedIcon(path, path));
                k--;
                break;
        }
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf)

Example 7 with CatalogTreeLeaf

use of jmri.jmrit.catalog.CatalogTreeLeaf in project JMRI by JMRI.

the class IconAdder method getDefaultIconNodeFromMap.

private CatalogTreeNode getDefaultIconNodeFromMap() {
    if (log.isDebugEnabled()) {
        log.debug("getDefaultIconNodeFromMap for node= " + _type + ", _order.size()= " + _order.size());
    }
    _defaultIcons = new CatalogTreeNode(_type);
    Iterator<Entry<String, JToggleButton>> it = _iconMap.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, JToggleButton> e = it.next();
        NamedIcon icon = (NamedIcon) e.getValue().getIcon();
        _defaultIcons.addLeaf(new CatalogTreeLeaf(e.getKey(), icon.getURL(), _order.indexOf(e.getKey())));
    }
    return _defaultIcons;
}
Also used : Entry(java.util.Map.Entry) NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) JToggleButton(javax.swing.JToggleButton) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 8 with CatalogTreeLeaf

use of jmri.jmrit.catalog.CatalogTreeLeaf in project JMRI by JMRI.

the class MultiSensorIconAdder method makeIcons.

/**
     * Build iconMap and orderArray from user's choice of defaults (override)
     */
@Override
protected void makeIcons(CatalogTreeNode n) {
    if (log.isDebugEnabled()) {
        log.debug("makeIcons from node= " + n.toString() + ", numChildren= " + n.getChildCount() + ", NumLeaves= " + n.getNumLeaves());
    }
    _iconMap = new HashMap<>(10);
    _order = new ArrayList<>();
    ArrayList<CatalogTreeLeaf> list = n.getLeaves();
    // adjust order of icons
    for (int i = list.size() - 1; i >= 0; i--) {
        CatalogTreeLeaf leaf = list.get(i);
        String name = leaf.getName();
        String path = leaf.getPath();
        if ("BeanStateInconsistent".equals(name)) {
            setIcon(0, name, new NamedIcon(path, path));
        } else if ("BeanStateUnknown".equals(name)) {
            setIcon(1, name, new NamedIcon(path, path));
        } else if ("SensorStateInactive".equals(name)) {
            setIcon(2, name, new NamedIcon(path, path));
        } else {
            int k = Character.digit(name.charAt(name.length() - 1), 10);
            setIcon(k + 3, name, new NamedIcon(path, path));
        }
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf)

Aggregations

CatalogTreeLeaf (jmri.jmrit.catalog.CatalogTreeLeaf)8 NamedIcon (jmri.jmrit.catalog.NamedIcon)5 CatalogTreeNode (jmri.jmrit.catalog.CatalogTreeNode)4 Element (org.jdom2.Element)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 JToggleButton (javax.swing.JToggleButton)1 SignalHead (jmri.SignalHead)1 Attribute (org.jdom2.Attribute)1