use of org.eclipse.xtext.parsetree.impl.bug305397.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.eclipse.xtext.parsetree.impl.bug305397.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.eclipse.xtext.parsetree.impl.bug305397.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.eclipse.xtext.parsetree.impl.bug305397.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;
}
use of org.eclipse.xtext.parsetree.impl.bug305397.Element in project JMRI by JMRI.
the class RpsPositionIconXml method store.
/**
* Default implementation for storing the contents of a RpsPositionIcon
*
* @param o Object to store, of type RpsPositionIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
RpsPositionIcon p = (RpsPositionIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("sensoricon");
storeCommonAttributes(p, element);
// include contents
element.setAttribute("active", p.getActiveIcon().getURL());
element.setAttribute("error", p.getErrorIcon().getURL());
element.setAttribute("rotate", String.valueOf(p.getActiveIcon().getRotation()));
element.setAttribute("momentary", p.getMomentary() ? "true" : "false");
element.setAttribute("sxscale", "" + p.getXScale());
element.setAttribute("syscale", "" + p.getYScale());
element.setAttribute("sxorigin", "" + p.getXOrigin());
element.setAttribute("syorigin", "" + p.getYOrigin());
element.setAttribute("showid", p.isShowID() ? "true" : "false");
if (p.getFilter() != null) {
element.setAttribute("filter", "" + p.getFilter());
}
element.addContent(storeIcon("active", p.getActiveIcon()));
element.addContent(storeIcon("error", p.getErrorIcon()));
element.setAttribute("class", "jmri.jmrit.display.configurexml.RpsPositionIconXml");
return element;
}
Aggregations