Search in sources :

Example 6 with PanelEditor

use of jmri.jmrit.display.panelEditor.PanelEditor in project JMRI by JMRI.

the class PanelEditorXml method store.

/**
     * Default implementation for storing the contents of a PanelEditor
     *
     * @param o Object to store, of type PanelEditor
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    PanelEditor p = (PanelEditor) o;
    Element panel = new Element("paneleditor");
    JFrame frame = p.getTargetFrame();
    Dimension size = frame.getSize();
    Point posn = frame.getLocation();
    panel.setAttribute("class", "jmri.jmrit.display.panelEditor.configurexml.PanelEditorXml");
    panel.setAttribute("name", "" + frame.getTitle());
    panel.setAttribute("x", "" + posn.x);
    panel.setAttribute("y", "" + posn.y);
    panel.setAttribute("height", "" + size.height);
    panel.setAttribute("width", "" + size.width);
    panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
    panel.setAttribute("positionable", "" + (p.allPositionable() ? "yes" : "no"));
    //panel.setAttribute("showcoordinates", ""+(p.showCoordinates()?"yes":"no"));
    panel.setAttribute("showtooltips", "" + (p.showTooltip() ? "yes" : "no"));
    panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
    panel.setAttribute("hide", p.isVisible() ? "no" : "yes");
    panel.setAttribute("panelmenu", p.isPanelMenuVisible() ? "yes" : "no");
    panel.setAttribute("scrollable", p.getScrollable());
    if (p.getBackgroundColor() != null) {
        panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
        panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
        panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
    }
    // include contents
    List<Positionable> contents = p.getContents();
    if (log.isDebugEnabled()) {
        log.debug("N elements: " + contents.size());
    }
    for (int i = 0; i < contents.size(); 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 element: " + e);
                e.printStackTrace();
            }
        }
    }
    return panel;
}
Also used : JFrame(javax.swing.JFrame) Element(org.jdom2.Element) Dimension(java.awt.Dimension) Point(java.awt.Point) Positionable(jmri.jmrit.display.Positionable) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) Point(java.awt.Point)

Aggregations

PanelEditor (jmri.jmrit.display.panelEditor.PanelEditor)6 JFrame (javax.swing.JFrame)3 Positionable (jmri.jmrit.display.Positionable)3 Element (org.jdom2.Element)3 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Point (java.awt.Point)2 IOException (java.io.IOException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Enumeration (java.util.Enumeration)1 Locale (java.util.Locale)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ConfigureManager (jmri.ConfigureManager)1