use of jmri.jmrit.display.panelEditor.PanelEditor 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.panelEditor.PanelEditor in project JMRI by JMRI.
the class IconEditorWindowTest method setUp.
// The minimal setup for log4J
@Override
protected void setUp() throws Exception {
super.setUp();
apps.tests.Log4JFixture.setUp();
// log existing windows in setup
JUnitUtil.resetWindows(true);
JUnitUtil.resetInstanceManager();
JUnitUtil.initInternalTurnoutManager();
JUnitUtil.initInternalSensorManager();
JUnitUtil.initInternalLightManager();
JUnitUtil.initMemoryManager();
JUnitUtil.initInternalSignalHeadManager();
JUnitUtil.initShutDownManager();
if (!GraphicsEnvironment.isHeadless()) {
_editor = new PanelEditor("IconEditorTestPanel");
Assert.assertNotNull(JFrameOperator.waitJFrame("IconEditorTestPanel", true, true));
_panel = _editor.getTargetPanel();
Assert.assertNotNull(_panel);
}
}
use of jmri.jmrit.display.panelEditor.PanelEditor in project JMRI by JMRI.
the class PanelServlet method getXmlPanel.
@Override
protected String getXmlPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
PanelEditor editor = (PanelEditor) getEditor(name);
Element panel = new Element("panel");
JFrame frame = editor.getTargetFrame();
panel.setAttribute("name", name);
panel.setAttribute("height", Integer.toString(frame.getContentPane().getHeight()));
panel.setAttribute("width", Integer.toString(frame.getContentPane().getWidth()));
panel.setAttribute("panelheight", Integer.toString(editor.getTargetPanel().getHeight()));
panel.setAttribute("panelwidth", Integer.toString(editor.getTargetPanel().getWidth()));
panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
if (editor.getBackgroundColor() != null) {
Element color = new Element("backgroundColor");
color.setAttribute("red", Integer.toString(editor.getBackgroundColor().getRed()));
color.setAttribute("green", Integer.toString(editor.getBackgroundColor().getGreen()));
color.setAttribute("blue", Integer.toString(editor.getBackgroundColor().getBlue()));
panel.addContent(color);
}
// include contents
List<Positionable> contents = editor.getContents();
log.debug("Panel has {} elements", contents.size());
for (Positionable sub : contents) {
if (sub != null) {
try {
Element e = ConfigXmlManager.elementFromObject(sub);
if (e != null) {
if ("signalmasticon".equals(e.getName())) {
//insert icon details into signalmast
e.addContent(getSignalMastIconsElement(e.getAttributeValue("signalmast")));
}
try {
e.setAttribute(JSON.ID, sub.getNamedBean().getSystemName());
} catch (NullPointerException ex) {
if (sub.getNamedBean() == null) {
log.debug("{} {} does not have an associated NamedBean", e.getName(), e.getAttribute(JSON.NAME));
} else {
log.debug("{} {} does not have a SystemName", e.getName(), e.getAttribute(JSON.NAME));
}
}
parsePortableURIs(e);
panel.addContent(e);
}
} catch (Exception ex) {
log.error("Error storing panel element: {}", ex.getMessage(), ex);
}
}
}
Document doc = new Document(panel);
XMLOutputter out = new XMLOutputter();
out.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
return out.outputString(doc);
} catch (NullPointerException ex) {
log.warn("Requested Panel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
}
}
use of jmri.jmrit.display.panelEditor.PanelEditor in project JMRI by JMRI.
the class PanelServlet method getJsonPanel.
@Override
protected String getJsonPanel(String name) {
log.debug("Getting {} for {}", getPanelType(), name);
try {
PanelEditor editor = (PanelEditor) getEditor(name);
ObjectNode root = this.mapper.createObjectNode();
ObjectNode panel = root.putObject("panel");
JFrame frame = editor.getTargetFrame();
panel.put("name", name);
panel.put("height", frame.getContentPane().getHeight());
panel.put("width", frame.getContentPane().getWidth());
panel.put("panelheight", frame.getContentPane().getHeight());
panel.put("panelwidth", frame.getContentPane().getWidth());
panel.put("showtooltips", editor.showTooltip());
panel.put("controlling", editor.allControlling());
if (editor.getBackgroundColor() != null) {
ObjectNode color = panel.putObject("backgroundColor");
color.put("red", editor.getBackgroundColor().getRed());
color.put("green", editor.getBackgroundColor().getGreen());
color.put("blue", editor.getBackgroundColor().getBlue());
}
// include contents
log.debug("N elements: {}", editor.getContents().size());
for (Positionable sub : editor.getContents()) {
try {
// TODO: get all panel contents as JSON
// I tried using JavaBean Introspection to simply build the contents using Jackson Databindings,
// but when a panel element has a reference to the panel or to itself as a property, this leads
// to infinite recursion
} catch (Exception ex) {
log.error("Error storing panel element: " + ex, ex);
}
}
return this.mapper.writeValueAsString(root);
} catch (NullPointerException ex) {
log.warn("Requested Panel [" + name + "] does not exist.");
return "ERROR Requested panel [" + name + "] does not exist.";
} catch (JsonGenerationException e) {
log.error("Error generating JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (JsonMappingException e) {
log.error("Error mapping JSON", e);
return "ERROR " + e.getLocalizedMessage();
} catch (IOException e) {
log.error("IOException", e);
return "ERROR " + e.getLocalizedMessage();
}
}
use of jmri.jmrit.display.panelEditor.PanelEditor in project JMRI by JMRI.
the class PanelEditorXml method load.
/**
* Create a PanelEditor object, then register and fill it, then pop it in a
* JFrame
*
* @param shared Top level Element to unpack.
* @return true if successful
*/
@Override
public boolean load(Element shared, Element perNode) {
boolean result = true;
// find coordinates
int x = 0;
int y = 0;
int height = 400;
int width = 300;
try {
x = shared.getAttribute("x").getIntValue();
y = shared.getAttribute("y").getIntValue();
height = shared.getAttribute("height").getIntValue();
width = shared.getAttribute("width").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert PanelEditor's attribute");
result = false;
}
// find the name
String name = "Panel";
if (shared.getAttribute("name") != null) {
name = shared.getAttribute("name").getValue();
}
// confirm that panel hasn't already been loaded
if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
log.warn("File contains a panel with the same name (" + name + ") as an existing panel");
result = false;
}
PanelEditor panel = new PanelEditor(name);
//panel.makeFrame(name);
jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
panel.getTargetFrame().setLocation(x, y);
panel.getTargetFrame().setSize(width, height);
panel.setTitle();
// Load editor option flags. This has to be done before the content
// items are loaded, to preserve the individual item settings
Attribute a;
boolean value = true;
if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllEditable(value);
value = true;
if ((a = shared.getAttribute("positionable")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllPositionable(value);
/*
value = false;
if ((a = element.getAttribute("showcoordinates"))!=null && a.getValue().equals("yes"))
value = true;
panel.setShowCoordinates(value);
*/
value = true;
if ((a = shared.getAttribute("showtooltips")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllShowTooltip(value);
value = true;
if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllControlling(value);
value = false;
if ((a = shared.getAttribute("hide")) != null && a.getValue().equals("yes")) {
value = true;
}
panel.setShowHidden(value);
value = true;
if ((a = shared.getAttribute("panelmenu")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setPanelMenuVisible(value);
String state = "both";
if ((a = shared.getAttribute("scrollable")) != null) {
state = a.getValue();
}
panel.setScroll(state);
// set color if needed
try {
int red = shared.getAttribute("redBackground").getIntValue();
int blue = shared.getAttribute("blueBackground").getIntValue();
int green = shared.getAttribute("greenBackground").getIntValue();
panel.setBackgroundColor(new Color(red, green, blue));
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse color attributes!");
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
//set the (global) editor display widgets to their flag settings
panel.initView();
// load the contents with their individual option settings
List<Element> items = shared.getChildren();
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
String adapterName = item.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(item, panel);
if (!panel.loadOK()) {
result = false;
}
} catch (Exception e) {
log.error("Exception while loading " + item.getName() + ":" + e);
result = false;
e.printStackTrace();
}
}
// dispose of url correction data
panel.disposeLoadData();
// display the results, with the editor in back
panel.pack();
panel.setAllEditable(panel.isEditable());
// we don't pack the target frame here, because size was specified
// TODO: Work out why, when calling this method, panel size is increased
// vertically (at least on MS Windows)
// always show the panel
panel.getTargetFrame().setVisible(true);
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(panel);
}
// reset the size and position, in case the display caused it to change
panel.getTargetFrame().setLocation(x, y);
panel.getTargetFrame().setSize(width, height);
return result;
}
Aggregations