Search in sources :

Example 6 with Editor

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

the class ReporterIconXml 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;
    ReporterIcon l = new ReporterIcon(ed);
    loadTextInfo(l, element);
    l.setReporter(jmri.InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(element.getAttribute("reporter").getValue()));
    l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.REPORTERS, element);
}
Also used : ReporterIcon(jmri.jmrit.display.ReporterIcon) Editor(jmri.jmrit.display.Editor)

Example 7 with Editor

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

the class PositionableRectangleXml method load.

/**
     * Create a PositionableShape, 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 ed = (Editor) o;
    PositionableRectangle ps = new PositionableRectangle(ed);
    Element elem = element.getChild("size");
    ps.setWidth(getInt(elem, "width"));
    ps.setHeight(getInt(elem, "height"));
    ed.putItem(ps);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(ps, Editor.MARKERS, element);
}
Also used : PositionableRectangle(jmri.jmrit.display.controlPanelEditor.shape.PositionableRectangle) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor)

Example 8 with Editor

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

the class LocoLabelXml method load.

/**
     * Create a PositionableShape, 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 ed = (Editor) o;
    LocoLabel ll = new LocoLabel(ed);
    Element elem = element.getChild("size");
    ll.setWidth(getInt(elem, "width"));
    ll.setHeight(getInt(elem, "height"));
    if (elem != null && elem.getAttribute("systemName") != null) {
        String name = elem.getAttribute("systemName").getValue();
        OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
        OBlock block = manager.getBySystemName(name);
        ll.setBlock(block);
        if (elem.getAttribute("trainName") != null && block != null) {
            block.setValue(elem.getAttribute("trainName").getValue());
        }
    } else {
        // don't put into editor's content list without           
        return;
    }
    ed.putItem(ll);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(ll, Editor.MARKERS, element);
}
Also used : LocoLabel(jmri.jmrit.display.controlPanelEditor.shape.LocoLabel) Element(org.jdom2.Element) OBlockManager(jmri.jmrit.logix.OBlockManager) Editor(jmri.jmrit.display.Editor) OBlock(jmri.jmrit.logix.OBlock)

Example 9 with Editor

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

the class Train method createTrainIcon.

public void createTrainIcon(RouteLocation rl) {
    if (_trainIcon != null && _trainIcon.isActive()) {
        _trainIcon.remove();
    }
    // if there's a panel specified, get it and place icon
    if (!Setup.getPanelName().equals(Setup.NONE)) {
        Editor editor = PanelMenu.instance().getEditorByName(Setup.getPanelName());
        if (editor != null) {
            _trainIcon = editor.addTrainIcon(getIconName());
            _trainIcon.setTrain(this);
            if (getIconName().length() > 9) {
                _trainIcon.setFont(jmri.util.FontUtil.deriveFont(_trainIcon.getFont(), 8.f));
            }
            if (rl != null) {
                _trainIcon.setLocation(rl.getTrainIconX(), rl.getTrainIconY());
            }
            // add throttle if there's a throttle manager
            if (jmri.InstanceManager.getNullableDefault(jmri.ThrottleManager.class) != null) {
                // add throttle if JMRI loco roster entry exist
                RosterEntry entry = null;
                if (getLeadEngine() != null) {
                    // first try and find a match based on loco road number
                    List<RosterEntry> entries = Roster.getDefault().matchingList(null, getLeadEngine().getNumber(), null, null, null, null, null);
                    if (entries.size() > 0) {
                        entry = entries.get(0);
                    }
                    if (entry == null) {
                        // now try finding a match based on DCC address
                        entries = Roster.getDefault().matchingList(null, null, getLeadEngine().getNumber(), null, null, null, null);
                        if (entries.size() > 0) {
                            entry = entries.get(0);
                        }
                    }
                }
                if (entry != null) {
                    _trainIcon.setRosterEntry(entry);
                    if (getLeadEngine().getConsist() != null) {
                        _trainIcon.setConsistNumber(getLeadEngine().getConsist().getConsistNumber());
                    }
                } else {
                    log.debug("Loco roster entry not found for train (" + getName() + ")");
                }
            }
        }
    }
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry) Editor(jmri.jmrit.display.Editor)

Example 10 with Editor

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

the class BlockContentsIconXml method load.

/**
     * Load, starting with the BlockContentsIcon 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) {
    Editor ed = null;
    BlockContentsIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.BlockContentsIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new BlockContentsIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("blockcontents");
    if (attr == null) {
        log.error("incorrect information for a block contents; must use block name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Block m = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(name);
    if (m != null) {
        l.setBlock(name);
    } else {
        log.error("Block named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    }
    Attribute a = element.getAttribute("selectable");
    if (a != null && a.getValue().equals("yes")) {
        l.setSelectable(true);
    } else {
        l.setSelectable(false);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("blockstate");
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String iconName = item.getAttribute("icon").getValue();
        NamedIcon icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed("Memory " + name, iconName);
            if (icon == null) {
                log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
            }
        }
        if (icon != null) {
            String keyValue = item.getAttribute("value").getValue();
            l.addKeyAndIcon(icon, keyValue);
        }
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setOriginalLocation(x, y);
    l.displayState();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Attribute(org.jdom2.Attribute) BlockContentsIcon(jmri.jmrit.display.BlockContentsIcon) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) Block(jmri.Block) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) 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