use of jmri.jmrit.display.MultiSensorIcon 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.MultiSensorIcon in project JMRI by JMRI.
the class MultiSensorIconXml method store.
/**
* Default implementation for storing the contents of a MultiSensorIcon
*
* @param o Object to store, of type MultiSensorIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
MultiSensorIcon p = (MultiSensorIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("multisensoricon");
storeCommonAttributes(p, element);
element.setAttribute("updown", p.getUpDown() ? "true" : "false");
for (int i = 0; i < p.getNumEntries(); i++) {
Element e = storeIcon("active", p.getSensorIcon(i));
e.setAttribute("sensor", p.getSensorName(i));
element.addContent(e);
}
element.addContent(storeIcon("inactive", p.getInactiveIcon()));
element.addContent(storeIcon("unknown", p.getUnknownIcon()));
element.addContent(storeIcon("inconsistent", p.getInconsistentIcon()));
element.setAttribute("class", "jmri.jmrit.display.configurexml.MultiSensorIconXml");
return element;
}
use of jmri.jmrit.display.MultiSensorIcon in project JMRI by JMRI.
the class MultiSensorIconFrame method make.
void make() {
MultiSensorIcon m = new MultiSensorIcon(layoutEditor);
m.setUnknownIcon(defaultIcons.getIcon(0));
m.setInconsistentIcon(defaultIcons.getIcon(1));
m.setInactiveIcon(defaultIcons.getIcon(2));
for (int i = 0; i < content.getComponentCount(); i++) {
Entry e = (Entry) content.getComponent(i);
if (e.sensor.getText().trim().equals("")) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("Error19", i + 1), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
isEmpty = 1;
// Keep Panel open to edit entry
return;
}
m.addEntry(e.sensor.getText(), e.ed.getIcon(0));
}
m.setUpDown(updown.isSelected());
m.setDisplayLevel(jmri.jmrit.display.Editor.SENSORS);
layoutEditor.addMultiSensor(m);
}
Aggregations