Search in sources :

Example 36 with DataConversionException

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

the class WiThrottlePreferences method load.

@Override
public void load(Element child) {
    Attribute a;
    if ((a = child.getAttribute("isUseEStop")) != null) {
        setUseEStop(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseEStop = this.isUseEStop();
    }
    if ((a = child.getAttribute("getEStopDelay")) != null) {
        try {
            setEStopDelay(Integer.valueOf(a.getValue()));
            this.asLoadedEStopDelay = this.getEStopDelay();
        } catch (NumberFormatException e) {
            log.debug(e.getLocalizedMessage(), e);
        }
    }
    if ((a = child.getAttribute("isUseMomF2")) != null) {
        setUseMomF2(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseMomF2 = this.isUseMomF2();
    }
    if ((a = child.getAttribute("getPort")) != null) {
        try {
            setPort(a.getIntValue());
        } catch (DataConversionException ex) {
            log.error("Port {} is invalid.", a.getValue());
        }
        this.asLoadedPort = this.getPort();
    }
    if ((a = child.getAttribute("isAllowTrackPower")) != null) {
        setAllowTrackPower(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTrackPower = this.isAllowTrackPower();
    }
    if ((a = child.getAttribute("isAllowTurnout")) != null) {
        setAllowTurnout(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTurnout = this.isAllowTurnout();
    }
    if ((a = child.getAttribute("isAllowRoute")) != null) {
        setAllowRoute(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowRoute = this.isAllowRoute();
    }
    if ((a = child.getAttribute("isAllowConsist")) != null) {
        setAllowConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowConsist = this.isAllowConsist();
    }
    if ((a = child.getAttribute("isUseWiFiConsist")) != null) {
        setUseWiFiConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseWiFiConsist = this.isUseWiFiConsist();
    }
}
Also used : Attribute(org.jdom2.Attribute) DataConversionException(org.jdom2.DataConversionException)

Example 37 with DataConversionException

use of org.jdom2.DataConversionException in project pcgen by PCGen.

the class NameGenPanel method loadFromDocument.

private void loadFromDocument(Document nameSet) throws DataConversionException {
    Element generator = nameSet.getRootElement();
    java.util.List<?> rulesets = generator.getChildren("RULESET");
    java.util.List<?> lists = generator.getChildren("LIST");
    ListIterator<?> listIterator = lists.listIterator();
    while (listIterator.hasNext()) {
        Element list = (Element) listIterator.next();
        loadList(list);
    }
    for (final Object ruleset : rulesets) {
        Element ruleSet = (Element) ruleset;
        RuleSet rs = loadRuleSet(ruleSet);
        allVars.addDataElement(rs);
    }
}
Also used : RuleSet(pcgen.core.doomsdaybook.RuleSet) DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element)

Example 38 with DataConversionException

use of org.jdom2.DataConversionException in project pcgen by PCGen.

the class NameGenPanel method loadList.

private String loadList(Element list) throws DataConversionException {
    pcgen.core.doomsdaybook.DDList dataList = new pcgen.core.doomsdaybook.DDList(allVars, list.getAttributeValue("title"), list.getAttributeValue("id"));
    java.util.List<?> elements = list.getChildren();
    for (final Object element : elements) {
        Element child = (Element) element;
        String elementName = child.getName();
        if (elementName.equals("VALUE")) {
            WeightedDataValue dv = new WeightedDataValue(child.getText(), child.getAttribute("weight").getIntValue());
            List<?> subElements = child.getChildren("SUBVALUE");
            for (final Object subElement1 : subElements) {
                Element subElement = (Element) subElement1;
                dv.addSubValue(subElement.getAttributeValue("type"), subElement.getText());
            }
            dataList.add(dv);
        }
    }
    allVars.addDataElement(dataList);
    return dataList.getId();
}
Also used : DataElement(pcgen.core.doomsdaybook.DataElement) Element(org.jdom2.Element) WeightedDataValue(pcgen.core.doomsdaybook.WeightedDataValue)

Example 39 with DataConversionException

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

the class JsonServerPreferences method load.

public void load(Element child) {
    Attribute a;
    a = child.getAttribute(HEARTBEAT_INTERVAL);
    if (a != null) {
        try {
            this.setHeartbeatInterval(a.getIntValue());
            this.asLoadedHeartbeatInterval = this.getHeartbeatInterval();
        } catch (DataConversionException e) {
            this.setHeartbeatInterval(15000);
            log.error("Unable to read heartbeat interval. Setting to default value.", e);
        }
    }
    a = child.getAttribute(PORT);
    if (a != null) {
        try {
            this.setPort(a.getIntValue());
            this.asLoadedPort = this.getPort();
        } catch (DataConversionException e) {
            this.setPort(2056);
            log.error("Unable to read port. Setting to default value.", e);
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) DataConversionException(org.jdom2.DataConversionException)

Example 40 with DataConversionException

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

the class SignalHeadIconXml 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) {
    // create the objects
    Editor ed = (Editor) o;
    SignalHeadIcon l = new SignalHeadIcon(ed);
    String name;
    Attribute attr = element.getAttribute("signalhead");
    if (attr == null) {
        log.error("incorrect information for signal head; must use signalhead name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    SignalHead sh = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name);
    if (sh != null) {
        l.setSignalHead(name);
    } else {
        log.error("SignalHead named '" + attr.getValue() + "' not found.");
        //    ed.loadFailed();
        return;
    }
    int rotation = 0;
    try {
        attr = element.getAttribute("rotate");
        rotation = attr.getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    List<Element> aspects = element.getChildren();
    if (aspects.size() > 0) {
        Element icons = element.getChild("icons");
        Element elem = element;
        if (icons != null) {
            List<Element> c = icons.getChildren();
            aspects = c;
            elem = icons;
        }
        for (int i = 0; i < aspects.size(); i++) {
            String aspect = aspects.get(i).getName();
            NamedIcon icon = loadIcon(l, aspect, elem, "SignalHead \"" + name + "\": icon \"" + aspect + "\" ", ed);
            if (icon != null) {
                l.setIcon(_nameMap.get(aspect), icon);
            } else {
                log.info("SignalHead \"" + name + "\": icon \"" + aspect + "\" removed");
            }
        }
        log.debug(aspects.size() + " icons loaded for " + l.getNameString());
    } else {
        // old style as attributes - somewhere around pre 2.5.4
        NamedIcon icon = loadSignalIcon("red", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateRed"), icon);
        }
        icon = loadSignalIcon("yellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateYellow"), icon);
        }
        icon = loadSignalIcon("green", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateGreen"), icon);
        }
        icon = loadSignalIcon("lunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateLunar"), icon);
        }
        icon = loadSignalIcon("held", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateHeld"), icon);
        }
        icon = loadSignalIcon("dark", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateDark"), icon);
        }
        icon = loadSignalIcon("flashred", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingRed"), icon);
        }
        icon = loadSignalIcon("flashyellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingYellow"), icon);
        }
        icon = loadSignalIcon("flashgreen", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingGreen"), icon);
        }
        icon = loadSignalIcon("flashlunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingLunar"), icon);
        }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    try {
        attr = element.getAttribute("clickmode");
        if (attr != null) {
            l.setClickMode(attr.getIntValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on clickmode attribute: " + e);
    }
    try {
        attr = element.getAttribute("litmode");
        if (attr != null) {
            l.setLitMode(attr.getBooleanValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on litmode attribute: " + e);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SIGNALS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalHeadIcon(jmri.jmrit.display.SignalHeadIcon) Editor(jmri.jmrit.display.Editor)

Aggregations

Element (org.jdom2.Element)49 Attribute (org.jdom2.Attribute)48 DataConversionException (org.jdom2.DataConversionException)18 Editor (jmri.jmrit.display.Editor)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)11 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)9 Color (java.awt.Color)7 Point2D (java.awt.geom.Point2D)6 Point (java.awt.Point)5 ConfigureManager (jmri.ConfigureManager)4 AbstractXmlAdapter (jmri.configurexml.AbstractXmlAdapter)4 XmlAdapter (jmri.configurexml.XmlAdapter)4 DataElement (pcgen.core.doomsdaybook.DataElement)4 Block (jmri.Block)3 Memory (jmri.Memory)3 SignalHead (jmri.SignalHead)3 Turnout (jmri.Turnout)3 Portal (jmri.jmrit.logix.Portal)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SortOrder (javax.swing.SortOrder)2