Search in sources :

Example 61 with DataConversionException

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

the class PositionFile method getReceiverMin.

/**
     * Get the nth receiver min time.
     *
     * @return 0 if not present
     */
public int getReceiverMin(int n) {
    List<Element> kids = root.getChildren("receiver");
    for (int i = 0; i < kids.size(); i++) {
        Element e = kids.get(i);
        Attribute a = e.getAttribute("number");
        if (a == null) {
            continue;
        }
        int num = -1;
        try {
            num = a.getIntValue();
        } catch (org.jdom2.DataConversionException ex1) {
            log.error("in getReceiverMin", ex1);
        }
        if (num != n) {
            continue;
        }
        a = e.getAttribute("mintime");
        if (a == null) {
            // default value
            return 0;
        }
        try {
            return a.getIntValue();
        } catch (org.jdom2.DataConversionException ex2) {
            return 0;
        }
    }
    return 0;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 62 with DataConversionException

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

the class PollingFile method getPollValues.

public void getPollValues() {
    Element e = root.getChild("poll");
    Attribute a = e.getAttribute("active");
    boolean poll = false;
    if (a != null && a.getValue().equals("true")) {
        poll = true;
    }
    Engine.instance().setPolling(poll);
    a = e.getAttribute("interval");
    int value = 0;
    try {
        if (a != null) {
            value = a.getIntValue();
        }
    } catch (org.jdom2.DataConversionException ex) {
        log.error("in getPollValues", ex);
    }
    Engine.instance().setPollingInterval(value);
    Engine.instance().setDirectPollMode();
    a = e.getAttribute("bscpoll");
    boolean bscpoll = false;
    if (a != null && a.getValue().equals("true")) {
        bscpoll = true;
    }
    if (bscpoll) {
        Engine.instance().setBscPollMode();
    }
    a = e.getAttribute("throttlepoll");
    boolean throttlepoll = false;
    if (a != null && a.getValue().equals("true")) {
        throttlepoll = true;
    }
    if (throttlepoll) {
        Engine.instance().setThrottlePollMode();
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 63 with DataConversionException

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

the class JmriUserPreferencesManager method readWindowDetails.

private void readWindowDetails() {
    // TODO: COMPLETE!
    Element element = this.readElement(WINDOWS_ELEMENT, WINDOWS_NAMESPACE);
    if (element != null) {
        element.getChildren("window").stream().forEach((window) -> {
            String reference = window.getAttributeValue("class");
            log.debug("Reading window details for {}", reference);
            try {
                if (window.getAttribute("locX") != null && window.getAttribute("locX") != null) {
                    double x = window.getAttribute("locX").getDoubleValue();
                    double y = window.getAttribute("locY").getDoubleValue();
                    this.setWindowLocation(reference, new java.awt.Point((int) x, (int) y));
                }
                if (window.getAttribute("width") != null && window.getAttribute("height") != null) {
                    double width = window.getAttribute("width").getDoubleValue();
                    double height = window.getAttribute("height").getDoubleValue();
                    this.setWindowSize(reference, new java.awt.Dimension((int) width, (int) height));
                }
            } catch (DataConversionException ex) {
                log.error("Unable to read dimensions of window \"{}\"", reference);
            }
            if (window.getChild("properties") != null) {
                window.getChild("properties").getChildren().stream().forEach((property) -> {
                    String key = property.getChild("key").getText();
                    try {
                        Class<?> cl = Class.forName(property.getChild("value").getAttributeValue("class"));
                        Constructor<?> ctor = cl.getConstructor(new Class<?>[] { String.class });
                        Object value = ctor.newInstance(new Object[] { property.getChild("value").getText() });
                        log.debug("Setting property {} for {} to {}", key, reference, value);
                        this.setProperty(reference, key, value);
                    } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
                        log.error("Unable to retrieve property \"{}\" for window \"{}\"", key, reference);
                    } catch (NullPointerException ex) {
                        // null properties do not get set
                        log.debug("Property \"{}\" for window \"{}\" is null", key, reference);
                    }
                });
            }
        });
    }
}
Also used : Element(org.jdom2.Element) Point(java.awt.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) Dimension(java.awt.Dimension) DataConversionException(org.jdom2.DataConversionException)

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