Search in sources :

Example 31 with NamedIcon

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

the class MultiSensorIconXml method loadSensorIcon.

private NamedIcon loadSensorIcon(String state, int rotation, MultiSensorIcon l, Element element, Editor ed) {
    String msg = "MultiSensor \"" + l.getNameString() + "\": icon \"" + state + "\" ";
    NamedIcon icon = loadIcon(l, state, element, msg, ed);
    if (icon == null) {
        if (element.getAttribute(state) != null) {
            String iconName = element.getAttribute(state).getValue();
            icon = NamedIcon.getIconByName(iconName);
            if (icon == null) {
                icon = ed.loadFailed(msg, iconName);
                if (icon == null) {
                    log.info(msg + " removed for url= " + iconName);
                }
            } else {
                icon.setRotation(rotation, l);
            }
        } else {
            log.warn("did not locate " + state + " for Multisensor icon file");
        }
    }
    if (icon == null) {
        log.info("MultiSensor Icon \"" + l.getNameString() + "\": icon \"" + state + "\" removed");
    }
    return icon;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 32 with NamedIcon

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

the class MultiSensorIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor an Object
     */
@Override
public void load(Element element, Object o) {
    Editor pe = (Editor) o;
    MultiSensorIcon l = new MultiSensorIcon(pe);
    // create the objects
    int rotation = 0;
    try {
        rotation = element.getAttribute("rotate").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    NamedIcon icon = loadSensorIcon("inactive", rotation, l, element, pe);
    if (icon != null) {
        l.setInactiveIcon(icon);
    } else {
        return;
    }
    icon = loadSensorIcon("unknown", rotation, l, element, pe);
    if (icon != null) {
        l.setUnknownIcon(icon);
    } else {
        return;
    }
    icon = loadSensorIcon("inconsistent", rotation, l, element, pe);
    if (icon != null) {
        l.setInconsistentIcon(icon);
    } else {
        return;
    }
    Attribute a = element.getAttribute("updown");
    if ((a != null) && a.getValue().equals("true")) {
        l.setUpDown(true);
    } else {
        l.setUpDown(false);
    }
    // get the icon pairs & load
    List<Element> items = element.getChildren();
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        if (item.getAttribute("sensor") != null) {
            String sensor = item.getAttribute("sensor").getValue();
            if (item.getAttribute("url") != null) {
                String name = item.getAttribute("url").getValue();
                icon = NamedIcon.getIconByName(name);
                if (icon == null) {
                    icon = pe.loadFailed("MultiSensor \"" + l.getNameString() + "\" ", name);
                    if (icon == null) {
                        log.error("MultiSensor \"" + l.getNameString() + "\" removed for url= " + name);
                        return;
                    }
                }
                try {
                    int deg = 0;
                    a = item.getAttribute("degrees");
                    if (a != null) {
                        deg = a.getIntValue();
                        double scale = 1.0;
                        a = item.getAttribute("scale");
                        if (a != null) {
                            scale = item.getAttribute("scale").getDoubleValue();
                        }
                        icon.setLoad(deg, scale, l);
                    }
                    if (deg == 0) {
                        a = item.getAttribute("rotate");
                        if (a != null) {
                            rotation = a.getIntValue();
                            icon.setRotation(rotation, l);
                        }
                    }
                } catch (org.jdom2.DataConversionException dce) {
                }
            } else {
                String name = item.getAttribute("icon").getValue();
                icon = NamedIcon.getIconByName(name);
                if (icon == null) {
                    icon = pe.loadFailed("MultiSensor \"" + l.getNameString(), name);
                    if (icon == null) {
                        log.info("MultiSensor \"" + l.getNameString() + " removed for url= " + name);
                        return;
                    }
                }
                if (rotation != 0) {
                    icon.setRotation(rotation, l);
                }
            }
            l.addEntry(sensor, icon);
        }
    }
    pe.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) MultiSensorIcon(jmri.jmrit.display.MultiSensorIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor)

Example 33 with NamedIcon

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

the class PositionableLabelXml method loadIcon.

public NamedIcon loadIcon(PositionableLabel l, String attrName, Element element, String name, Editor ed) {
    NamedIcon icon = getNamedIcon(attrName, element, name, ed);
    if (icon != null) {
        try {
            int deg = 0;
            double scale = 1.0;
            Element elem = element.getChild(attrName);
            if (elem != null) {
                Attribute a = elem.getAttribute("degrees");
                if (a != null) {
                    deg = a.getIntValue();
                }
                a = elem.getAttribute("scale");
                if (a != null) {
                    scale = elem.getAttribute("scale").getDoubleValue();
                }
                icon.setLoad(deg, scale, l);
                if (deg == 0) {
                    // "rotate" attribute is JMRI 2.9.3 and before
                    a = elem.getAttribute("rotate");
                    if (a != null) {
                        int rotation = a.getIntValue();
                        // 2.9.3 and before, only unscaled icons rotate
                        if (scale == 1.0) {
                            icon.setRotation(rotation, l);
                        }
                    }
                    // "rotation" element is JMRI 2.9.4 and after
                    Element e = elem.getChild("rotation");
                    if (e != null) {
                        // ver 2.9.4 allows orthogonal rotations of scaled icons
                        int rotation = Integer.parseInt(e.getText());
                        icon.setRotation(rotation, l);
                    }
                }
            }
        } catch (org.jdom2.DataConversionException dce) {
        }
    }
    return icon;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) DataConversionException(org.jdom2.DataConversionException)

Example 34 with NamedIcon

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

the class PositionableLabelXml method getNamedIcon.

protected NamedIcon getNamedIcon(String childName, Element element, String name, Editor ed) {
    NamedIcon icon = null;
    Element elem = element.getChild(childName);
    if (elem != null) {
        String iconName = elem.getAttribute("url").getValue();
        icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed(name, iconName);
            if (icon == null) {
                log.info(name + " removed for url= " + iconName);
            }
        }
    } else {
        log.debug("getNamedIcon: child element \"" + childName + "\" not found in element " + element.getName());
    }
    return icon;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Element(org.jdom2.Element)

Example 35 with NamedIcon

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

the class SensorIconXml 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;
    SensorIcon l;
    String name;
    Attribute attr = element.getAttribute("sensor");
    if (attr == null) {
        log.error("incorrect information for sensor; must use sensor name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    _icon = true;
    if (element.getAttribute("icon") != null) {
        String yesno = element.getAttribute("icon").getValue();
        if ((yesno != null) && (!yesno.equals(""))) {
            if (yesno.equals("yes")) {
                _icon = true;
            } else if (yesno.equals("no")) {
                _icon = false;
            }
        }
    }
    if (_icon) {
        l = new SensorIcon(new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"), ed);
    } else {
        l = new SensorIcon("  ", ed);
    }
    int rotation = 0;
    try {
        rotation = element.getAttribute("rotate").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    if (loadSensorIcon("active", rotation, l, element, name, ed) == null) {
        return;
    }
    if (loadSensorIcon("inactive", rotation, l, element, name, ed) == null) {
        return;
    }
    if (loadSensorIcon("unknown", rotation, l, element, name, ed) == null) {
        return;
    }
    if (loadSensorIcon("inconsistent", rotation, l, element, name, ed) == null) {
        return;
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    Attribute a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    loadTextInfo(l, element);
    l.setSensor(name);
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SENSORS, element);
    if (l.isIcon() && l.getText() != null) {
        l.setOpaque(false);
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) SensorIcon(jmri.jmrit.display.SensorIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) 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