Search in sources :

Example 11 with Editor

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

the class IndicatorTrackIconXml method load.

/**
     * Create a IndicatorTrackIcon, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    IndicatorTrackIcon l = new IndicatorTrackIcon(p);
    Element elem = element.getChild("iconmap");
    if (elem != null) {
        List<Element> status = elem.getChildren();
        if (status.size() > 0) {
            for (int i = 0; i < status.size(); i++) {
                String msg = "IndicatorTrack \"" + l.getNameString() + "\" icon \"" + status.get(i).getName() + "\" ";
                NamedIcon icon = loadIcon(l, status.get(i).getName(), elem, msg, p);
                if (icon != null) {
                    l.setIcon(status.get(i).getName(), icon);
                } else {
                    log.info(msg + " removed for url= " + status.get(i).getName());
                    return;
                }
            }
        }
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    Element name = element.getChild("occupancyblock");
    if (name != null) {
        l.setOccBlock(name.getText());
    } else {
        // only write sensor if no OBlock, don't write double sensing
        name = element.getChild("occupancysensor");
        if (name != null) {
            l.setOccSensor(name.getText());
        }
    }
    l.setShowTrain(false);
    name = element.getChild("showTrainName");
    if (name != null) {
        if ("yes".equals(name.getText())) {
            l.setShowTrain(true);
        }
    }
    elem = element.getChild("paths");
    if (elem != null) {
        ArrayList<String> paths = new ArrayList<String>();
        List<Element> pth = elem.getChildren();
        for (int i = 0; i < pth.size(); i++) {
            paths.add(pth.get(i).getText());
        }
        l.setPaths(paths);
    }
    l.displayState(l.getStatus());
    l.updateSize();
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Editor(jmri.jmrit.display.Editor)

Example 12 with Editor

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

the class MemoryComboIconXml method load.

/**
     * Load, starting with the memoryComboIcon 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) {
    // create the objects
    Editor p = (Editor) o;
    Element elem = element.getChild("itemList");
    List<Element> list = elem.getChildren("item");
    String[] items = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        Element e = list.get(i);
        String item = e.getText();
        try {
            int idx = e.getAttribute("index").getIntValue();
            items[idx] = item;
        } catch (org.jdom2.DataConversionException ex) {
            log.error("failed to convert ComboBoxIcon index attribute");
            if (items[i] == null) {
                items[i] = item;
            }
        }
    }
    MemoryComboIcon l = new MemoryComboIcon(p, items);
    loadTextInfo(l, element);
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
        log.error("incorrect information for a memory location; must use memory name");
        p.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (m != null) {
        l.setMemory(name);
    } else {
        log.error("Memory named '" + attr.getValue() + "' not found.");
        p.loadFailed();
        return;
    }
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
}
Also used : Attribute(org.jdom2.Attribute) Memory(jmri.Memory) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) MemoryComboIcon(jmri.jmrit.display.MemoryComboIcon)

Example 13 with Editor

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

the class LinkingLabelXml method load.

/**
     * Create LinkingLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LinkingLabel l = null;
    String url = element.getChild("url").getText();
    // get object class and determine editor being used
    Editor editor = (Editor) o;
    if (element.getAttribute("icon") != null) {
        NamedIcon icon = null;
        String name = element.getAttribute("icon").getValue();
        //            if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
        if (name.equals("yes")) {
            icon = getNamedIcon("icon", element, "LinkingLabel ", editor);
        } else {
            icon = NamedIcon.getIconByName(name);
            if (icon == null) {
                icon = editor.loadFailed("LinkingLabel", name);
                if (icon == null) {
                    log.info("LinkingLabel icon removed for url= " + name);
                    return;
                }
            }
        }
        // abort if name != yes and have null icon
        if (icon == null && !name.equals("yes")) {
            log.info("LinkingLabel icon removed for url= " + name);
            return;
        }
        l = new LinkingLabel(icon, editor, url);
        // no text
        l.setPopupUtility(null);
        try {
            Attribute a = element.getAttribute("rotate");
            if (a != null && icon != null) {
                int rotation = element.getAttribute("rotate").getIntValue();
                icon.setRotation(rotation, l);
            }
        } catch (org.jdom2.DataConversionException e) {
        }
        if (name.equals("yes")) {
            NamedIcon nIcon = loadIcon(l, "icon", element, "LinkingLabel ", editor);
            if (nIcon != null) {
                l.updateIcon(nIcon);
            } else {
                log.info("LinkingLabel icon removed for url= " + name);
                return;
            }
        } else {
            l.updateIcon(icon);
        }
    //l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
    } else if (element.getAttribute("text") != null) {
        l = new LinkingLabel(element.getAttribute("text").getValue(), editor, url);
        loadTextInfo(l, element);
    } else {
        log.error("LinkingLabel is null!");
        if (log.isDebugEnabled()) {
            java.util.List<Attribute> attrs = element.getAttributes();
            log.debug("\tElement Has " + attrs.size() + " Attributes:");
            for (int i = 0; i < attrs.size(); i++) {
                Attribute a = attrs.get(i);
                log.debug("\t\t" + a.getName() + " = " + a.getValue());
            }
            java.util.List<Element> kids = element.getChildren();
            log.debug("\tElementHas " + kids.size() + " children:");
            for (int i = 0; i < kids.size(); i++) {
                Element e = kids.get(i);
                log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
            }
        }
        editor.loadFailed();
        return;
    }
    editor.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.LABELS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) LinkingLabel(jmri.jmrit.display.LinkingLabel) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor)

Example 14 with Editor

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

the class LocoIconXml 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) {
    Editor ed = (Editor) o;
    LocoIcon l = new LocoIcon(ed);
    // create the objects
    String textName = "error";
    try {
        textName = element.getAttribute("text").getValue();
    } catch (Exception e) {
        log.error("failed to get loco text attribute ex= " + e);
    }
    String name = "error";
    NamedIcon icon;
    try {
        name = element.getAttribute("icon").getValue();
    } catch (Exception e) {
        log.error("failed to get icon attribute ex= " + e);
    }
    if (name.equals("yes")) {
        icon = loadIcon(l, "icon", element, "LocoIcon", ed);
    } else {
        icon = NamedIcon.getIconByName(name);
        if (icon == null) {
            icon = ed.loadFailed("LocoIcon", name);
            if (icon == null) {
                log.info("LocoIcon icon removed for url= " + name);
                return;
            }
        }
    }
    l.updateIcon(icon);
    try {
        int x = element.getAttribute("dockX").getIntValue();
        int y = element.getAttribute("dockY").getIntValue();
        l.setDockingLocation(x, y);
    //           l.dock();
    } catch (Exception e) {
        log.warn("failed to get docking location= " + e);
    }
    String rosterId = null;
    try {
        rosterId = element.getAttribute("rosterentry").getValue();
        RosterEntry entry = Roster.getDefault().entryFromTitle(rosterId);
        l.setRosterEntry(entry);
    } catch (Exception e) {
        log.debug("no roster entry for " + rosterId + ", ex= " + e);
    }
    ed.putLocoIcon(l, textName);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MARKERS, element);
    loadTextInfo(l, element);
    // to detect "background" color for use in Tracker, examine icon file 
    l.init();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LocoIcon(jmri.jmrit.display.LocoIcon) RosterEntry(jmri.jmrit.roster.RosterEntry) Editor(jmri.jmrit.display.Editor)

Example 15 with Editor

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

the class LightIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    LightIcon l = new LightIcon(p);
    String name;
    try {
        name = element.getAttribute("light").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for light; must use light name");
        p.loadFailed();
        return;
    }
    l.setLight(name);
    Element icons = element.getChild("icons");
    if (icons == null) {
        if (log.isDebugEnabled()) {
            log.debug("Main element of Light " + name + "has no icons");
        }
    } else {
        NamedIcon icon = loadIcon(l, "on", icons, "LightIcon \"" + name + "\": icon \"on\" ", p);
        if (icon != null) {
            l.setOnIcon(icon);
        } else {
            log.info("LightIcon \"" + name + "\": icon \"on\" removed");
            return;
        }
        icon = loadIcon(l, "off", icons, "LightIcon \"" + name + "\": icon \"off\" ", p);
        if (icon != null) {
            l.setOffIcon(icon);
        } else {
            log.info("LightIcon \"" + name + "\": icon \"off\" removed");
            return;
        }
        icon = loadIcon(l, "unknown", icons, "LightIcon \"" + name + "\": icon \"unknown\" ", p);
        if (icon != null) {
            l.setUnknownIcon(icon);
        } else {
            log.info("LightIcon \"" + name + "\": icon \"unknown\" removed");
            return;
        }
        icon = loadIcon(l, "inconsistent", icons, "LightIcon \"" + name + "\": icon \"inconsistent\" ", p);
        if (icon != null) {
            l.setInconsistentIcon(icon);
        } else {
            log.info("LightIcon \"" + name + "\": icon \"inconsistent\" removed");
            return;
        }
    }
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.LIGHTS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LightIcon(jmri.jmrit.display.LightIcon) Element(org.jdom2.Element) 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