Search in sources :

Example 86 with NamedIcon

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

the class SignalMastIcon method displayState.

/**
     * Drive the current state of the display from the state of the underlying
     * SignalMast object.
     */
public void displayState(String state) {
    updateSize();
    if (log.isDebugEnabled()) {
        // Avoid signal lookup unless needed
        if (getSignalMast() == null) {
            log.debug("Display state " + state + ", disconnected");
        } else {
            log.debug("Display state " + state + " for " + getSignalMast().getSystemName());
        }
    }
    if (isText()) {
        if (getSignalMast().getHeld()) {
            if (isText()) {
                super.setText(Bundle.getMessage("Held"));
            }
            return;
        } else if (getLitMode() && !getSignalMast().getLit()) {
            super.setText(Bundle.getMessage("Dark"));
            return;
        }
        super.setText(state);
    }
    if (isIcon()) {
        if ((state != null) && (getSignalMast() != null)) {
            String s = getSignalMast().getAppearanceMap().getImageLink(state, useIconSet);
            if ((getSignalMast().getHeld()) && (getSignalMast().getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.HELD) != null)) {
                s = getSignalMast().getAppearanceMap().getImageLink("$held", useIconSet);
            } else if (getLitMode() && !getSignalMast().getLit() && (getSignalMast().getAppearanceMap().getImageLink("$dark", useIconSet) != null)) {
                s = getSignalMast().getAppearanceMap().getImageLink("$dark", useIconSet);
            }
            if (s.equals("")) {
                /*We have no appearance to set, therefore we will exit at this point.
                     This can be considered normal if we are requesting an appearance 
                     that is not support or configured, such as dark or held */
                return;
            }
            if (!s.contains("preference:")) {
                s = s.substring(s.indexOf("resources"));
            }
            // tiny global cache, due to number of icons
            if (_iconMap == null) {
                getIcons();
            }
            NamedIcon n = _iconMap.get(s);
            super.setIcon(n);
            updateSize();
            setSize(n.getIconWidth(), n.getIconHeight());
        }
    } else {
        super.setIcon(null);
    }
    return;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 87 with NamedIcon

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

the class SensorIcon method updateSensor.

void updateSensor() {
    HashMap<String, NamedIcon> oldMap = cloneMap(_iconMap, this);
    setSensor(_iconEditor.getTableSelection().getDisplayName());
    Hashtable<String, NamedIcon> iconMap = _iconEditor.getIconMap();
    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);
    }
    _iconEditorFrame.dispose();
    _iconEditorFrame = null;
    _iconEditor = null;
    invalidate();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Entry(java.util.Map.Entry)

Example 88 with NamedIcon

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

the class SensorIcon method updateItem.

void updateItem() {
    HashMap<String, NamedIcon> oldMap = cloneMap(_iconMap, this);
    setSensor(_itemPanel.getTableSelection().getSystemName());
    _iconFamily = _itemPanel.getFamilyName();
    HashMap<String, NamedIcon> iconMap = _itemPanel.getIconMap();
    if (iconMap != null) {
        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;
    _itemPanel.dispose();
    _itemPanel = null;
    invalidate();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Entry(java.util.Map.Entry)

Example 89 with NamedIcon

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

the class RpsPositionIconXml 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) {
    Editor ed = (Editor) o;
    RpsPositionIcon l = new RpsPositionIcon(ed);
    // create the objects
    String name = element.getAttribute("active").getValue();
    NamedIcon active = NamedIcon.getIconByName(name);
    if (active == null) {
        active = ed.loadFailed("RpsPositionIcon: icon \"active\" ", name);
        if (active == null) {
            log.info("RpsPositionIcon: icon \"active\" removed for url= " + name);
            return;
        }
    }
    l.setActiveIcon(active);
    name = element.getAttribute("error").getValue();
    NamedIcon error = NamedIcon.getIconByName(name);
    if (error == null) {
        error = ed.loadFailed("RpsPositionIcon: icon \"error\" ", name);
        if (error == null) {
            log.info("RpsPositionIcon: \"error\" removed for url= " + name);
            return;
        }
    }
    l.setErrorIcon(error);
    try {
        Attribute a = element.getAttribute("rotate");
        if (a != null) {
            int rotation = element.getAttribute("rotate").getIntValue();
            active.setRotation(rotation, l);
            error.setRotation(rotation, l);
        }
    } catch (org.jdom2.DataConversionException e) {
    }
    Attribute a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    a = element.getAttribute("showid");
    if ((a != null) && a.getValue().equals("true")) {
        l.setShowID(true);
    } else {
        l.setShowID(false);
    }
    a = element.getAttribute("filter");
    if (a != null) {
        l.setFilter(a.getValue());
    }
    double sxScale = 0.;
    double syScale = 0.;
    int sxOrigin = 0;
    int syOrigin = 0;
    try {
        sxScale = element.getAttribute("sxscale").getDoubleValue();
        syScale = element.getAttribute("syscale").getDoubleValue();
        sxOrigin = element.getAttribute("sxorigin").getIntValue();
        syOrigin = element.getAttribute("syorigin").getIntValue();
    } catch (NullPointerException e1) {
        log.error("missing transform attribute");
    } catch (org.jdom2.DataConversionException e2) {
        log.error("failed to convert transform attributes");
    }
    l.setTransform(sxScale, syScale, sxOrigin, syOrigin);
    NamedIcon icon = loadIcon(l, "active", element, "RpsPositionIcon ", ed);
    if (icon != null) {
        l.setActiveIcon(icon);
    }
    icon = loadIcon(l, "error", element, "RpsPositionIcon ", ed);
    if (icon != null) {
        l.setErrorIcon(icon);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SENSORS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Editor(jmri.jmrit.display.Editor) RpsPositionIcon(jmri.jmrit.display.RpsPositionIcon)

Example 90 with NamedIcon

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

the class MemoryIconXml method load.

/**
     * Load, starting with the memoryicon element, then all the value-icon pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    Editor ed = null;
    MemoryIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.MemoryIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new MemoryIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
        log.error("incorrect information for a memory location; must use memory name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (m != null) {
        l.setMemory(name);
    } else {
        log.error("Memory named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    }
    Attribute a = element.getAttribute("selectable");
    if (a != null && a.getValue().equals("yes")) {
        l.setSelectable(true);
    } else {
        l.setSelectable(false);
    }
    a = element.getAttribute("updateBlockValue");
    if (a != null && a.getValue().equals("yes")) {
        l.updateBlockValueOnChange(true);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("memorystate");
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String iconName = item.getAttribute("icon").getValue();
        NamedIcon icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed("Memory " + name, iconName);
            if (icon == null) {
                log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
            }
        }
        if (icon != null) {
            String keyValue = item.getAttribute("value").getValue();
            l.addKeyAndIcon(icon, keyValue);
        }
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setOriginalLocation(x, y);
    l.displayState();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) MemoryIcon(jmri.jmrit.display.MemoryIcon) Attribute(org.jdom2.Attribute) Memory(jmri.Memory) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) 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