use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class PositionableLabelXml method store.
/**
* Default implementation for storing the contents of a PositionableLabel
*
* @param o Object to store, of type PositionableLabel
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
PositionableLabel p = (PositionableLabel) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("positionablelabel");
storeCommonAttributes(p, element);
if (p.isText()) {
if (p.getUnRotatedText() != null) {
element.setAttribute("text", p.getUnRotatedText());
}
storeTextInfo(p, element);
}
if (p.isIcon() && p.getIcon() != null) {
element.setAttribute("icon", "yes");
element.addContent(storeIcon("icon", (NamedIcon) p.getIcon()));
}
element.setAttribute("class", "jmri.jmrit.display.configurexml.PositionableLabelXml");
return element;
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class PositionableLabelXml method load.
/**
* Create a PositionableLabel, 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
PositionableLabel l = null;
// get object class and determine editor being used
Editor editor = (Editor) o;
if (element.getAttribute("icon") != null) {
NamedIcon icon;
String name = element.getAttribute("icon").getValue();
// if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
if (name.equals("yes")) {
icon = getNamedIcon("icon", element, "PositionableLabel ", editor);
} else {
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = editor.loadFailed("PositionableLabel", name);
if (icon == null) {
log.info("PositionableLabel icon removed for url= " + name);
return;
}
}
}
// abort if name != yes and have null icon
if (icon == null && !name.equals("yes")) {
log.info("PositionableLabel icon removed for url= " + name);
return;
}
l = new PositionableLabel(icon, editor);
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, "PositionableLabel ", editor);
if (nIcon != null) {
l.updateIcon(nIcon);
} else {
log.info("PositionableLabel icon removed for url= " + name);
return;
}
} else {
l.updateIcon(icon);
}
}
if (element.getAttribute("text") != null) {
if (l == null) {
l = new PositionableLabel(element.getAttribute("text").getValue(), editor);
}
loadTextInfo(l, element);
} else if (l == null) {
log.error("PositionableLabel 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 MemoryIconXml method store.
/**
* Default implementation for storing the contents of a MemoryIcon
*
* @param o Object to store, of type MemoryIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
MemoryIcon p = (MemoryIcon) o;
Element element = new Element("memoryicon");
// include attributes
element.setAttribute("memory", p.getNamedMemory().getName());
storeCommonAttributes(p, element);
storeTextInfo(p, element);
//Then we need to replace the x, y values with the original ones.
if (p.getPopupUtility().getFixedWidth() == 0 && p.getPopupUtility().getJustification() != 0) {
element.setAttribute("x", "" + p.getOriginalX());
element.setAttribute("y", "" + p.getOriginalY());
}
element.setAttribute("selectable", (p.isSelectable() ? "yes" : "no"));
if (p.updateBlockValueOnChange()) {
element.setAttribute("updateBlockValue", (p.updateBlockValueOnChange() ? "yes" : "no"));
}
element.setAttribute("class", "jmri.jmrit.display.configurexml.MemoryIconXml");
if (p.getDefaultIcon() != null) {
element.setAttribute("defaulticon", p.getDefaultIcon().getURL());
}
// include contents
java.util.HashMap<String, NamedIcon> map = p.getMap();
if (map != null) {
java.util.Iterator<java.util.Map.Entry<String, NamedIcon>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
java.util.Map.Entry<String, NamedIcon> mi = iterator.next();
String key = mi.getKey();
String value = mi.getValue().getName();
Element e2 = new Element("memorystate");
e2.setAttribute("value", key);
e2.setAttribute("icon", value);
element.addContent(e2);
}
}
return element;
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class SensorIconXml method loadSensorIcon.
private NamedIcon loadSensorIcon(String state, int rotation, SensorIcon l, Element element, String name, Editor ed) {
String msg = "SensorIcon \"" + name + "\": icon \"" + state + "\" ";
// loadIcon gets icon as an element
NamedIcon icon = loadIcon(l, state, element, msg, ed);
if (icon == null && _icon) {
// old config files may define icons as attributes
String iconName;
if (element.getAttribute(state) != null && !(iconName = element.getAttribute(state).getValue()).equals("")) {
icon = NamedIcon.getIconByName(iconName);
if (icon == null) {
icon = ed.loadFailed(msg, iconName);
if (icon == null) {
log.info(msg + " removed for url= " + iconName);
}
} else {
icon.setRotation(rotation, l);
}
} else {
log.warn("did not locate " + state + " icon file for " + name);
}
}
if (icon == null) {
log.info(msg + " removed");
} else {
l.setIcon(_nameMap.get(state), icon);
}
return icon;
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class EditPortalFrame method makeDndIconPanel.
/**
* ******************** DnD ****************************
*/
protected JPanel makeDndIconPanel() {
_dndPanel = new JPanel();
String fileName = "resources/icons/throttles/RoundRedCircle20.png";
NamedIcon icon = new NamedIcon(fileName, fileName);
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), Bundle.getMessage("BeanNamePortal")));
try {
JLabel label = new IconDragJLabel(new DataFlavor(Editor.POSITIONABLE_FLAVOR));
label.setIcon(icon);
label.setName(Bundle.getMessage("BeanNamePortal"));
panel.add(label);
} catch (java.lang.ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
_dndPanel.add(panel);
return _dndPanel;
}
Aggregations