Search in sources :

Example 26 with Attribute

use of org.jdom2.Attribute in project JMRI by JMRI.

the class DefaultCatalogTreeManagerXml method addLeaves.

private void addLeaves(Element element, CatalogTreeNode node) {
    List<Element> leafList = element.getChildren("leaf");
    for (int i = 0; i < leafList.size(); i++) {
        Element elem = leafList.get(i);
        Attribute attr = elem.getAttribute("name");
        if (attr == null) {
            log.error("unexpected null leaf name. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String name = attr.getValue();
        attr = elem.getAttribute("path");
        if (attr == null) {
            log.error("unexpected null leaf path. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String path = attr.getValue();
        // use the method that maintains the same order
        node.addLeaf(new CatalogTreeLeaf(name, path, 0));
    }
}
Also used : CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 27 with Attribute

use of org.jdom2.Attribute in project JMRI by JMRI.

the class PositionableLabelXml method loadCommonAttributes.

public void loadCommonAttributes(Positionable l, int defaultLevel, Element element) {
    Attribute a = element.getAttribute("forcecontroloff");
    if ((a != null) && a.getValue().equals("true")) {
        l.setControlling(false);
    } else {
        l.setControlling(true);
    }
    // find coordinates
    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.setLocation(x, y);
    // find display level
    int level = defaultLevel;
    try {
        level = element.getAttribute("level").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse level attribute!");
    } catch (NullPointerException e) {
    // considered normal if the attribute not present
    }
    l.setDisplayLevel(level);
    a = element.getAttribute("hidden");
    if ((a != null) && a.getValue().equals("yes")) {
        l.setHidden(true);
        l.setVisible(false);
    }
    a = element.getAttribute("positionable");
    if ((a != null) && a.getValue().equals("true")) {
        l.setPositionable(true);
    } else {
        l.setPositionable(false);
    }
    a = element.getAttribute("showtooltip");
    if ((a != null) && a.getValue().equals("true")) {
        l.setShowTooltip(true);
    } else {
        l.setShowTooltip(false);
    }
    a = element.getAttribute("editable");
    if ((a != null) && a.getValue().equals("true")) {
        l.setEditable(true);
    } else {
        l.setEditable(false);
    }
    a = element.getAttribute("degrees");
    if (a != null && l instanceof PositionableLabel) {
        try {
            int deg = a.getIntValue();
            ((PositionableLabel) l).setDegrees(deg);
        } catch (org.jdom2.DataConversionException dce) {
        }
    }
    Element elem = element.getChild("tooltip");
    if (elem == null) {
        // pre JMRI 3.5.2
        elem = element.getChild("toolTip");
    }
    if (elem != null) {
        ToolTip tip = l.getTooltip();
        if (tip != null) {
            tip.setText(elem.getText());
        }
    }
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) PositionableLabel(jmri.jmrit.display.PositionableLabel) DataConversionException(org.jdom2.DataConversionException)

Example 28 with Attribute

use of org.jdom2.Attribute 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 29 with Attribute

use of org.jdom2.Attribute 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 30 with Attribute

use of org.jdom2.Attribute 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

Attribute (org.jdom2.Attribute)104 Element (org.jdom2.Element)96 DataConversionException (org.jdom2.DataConversionException)17 Editor (jmri.jmrit.display.Editor)15 ArrayList (java.util.ArrayList)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)10 File (java.io.File)8 Color (java.awt.Color)7 List (java.util.List)7 HashMap (java.util.HashMap)6 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5 ASN1Encodable (com.android.org.bouncycastle.asn1.ASN1Encodable)5 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1Set (com.android.org.bouncycastle.asn1.ASN1Set)5 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5