use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class JsonUtilHttpService method getPanels.
public JsonNode getPanels(Locale locale, String format) {
ArrayNode root = mapper.createArrayNode();
// list loaded Panels (ControlPanelEditor, PanelEditor, LayoutEditor, SwitchboardEditor)
// list ControlPanelEditors
Editor.getEditors(ControlPanelEditor.class).stream().map((editor) -> this.getPanel(locale, editor, format)).filter((panel) -> (panel != null)).forEach((panel) -> {
root.add(panel);
});
// list LayoutEditors and PanelEditors
Editor.getEditors(PanelEditor.class).stream().map((editor) -> this.getPanel(locale, editor, format)).filter((panel) -> (panel != null)).forEach((panel) -> {
root.add(panel);
});
// list SwitchboardEditors
Editor.getEditors(SwitchboardEditor.class).stream().map((editor) -> this.getPanel(locale, editor, format)).filter((panel) -> (panel != null)).forEach((panel) -> {
root.add(panel);
});
return root;
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class LayoutEditorXml method store.
/**
* Default implementation for storing the contents of a LayoutEditor
*
* @param o Object to store, of type LayoutEditor
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LayoutEditor p = (LayoutEditor) o;
Element panel = new Element("LayoutEditor");
panel.setAttribute("class", getClass().getName());
panel.setAttribute("name", p.getLayoutName());
panel.setAttribute("x", "" + p.getUpperLeftX());
panel.setAttribute("y", "" + p.getUpperLeftY());
// From this version onwards separate sizes for window and panel are stored the
// following two statements allow files written here to be read in 2.2 and before
panel.setAttribute("height", "" + p.getLayoutHeight());
panel.setAttribute("width", "" + p.getLayoutWidth());
// From this version onwards separate sizes for window and panel are stored
panel.setAttribute("windowheight", "" + p.getWindowHeight());
panel.setAttribute("windowwidth", "" + p.getWindowWidth());
panel.setAttribute("panelheight", "" + p.getLayoutHeight());
panel.setAttribute("panelwidth", "" + p.getLayoutWidth());
// deprecated
panel.setAttribute("sliders", "" + (p.getScroll() ? "yes" : "no"));
panel.setAttribute("scrollable", "" + p.getScrollable());
panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
panel.setAttribute("positionable", "" + (p.allPositionable() ? "yes" : "no"));
panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
panel.setAttribute("animating", "" + (p.isAnimating() ? "yes" : "no"));
panel.setAttribute("showhelpbar", "" + (p.getShowHelpBar() ? "yes" : "no"));
panel.setAttribute("drawgrid", "" + (p.getDrawGrid() ? "yes" : "no"));
panel.setAttribute("snaponadd", "" + (p.getSnapOnAdd() ? "yes" : "no"));
panel.setAttribute("snaponmove", "" + (p.getSnapOnMove() ? "yes" : "no"));
panel.setAttribute("antialiasing", "" + (p.getAntialiasingOn() ? "yes" : "no"));
panel.setAttribute("turnoutcircles", "" + (p.getTurnoutCircles() ? "yes" : "no"));
panel.setAttribute("tooltipsnotedit", "" + (p.getTooltipsNotEdit() ? "yes" : "no"));
panel.setAttribute("tooltipsinedit", "" + (p.getTooltipsInEdit() ? "yes" : "no"));
panel.setAttribute("mainlinetrackwidth", "" + p.getMainlineTrackWidth());
panel.setAttribute("xscale", Float.toString((float) p.getXScale()));
panel.setAttribute("yscale", Float.toString((float) p.getYScale()));
panel.setAttribute("sidetrackwidth", "" + p.getSideTrackWidth());
panel.setAttribute("defaulttrackcolor", p.getDefaultTrackColor());
panel.setAttribute("defaultoccupiedtrackcolor", p.getDefaultOccupiedTrackColor());
panel.setAttribute("defaultalternativetrackcolor", p.getDefaultAlternativeTrackColor());
panel.setAttribute("defaulttextcolor", p.getDefaultTextColor());
panel.setAttribute("turnoutcirclecolor", p.getTurnoutCircleColor());
panel.setAttribute("turnoutcirclesize", "" + p.getTurnoutCircleSize());
panel.setAttribute("turnoutdrawunselectedleg", (p.getTurnoutDrawUnselectedLeg() ? "yes" : "no"));
panel.setAttribute("turnoutbx", Float.toString((float) p.getTurnoutBX()));
panel.setAttribute("turnoutcx", Float.toString((float) p.getTurnoutCX()));
panel.setAttribute("turnoutwid", Float.toString((float) p.getTurnoutWid()));
panel.setAttribute("xoverlong", Float.toString((float) p.getXOverLong()));
panel.setAttribute("xoverhwid", Float.toString((float) p.getXOverHWid()));
panel.setAttribute("xovershort", Float.toString((float) p.getXOverShort()));
panel.setAttribute("autoblkgenerate", "" + (p.getAutoBlockAssignment() ? "yes" : "no"));
if (p.getBackgroundColor() != null) {
panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
}
panel.setAttribute("gridSize", "" + p.getGridSize());
panel.setAttribute("gridSize2nd", "" + p.getGridSize2nd());
p.resetDirty();
panel.setAttribute("openDispatcher", p.getOpenDispatcherOnLoad() ? "yes" : "no");
panel.setAttribute("useDirectTurnoutControl", p.getDirectTurnoutControl() ? "yes" : "no");
// note: moving zoom attribute into per-window user preference
//panel.setAttribute("zoom", Double.toString(p.getZoom()));
// include contents (Icons and Labels)
List<Positionable> contents = p.getContents();
int num = contents.size();
if (num > 0) {
for (int i = 0; i < num; i++) {
Positionable sub = contents.get(i);
if (sub != null && sub.storeItem()) {
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel contents element: " + e);
}
} else {
log.warn("Null entry found when storing panel contents.");
}
}
}
// include LayoutTurnouts
num = p.turnoutList.size();
if (log.isDebugEnabled()) {
log.debug("N layoutturnout elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.turnoutList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel layoutturnout element: " + e);
}
}
}
// include TrackSegments
num = p.trackList.size();
if (log.isDebugEnabled()) {
log.debug("N tracksegment elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.trackList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel tracksegment element: " + e);
}
}
}
// include PositionablePoints
num = p.pointList.size();
if (log.isDebugEnabled()) {
log.debug("N positionablepoint elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.pointList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel positionalpoint element: " + e);
}
}
}
// include LevelXings
num = p.xingList.size();
if (log.isDebugEnabled()) {
log.debug("N levelxing elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.xingList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel levelxing element: " + e);
}
}
}
// include LayoutSlips
num = p.slipList.size();
if (log.isDebugEnabled()) {
log.debug("N layoutSlip elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.slipList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel layoutSlip element: " + e);
}
}
}
// include LayoutTurntables
num = p.turntableList.size();
if (log.isDebugEnabled()) {
log.debug("N turntable elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.turntableList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel turntable element: " + e);
}
}
}
return panel;
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class LayoutSlipXml method load.
/**
* Load, starting with the LayoutSlip element, then all the other data
*
* @param element Top level Element to unpack.
* @param o LayoutEditor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
LayoutEditor p = (LayoutEditor) o;
// get center point
String name = element.getAttribute("ident").getValue();
double x = 0.0;
double y = 0.0;
try {
x = element.getAttribute("xcen").getFloatValue();
y = element.getAttribute("ycen").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert layoutslip center attribute");
}
int type = LayoutSlip.SINGLE_SLIP;
try {
type = element.getAttribute("slipType").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert layoutslip type attribute");
}
// create the new LayoutSlip
LayoutSlip l = new LayoutSlip(name, new Point2D.Double(x, y), 0.0, p, type);
// get remaining attributes
Attribute a = element.getAttribute("blockname");
if (a != null) {
l.tBlockName = a.getValue();
}
a = element.getAttribute("connectaname");
if (a != null) {
l.connectAName = a.getValue();
}
a = element.getAttribute("connectbname");
if (a != null) {
l.connectBName = a.getValue();
}
a = element.getAttribute("connectcname");
if (a != null) {
l.connectCName = a.getValue();
}
a = element.getAttribute("connectdname");
if (a != null) {
l.connectDName = a.getValue();
}
l.setSignalA1Name(getElement(element, "signala1name"));
l.setSignalB1Name(getElement(element, "signalb1name"));
l.setSignalC1Name(getElement(element, "signalc1name"));
l.setSignalD1Name(getElement(element, "signald1name"));
l.setSignalA2Name(getElement(element, "signala2name"));
l.setSignalB2Name(getElement(element, "signalb2name"));
l.setSignalC2Name(getElement(element, "signalc2name"));
l.setSignalD2Name(getElement(element, "signald2name"));
try {
x = element.getAttribute("xa").getFloatValue();
y = element.getAttribute("ya").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert LayoutSlip a coords attribute");
}
l.setCoordsA(new Point2D.Double(x, y));
try {
x = element.getAttribute("xb").getFloatValue();
y = element.getAttribute("yb").getFloatValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert LayoutSlip b coords attribute");
}
l.setCoordsB(new Point2D.Double(x, y));
l.setSignalAMast(getElement(element, "signalAMast"));
l.setSignalBMast(getElement(element, "signalBMast"));
l.setSignalCMast(getElement(element, "signalCMast"));
l.setSignalDMast(getElement(element, "signalDMast"));
l.setSensorA(getElement(element, "sensorA"));
l.setSensorB(getElement(element, "sensorB"));
l.setSensorC(getElement(element, "sensorC"));
l.setSensorD(getElement(element, "sensorD"));
l.setTurnout(getElement(element, "turnout"));
l.setTurnoutB(getElement(element, "turnoutB"));
if (element.getChild("states") != null) {
Element state = element.getChild("states");
if (state.getChild("A-C") != null) {
Element ac = state.getChild("A-C");
l.setTurnoutStates(LayoutSlip.STATE_AC, ac.getChild("turnout").getText(), ac.getChild("turnoutB").getText());
}
if (state.getChild("A-D") != null) {
Element ad = state.getChild("A-D");
l.setTurnoutStates(LayoutSlip.STATE_AD, ad.getChild("turnout").getText(), ad.getChild("turnoutB").getText());
}
if (state.getChild("B-D") != null) {
Element bd = state.getChild("B-D");
l.setTurnoutStates(LayoutSlip.STATE_BD, bd.getChild("turnout").getText(), bd.getChild("turnoutB").getText());
}
if (state.getChild("B-C") != null) {
Element bc = state.getChild("B-C");
l.setTurnoutStates(LayoutSlip.STATE_BC, bc.getChild("turnout").getText(), bc.getChild("turnoutB").getText());
}
}
p.slipList.add(l);
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class OptionsFile method writeDispatcherOptions.
/*
* Writes out Dispatcher options to a file in the user's preferences directory
*/
public void writeDispatcherOptions(DispatcherFrame f) throws java.io.IOException {
log.debug("Saving Dispatcher options to file {}", defaultFileName);
dispatcher = f;
root = new Element("dispatcheroptions");
doc = newDocument(root, dtdLocation + "dispatcher-options.dtd");
// add XSLT processing instruction
// <?xml-stylesheet type="text/xsl" href="XSLT/block-values.xsl"?>
java.util.Map<String, String> m = new java.util.HashMap<String, String>();
m.put("type", "text/xsl");
m.put("href", xsltLocation + "dispatcheroptions.xsl");
org.jdom2.ProcessingInstruction p = new org.jdom2.ProcessingInstruction("xml-stylesheet", m);
doc.addContent(0, p);
// save Dispatcher Options in xml format
Element options = new Element("options");
LayoutEditor le = dispatcher.getLayoutEditor();
if (le != null) {
options.setAttribute("lename", le.getTitle());
}
options.setAttribute("useconnectivity", "" + (dispatcher.getUseConnectivity() ? "yes" : "no"));
options.setAttribute("trainsfromroster", "" + (dispatcher.getTrainsFromRoster() ? "yes" : "no"));
options.setAttribute("trainsfromtrains", "" + (dispatcher.getTrainsFromTrains() ? "yes" : "no"));
options.setAttribute("trainsfromuser", "" + (dispatcher.getTrainsFromUser() ? "yes" : "no"));
options.setAttribute("autoallocate", "" + (dispatcher.getAutoAllocate() ? "yes" : "no"));
options.setAttribute("autoturnouts", "" + (dispatcher.getAutoTurnouts() ? "yes" : "no"));
options.setAttribute("trustknownturnouts", "" + (dispatcher.getTrustKnownTurnouts() ? "yes" : "no"));
options.setAttribute("minthrottleinterval", "" + (dispatcher.getMinThrottleInterval()));
options.setAttribute("fullramptime", "" + (dispatcher.getFullRampTime()));
options.setAttribute("hasoccupancydetection", "" + (dispatcher.getHasOccupancyDetection() ? "yes" : "no"));
options.setAttribute("shortactivetrainnames", "" + (dispatcher.getShortActiveTrainNames() ? "yes" : "no"));
options.setAttribute("shortnameinblock", "" + (dispatcher.getShortNameInBlock() ? "yes" : "no"));
options.setAttribute("extracolorforallocated", "" + (dispatcher.getExtraColorForAllocated() ? "yes" : "no"));
options.setAttribute("nameinallocatedblock", "" + (dispatcher.getNameInAllocatedBlock() ? "yes" : "no"));
options.setAttribute("supportvsdecoder", "" + (dispatcher.getSupportVSDecoder() ? "yes" : "no"));
options.setAttribute("layoutscale", Scale.getShortScaleID(dispatcher.getScale()));
options.setAttribute("usescalemeters", "" + (dispatcher.getUseScaleMeters() ? "yes" : "no"));
options.setAttribute("userosterentryinblock", "" + (dispatcher.getRosterEntryInBlock() ? "yes" : "no"));
if (dispatcher.getSignalType() == 0x00) {
options.setAttribute("usesignaltype", "signalhead");
} else {
options.setAttribute("usesignaltype", "signalmast");
}
root.addContent(options);
// write out the file
try {
if (!checkFile(defaultFileName)) {
// file does not exist, create it
File file = new File(defaultFileName);
if (// create new file and check result
!file.createNewFile()) {
log.error("createNewFile failed");
}
}
// write content to file
writeXML(findFile(defaultFileName), doc);
} catch (java.io.IOException ioe) {
log.error("IO Exception " + ioe);
throw (ioe);
}
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor 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();
}
Aggregations