use of org.jdom2.output.Format in project JMRI by JMRI.
the class PaneProgFrameTest method setupDoc.
// provide a test document in the above static variables
void setupDoc() {
// create a JDOM tree with just some elements
root = new Element("programmer-config");
doc = new Document(root);
doc.setDocType(new DocType("programmer-config", "programmer-config.dtd"));
// add some elements
root.addContent(new Element("programmer").setAttribute("showFnLanelPane", "yes").setAttribute("showRosterMediaPane", "yes").addContent(new Element("pane").setAttribute("name", "Basic").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Start voltage")).addContent(new Element("display").setAttribute("item", "Normal direction of motion"))).addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "checkbox")).addContent(new Element("display").setAttribute("item", "Normal direction of motion").setAttribute("format", "radiobuttons")))).addContent(new Element("pane").setAttribute("name", "CV").addContent(new Element("column").addContent(new Element("cvtable")))).addContent(new Element("pane").setAttribute("name", "Other").addContent(new Element("column").addContent(new Element("display").setAttribute("item", "Address")).addContent(new Element("display").setAttribute("item", "Normal direction of motion")))));
return;
}
use of org.jdom2.output.Format in project JMRI by JMRI.
the class LoadXmlThrottlesLayoutAction method loadThrottlesLayout.
/**
* Parse the XML file and create ThrottleFrames. Returns true if throttle
* loaded successfully.
*
* @param f The XML file containing throttles.
*/
@SuppressWarnings("unchecked")
public boolean loadThrottlesLayout(java.io.File f) throws java.io.IOException {
try {
ThrottlePrefs prefs = new ThrottlePrefs();
Element root = prefs.rootFromFile(f);
List<Element> throttles = root.getChildren("ThrottleFrame");
if ((throttles != null) && (throttles.size() > 0)) {
// OLD FORMAT
for (java.util.Iterator<Element> i = throttles.iterator(); i.hasNext(); ) {
ThrottleFrame tf = ThrottleFrameManager.instance().createThrottleFrame();
tf.setXml(i.next());
tf.toFront();
}
} else {
throttles = root.getChildren("ThrottleWindow");
for (java.util.Iterator<Element> i = throttles.iterator(); i.hasNext(); ) {
ThrottleWindow tw = ThrottleFrameManager.instance().createThrottleWindow();
tw.setXml(i.next());
tw.setVisible(true);
}
Element tlp = root.getChild("ThrottlesListPanel");
if (tlp != null) {
ThrottleFrameManager.instance().getThrottlesListPanel().setXml(tlp);
}
}
} catch (org.jdom2.JDOMException ex) {
log.warn("Loading Throttles exception", ex);
return false;
}
return true;
}
use of org.jdom2.output.Format in project JMRI by JMRI.
the class LocoAddressXml method store.
/**
* Default implementation for storing the contents of a LocoAddress
*
* @param o Object to store, of type LocoAddress
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LocoAddress p = (LocoAddress) o;
Element element = new Element("locoaddress");
// include contents, we shall also store the old format for backward compatability
DccLocoAddressXml adapter = new DccLocoAddressXml();
element.addContent(adapter.store(p));
if (p != null) {
element.addContent(new Element("number").addContent("" + p.getNumber()));
element.addContent(new Element("protocol").addContent(p.getProtocol().getShortName()));
} else {
element.addContent(new Element("number").addContent(""));
element.addContent(new Element("protocol").addContent(""));
}
return element;
}
use of org.jdom2.output.Format in project JMRI by JMRI.
the class CarManager method load.
public void load(Element root) {
// new format using elements starting version 3.3.1
if (root.getChild(Xml.NEW_KERNELS) != null) {
@SuppressWarnings("unchecked") List<Element> eKernels = root.getChild(Xml.NEW_KERNELS).getChildren(Xml.KERNEL);
log.debug("Car manager sees {} kernels", eKernels.size());
Attribute a;
for (Element eKernel : eKernels) {
if ((a = eKernel.getAttribute(Xml.NAME)) != null) {
newKernel(a.getValue());
}
}
} else // old format
if (root.getChild(Xml.KERNELS) != null) {
String names = root.getChildText(Xml.KERNELS);
if (!names.equals("")) {
// NOI18N
String[] kernelNames = names.split("%%");
log.debug("kernels: {}", names);
for (String name : kernelNames) {
newKernel(name);
}
}
}
if (root.getChild(Xml.CARS) != null) {
@SuppressWarnings("unchecked") List<Element> eCars = root.getChild(Xml.CARS).getChildren(Xml.CAR);
log.debug("readFile sees {} cars", eCars.size());
for (Element eCar : eCars) {
register(new Car(eCar));
}
}
}
use of org.jdom2.output.Format 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;
}
Aggregations