use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class PositionableLabelXml method loadIcon.
public NamedIcon loadIcon(PositionableLabel l, String attrName, Element element, String name, Editor ed) {
NamedIcon icon = getNamedIcon(attrName, element, name, ed);
if (icon != null) {
try {
int deg = 0;
double scale = 1.0;
Element elem = element.getChild(attrName);
if (elem != null) {
Attribute a = elem.getAttribute("degrees");
if (a != null) {
deg = a.getIntValue();
}
a = elem.getAttribute("scale");
if (a != null) {
scale = elem.getAttribute("scale").getDoubleValue();
}
icon.setLoad(deg, scale, l);
if (deg == 0) {
// "rotate" attribute is JMRI 2.9.3 and before
a = elem.getAttribute("rotate");
if (a != null) {
int rotation = a.getIntValue();
// 2.9.3 and before, only unscaled icons rotate
if (scale == 1.0) {
icon.setRotation(rotation, l);
}
}
// "rotation" element is JMRI 2.9.4 and after
Element e = elem.getChild("rotation");
if (e != null) {
// ver 2.9.4 allows orthogonal rotations of scaled icons
int rotation = Integer.parseInt(e.getText());
icon.setRotation(rotation, l);
}
}
}
} catch (org.jdom2.DataConversionException dce) {
}
}
return icon;
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class PositionableLabelXml method storeCommonAttributes.
/**
* Default implementation for storing the common contents of an Icon
*
* @param p the icon to store
* @param element the XML representation of the icon
*/
public void storeCommonAttributes(Positionable p, Element element) {
element.setAttribute("x", "" + p.getX());
element.setAttribute("y", "" + p.getY());
element.setAttribute("level", String.valueOf(p.getDisplayLevel()));
element.setAttribute("forcecontroloff", !p.isControlling() ? "true" : "false");
element.setAttribute("hidden", p.isHidden() ? "yes" : "no");
element.setAttribute("positionable", p.isPositionable() ? "true" : "false");
element.setAttribute("showtooltip", p.showTooltip() ? "true" : "false");
element.setAttribute("editable", p.isEditable() ? "true" : "false");
ToolTip tip = p.getTooltip();
String txt = tip.getText();
if (txt != null) {
// was written as "toolTip" 3.5.1 and before
Element elem = new Element("tooltip").addContent(txt);
element.addContent(elem);
}
if (p.getDegrees() != 0) {
element.setAttribute("degrees", "" + p.getDegrees());
}
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class PositionableLabelXml method getNamedIcon.
protected NamedIcon getNamedIcon(String childName, Element element, String name, Editor ed) {
NamedIcon icon = null;
Element elem = element.getChild(childName);
if (elem != null) {
String iconName = elem.getAttribute("url").getValue();
icon = NamedIcon.getIconByName(iconName);
if (icon == null) {
icon = ed.loadFailed(name, iconName);
if (icon == null) {
log.info(name + " removed for url= " + iconName);
}
}
} else {
log.debug("getNamedIcon: child element \"" + childName + "\" not found in element " + element.getName());
}
return icon;
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class SensorIconXml 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) {
Editor ed = (Editor) o;
SensorIcon l;
String name;
Attribute attr = element.getAttribute("sensor");
if (attr == null) {
log.error("incorrect information for sensor; must use sensor name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
}
_icon = true;
if (element.getAttribute("icon") != null) {
String yesno = element.getAttribute("icon").getValue();
if ((yesno != null) && (!yesno.equals(""))) {
if (yesno.equals("yes")) {
_icon = true;
} else if (yesno.equals("no")) {
_icon = false;
}
}
}
if (_icon) {
l = new SensorIcon(new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"), ed);
} else {
l = new SensorIcon(" ", ed);
}
int rotation = 0;
try {
rotation = element.getAttribute("rotate").getIntValue();
} catch (org.jdom2.DataConversionException e) {
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
if (loadSensorIcon("active", rotation, l, element, name, ed) == null) {
return;
}
if (loadSensorIcon("inactive", rotation, l, element, name, ed) == null) {
return;
}
if (loadSensorIcon("unknown", rotation, l, element, name, ed) == null) {
return;
}
if (loadSensorIcon("inconsistent", rotation, l, element, name, ed) == null) {
return;
}
Element elem = element.getChild("iconmaps");
if (elem != null) {
attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
Attribute a = element.getAttribute("momentary");
if ((a != null) && a.getValue().equals("true")) {
l.setMomentary(true);
} else {
l.setMomentary(false);
}
loadTextInfo(l, element);
l.setSensor(name);
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SENSORS, element);
if (l.isIcon() && l.getText() != null) {
l.setOpaque(false);
}
}
use of org.neo4j.ogm.domain.gh806.Element in project JMRI by JMRI.
the class SensorIconXml method store.
/**
* Default implementation for storing the contents of a SensorIcon
*
* @param o Object to store, of type SensorIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
SensorIcon p = (SensorIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("sensoricon");
element.setAttribute("sensor", p.getNamedSensor().getName());
storeCommonAttributes(p, element);
element.setAttribute("momentary", p.getMomentary() ? "true" : "false");
element.setAttribute("icon", p.isIcon() ? "yes" : "no");
storeIconInfo(p, element);
storeTextInfo(p, element);
element.setAttribute("class", "jmri.jmrit.display.configurexml.SensorIconXml");
return element;
}
Aggregations