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;
}
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();
}
}
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);
}
});
}
});
}
}
Aggregations