use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class SignalMastIcon method displayState.
/**
* Drive the current state of the display from the state of the underlying
* SignalMast object.
*/
public void displayState(String state) {
updateSize();
if (log.isDebugEnabled()) {
// Avoid signal lookup unless needed
if (getSignalMast() == null) {
log.debug("Display state " + state + ", disconnected");
} else {
log.debug("Display state " + state + " for " + getSignalMast().getSystemName());
}
}
if (isText()) {
if (getSignalMast().getHeld()) {
if (isText()) {
super.setText(Bundle.getMessage("Held"));
}
return;
} else if (getLitMode() && !getSignalMast().getLit()) {
super.setText(Bundle.getMessage("Dark"));
return;
}
super.setText(state);
}
if (isIcon()) {
if ((state != null) && (getSignalMast() != null)) {
String s = getSignalMast().getAppearanceMap().getImageLink(state, useIconSet);
if ((getSignalMast().getHeld()) && (getSignalMast().getAppearanceMap().getSpecificAppearance(jmri.SignalAppearanceMap.HELD) != null)) {
s = getSignalMast().getAppearanceMap().getImageLink("$held", useIconSet);
} else if (getLitMode() && !getSignalMast().getLit() && (getSignalMast().getAppearanceMap().getImageLink("$dark", useIconSet) != null)) {
s = getSignalMast().getAppearanceMap().getImageLink("$dark", useIconSet);
}
if (s.equals("")) {
/*We have no appearance to set, therefore we will exit at this point.
This can be considered normal if we are requesting an appearance
that is not support or configured, such as dark or held */
return;
}
if (!s.contains("preference:")) {
s = s.substring(s.indexOf("resources"));
}
// tiny global cache, due to number of icons
if (_iconMap == null) {
getIcons();
}
NamedIcon n = _iconMap.get(s);
super.setIcon(n);
updateSize();
setSize(n.getIconWidth(), n.getIconHeight());
}
} else {
super.setIcon(null);
}
return;
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class SensorIcon method updateSensor.
void updateSensor() {
HashMap<String, NamedIcon> oldMap = cloneMap(_iconMap, this);
setSensor(_iconEditor.getTableSelection().getDisplayName());
Hashtable<String, NamedIcon> iconMap = _iconEditor.getIconMap();
Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
while (it.hasNext()) {
Entry<String, NamedIcon> entry = it.next();
if (log.isDebugEnabled()) {
log.debug("key= " + entry.getKey());
}
NamedIcon newIcon = entry.getValue();
NamedIcon oldIcon = oldMap.get(entry.getKey());
newIcon.setLoad(oldIcon.getDegrees(), oldIcon.getScale(), this);
newIcon.setRotation(oldIcon.getRotation(), this);
setIcon(entry.getKey(), newIcon);
}
_iconEditorFrame.dispose();
_iconEditorFrame = null;
_iconEditor = null;
invalidate();
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class SensorIcon method updateItem.
void updateItem() {
HashMap<String, NamedIcon> oldMap = cloneMap(_iconMap, this);
setSensor(_itemPanel.getTableSelection().getSystemName());
_iconFamily = _itemPanel.getFamilyName();
HashMap<String, NamedIcon> iconMap = _itemPanel.getIconMap();
if (iconMap != null) {
Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
while (it.hasNext()) {
Entry<String, NamedIcon> entry = it.next();
if (log.isDebugEnabled()) {
log.debug("key= " + entry.getKey());
}
NamedIcon newIcon = entry.getValue();
NamedIcon oldIcon = oldMap.get(entry.getKey());
newIcon.setLoad(oldIcon.getDegrees(), oldIcon.getScale(), this);
newIcon.setRotation(oldIcon.getRotation(), this);
setIcon(entry.getKey(), newIcon);
}
}
// otherwise retain current map
// jmri.jmrit.catalog.ImageIndexEditor.checkImageIndex();
_paletteFrame.dispose();
_paletteFrame = null;
_itemPanel.dispose();
_itemPanel = null;
invalidate();
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class RpsPositionIconXml 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;
RpsPositionIcon l = new RpsPositionIcon(ed);
// create the objects
String name = element.getAttribute("active").getValue();
NamedIcon active = NamedIcon.getIconByName(name);
if (active == null) {
active = ed.loadFailed("RpsPositionIcon: icon \"active\" ", name);
if (active == null) {
log.info("RpsPositionIcon: icon \"active\" removed for url= " + name);
return;
}
}
l.setActiveIcon(active);
name = element.getAttribute("error").getValue();
NamedIcon error = NamedIcon.getIconByName(name);
if (error == null) {
error = ed.loadFailed("RpsPositionIcon: icon \"error\" ", name);
if (error == null) {
log.info("RpsPositionIcon: \"error\" removed for url= " + name);
return;
}
}
l.setErrorIcon(error);
try {
Attribute a = element.getAttribute("rotate");
if (a != null) {
int rotation = element.getAttribute("rotate").getIntValue();
active.setRotation(rotation, l);
error.setRotation(rotation, l);
}
} catch (org.jdom2.DataConversionException e) {
}
Attribute a = element.getAttribute("momentary");
if ((a != null) && a.getValue().equals("true")) {
l.setMomentary(true);
} else {
l.setMomentary(false);
}
a = element.getAttribute("showid");
if ((a != null) && a.getValue().equals("true")) {
l.setShowID(true);
} else {
l.setShowID(false);
}
a = element.getAttribute("filter");
if (a != null) {
l.setFilter(a.getValue());
}
double sxScale = 0.;
double syScale = 0.;
int sxOrigin = 0;
int syOrigin = 0;
try {
sxScale = element.getAttribute("sxscale").getDoubleValue();
syScale = element.getAttribute("syscale").getDoubleValue();
sxOrigin = element.getAttribute("sxorigin").getIntValue();
syOrigin = element.getAttribute("syorigin").getIntValue();
} catch (NullPointerException e1) {
log.error("missing transform attribute");
} catch (org.jdom2.DataConversionException e2) {
log.error("failed to convert transform attributes");
}
l.setTransform(sxScale, syScale, sxOrigin, syOrigin);
NamedIcon icon = loadIcon(l, "active", element, "RpsPositionIcon ", ed);
if (icon != null) {
l.setActiveIcon(icon);
}
icon = loadIcon(l, "error", element, "RpsPositionIcon ", ed);
if (icon != null) {
l.setErrorIcon(icon);
}
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.SENSORS, element);
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class MemoryIconXml method load.
/**
* Load, starting with the memoryicon 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;
MemoryIcon l;
if (o instanceof LayoutEditor) {
ed = (LayoutEditor) o;
l = new jmri.jmrit.display.layoutEditor.MemoryIcon(" ", (LayoutEditor) ed);
} else if (o instanceof jmri.jmrit.display.Editor) {
ed = (Editor) o;
l = new MemoryIcon("", ed);
} else {
log.error("Unrecognizable class - " + o.getClass().getName());
return;
}
String name;
Attribute attr = element.getAttribute("memory");
if (attr == null) {
log.error("incorrect information for a memory location; must use memory name");
ed.loadFailed();
return;
} else {
name = attr.getValue();
}
loadTextInfo(l, element);
Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
if (m != null) {
l.setMemory(name);
} else {
log.error("Memory 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);
}
a = element.getAttribute("updateBlockValue");
if (a != null && a.getValue().equals("yes")) {
l.updateBlockValueOnChange(true);
}
// get the icon pairs
List<Element> items = element.getChildren("memorystate");
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();
}
Aggregations