use of org.jdom2.Text in project JMRI by JMRI.
the class FunctionPanel method getXml.
/**
* Collect the prefs of this object into XML Element
* <ul>
* <li> Window prefs
* <li> Each button has id, text, lock state.
* </ul>
*
* @return the XML of this object.
*/
public Element getXml() {
Element me = new Element("FunctionPanel");
java.util.ArrayList<Element> children = new java.util.ArrayList<Element>(1 + FunctionPanel.NUM_FUNCTION_BUTTONS);
children.add(WindowPreferences.getPreferences(this));
for (int i = 0; i < FunctionPanel.NUM_FUNCTION_BUTTONS; i++) {
children.add(functionButton[i].getXml());
}
me.setContent(children);
return me;
}
use of org.jdom2.Text in project JMRI by JMRI.
the class PollingFile method prepare.
/**
* Initialize for writing information.
* <P>
* This is followed by multiple "set" calls, then a "store"
*/
public void prepare() {
root = new Element("rpsfile");
doc = newDocument(root, dtdLocation + "rpsroster-2-3-8.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/rpsroster.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "rpsroster.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
}
use of org.jdom2.Text in project JMRI by JMRI.
the class PositionFile method prepare.
/**
* Initialize for writing information.
* <P>
* This is followed by multiple "set" calls, then a "store"
*/
public void prepare() {
root = new Element("rpsfile");
doc = newDocument(root, dtdLocation + "rpsfile.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/rpsfile.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "rpsfile.xsl");
ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
}
use of org.jdom2.Text in project JMRI by JMRI.
the class LinkingLabelXml method load.
/**
* Create LinkingLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
LinkingLabel l = null;
String url = element.getChild("url").getText();
// get object class and determine editor being used
Editor editor = (Editor) o;
if (element.getAttribute("icon") != null) {
NamedIcon icon = null;
String name = element.getAttribute("icon").getValue();
// if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
if (name.equals("yes")) {
icon = getNamedIcon("icon", element, "LinkingLabel ", editor);
} else {
icon = NamedIcon.getIconByName(name);
if (icon == null) {
icon = editor.loadFailed("LinkingLabel", name);
if (icon == null) {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
}
}
// abort if name != yes and have null icon
if (icon == null && !name.equals("yes")) {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
l = new LinkingLabel(icon, editor, url);
// no text
l.setPopupUtility(null);
try {
Attribute a = element.getAttribute("rotate");
if (a != null && icon != null) {
int rotation = element.getAttribute("rotate").getIntValue();
icon.setRotation(rotation, l);
}
} catch (org.jdom2.DataConversionException e) {
}
if (name.equals("yes")) {
NamedIcon nIcon = loadIcon(l, "icon", element, "LinkingLabel ", editor);
if (nIcon != null) {
l.updateIcon(nIcon);
} else {
log.info("LinkingLabel icon removed for url= " + name);
return;
}
} else {
l.updateIcon(icon);
}
//l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
} else if (element.getAttribute("text") != null) {
l = new LinkingLabel(element.getAttribute("text").getValue(), editor, url);
loadTextInfo(l, element);
} else {
log.error("LinkingLabel is null!");
if (log.isDebugEnabled()) {
java.util.List<Attribute> attrs = element.getAttributes();
log.debug("\tElement Has " + attrs.size() + " Attributes:");
for (int i = 0; i < attrs.size(); i++) {
Attribute a = attrs.get(i);
log.debug("\t\t" + a.getName() + " = " + a.getValue());
}
java.util.List<Element> kids = element.getChildren();
log.debug("\tElementHas " + kids.size() + " children:");
for (int i = 0; i < kids.size(); i++) {
Element e = kids.get(i);
log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
}
}
editor.loadFailed();
return;
}
editor.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.LABELS, element);
}
use of org.jdom2.Text in project JMRI by JMRI.
the class GuiUtilBase method actionFromNode.
static Action actionFromNode(Element child, WindowInterface wi, Object context) {
String name = null;
Icon icon = null;
HashMap<String, String> parameters = new HashMap<>();
if (child == null) {
log.warn("Action from node called without child");
return createEmptyMenuItem(null, "<none>");
}
name = LocaleSelector.getAttribute(child, "name");
if ((name == null) || (name.equals(""))) {
if (child.getChild("name") != null) {
name = child.getChild("name").getText();
}
}
if (child.getChild("icon") != null) {
icon = new ImageIcon(FileUtil.findURL(child.getChild("icon").getText()));
}
//This bit does not size very well, but it works for now.
if (child.getChild("option") != null) {
child.getChildren("option").stream().forEach((item) -> {
String setting = ((Element) item).getAttribute("setting").getValue();
String setMethod = ((Element) item).getText();
parameters.put(setMethod, setting);
});
}
if (child.getChild("adapter") != null) {
String classname = child.getChild("adapter").getText();
JmriAbstractAction a = null;
try {
Class<?> c = Class.forName(classname);
for (java.lang.reflect.Constructor<?> ct : c.getConstructors()) {
// look for one with right arguments
if (icon == null) {
Class<?>[] parms = ct.getParameterTypes();
if (parms.length != 2) {
continue;
}
if (parms[0] != String.class) {
continue;
}
if (parms[1] != WindowInterface.class) {
continue;
}
// found it!
a = (JmriAbstractAction) ct.newInstance(new Object[] { name, wi });
a.setName(name);
a.setContext(context);
setParameters(a, parameters);
return a;
} else {
Class<?>[] parms = ct.getParameterTypes();
if (parms.length != 3) {
continue;
}
if (parms[0] != String.class) {
continue;
}
if (parms[1] != Icon.class) {
continue;
}
if (parms[2] != WindowInterface.class) {
continue;
}
// found it!
a = (JmriAbstractAction) ct.newInstance(new Object[] { name, icon, wi });
a.setName(name);
a.setContext(context);
setParameters(a, parameters);
return a;
}
}
log.warn("Did not find suitable ctor for " + classname + (icon != null ? " with" : " without") + " icon");
return createEmptyMenuItem(icon, name);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | java.lang.reflect.InvocationTargetException e) {
log.warn("failed to load GUI adapter class: " + classname + " due to: " + e);
return createEmptyMenuItem(icon, name);
}
} else if (child.getChild("panel") != null) {
try {
JmriNamedPaneAction act;
if (icon == null) {
act = new JmriNamedPaneAction(name, wi, child.getChild("panel").getText());
} else {
act = new JmriNamedPaneAction(name, icon, wi, child.getChild("panel").getText());
}
act.setContext(context);
setParameters(act, parameters);
return act;
} catch (Exception ex) {
log.warn("could not load toolbar adapter class: " + child.getChild("panel").getText() + " due to " + ex);
return createEmptyMenuItem(icon, name);
}
} else if (child.getChild("help") != null) {
String reference = child.getChild("help").getText();
return jmri.util.HelpUtil.getHelpAction(name, icon, reference);
} else if (child.getChild("current") != null) {
String[] method = { child.getChild("current").getText() };
return createActionInCallingWindow(context, method, name, icon);
//Relates to the instance that has called it
} else {
// make from icon or text without associated function
return createEmptyMenuItem(icon, name);
}
}
Aggregations