use of jmri.Memory in project JMRI by JMRI.
the class JsonUtil method getMemory.
/*
* deprecated in favor of the implementations of the {@code do*} methods in
* {@link jmri.server.json.JsonHttpService}.
* @deprecated since 4.5.1
*/
@Deprecated
public static JsonNode getMemory(Locale locale, String name) throws JsonException {
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, MEMORY);
ObjectNode data = root.putObject(DATA);
Memory memory = InstanceManager.memoryManagerInstance().getMemory(name);
try {
data.put(NAME, memory.getSystemName());
data.put(USERNAME, memory.getUserName());
data.put(COMMENT, memory.getComment());
if (memory.getValue() == null) {
data.putNull(VALUE);
} else {
data.put(VALUE, memory.getValue().toString());
}
} catch (NullPointerException e) {
log.error("Unable to get memory [{}].", name);
throw new JsonException(404, Bundle.getMessage(locale, "ErrorObject", MEMORY, name));
}
return root;
}
use of jmri.Memory in project JMRI by JMRI.
the class MemoryInputIcon method setMemory.
/**
* Attached a named Memory to this display item
*
* @param pName Used as a system/user name to lookup the Memory object
*/
public void setMemory(String pName) {
log.debug("setMemory for memory= {}", pName);
if (InstanceManager.getNullableDefault(jmri.MemoryManager.class) != null) {
try {
Memory memory = InstanceManager.memoryManagerInstance().provideMemory(pName);
setMemory(jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(pName, memory));
} catch (IllegalArgumentException e) {
log.error("Memory '" + pName + "' not available, icon won't see changes");
}
} else {
log.error("No MemoryManager for this protocol, icon won't see changes");
}
updateSize();
}
use of jmri.Memory in project JMRI by JMRI.
the class MemoryComboIcon method setMemory.
/**
* Attached a named Memory to this display item
*
* @param pName Used as a system/user name to lookup the Memory object
*/
public void setMemory(String pName) {
log.debug("setMemory for memory= {}", pName);
if (InstanceManager.getNullableDefault(jmri.MemoryManager.class) != null) {
try {
Memory memory = InstanceManager.memoryManagerInstance().provideMemory(pName);
setMemory(jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(pName, memory));
} catch (IllegalArgumentException e) {
log.error("No MemoryManager for this protocol, icon won't see changes");
}
}
updateSize();
}
use of jmri.Memory 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();
}
use of jmri.Memory in project JMRI by JMRI.
the class MemoryInputIconXml method load.
/**
* Load, starting with the memoryInputIcon 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) {
// create the objects
Editor p = (Editor) o;
int nCol = 2;
try {
nCol = element.getAttribute("colWidth").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert colWidth attribute");
}
MemoryInputIcon l = new MemoryInputIcon(nCol, p);
loadTextInfo(l, element);
String name;
Attribute attr = element.getAttribute("memory");
if (attr == null) {
log.error("incorrect information for a memory location; must use memory name");
p.loadFailed();
return;
} else {
name = attr.getValue();
}
Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
if (m != null) {
l.setMemory(name);
} else {
log.error("Memory named '" + attr.getValue() + "' not found.");
p.loadFailed();
return;
}
p.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.MEMORIES, element);
javax.swing.JComponent textField = l.getTextComponent();
jmri.jmrit.display.PositionablePopupUtil util = l.getPopupUtility();
if (util.hasBackground()) {
textField.setBackground(util.getBackground());
} else {
textField.setBackground(null);
textField.setOpaque(false);
}
}
Aggregations