use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class BlockContentsIconXml method load.
/**
* Load, starting with the BlockContentsIcon element, then all the
* value-icon pairs
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
Editor ed = null;
BlockContentsIcon l;
if (o instanceof LayoutEditor) {
ed = (LayoutEditor) o;
l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon(" ", (LayoutEditor) ed);
} else if (o instanceof jmri.jmrit.display.Editor) {
ed = (Editor) o;
l = new BlockContentsIcon("", ed);
} else {
log.error("Unrecognizable class - " + o.getClass().getName());
return;
}
String name;
Attribute attr = element.getAttribute("blockcontents");
if (attr == null) {
log.error("incorrect information for a block contents; must use block name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
}
loadTextInfo(l, element);
Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
if (m != null) {
l.setBlock(name);
} else {
log.error("Block named '" + attr.getValue() + "' not found.");
ed.loadFailed();
}
Attribute a = element.getAttribute("selectable");
if (a != null && a.getValue().equals("yes")) {
l.setSelectable(true);
} else {
l.setSelectable(false);
}
// get the icon pairs
List<Element> items = element.getChildren("blockstate");
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
String iconName = item.getAttribute("icon").getValue();
NamedIcon icon = NamedIcon.getIconByName(iconName);
if (icon == null) {
icon = ed.loadFailed("Memory " + name, iconName);
if (icon == null) {
log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
}
}
if (icon != null) {
String keyValue = item.getAttribute("value").getValue();
l.addKeyAndIcon(icon, keyValue);
}
}
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.MEMORIES, element);
int x = 0;
int y = 0;
try {
x = element.getAttribute("x").getIntValue();
y = element.getAttribute("y").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert positional attribute");
}
l.setOriginalLocation(x, y);
l.displayState();
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class IndicatorTrackIconXml method load.
/**
* Create a IndicatorTrackIcon, 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 p = (Editor) o;
IndicatorTrackIcon l = new IndicatorTrackIcon(p);
Element elem = element.getChild("iconmap");
if (elem != null) {
List<Element> status = elem.getChildren();
if (status.size() > 0) {
for (int i = 0; i < status.size(); i++) {
String msg = "IndicatorTrack \"" + l.getNameString() + "\" icon \"" + status.get(i).getName() + "\" ";
NamedIcon icon = loadIcon(l, status.get(i).getName(), elem, msg, p);
if (icon != null) {
l.setIcon(status.get(i).getName(), icon);
} else {
log.info(msg + " removed for url= " + status.get(i).getName());
return;
}
}
}
Attribute attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
Element name = element.getChild("occupancyblock");
if (name != null) {
l.setOccBlock(name.getText());
} else {
// only write sensor if no OBlock, don't write double sensing
name = element.getChild("occupancysensor");
if (name != null) {
l.setOccSensor(name.getText());
}
}
l.setShowTrain(false);
name = element.getChild("showTrainName");
if (name != null) {
if ("yes".equals(name.getText())) {
l.setShowTrain(true);
}
}
elem = element.getChild("paths");
if (elem != null) {
ArrayList<String> paths = new ArrayList<String>();
List<Element> pth = elem.getChildren();
for (int i = 0; i < pth.size(); i++) {
paths.add(pth.get(i).getText());
}
l.setPaths(paths);
}
l.displayState(l.getStatus());
l.updateSize();
p.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.TURNOUTS, element);
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class IndicatorTurnoutIconXml method store.
/**
* Default implementation for storing the contents of a IndicatorTurnoutIcon
*
* @param o Object to store, of type IndicatorTurnoutIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
IndicatorTurnoutIcon p = (IndicatorTurnoutIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("indicatorturnouticon");
storeCommonAttributes(p, element);
NamedBeanHandle<Turnout> t = p.getNamedTurnout();
if (t != null) {
element.addContent(storeNamedBean("turnout", t));
}
NamedBeanHandle<OBlock> b = p.getNamedOccBlock();
if (b != null) {
element.addContent(storeNamedBean("occupancyblock", b));
}
NamedBeanHandle<Sensor> s = p.getNamedOccSensor();
if (b == null && s != null) {
// only write sensor if no OBlock
element.addContent(storeNamedBean("occupancysensor", s));
}
Element elem = new Element("showTrainName");
String show = "no";
if (p.showTrain()) {
show = "yes";
}
elem.addContent(show);
element.addContent(elem);
HashMap<String, HashMap<Integer, NamedIcon>> iconMaps = p.getIconMaps();
Iterator<Entry<String, HashMap<Integer, NamedIcon>>> it = iconMaps.entrySet().iterator();
Element el = new Element("iconmaps");
String family = p.getFamily();
if (family != null) {
el.setAttribute("family", family);
}
while (it.hasNext()) {
Entry<String, HashMap<Integer, NamedIcon>> ent = it.next();
elem = new Element(ent.getKey());
Iterator<Entry<Integer, NamedIcon>> iter = ent.getValue().entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer, NamedIcon> entry = iter.next();
elem.addContent(storeIcon(p.getStateName(entry.getKey()), entry.getValue()));
}
el.addContent(elem);
}
element.addContent(el);
elem = new Element("paths");
ArrayList<String> paths = p.getPaths();
if (paths != null) {
for (int i = 0; i < paths.size(); i++) {
Element e = new Element("path");
e.addContent(paths.get(i));
elem.addContent(e);
}
element.addContent(elem);
}
element.setAttribute("class", "jmri.jmrit.display.configurexml.IndicatorTurnoutIconXml");
return element;
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class LinkingLabelXml method load.
/**
* Create LinkingLabel, 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
LinkingLabel l = null;
String url = element.getChild("url").getText();
// get object class and determine editor being used
Editor editor = (Editor) o;
if (element.getAttribute("icon") != null) {
NamedIcon icon = null;
String name = element.getAttribute("icon").getValue();
// if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
if (name.equals("yes")) {
icon = getNamedIcon("icon", element, "LinkingLabel ", editor);
} else {
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = editor.loadFailed("LinkingLabel", name);
if (icon == null) {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
}
}
// abort if name != yes and have null icon
if (icon == null && !name.equals("yes")) {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
l = new LinkingLabel(icon, editor, url);
// no text
l.setPopupUtility(null);
try {
Attribute a = element.getAttribute("rotate");
if (a != null && icon != null) {
int rotation = element.getAttribute("rotate").getIntValue();
icon.setRotation(rotation, l);
}
} catch (org.jdom2.DataConversionException e) {
}
if (name.equals("yes")) {
NamedIcon nIcon = loadIcon(l, "icon", element, "LinkingLabel ", editor);
if (nIcon != null) {
l.updateIcon(nIcon);
} else {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
} else {
l.updateIcon(icon);
}
//l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
} else if (element.getAttribute("text") != null) {
l = new LinkingLabel(element.getAttribute("text").getValue(), editor, url);
loadTextInfo(l, element);
} else {
log.error("LinkingLabel is null!");
if (log.isDebugEnabled()) {
java.util.List<Attribute> attrs = element.getAttributes();
log.debug("\tElement Has " + attrs.size() + " Attributes:");
for (int i = 0; i < attrs.size(); i++) {
Attribute a = attrs.get(i);
log.debug("\t\t" + a.getName() + " = " + a.getValue());
}
java.util.List<Element> kids = element.getChildren();
log.debug("\tElementHas " + kids.size() + " children:");
for (int i = 0; i < kids.size(); i++) {
Element e = kids.get(i);
log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
}
}
editor.loadFailed();
return;
}
editor.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.LABELS, element);
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class LocoIconXml 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;
LocoIcon l = new LocoIcon(ed);
// create the objects
String textName = "error";
try {
textName = element.getAttribute("text").getValue();
} catch (Exception e) {
log.error("failed to get loco text attribute ex= " + e);
}
String name = "error";
NamedIcon icon;
try {
name = element.getAttribute("icon").getValue();
} catch (Exception e) {
log.error("failed to get icon attribute ex= " + e);
}
if (name.equals("yes")) {
icon = loadIcon(l, "icon", element, "LocoIcon", ed);
} else {
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = ed.loadFailed("LocoIcon", name);
if (icon == null) {
log.info("LocoIcon icon removed for url= " + name);
return;
}
}
}
l.updateIcon(icon);
try {
int x = element.getAttribute("dockX").getIntValue();
int y = element.getAttribute("dockY").getIntValue();
l.setDockingLocation(x, y);
// l.dock();
} catch (Exception e) {
log.warn("failed to get docking location= " + e);
}
String rosterId = null;
try {
rosterId = element.getAttribute("rosterentry").getValue();
RosterEntry entry = Roster.getDefault().entryFromTitle(rosterId);
l.setRosterEntry(entry);
} catch (Exception e) {
log.debug("no roster entry for " + rosterId + ", ex= " + e);
}
ed.putLocoIcon(l, textName);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.MARKERS, element);
loadTextInfo(l, element);
// to detect "background" color for use in Tracker, examine icon file
l.init();
}
Aggregations