Search in sources :

Example 26 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class EntryExitPairs method getSourceList.

/**
     * Return a list of all source (origin) points on a given
     * Layout Editor panel.
     *
     * @param panel  A Layout Editor panel
     * @return A list of source objects
     */
public List<Object> getSourceList(LayoutEditor panel) {
    List<Object> list = new ArrayList<Object>();
    for (Entry<PointDetails, Source> e : nxpair.entrySet()) {
        Object obj = (e.getKey()).getRefObject();
        LayoutEditor pan = (e.getKey()).getPanel();
        if (pan == panel) {
            if (!list.contains(obj)) {
                list.add(obj);
            }
        }
    // end while
    }
    return list;
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ArrayList(java.util.ArrayList) PointDetails(jmri.jmrit.signalling.entryexit.PointDetails) Source(jmri.jmrit.signalling.entryexit.Source)

Example 27 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class JsonUtilHttpService method getPanel.

public ObjectNode getPanel(Locale locale, Editor editor, String format) {
    if (editor.getAllowInFrameServlet()) {
        String title = ((JmriJFrame) editor.getTargetPanel().getTopLevelAncestor()).getTitle();
        if (!title.isEmpty() && !Arrays.asList(WebServerPreferences.getDefault().getDisallowedFrames()).contains(title)) {
            String type = PANEL;
            String name = "Panel";
            if (editor instanceof ControlPanelEditor) {
                type = CONTROL_PANEL;
                name = "ControlPanel";
            } else if (editor instanceof LayoutEditor) {
                type = LAYOUT_PANEL;
                name = "Layout";
            } else if (editor instanceof SwitchboardEditor) {
                type = SWITCHBOARD_PANEL;
                name = "Switchboard";
            }
            ObjectNode root = this.mapper.createObjectNode();
            root.put(TYPE, PANEL);
            ObjectNode data = root.putObject(DATA);
            // NOI18N
            data.put(NAME, name + "/" + title.replaceAll(" ", "%20").replaceAll("#", "%23"));
            // NOI18N
            data.put(URL, "/panel/" + data.path(NAME).asText() + "?format=" + format);
            data.put(USERNAME, title);
            data.put(TYPE, type);
            return root;
        }
    }
    return null;
}
Also used : SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) JmriJFrame(jmri.util.JmriJFrame)

Example 28 with LayoutEditor

use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.

the class LayoutPanelServlet method getXmlPanel.

@Override
protected String getXmlPanel(String name) {
    log.debug("Getting {} for {}", getPanelType(), name);
    try {
        LayoutEditor editor = (LayoutEditor) getEditor(name);
        Element panel = new Element("panel");
        panel.setAttribute("name", name);
        panel.setAttribute("paneltype", getPanelType());
        panel.setAttribute("height", Integer.toString(editor.getLayoutHeight()));
        panel.setAttribute("width", Integer.toString(editor.getLayoutWidth()));
        panel.setAttribute("panelheight", Integer.toString(editor.getLayoutHeight()));
        panel.setAttribute("panelwidth", Integer.toString(editor.getLayoutWidth()));
        panel.setAttribute("showtooltips", (editor.showTooltip()) ? "yes" : "no");
        panel.setAttribute("controlling", (editor.allControlling()) ? "yes" : "no");
        panel.setAttribute("xscale", Float.toString((float) editor.getXScale()));
        panel.setAttribute("yscale", Float.toString((float) editor.getYScale()));
        panel.setAttribute("mainlinetrackwidth", Integer.toString(editor.getMainlineTrackWidth()));
        panel.setAttribute("sidetrackwidth", Integer.toString(editor.getSideTrackWidth()));
        panel.setAttribute("turnoutcircles", (editor.getTurnoutCircles()) ? "yes" : "no");
        panel.setAttribute("turnoutcirclesize", Integer.toString(editor.getTurnoutCircleSize()));
        panel.setAttribute("turnoutdrawunselectedleg", (editor.getTurnoutDrawUnselectedLeg()) ? "yes" : "no");
        if (editor.getBackgroundColor() == null) {
            panel.setAttribute("backgroundcolor", ColorUtil.colorToString(Color.lightGray));
        } else {
            panel.setAttribute("backgroundcolor", ColorUtil.colorToString(editor.getBackgroundColor()));
        }
        panel.setAttribute("defaulttrackcolor", editor.getDefaultTrackColor());
        panel.setAttribute("defaultoccupiedtrackcolor", editor.getDefaultOccupiedTrackColor());
        panel.setAttribute("defaultalternativetrackcolor", editor.getDefaultAlternativeTrackColor());
        panel.setAttribute("defaulttextcolor", editor.getDefaultTextColor());
        panel.setAttribute("turnoutcirclecolor", editor.getTurnoutCircleColor());
        // include positionable elements
        List<Positionable> contents = editor.getContents();
        log.debug("N positionable 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, ex);
                }
            }
        }
        // include PositionablePoints
        int num = editor.pointList.size();
        log.debug("N positionablepoint elements: {}", num);
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                Object sub = editor.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 LayoutBlocks
        LayoutBlockManager tm = InstanceManager.getDefault(LayoutBlockManager.class);
        java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
        SensorManager sm = InstanceManager.sensorManagerInstance();
        num = 0;
        while (iter.hasNext()) {
            String sname = iter.next();
            if (sname == null) {
                log.error("System name null during LayoutBlock store");
            }
            LayoutBlock b = tm.getBySystemName(sname);
            if (b.getUseCount() > 0) {
                // save only those LayoutBlocks that are in use--skip abandoned ones
                Element elem = new Element("layoutblock").setAttribute("systemname", sname);
                String uname = b.getUserName();
                if (uname != null && !uname.isEmpty()) {
                    elem.setAttribute("username", uname);
                }
                // get occupancy sensor from layoutblock if it is valid
                if (!b.getOccupancySensorName().isEmpty()) {
                    Sensor s = sm.getSensor(b.getOccupancySensorName());
                    if (s != null) {
                        //send systemname
                        elem.setAttribute("occupancysensor", s.getSystemName());
                    }
                //if layoutblock has no occupancy sensor, use one from block, if it is populated
                } else {
                    Sensor s = b.getBlock().getSensor();
                    if (s != null) {
                        //send systemname
                        elem.setAttribute("occupancysensor", s.getSystemName());
                    }
                }
                elem.setAttribute("occupiedsense", Integer.toString(b.getOccupiedSense()));
                elem.setAttribute("trackcolor", ColorUtil.colorToString(b.getBlockTrackColor()));
                elem.setAttribute("occupiedcolor", ColorUtil.colorToString(b.getBlockOccupiedColor()));
                elem.setAttribute("extracolor", ColorUtil.colorToString(b.getBlockExtraColor()));
                if (!b.getMemoryName().isEmpty()) {
                    elem.setAttribute("memory", b.getMemoryName());
                }
                if (!b.useDefaultMetric()) {
                    elem.addContent(new Element("metric").addContent(Integer.toString(b.getBlockMetric())));
                }
                //add to the panel xml
                panel.addContent(elem);
                num++;
            }
        }
        log.debug("N layoutblock elements: {}", num);
        // include LevelXings
        num = editor.xingList.size();
        log.debug("N levelxing elements: {}", num);
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                Object sub = editor.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 LayoutTurnouts
        num = editor.turnoutList.size();
        log.debug("N layoutturnout elements: {}", num);
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                Object sub = editor.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 = editor.trackList.size();
        log.debug("N tracksegment elements: {}", num);
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                Object sub = editor.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 LayoutSlips
        num = editor.slipList.size();
        log.debug("N layoutSlip elements: {}", num);
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                Object sub = editor.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 = editor.turntableList.size();
        log.debug("N turntable elements: {}", num);
        if (num > 0) {
            for (int i = 0; i < num; i++) {
                Object sub = editor.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);
                }
            }
        }
        //write out formatted document
        Document doc = new Document(panel);
        XMLOutputter fmt = new XMLOutputter();
        fmt.setFormat(Format.getPrettyFormat().setLineSeparator(System.getProperty("line.separator")).setTextMode(Format.TextMode.TRIM));
        return fmt.outputString(doc);
    } catch (NullPointerException ex) {
        log.warn("Requested Layout panel [" + name + "] does not exist.");
        return "ERROR Requested panel [" + name + "] does not exist.";
    }
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Element(org.jdom2.Element) Document(org.jdom2.Document) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) SensorManager(jmri.SensorManager) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Positionable(jmri.jmrit.display.Positionable) Sensor(jmri.Sensor)

Aggregations

LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)28 Element (org.jdom2.Element)12 Attribute (org.jdom2.Attribute)9 Point2D (java.awt.geom.Point2D)6 ArrayList (java.util.ArrayList)5 PointDetails (jmri.jmrit.signalling.entryexit.PointDetails)5 Source (jmri.jmrit.signalling.entryexit.Source)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 Editor (jmri.jmrit.display.Editor)3 ControlPanelEditor (jmri.jmrit.display.controlPanelEditor.ControlPanelEditor)3 JmriJFrame (jmri.util.JmriJFrame)3 ConfigureManager (jmri.ConfigureManager)2 Sensor (jmri.Sensor)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Positionable (jmri.jmrit.display.Positionable)2 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)2 SwitchboardEditor (jmri.jmrit.display.switchboardEditor.SwitchboardEditor)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1