Search in sources :

Example 16 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class SetTrainIconPositionFrame method placeTestIcons.

// place test markers on panel
private void placeTestIcons() {
    removeIcons();
    if (locationBox.getSelectedItem() == null) {
        return;
    }
    Editor editor = PanelMenu.instance().getEditorByName(Setup.getPanelName());
    if (editor == null) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("LoadPanel"), new Object[] { Setup.getPanelName() }), Bundle.getMessage("PanelNotFound"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    Location l = (Location) locationBox.getSelectedItem();
    if (l != null) {
        // East icon
        if ((Setup.getTrainDirection() & Setup.EAST) == Setup.EAST) {
            _tIonEast = editor.addTrainIcon(Bundle.getMessage("East"));
            _tIonEast.getTooltip().setText(l.getName());
            _tIonEast.getTooltip().setBackgroundColor(Color.white);
            _tIonEast.setLocoColor(Setup.getTrainIconColorEast());
            _tIonEast.setLocation((Integer) spinTrainIconEastX.getValue(), (Integer) spinTrainIconEastY.getValue());
            addIconListener(_tIonEast);
        }
        // West icon
        if ((Setup.getTrainDirection() & Setup.WEST) == Setup.WEST) {
            _tIonWest = editor.addTrainIcon(Bundle.getMessage("West"));
            _tIonWest.getTooltip().setText(l.getName());
            _tIonWest.getTooltip().setBackgroundColor(Color.white);
            _tIonWest.setLocoColor(Setup.getTrainIconColorWest());
            _tIonWest.setLocation((Integer) spinTrainIconWestX.getValue(), (Integer) spinTrainIconWestY.getValue());
            addIconListener(_tIonWest);
        }
        // North icon
        if ((Setup.getTrainDirection() & Setup.NORTH) == Setup.NORTH) {
            _tIonNorth = editor.addTrainIcon(Bundle.getMessage("North"));
            _tIonNorth.getTooltip().setText(l.getName());
            _tIonNorth.getTooltip().setBackgroundColor(Color.white);
            _tIonNorth.setLocoColor(Setup.getTrainIconColorNorth());
            _tIonNorth.setLocation((Integer) spinTrainIconNorthX.getValue(), (Integer) spinTrainIconNorthY.getValue());
            addIconListener(_tIonNorth);
        }
        // South icon
        if ((Setup.getTrainDirection() & Setup.SOUTH) == Setup.SOUTH) {
            _tIonSouth = editor.addTrainIcon(Bundle.getMessage("South"));
            _tIonSouth.getTooltip().setText(l.getName());
            _tIonSouth.getTooltip().setBackgroundColor(Color.white);
            _tIonSouth.setLocoColor(Setup.getTrainIconColorSouth());
            _tIonSouth.setLocation((Integer) spinTrainIconSouthX.getValue(), (Integer) spinTrainIconSouthY.getValue());
            addIconListener(_tIonSouth);
        }
    }
}
Also used : Editor(jmri.jmrit.display.Editor) Location(jmri.jmrit.operations.locations.Location)

Example 17 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class SetTrainIconRouteFrame method placeTestIcons.

// place test markers on panel
private void placeTestIcons() {
    Editor editor = PanelMenu.instance().getEditorByName(Setup.getPanelName());
    if (editor == null) {
        JOptionPane.showMessageDialog(this, MessageFormat.format(Bundle.getMessage("LoadPanel"), new Object[] { Setup.getPanelName() }), Bundle.getMessage("PanelNotFound"), JOptionPane.ERROR_MESSAGE);
    } else {
        if (_tIon != null) {
            _tIon.remove();
        }
        // icon
        _tIon = editor.addTrainIcon(_rl.getName());
        _tIon.getTooltip().setText(_route.getName());
        _tIon.getTooltip().setBackgroundColor(Color.white);
        _tIon.setLocation(_rl.getTrainIconX(), _rl.getTrainIconY());
        setTrainIconNameAndColor();
        addIconListener(_tIon);
    }
}
Also used : Editor(jmri.jmrit.display.Editor)

Example 18 with Editor

use of jmri.jmrit.display.Editor 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;
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Arrays(java.util.Arrays) Enumeration(java.util.Enumeration) ConnectionConfig(jmri.jmrix.ConnectionConfig) URL(jmri.server.json.JSON.URL) ProfileManager(jmri.profile.ProfileManager) DccLocoAddress(jmri.DccLocoAddress) JmriJFrame(jmri.util.JmriJFrame) PANEL(jmri.server.json.JSON.PANEL) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Editor(jmri.jmrit.display.Editor) JsonException(jmri.server.json.JsonException) SWITCHBOARD_PANEL(jmri.server.json.JSON.SWITCHBOARD_PANEL) ArrayList(java.util.ArrayList) TYPE(jmri.server.json.JSON.TYPE) JsonServerPreferences(jmri.jmris.json.JsonServerPreferences) ConnectionConfigManager(jmri.jmrix.ConnectionConfigManager) Locale(java.util.Locale) Profile(jmri.profile.Profile) SwitchboardEditor(jmri.jmrit.display.switchboardEditor.SwitchboardEditor) PanelEditor(jmri.jmrit.display.panelEditor.PanelEditor) JsonNode(com.fasterxml.jackson.databind.JsonNode) NAME(jmri.server.json.JSON.NAME) InstanceManager(jmri.InstanceManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HttpServletResponse(javax.servlet.http.HttpServletResponse) JsonHttpService(jmri.server.json.JsonHttpService) Metadata(jmri.Metadata) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) WebServerPreferences(jmri.web.server.WebServerPreferences) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) CONTROL_PANEL(jmri.server.json.JSON.CONTROL_PANEL) ConnectionNameFromSystemName(jmri.util.ConnectionNameFromSystemName) DATA(jmri.server.json.JSON.DATA) USERNAME(jmri.server.json.JSON.USERNAME) JSON(jmri.server.json.JSON) NodeIdentity(jmri.util.node.NodeIdentity) ZeroConfService(jmri.util.zeroconf.ZeroConfService) LAYOUT_PANEL(jmri.server.json.JSON.LAYOUT_PANEL) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 19 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class SignalHeadIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor ed = (Editor) o;
    SignalHeadIcon l = new SignalHeadIcon(ed);
    String name;
    Attribute attr = element.getAttribute("signalhead");
    if (attr == null) {
        log.error("incorrect information for signal head; must use signalhead name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    SignalHead sh = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name);
    if (sh != null) {
        l.setSignalHead(name);
    } else {
        log.error("SignalHead named '" + attr.getValue() + "' not found.");
        //    ed.loadFailed();
        return;
    }
    int rotation = 0;
    try {
        attr = element.getAttribute("rotate");
        rotation = attr.getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    List<Element> aspects = element.getChildren();
    if (aspects.size() > 0) {
        Element icons = element.getChild("icons");
        Element elem = element;
        if (icons != null) {
            List<Element> c = icons.getChildren();
            aspects = c;
            elem = icons;
        }
        for (int i = 0; i < aspects.size(); i++) {
            String aspect = aspects.get(i).getName();
            NamedIcon icon = loadIcon(l, aspect, elem, "SignalHead \"" + name + "\": icon \"" + aspect + "\" ", ed);
            if (icon != null) {
                l.setIcon(_nameMap.get(aspect), icon);
            } else {
                log.info("SignalHead \"" + name + "\": icon \"" + aspect + "\" removed");
            }
        }
        log.debug(aspects.size() + " icons loaded for " + l.getNameString());
    } else {
        // old style as attributes - somewhere around pre 2.5.4
        NamedIcon icon = loadSignalIcon("red", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateRed"), icon);
        }
        icon = loadSignalIcon("yellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateYellow"), icon);
        }
        icon = loadSignalIcon("green", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateGreen"), icon);
        }
        icon = loadSignalIcon("lunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateLunar"), icon);
        }
        icon = loadSignalIcon("held", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateHeld"), icon);
        }
        icon = loadSignalIcon("dark", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateDark"), icon);
        }
        icon = loadSignalIcon("flashred", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingRed"), icon);
        }
        icon = loadSignalIcon("flashyellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingYellow"), icon);
        }
        icon = loadSignalIcon("flashgreen", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingGreen"), icon);
        }
        icon = loadSignalIcon("flashlunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingLunar"), icon);
        }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    try {
        attr = element.getAttribute("clickmode");
        if (attr != null) {
            l.setClickMode(attr.getIntValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on clickmode attribute: " + e);
    }
    try {
        attr = element.getAttribute("litmode");
        if (attr != null) {
            l.setLitMode(attr.getBooleanValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on litmode attribute: " + e);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SIGNALS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalHeadIcon(jmri.jmrit.display.SignalHeadIcon) Editor(jmri.jmrit.display.Editor)

Example 20 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class SignalMastIconXml method load.

/**
     * Create a SignalMastIcon, then add
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor ed = (Editor) o;
    SignalMastIcon l = new SignalMastIcon(ed);
    String name;
    Attribute attr;
    /*
         * We need to set the rotation and scaling first, prior to setting the
         * signalmast, otherwise we end up in a situation where by the icons do
         * not get rotated or scaled correctly.
         **/
    try {
        int rotation = 0;
        double scale = 1.0;
        // former attribute name.
        attr = element.getAttribute("rotation");
        if (attr != null) {
            rotation = attr.getIntValue();
        }
        attr = element.getAttribute("degrees");
        if (attr != null) {
            rotation = attr.getIntValue();
        }
        l.rotate(rotation);
        attr = element.getAttribute("scale");
        String text = "Error attr null";
        if (attr != null) {
            scale = attr.getDoubleValue();
            text = attr.getValue();
        }
        l.setScale(scale);
        if (log.isDebugEnabled()) {
            log.debug("Load SignalMast rotation= " + rotation + " scale= " + scale + " attr text= " + text);
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert rotation or scale attribute");
    }
    attr = element.getAttribute("signalmast");
    if (attr == null) {
        log.error("incorrect information for signal mast; must use signalmast name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
        if (log.isDebugEnabled()) {
            log.debug("Load SignalMast " + name);
        }
    }
    SignalMast sh = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(name);
    if (sh != null) {
        l.setSignalMast(name);
    } else {
        log.error("SignalMast named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    //    return;
    }
    attr = element.getAttribute("imageset");
    if (attr != null) {
        l.useIconSet(attr.getValue());
    }
    attr = element.getAttribute("imageset");
    if (attr != null) {
        l.useIconSet(attr.getValue());
    }
    try {
        attr = element.getAttribute("clickmode");
        if (attr != null) {
            l.setClickMode(attr.getIntValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on clickmode attribute: " + e);
    }
    try {
        attr = element.getAttribute("litmode");
        if (attr != null) {
            l.setLitMode(attr.getBooleanValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on litmode attribute: " + e);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SIGNALS, element);
}
Also used : Attribute(org.jdom2.Attribute) SignalMastIcon(jmri.jmrit.display.SignalMastIcon) SignalMast(jmri.SignalMast) Editor(jmri.jmrit.display.Editor)

Aggregations

Editor (jmri.jmrit.display.Editor)36 Element (org.jdom2.Element)18 Attribute (org.jdom2.Attribute)15 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 ArrayList (java.util.ArrayList)3 Memory (jmri.Memory)3 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 ImageIndexEditor (jmri.jmrit.catalog.ImageIndexEditor)2 RosterEntry (jmri.jmrit.roster.RosterEntry)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Point (java.awt.Point)1 GeneralPath (java.awt.geom.GeneralPath)1 Arrays (java.util.Arrays)1