Search in sources :

Example 1 with MultiSensorIcon

use of jmri.jmrit.display.MultiSensorIcon 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 2 with MultiSensorIcon

use of jmri.jmrit.display.MultiSensorIcon in project JMRI by JMRI.

the class MultiSensorIconXml method store.

/**
     * Default implementation for storing the contents of a MultiSensorIcon
     *
     * @param o Object to store, of type MultiSensorIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    MultiSensorIcon p = (MultiSensorIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("multisensoricon");
    storeCommonAttributes(p, element);
    element.setAttribute("updown", p.getUpDown() ? "true" : "false");
    for (int i = 0; i < p.getNumEntries(); i++) {
        Element e = storeIcon("active", p.getSensorIcon(i));
        e.setAttribute("sensor", p.getSensorName(i));
        element.addContent(e);
    }
    element.addContent(storeIcon("inactive", p.getInactiveIcon()));
    element.addContent(storeIcon("unknown", p.getUnknownIcon()));
    element.addContent(storeIcon("inconsistent", p.getInconsistentIcon()));
    element.setAttribute("class", "jmri.jmrit.display.configurexml.MultiSensorIconXml");
    return element;
}
Also used : MultiSensorIcon(jmri.jmrit.display.MultiSensorIcon) Element(org.jdom2.Element)

Example 3 with MultiSensorIcon

use of jmri.jmrit.display.MultiSensorIcon in project JMRI by JMRI.

the class MultiSensorIconFrame method make.

void make() {
    MultiSensorIcon m = new MultiSensorIcon(layoutEditor);
    m.setUnknownIcon(defaultIcons.getIcon(0));
    m.setInconsistentIcon(defaultIcons.getIcon(1));
    m.setInactiveIcon(defaultIcons.getIcon(2));
    for (int i = 0; i < content.getComponentCount(); i++) {
        Entry e = (Entry) content.getComponent(i);
        if (e.sensor.getText().trim().equals("")) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("Error19", i + 1), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
            isEmpty = 1;
            // Keep Panel open to edit entry
            return;
        }
        m.addEntry(e.sensor.getText(), e.ed.getIcon(0));
    }
    m.setUpDown(updown.isSelected());
    m.setDisplayLevel(jmri.jmrit.display.Editor.SENSORS);
    layoutEditor.addMultiSensor(m);
}
Also used : MultiSensorIcon(jmri.jmrit.display.MultiSensorIcon)

Aggregations

MultiSensorIcon (jmri.jmrit.display.MultiSensorIcon)3 Element (org.jdom2.Element)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)1 Editor (jmri.jmrit.display.Editor)1 Attribute (org.jdom2.Attribute)1