use of jmri.jmrit.display.SignalHeadIcon in project JMRI by JMRI.
the class SignalHeadIconXml method store.
/**
* Default implementation for storing the contents of a SignalHeadIcon
*
* @param o Object to store, of type SignalHeadIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
SignalHeadIcon p = (SignalHeadIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("signalheadicon");
element.setAttribute("signalhead", "" + p.getNamedSignalHead().getName());
storeCommonAttributes(p, element);
element.setAttribute("clickmode", "" + p.getClickMode());
element.setAttribute("litmode", "" + p.getLitMode());
Element elem = new Element("icons");
NamedIcon icon = p.getIcon(rbean.getString("SignalHeadStateHeld"));
if (icon != null) {
elem.addContent(storeIcon("held", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateDark"));
if (icon != null) {
elem.addContent(storeIcon("dark", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateRed"));
if (icon != null) {
elem.addContent(storeIcon("red", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateYellow"));
if (icon != null) {
elem.addContent(storeIcon("yellow", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateGreen"));
if (icon != null) {
elem.addContent(storeIcon("green", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateLunar"));
if (icon != null) {
elem.addContent(storeIcon("lunar", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingRed"));
if (icon != null) {
elem.addContent(storeIcon("flashred", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingYellow"));
if (icon != null) {
elem.addContent(storeIcon("flashyellow", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingGreen"));
if (icon != null) {
elem.addContent(storeIcon("flashgreen", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingLunar"));
if (icon != null) {
elem.addContent(storeIcon("flashlunar", icon));
}
element.addContent(elem);
elem = new Element("iconmaps");
String family = p.getFamily();
if (family != null) {
elem.setAttribute("family", family);
}
element.addContent(elem);
element.setAttribute("class", "jmri.jmrit.display.configurexml.SignalHeadIconXml");
return element;
}
use of jmri.jmrit.display.SignalHeadIcon 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);
}
Aggregations