use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class MultiSensorIconXml method load.
/**
* Create a PositionableLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o an Editor an Object
*/
@Override
public void load(Element element, Object o) {
Editor pe = (Editor) o;
MultiSensorIcon l = new MultiSensorIcon(pe);
// create the objects
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
}
NamedIcon icon = loadSensorIcon("inactive", rotation, l, element, pe);
if (icon != null) {
l.setInactiveIcon(icon);
} else {
return;
}
icon = loadSensorIcon("unknown", rotation, l, element, pe);
if (icon != null) {
l.setUnknownIcon(icon);
} else {
return;
}
icon = loadSensorIcon("inconsistent", rotation, l, element, pe);
if (icon != null) {
l.setInconsistentIcon(icon);
} else {
return;
}
Attribute a = element.getAttribute("updown");
if ((a != null) && a.getValue().equals("true")) {
l.setUpDown(true);
} else {
l.setUpDown(false);
}
// get the icon pairs & load
List<Element> items = element.getChildren();
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
if (item.getAttribute("sensor") != null) {
String sensor = item.getAttribute("sensor").getValue();
if (item.getAttribute("url") != null) {
String name = item.getAttribute("url").getValue();
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = pe.loadFailed("MultiSensor \"" + l.getNameString() + "\" ", name);
if (icon == null) {
log.error("MultiSensor \"" + l.getNameString() + "\" removed for url= " + name);
return;
}
}
try {
int deg = 0;
a = item.getAttribute("degrees");
if (a != null) {
deg = a.getIntValue();
double scale = 1.0;
a = item.getAttribute("scale");
if (a != null) {
scale = item.getAttribute("scale").getDoubleValue();
}
icon.setLoad(deg, scale, l);
}
if (deg == 0) {
a = item.getAttribute("rotate");
if (a != null) {
rotation = a.getIntValue();
icon.setRotation(rotation, l);
}
}
} catch (org.jdom2.DataConversionException dce) {
}
} else {
String name = item.getAttribute("icon").getValue();
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = pe.loadFailed("MultiSensor \"" + l.getNameString(), name);
if (icon == null) {
log.info("MultiSensor \"" + l.getNameString() + " removed for url= " + name);
return;
}
}
if (rotation != 0) {
icon.setRotation(rotation, l);
}
}
l.addEntry(sensor, icon);
}
}
pe.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SENSORS, element);
}
use of jmri.jmrit.display.Editor 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 jmri.jmrit.display.Editor in project JMRI by JMRI.
the class MemorySpinnerIconXml method load.
/**
* Load, starting with the memoryicon element, then all the value-icon pairs
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor p = (Editor) o;
MemorySpinnerIcon l = new MemorySpinnerIcon(p);
l.setMemory(element.getAttribute("memory").getValue());
loadTextInfo(l, element);
p.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.MEMORIES, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class ReporterIconXml 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;
ReporterIcon l = new ReporterIcon(ed);
loadTextInfo(l, element);
l.setReporter(jmri.InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(element.getAttribute("reporter").getValue()));
l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.REPORTERS, element);
}
use of jmri.jmrit.display.Editor in project JMRI by JMRI.
the class PositionableRectangleXml method load.
/**
* Create a PositionableShape, 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
Editor ed = (Editor) o;
PositionableRectangle ps = new PositionableRectangle(ed);
Element elem = element.getChild("size");
ps.setWidth(getInt(elem, "width"));
ps.setHeight(getInt(elem, "height"));
ed.putItem(ps);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(ps, Editor.MARKERS, element);
}
Aggregations