Search in sources :

Example 71 with NamedIcon

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

the class IconAdder method getIconMap.

/**
     * Returns a new Hashtable of only the icons selected for display.
     *
     * @return a map of icons using the icon labels as keys
     */
public Hashtable<String, NamedIcon> getIconMap() {
    log.debug("getIconMap: _allowDeletes= {}", _allowDeletes);
    Hashtable<String, NamedIcon> iconMap = new Hashtable<>();
    Iterator<String> iter = _iconMap.keySet().iterator();
    while (iter.hasNext()) {
        String key = iter.next();
        JToggleButton button = _iconMap.get(key);
        if (log.isDebugEnabled()) {
            log.debug("getIconMap: key= " + key + ", button.isSelected()= " + button.isSelected());
        }
        if (!_allowDeletes || !button.isSelected()) {
            iconMap.put(key, new NamedIcon((NamedIcon) button.getIcon()));
        }
    }
    return iconMap;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) JToggleButton(javax.swing.JToggleButton) Hashtable(java.util.Hashtable)

Example 72 with NamedIcon

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

the class IndicatorTrackIcon method updateItem.

void updateItem() {
    setOccSensor(_trackPanel.getOccSensor());
    setOccBlock(_trackPanel.getOccBlock());
    _pathUtil.setShowTrain(_trackPanel.getShowTrainName());
    _iconFamily = _trackPanel.getFamilyName();
    _pathUtil.setPaths(_trackPanel.getPaths());
    HashMap<String, NamedIcon> iconMap = _trackPanel.getIconMap();
    if (iconMap != null) {
        HashMap<String, NamedIcon> oldMap = cloneMap(_iconMap, this);
        Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, NamedIcon> entry = it.next();
            if (log.isDebugEnabled()) {
                log.debug("key= " + entry.getKey());
            }
            NamedIcon newIcon = entry.getValue();
            NamedIcon oldIcon = oldMap.get(entry.getKey());
            newIcon.setLoad(oldIcon.getDegrees(), oldIcon.getScale(), this);
            newIcon.setRotation(oldIcon.getRotation(), this);
            setIcon(entry.getKey(), newIcon);
        }
    }
    // otherwise retain current map
    //        jmri.jmrit.catalog.ImageIndexEditor.checkImageIndex();
    _paletteFrame.dispose();
    _paletteFrame = null;
    _trackPanel.dispose();
    _trackPanel = null;
    displayState(_status);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Entry(java.util.Map.Entry)

Example 73 with NamedIcon

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

the class IndicatorTrackIcon method setOccBlockHandle.

@Override
public void setOccBlockHandle(NamedBeanHandle<OBlock> blockHandle) {
    if (namedOccBlock != null) {
        getOccBlock().removePropertyChangeListener(this);
    }
    namedOccBlock = blockHandle;
    if (namedOccBlock != null) {
        if (_iconMap == null) {
            _iconMap = new HashMap<String, NamedIcon>();
        }
        OBlock block = getOccBlock();
        block.addPropertyChangeListener(this, namedOccBlock.getName(), "Indicator Track");
        setStatus(block, block.getState());
        displayState(_status);
        setTooltip(new ToolTip(block.getDescription(), 0, 0));
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) OBlock(jmri.jmrit.logix.OBlock)

Example 74 with NamedIcon

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

the class SignalHeadIconXml method loadSignalIcon.

private NamedIcon loadSignalIcon(String aspect, int rotation, SignalHeadIcon l, Element element, String name, Editor ed) {
    String msg = "SignalHead \"" + name + "\": icon \"" + aspect + "\" ";
    NamedIcon icon = loadIcon(l, aspect, element, msg, ed);
    if (icon == null) {
        if (element.getAttribute(aspect) != null) {
            String iconName = element.getAttribute(aspect).getValue();
            icon = NamedIcon.getIconByName(iconName);
            if (icon == null) {
                icon = ed.loadFailed(msg, iconName);
                if (icon == null) {
                    log.info(msg + " removed for url= " + iconName);
                }
            }
            if (icon != null) {
                icon.setRotation(rotation, l);
            }
        } else {
            log.info("did not load file aspect " + aspect + " for SignalHead " + name);
        }
    }
    if (icon == null) {
        log.info("SignalHead Icon \"" + name + "\": icon \"" + aspect + "\" removed");
    }
    return icon;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 75 with NamedIcon

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

the class SignalHeadIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor ed = (Editor) o;
    SignalHeadIcon l = new SignalHeadIcon(ed);
    String name;
    Attribute attr = element.getAttribute("signalhead");
    if (attr == null) {
        log.error("incorrect information for signal head; must use signalhead name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    SignalHead sh = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name);
    if (sh != null) {
        l.setSignalHead(name);
    } else {
        log.error("SignalHead named '" + attr.getValue() + "' not found.");
        //    ed.loadFailed();
        return;
    }
    int rotation = 0;
    try {
        attr = element.getAttribute("rotate");
        rotation = attr.getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    List<Element> aspects = element.getChildren();
    if (aspects.size() > 0) {
        Element icons = element.getChild("icons");
        Element elem = element;
        if (icons != null) {
            List<Element> c = icons.getChildren();
            aspects = c;
            elem = icons;
        }
        for (int i = 0; i < aspects.size(); i++) {
            String aspect = aspects.get(i).getName();
            NamedIcon icon = loadIcon(l, aspect, elem, "SignalHead \"" + name + "\": icon \"" + aspect + "\" ", ed);
            if (icon != null) {
                l.setIcon(_nameMap.get(aspect), icon);
            } else {
                log.info("SignalHead \"" + name + "\": icon \"" + aspect + "\" removed");
            }
        }
        log.debug(aspects.size() + " icons loaded for " + l.getNameString());
    } else {
        // old style as attributes - somewhere around pre 2.5.4
        NamedIcon icon = loadSignalIcon("red", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateRed"), icon);
        }
        icon = loadSignalIcon("yellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateYellow"), icon);
        }
        icon = loadSignalIcon("green", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateGreen"), icon);
        }
        icon = loadSignalIcon("lunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateLunar"), icon);
        }
        icon = loadSignalIcon("held", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateHeld"), icon);
        }
        icon = loadSignalIcon("dark", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateDark"), icon);
        }
        icon = loadSignalIcon("flashred", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingRed"), icon);
        }
        icon = loadSignalIcon("flashyellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingYellow"), icon);
        }
        icon = loadSignalIcon("flashgreen", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingGreen"), icon);
        }
        icon = loadSignalIcon("flashlunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingLunar"), icon);
        }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    try {
        attr = element.getAttribute("clickmode");
        if (attr != null) {
            l.setClickMode(attr.getIntValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on clickmode attribute: " + e);
    }
    try {
        attr = element.getAttribute("litmode");
        if (attr != null) {
            l.setLitMode(attr.getBooleanValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on litmode attribute: " + e);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SIGNALS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalHeadIcon(jmri.jmrit.display.SignalHeadIcon) Editor(jmri.jmrit.display.Editor)

Aggregations

NamedIcon (jmri.jmrit.catalog.NamedIcon)128 Entry (java.util.Map.Entry)28 Element (org.jdom2.Element)27 HashMap (java.util.HashMap)23 JPanel (javax.swing.JPanel)13 Editor (jmri.jmrit.display.Editor)13 Attribute (org.jdom2.Attribute)13 ActionEvent (java.awt.event.ActionEvent)12 ActionListener (java.awt.event.ActionListener)12 JLabel (javax.swing.JLabel)11 JButton (javax.swing.JButton)10 DataFlavor (java.awt.datatransfer.DataFlavor)6 CatalogTreeNode (jmri.jmrit.catalog.CatalogTreeNode)6 DragJLabel (jmri.jmrit.catalog.DragJLabel)6 Sensor (jmri.Sensor)5 CatalogTreeLeaf (jmri.jmrit.catalog.CatalogTreeLeaf)5 RosterEntry (jmri.jmrit.roster.RosterEntry)5 Point (java.awt.Point)4 JComponent (javax.swing.JComponent)4 JDialog (javax.swing.JDialog)4