Search in sources :

Example 71 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class PositionableLabelXml method storeCommonAttributes.

/**
     * Default implementation for storing the common contents of an Icon
     *
     * @param p the icon to store
     * @param element the XML representation of the icon
     */
public void storeCommonAttributes(Positionable p, Element element) {
    element.setAttribute("x", "" + p.getX());
    element.setAttribute("y", "" + p.getY());
    element.setAttribute("level", String.valueOf(p.getDisplayLevel()));
    element.setAttribute("forcecontroloff", !p.isControlling() ? "true" : "false");
    element.setAttribute("hidden", p.isHidden() ? "yes" : "no");
    element.setAttribute("positionable", p.isPositionable() ? "true" : "false");
    element.setAttribute("showtooltip", p.showTooltip() ? "true" : "false");
    element.setAttribute("editable", p.isEditable() ? "true" : "false");
    ToolTip tip = p.getTooltip();
    String txt = tip.getText();
    if (txt != null) {
        // was written as "toolTip" 3.5.1 and before
        Element elem = new Element("tooltip").addContent(txt);
        element.addContent(elem);
    }
    if (p.getDegrees() != 0) {
        element.setAttribute("degrees", "" + p.getDegrees());
    }
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Element(org.jdom2.Element)

Example 72 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element 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 73 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element 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)

Example 74 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class SensorIconXml method store.

/**
     * Default implementation for storing the contents of a SensorIcon
     *
     * @param o Object to store, of type SensorIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SensorIcon p = (SensorIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("sensoricon");
    element.setAttribute("sensor", p.getNamedSensor().getName());
    storeCommonAttributes(p, element);
    element.setAttribute("momentary", p.getMomentary() ? "true" : "false");
    element.setAttribute("icon", p.isIcon() ? "yes" : "no");
    storeIconInfo(p, element);
    storeTextInfo(p, element);
    element.setAttribute("class", "jmri.jmrit.display.configurexml.SensorIconXml");
    return element;
}
Also used : SensorIcon(jmri.jmrit.display.SensorIcon) Element(org.jdom2.Element)

Example 75 with Element

use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.

the class RpsPositionIconXml method store.

/**
     * Default implementation for storing the contents of a RpsPositionIcon
     *
     * @param o Object to store, of type RpsPositionIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    RpsPositionIcon p = (RpsPositionIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("sensoricon");
    storeCommonAttributes(p, element);
    // include contents
    element.setAttribute("active", p.getActiveIcon().getURL());
    element.setAttribute("error", p.getErrorIcon().getURL());
    element.setAttribute("rotate", String.valueOf(p.getActiveIcon().getRotation()));
    element.setAttribute("momentary", p.getMomentary() ? "true" : "false");
    element.setAttribute("sxscale", "" + p.getXScale());
    element.setAttribute("syscale", "" + p.getYScale());
    element.setAttribute("sxorigin", "" + p.getXOrigin());
    element.setAttribute("syorigin", "" + p.getYOrigin());
    element.setAttribute("showid", p.isShowID() ? "true" : "false");
    if (p.getFilter() != null) {
        element.setAttribute("filter", "" + p.getFilter());
    }
    element.addContent(storeIcon("active", p.getActiveIcon()));
    element.addContent(storeIcon("error", p.getErrorIcon()));
    element.setAttribute("class", "jmri.jmrit.display.configurexml.RpsPositionIconXml");
    return element;
}
Also used : Element(org.jdom2.Element) RpsPositionIcon(jmri.jmrit.display.RpsPositionIcon)

Aggregations

Element (org.jdom2.Element)829 Attribute (org.jdom2.Attribute)76 Document (org.jdom2.Document)75 Test (org.junit.Test)70 File (java.io.File)53 ArrayList (java.util.ArrayList)45 JDOMException (org.jdom2.JDOMException)37 IOException (java.io.IOException)34 HashMap (java.util.HashMap)28 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 List (java.util.List)26 XmlFile (jmri.jmrit.XmlFile)24 SAXBuilder (org.jdom2.input.SAXBuilder)21 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 XMLOutputter (org.jdom2.output.XMLOutputter)18 Namespace (org.jdom2.Namespace)17 Point (java.awt.Point)15