use of com.zhan_dui.utils.m3u8.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 com.zhan_dui.utils.m3u8.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 com.zhan_dui.utils.m3u8.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 com.zhan_dui.utils.m3u8.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;
}
}
}
use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.
the class MergSD2SignalHeadXml method load.
@Override
public boolean load(Element shared, Element perNode) {
int aspects = 2;
List<Element> l = shared.getChildren("turnoutname");
if (l.size() == 0) {
l = shared.getChildren("turnout");
aspects = l.size() + 1;
}
NamedBeanHandle<Turnout> input1 = null;
NamedBeanHandle<Turnout> input2 = null;
NamedBeanHandle<Turnout> input3 = null;
String yesno = "";
boolean feather = false;
boolean home = true;
// put it together
String sys = getSystemName(shared);
String uname = getUserName(shared);
if (shared.getAttribute("feather") != null) {
yesno = shared.getAttribute("feather").getValue();
}
if ((yesno != null) && (!yesno.equals(""))) {
if (yesno.equals("yes")) {
feather = true;
} else if (yesno.equals("no")) {
feather = false;
}
}
if (shared.getAttribute("home") != null) {
yesno = shared.getAttribute("home").getValue();
}
if ((yesno != null) && (!yesno.equals(""))) {
if (yesno.equals("yes")) {
home = true;
} else if (yesno.equals("no")) {
home = false;
}
}
try {
aspects = shared.getAttribute("aspects").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse level attribute!");
} catch (NullPointerException e) {
// considered normal if the attribute not present
}
SignalHead h;
//@TODO could re-arange this so that it falls through
switch(aspects) {
case 2:
input1 = loadTurnout(l.get(0));
break;
case 3:
input1 = loadTurnout(l.get(0));
input2 = loadTurnout(l.get(1));
break;
case 4:
input1 = loadTurnout(l.get(0));
input2 = loadTurnout(l.get(1));
input3 = loadTurnout(l.get(2));
break;
default:
log.error("incorrect number of aspects " + aspects + " when loading Signal " + sys);
}
if (uname == null) {
h = new MergSD2SignalHead(sys, aspects, input1, input2, input3, feather, home);
} else {
h = new MergSD2SignalHead(sys, uname, aspects, input1, input2, input3, feather, home);
}
loadCommon(h, shared);
InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
return true;
}
Aggregations