use of org.jdom2.Attribute 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);
}
}
}
use of org.jdom2.Attribute in project JMRI by JMRI.
the class DefaultCatalogTreeManagerXml method loadCatalogTrees.
/**
* Utility method to load the individual CatalogTree objects.
*
* @param catalogTrees element containing trees
*/
public void loadCatalogTrees(Element catalogTrees) {
List<Element> catList = catalogTrees.getChildren("catalogTree");
if (log.isDebugEnabled()) {
log.debug("loadCatalogTrees: found " + catList.size() + " CatalogTree objects");
}
CatalogTreeManager mgr = InstanceManager.getDefault(jmri.CatalogTreeManager.class);
for (int i = 0; i < catList.size(); i++) {
Element elem = catList.get(i);
Attribute attr = elem.getAttribute("systemName");
if (attr == null) {
log.warn("unexpected null systemName. elem= " + elem + ", attrs= " + elem.getAttributes());
continue;
}
String sysName = attr.getValue();
String userName;
attr = elem.getAttribute("userName");
if (attr == null) {
log.warn("unexpected null userName. attrs= " + elem.getAttributes());
continue;
} else {
userName = attr.getValue();
}
DefaultTreeModel ct = (DefaultTreeModel) mgr.getBySystemName(sysName);
if (ct != null) {
// tree already registered
continue;
}
ct = (DefaultTreeModel) mgr.newCatalogTree(sysName, userName);
if (log.isDebugEnabled()) {
log.debug("CatalogTree: sysName= " + sysName + ", userName= " + userName);
}
CatalogTreeNode root = (CatalogTreeNode) ct.getRoot();
elem = elem.getChild("node");
loadNode(elem, root, ct);
}
}
use of org.jdom2.Attribute 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);
}
use of org.jdom2.Attribute 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.Attribute in project JMRI by JMRI.
the class LayoutEditorXml method store.
/**
* Default implementation for storing the contents of a LayoutEditor
*
* @param o Object to store, of type LayoutEditor
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LayoutEditor p = (LayoutEditor) o;
Element panel = new Element("LayoutEditor");
panel.setAttribute("class", getClass().getName());
panel.setAttribute("name", p.getLayoutName());
panel.setAttribute("x", "" + p.getUpperLeftX());
panel.setAttribute("y", "" + p.getUpperLeftY());
// From this version onwards separate sizes for window and panel are stored the
// following two statements allow files written here to be read in 2.2 and before
panel.setAttribute("height", "" + p.getLayoutHeight());
panel.setAttribute("width", "" + p.getLayoutWidth());
// From this version onwards separate sizes for window and panel are stored
panel.setAttribute("windowheight", "" + p.getWindowHeight());
panel.setAttribute("windowwidth", "" + p.getWindowWidth());
panel.setAttribute("panelheight", "" + p.getLayoutHeight());
panel.setAttribute("panelwidth", "" + p.getLayoutWidth());
// deprecated
panel.setAttribute("sliders", "" + (p.getScroll() ? "yes" : "no"));
panel.setAttribute("scrollable", "" + p.getScrollable());
panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
panel.setAttribute("positionable", "" + (p.allPositionable() ? "yes" : "no"));
panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
panel.setAttribute("animating", "" + (p.isAnimating() ? "yes" : "no"));
panel.setAttribute("showhelpbar", "" + (p.getShowHelpBar() ? "yes" : "no"));
panel.setAttribute("drawgrid", "" + (p.getDrawGrid() ? "yes" : "no"));
panel.setAttribute("snaponadd", "" + (p.getSnapOnAdd() ? "yes" : "no"));
panel.setAttribute("snaponmove", "" + (p.getSnapOnMove() ? "yes" : "no"));
panel.setAttribute("antialiasing", "" + (p.getAntialiasingOn() ? "yes" : "no"));
panel.setAttribute("turnoutcircles", "" + (p.getTurnoutCircles() ? "yes" : "no"));
panel.setAttribute("tooltipsnotedit", "" + (p.getTooltipsNotEdit() ? "yes" : "no"));
panel.setAttribute("tooltipsinedit", "" + (p.getTooltipsInEdit() ? "yes" : "no"));
panel.setAttribute("mainlinetrackwidth", "" + p.getMainlineTrackWidth());
panel.setAttribute("xscale", Float.toString((float) p.getXScale()));
panel.setAttribute("yscale", Float.toString((float) p.getYScale()));
panel.setAttribute("sidetrackwidth", "" + p.getSideTrackWidth());
panel.setAttribute("defaulttrackcolor", p.getDefaultTrackColor());
panel.setAttribute("defaultoccupiedtrackcolor", p.getDefaultOccupiedTrackColor());
panel.setAttribute("defaultalternativetrackcolor", p.getDefaultAlternativeTrackColor());
panel.setAttribute("defaulttextcolor", p.getDefaultTextColor());
panel.setAttribute("turnoutcirclecolor", p.getTurnoutCircleColor());
panel.setAttribute("turnoutcirclesize", "" + p.getTurnoutCircleSize());
panel.setAttribute("turnoutdrawunselectedleg", (p.getTurnoutDrawUnselectedLeg() ? "yes" : "no"));
panel.setAttribute("turnoutbx", Float.toString((float) p.getTurnoutBX()));
panel.setAttribute("turnoutcx", Float.toString((float) p.getTurnoutCX()));
panel.setAttribute("turnoutwid", Float.toString((float) p.getTurnoutWid()));
panel.setAttribute("xoverlong", Float.toString((float) p.getXOverLong()));
panel.setAttribute("xoverhwid", Float.toString((float) p.getXOverHWid()));
panel.setAttribute("xovershort", Float.toString((float) p.getXOverShort()));
panel.setAttribute("autoblkgenerate", "" + (p.getAutoBlockAssignment() ? "yes" : "no"));
if (p.getBackgroundColor() != null) {
panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
}
panel.setAttribute("gridSize", "" + p.getGridSize());
panel.setAttribute("gridSize2nd", "" + p.getGridSize2nd());
p.resetDirty();
panel.setAttribute("openDispatcher", p.getOpenDispatcherOnLoad() ? "yes" : "no");
panel.setAttribute("useDirectTurnoutControl", p.getDirectTurnoutControl() ? "yes" : "no");
// note: moving zoom attribute into per-window user preference
//panel.setAttribute("zoom", Double.toString(p.getZoom()));
// include contents (Icons and Labels)
List<Positionable> contents = p.getContents();
int num = contents.size();
if (num > 0) {
for (int i = 0; i < num; i++) {
Positionable sub = contents.get(i);
if (sub != null && sub.storeItem()) {
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel contents element: " + e);
}
} else {
log.warn("Null entry found when storing panel contents.");
}
}
}
// include LayoutTurnouts
num = p.turnoutList.size();
if (log.isDebugEnabled()) {
log.debug("N layoutturnout elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.turnoutList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel layoutturnout element: " + e);
}
}
}
// include TrackSegments
num = p.trackList.size();
if (log.isDebugEnabled()) {
log.debug("N tracksegment elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.trackList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel tracksegment element: " + e);
}
}
}
// include PositionablePoints
num = p.pointList.size();
if (log.isDebugEnabled()) {
log.debug("N positionablepoint elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.pointList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel positionalpoint element: " + e);
}
}
}
// include LevelXings
num = p.xingList.size();
if (log.isDebugEnabled()) {
log.debug("N levelxing elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.xingList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel levelxing element: " + e);
}
}
}
// include LayoutSlips
num = p.slipList.size();
if (log.isDebugEnabled()) {
log.debug("N layoutSlip elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.slipList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel layoutSlip element: " + e);
}
}
}
// include LayoutTurntables
num = p.turntableList.size();
if (log.isDebugEnabled()) {
log.debug("N turntable elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.turntableList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel turntable element: " + e);
}
}
}
return panel;
}
Aggregations