use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class PositionFile method getReceiverPosition.
/**
* Get the nth receiver position in the file.
*
* @return null if not present
*/
public Point3d getReceiverPosition(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 ex) {
log.error("in getReceiverPosition", ex);
}
if (num == n) {
return positionFromElement(e.getChild("position"));
}
}
return null;
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class PositionFile method getReceiverActive.
/**
* Get the nth receiver active state in the file.
*
* @return true if not present
*/
public boolean getReceiverActive(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 ex) {
log.error("in getReceiverActive", ex);
}
if (num != n) {
continue;
}
a = e.getAttribute("active");
if (a == null) {
// default value
return true;
}
if (a.getValue().equals("false")) {
return false;
}
return true;
}
return true;
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class BlockContentsIconXml method load.
/**
* Load, starting with the BlockContentsIcon element, then all the
* value-icon pairs
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
Editor ed = null;
BlockContentsIcon l;
if (o instanceof LayoutEditor) {
ed = (LayoutEditor) o;
l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon(" ", (LayoutEditor) ed);
} else if (o instanceof jmri.jmrit.display.Editor) {
ed = (Editor) o;
l = new BlockContentsIcon("", ed);
} else {
log.error("Unrecognizable class - " + o.getClass().getName());
return;
}
String name;
Attribute attr = element.getAttribute("blockcontents");
if (attr == null) {
log.error("incorrect information for a block contents; must use block name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
}
loadTextInfo(l, element);
Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
if (m != null) {
l.setBlock(name);
} else {
log.error("Block named '" + attr.getValue() + "' not found.");
ed.loadFailed();
}
Attribute a = element.getAttribute("selectable");
if (a != null && a.getValue().equals("yes")) {
l.setSelectable(true);
} else {
l.setSelectable(false);
}
// get the icon pairs
List<Element> items = element.getChildren("blockstate");
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
String iconName = item.getAttribute("icon").getValue();
NamedIcon icon = NamedIcon.getIconByName(iconName);
if (icon == null) {
icon = ed.loadFailed("Memory " + name, iconName);
if (icon == null) {
log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
}
}
if (icon != null) {
String keyValue = item.getAttribute("value").getValue();
l.addKeyAndIcon(icon, keyValue);
}
}
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.MEMORIES, element);
int x = 0;
int y = 0;
try {
x = element.getAttribute("x").getIntValue();
y = element.getAttribute("y").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert positional attribute");
}
l.setOriginalLocation(x, y);
l.displayState();
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class MemoryComboIconXml method load.
/**
* Load, starting with the memoryComboIcon element, then all the value-icon
* pairs
*
* @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 p = (Editor) o;
Element elem = element.getChild("itemList");
List<Element> list = elem.getChildren("item");
String[] items = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
Element e = list.get(i);
String item = e.getText();
try {
int idx = e.getAttribute("index").getIntValue();
items[idx] = item;
} catch (org.jdom2.DataConversionException ex) {
log.error("failed to convert ComboBoxIcon index attribute");
if (items[i] == null) {
items[i] = item;
}
}
}
MemoryComboIcon l = new MemoryComboIcon(p, items);
loadTextInfo(l, element);
String name;
Attribute attr = element.getAttribute("memory");
if (attr == null) {
log.error("incorrect information for a memory location; must use memory name");
p.loadFailed();
return;
} else {
name = attr.getValue();
}
Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
if (m != null) {
l.setMemory(name);
} else {
log.error("Memory named '" + attr.getValue() + "' not found.");
p.loadFailed();
return;
}
p.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.MEMORIES, element);
}
use of org.jdom2.DataConversionException in project JMRI by JMRI.
the class LinkingLabelXml method load.
/**
* Create LinkingLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
LinkingLabel l = null;
String url = element.getChild("url").getText();
// get object class and determine editor being used
Editor editor = (Editor) o;
if (element.getAttribute("icon") != null) {
NamedIcon icon = null;
String name = element.getAttribute("icon").getValue();
// if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
if (name.equals("yes")) {
icon = getNamedIcon("icon", element, "LinkingLabel ", editor);
} else {
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = editor.loadFailed("LinkingLabel", name);
if (icon == null) {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
}
}
// abort if name != yes and have null icon
if (icon == null && !name.equals("yes")) {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
l = new LinkingLabel(icon, editor, url);
// no text
l.setPopupUtility(null);
try {
Attribute a = element.getAttribute("rotate");
if (a != null && icon != null) {
int rotation = element.getAttribute("rotate").getIntValue();
icon.setRotation(rotation, l);
}
} catch (org.jdom2.DataConversionException e) {
}
if (name.equals("yes")) {
NamedIcon nIcon = loadIcon(l, "icon", element, "LinkingLabel ", editor);
if (nIcon != null) {
l.updateIcon(nIcon);
} else {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
} else {
l.updateIcon(icon);
}
//l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
} else if (element.getAttribute("text") != null) {
l = new LinkingLabel(element.getAttribute("text").getValue(), editor, url);
loadTextInfo(l, element);
} else {
log.error("LinkingLabel is null!");
if (log.isDebugEnabled()) {
java.util.List<Attribute> attrs = element.getAttributes();
log.debug("\tElement Has " + attrs.size() + " Attributes:");
for (int i = 0; i < attrs.size(); i++) {
Attribute a = attrs.get(i);
log.debug("\t\t" + a.getName() + " = " + a.getValue());
}
java.util.List<Element> kids = element.getChildren();
log.debug("\tElementHas " + kids.size() + " children:");
for (int i = 0; i < kids.size(); i++) {
Element e = kids.get(i);
log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
}
}
editor.loadFailed();
return;
}
editor.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.LABELS, element);
}
Aggregations