use of org.jdom2.Element in project JMRI by JMRI.
the class ConfigXmlManager method addPrefsStore.
protected void addPrefsStore(Element root) {
for (int i = 0; i < plist.size(); i++) {
Object o = plist.get(i);
Element e = elementFromObject(o);
if (e != null) {
root.addContent(e);
}
}
}
use of org.jdom2.Element in project JMRI by JMRI.
the class ConfigXmlManager method storeConfig.
/**
* Writes prefs to a file.
*
* @param file config file to write.
*/
@Override
public boolean storeConfig(File file) {
boolean result = true;
Element root = initStore();
if (!addConfigStore(root)) {
result = false;
}
includeHistory(root);
if (!finalStore(root, file)) {
result = false;
}
return result;
}
use of org.jdom2.Element in project JMRI by JMRI.
the class DefaultIdTag method store.
@Override
public Element store(boolean storeState) {
//NOI18N
Element e = new Element("idtag");
// e.setAttribute("systemName", this.mSystemName); // not needed from 2.11.1
//NOI18N
e.addContent(new Element("systemName").addContent(this.mSystemName));
if (this.mUserName != null && this.mUserName.length() > 0) {
// e.setAttribute("userName", this.mUserName); // not needed from 2.11.1
//NOI18N
e.addContent(new Element("userName").addContent(this.mUserName));
}
if (this.getComment() != null && this.getComment().length() > 0) {
//NOI18N
e.addContent(new Element("comment").addContent(this.getComment()));
}
if (this.getWhereLastSeen() != null && storeState) {
//NOI18N
e.addContent(new Element("whereLastSeen").addContent(this.getWhereLastSeen().getSystemName()));
}
if (this.getWhenLastSeen() != null && storeState) {
//NOI18N
e.addContent(new Element("whenLastSeen").addContent(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(this.getWhenLastSeen())));
}
return e;
}
use of org.jdom2.Element in project JMRI by JMRI.
the class MergSD2SignalHeadXml method addTurnoutElement.
Element addTurnoutElement(NamedBeanHandle<Turnout> to, String which) {
Element el = new Element("turnoutname");
el.setAttribute("defines", which);
el.addContent(to.getName());
return el;
}
use of org.jdom2.Element in project JMRI by JMRI.
the class MergSD2SignalHeadXml method loadTurnout.
NamedBeanHandle<Turnout> loadTurnout(Object o) {
Element e = (Element) o;
if (e.getName().equals("turnout")) {
String name = e.getAttribute("systemName").getValue();
Turnout t;
if (e.getAttribute("userName") != null && !e.getAttribute("userName").getValue().equals("")) {
name = e.getAttribute("userName").getValue();
t = InstanceManager.turnoutManagerInstance().getTurnout(name);
} else {
t = InstanceManager.turnoutManagerInstance().getBySystemName(name);
}
return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
} else {
String name = e.getText();
try {
Turnout t = InstanceManager.turnoutManagerInstance().provideTurnout(name);
return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
} catch (IllegalArgumentException ex) {
log.warn("Failed to provide Turnout \"{}\" in loadTurnout", name);
return null;
}
}
}
Aggregations