use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class SignalMastIconXml method load.
/**
* Create a SignalMastIcon, then add
*
* @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;
SignalMastIcon l = new SignalMastIcon(ed);
String name;
Attribute attr;
/*
* We need to set the rotation and scaling first, prior to setting the
* signalmast, otherwise we end up in a situation where by the icons do
* not get rotated or scaled correctly.
**/
try {
int rotation = 0;
double scale = 1.0;
// former attribute name.
attr = element.getAttribute("rotation");
if (attr != null) {
rotation = attr.getIntValue();
}
attr = element.getAttribute("degrees");
if (attr != null) {
rotation = attr.getIntValue();
}
l.rotate(rotation);
attr = element.getAttribute("scale");
String text = "Error attr null";
if (attr != null) {
scale = attr.getDoubleValue();
text = attr.getValue();
}
l.setScale(scale);
if (log.isDebugEnabled()) {
log.debug("Load SignalMast rotation= " + rotation + " scale= " + scale + " attr text= " + text);
}
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert rotation or scale attribute");
}
attr = element.getAttribute("signalmast");
if (attr == null) {
log.error("incorrect information for signal mast; must use signalmast name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
if (log.isDebugEnabled()) {
log.debug("Load SignalMast " + name);
}
}
SignalMast sh = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
if (sh != null) {
l.setSignalMast(name);
} else {
log.error("SignalMast named '" + attr.getValue() + "' not found.");
ed.loadFailed();
// return;
}
attr = element.getAttribute("imageset");
if (attr != null) {
l.useIconSet(attr.getValue());
}
attr = element.getAttribute("imageset");
if (attr != null) {
l.useIconSet(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);
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class SensorIconXml method loadSensorTextState.
private void loadSensorTextState(String state, SensorIcon l, Element element) {
String name = null;
Color clrText = null;
Color clrBackground = null;
List<Element> textList = element.getChildren(state.toLowerCase() + "Text");
if (log.isDebugEnabled()) {
log.debug("Found " + textList.size() + " " + state + "Text objects");
}
if (textList.size() > 0) {
Element elem = textList.get(0);
try {
name = elem.getAttribute("text").getValue();
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
try {
int red = elem.getAttribute("red").getIntValue();
int blue = elem.getAttribute("blue").getIntValue();
int green = elem.getAttribute("green").getIntValue();
clrText = new Color(red, green, blue);
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse color attributes!");
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
try {
int red = elem.getAttribute("redBack").getIntValue();
int blue = elem.getAttribute("blueBack").getIntValue();
int green = elem.getAttribute("greenBack").getIntValue();
clrBackground = new Color(red, green, blue);
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse color attributes!");
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
} else {
if (element.getAttribute(state.toLowerCase()) != null) {
name = element.getAttribute(state.toLowerCase()).getValue();
}
try {
int red = element.getAttribute("red" + state).getIntValue();
int blue = element.getAttribute("blue" + state).getIntValue();
int green = element.getAttribute("green" + state).getIntValue();
clrText = new Color(red, green, blue);
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse color attributes!");
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
try {
int red = element.getAttribute("red" + state + "Back").getIntValue();
int blue = element.getAttribute("blue" + state + "Back").getIntValue();
int green = element.getAttribute("green" + state + "Back").getIntValue();
clrBackground = new Color(red, green, blue);
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse color attributes!");
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
}
if (state.equals("Active")) {
if (name != null) {
l.setActiveText(name);
}
if (clrText != null) {
l.setTextActive(clrText);
}
if (clrBackground != null) {
l.setBackgroundActive(clrBackground);
}
} else if (state.equals("InActive")) {
if (name != null) {
l.setInactiveText(name);
}
if (clrText != null) {
l.setTextInActive(clrText);
}
if (clrBackground != null) {
l.setBackgroundInActive(clrBackground);
}
} else if (state.equals("Unknown")) {
if (name != null) {
l.setUnknownText(name);
}
if (clrText != null) {
l.setTextUnknown(clrText);
}
if (clrBackground != null) {
l.setBackgroundUnknown(clrBackground);
}
} else if (state.equals("Inconsistent")) {
if (name != null) {
l.setInconsistentText(name);
}
if (clrText != null) {
l.setTextInconsistent(clrText);
}
if (clrBackground != null) {
l.setBackgroundInconsistent(clrBackground);
}
}
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class LayoutSlipXml method load.
/**
* Load, starting with the LayoutSlip element, then all the other data
*
* @param element Top level Element to unpack.
* @param o LayoutEditor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
LayoutEditor p = (LayoutEditor) o;
// get center point
String name = element.getAttribute("ident").getValue();
double x = 0.0;
double y = 0.0;
try {
x = element.getAttribute("xcen").getFloatValue();
y = element.getAttribute("ycen").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert layoutslip center attribute");
}
int type = LayoutSlip.SINGLE_SLIP;
try {
type = element.getAttribute("slipType").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert layoutslip type attribute");
}
// create the new LayoutSlip
LayoutSlip l = new LayoutSlip(name, new Point2D.Double(x, y), 0.0, p, type);
// get remaining attributes
Attribute a = element.getAttribute("blockname");
if (a != null) {
l.tBlockName = a.getValue();
}
a = element.getAttribute("connectaname");
if (a != null) {
l.connectAName = a.getValue();
}
a = element.getAttribute("connectbname");
if (a != null) {
l.connectBName = a.getValue();
}
a = element.getAttribute("connectcname");
if (a != null) {
l.connectCName = a.getValue();
}
a = element.getAttribute("connectdname");
if (a != null) {
l.connectDName = a.getValue();
}
l.setSignalA1Name(getElement(element, "signala1name"));
l.setSignalB1Name(getElement(element, "signalb1name"));
l.setSignalC1Name(getElement(element, "signalc1name"));
l.setSignalD1Name(getElement(element, "signald1name"));
l.setSignalA2Name(getElement(element, "signala2name"));
l.setSignalB2Name(getElement(element, "signalb2name"));
l.setSignalC2Name(getElement(element, "signalc2name"));
l.setSignalD2Name(getElement(element, "signald2name"));
try {
x = element.getAttribute("xa").getFloatValue();
y = element.getAttribute("ya").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert LayoutSlip a coords attribute");
}
l.setCoordsA(new Point2D.Double(x, y));
try {
x = element.getAttribute("xb").getFloatValue();
y = element.getAttribute("yb").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert LayoutSlip b coords attribute");
}
l.setCoordsB(new Point2D.Double(x, y));
l.setSignalAMast(getElement(element, "signalAMast"));
l.setSignalBMast(getElement(element, "signalBMast"));
l.setSignalCMast(getElement(element, "signalCMast"));
l.setSignalDMast(getElement(element, "signalDMast"));
l.setSensorA(getElement(element, "sensorA"));
l.setSensorB(getElement(element, "sensorB"));
l.setSensorC(getElement(element, "sensorC"));
l.setSensorD(getElement(element, "sensorD"));
l.setTurnout(getElement(element, "turnout"));
l.setTurnoutB(getElement(element, "turnoutB"));
if (element.getChild("states") != null) {
Element state = element.getChild("states");
if (state.getChild("A-C") != null) {
Element ac = state.getChild("A-C");
l.setTurnoutStates(LayoutSlip.STATE_AC, ac.getChild("turnout").getText(), ac.getChild("turnoutB").getText());
}
if (state.getChild("A-D") != null) {
Element ad = state.getChild("A-D");
l.setTurnoutStates(LayoutSlip.STATE_AD, ad.getChild("turnout").getText(), ad.getChild("turnoutB").getText());
}
if (state.getChild("B-D") != null) {
Element bd = state.getChild("B-D");
l.setTurnoutStates(LayoutSlip.STATE_BD, bd.getChild("turnout").getText(), bd.getChild("turnoutB").getText());
}
if (state.getChild("B-C") != null) {
Element bc = state.getChild("B-C");
l.setTurnoutStates(LayoutSlip.STATE_BC, bc.getChild("turnout").getText(), bc.getChild("turnoutB").getText());
}
}
p.slipList.add(l);
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class WarrantManagerXml method loadThrottleCommand.
static ThrottleSetting loadThrottleCommand(Element elem) {
long time = 0;
try {
time = elem.getAttribute("time").getLongValue();
} catch (org.jdom2.DataConversionException dce) {
}
Attribute attr = elem.getAttribute("command");
String command = null;
if (attr != null)
command = attr.getValue();
attr = elem.getAttribute("value");
String value = null;
if (attr != null)
value = attr.getValue();
attr = elem.getAttribute("block");
String block = null;
if (attr != null)
block = attr.getValue();
return new ThrottleSetting(time, command, value, block);
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class AbstractServerPreferences method load.
public void load(Element child) {
Attribute a;
a = child.getAttribute(PORT);
if (a != null) {
try {
this.setPort(a.getIntValue());
this.asLoadedPort = this.getPort();
} catch (DataConversionException e) {
this.setPort(getDefaultPort());
log.error("Unable to read port. Setting to default value.", e);
}
}
}
Aggregations