Search in sources :

Example 21 with Editor

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

the class ControlPanelEditor method makeIconMenu.

protected void makeIconMenu() {
    _iconMenu = new JMenu(Bundle.getMessage("MenuIcon"));
    _menuBar.add(_iconMenu, 0);
    JMenuItem mi = new JMenuItem(Bundle.getMessage("MenuItemItemPalette"));
    mi.addActionListener(new ActionListener() {

        Editor editor;

        ActionListener init(Editor ed) {
            editor = ed;
            return this;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (_itemPalette == null) {
                _itemPalette = new ItemPalette(Bundle.getMessage("MenuItemItemPalette"), editor);
            }
            _itemPalette.setVisible(true);
        }
    }.init(this));
    if (SystemType.isMacOSX()) {
        mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.META_MASK));
    } else {
        mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.CTRL_MASK));
    }
    _iconMenu.add(mi);
    _iconMenu.add(new jmri.jmrit.beantable.OBlockTableAction(Bundle.getMessage("MenuItemOBlockTable")));
    mi = (JMenuItem) _iconMenu.getMenuComponent(1);
    if (SystemType.isMacOSX()) {
        mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.META_MASK));
    } else {
        mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK));
    }
    _iconMenu.add(new jmri.jmrit.beantable.ListedTableAction(Bundle.getMessage("MenuItemTableList")));
    mi = (JMenuItem) _iconMenu.getMenuComponent(2);
    if (SystemType.isMacOSX()) {
        mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.META_MASK));
    } else {
        mi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
    }
}
Also used : ItemPalette(jmri.jmrit.display.palette.ItemPalette) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) Editor(jmri.jmrit.display.Editor) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenu(javax.swing.JMenu)

Example 22 with Editor

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

the class PositionableCircleXml 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;
    PositionableCircle ps = new PositionableCircle(ed);
    Element elem = element.getChild("size");
    // actually diameter - too late to change name
    ps.setWidth(getInt(elem, "radius"));
    // get object class and determine editor being used
    Editor editor = (Editor) o;
    editor.putItem(ps);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(ps, Editor.MARKERS, element);
}
Also used : Element(org.jdom2.Element) PositionableCircle(jmri.jmrit.display.controlPanelEditor.shape.PositionableCircle) Editor(jmri.jmrit.display.Editor)

Example 23 with Editor

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

the class RpsPositionIconXml 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;
    RpsPositionIcon l = new RpsPositionIcon(ed);
    // create the objects
    String name = element.getAttribute("active").getValue();
    NamedIcon active = NamedIcon.getIconByName(name);
    if (active == null) {
        active = ed.loadFailed("RpsPositionIcon: icon \"active\" ", name);
        if (active == null) {
            log.info("RpsPositionIcon: icon \"active\" removed for url= " + name);
            return;
        }
    }
    l.setActiveIcon(active);
    name = element.getAttribute("error").getValue();
    NamedIcon error = NamedIcon.getIconByName(name);
    if (error == null) {
        error = ed.loadFailed("RpsPositionIcon: icon \"error\" ", name);
        if (error == null) {
            log.info("RpsPositionIcon: \"error\" removed for url= " + name);
            return;
        }
    }
    l.setErrorIcon(error);
    try {
        Attribute a = element.getAttribute("rotate");
        if (a != null) {
            int rotation = element.getAttribute("rotate").getIntValue();
            active.setRotation(rotation, l);
            error.setRotation(rotation, l);
        }
    } catch (org.jdom2.DataConversionException e) {
    }
    Attribute a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    a = element.getAttribute("showid");
    if ((a != null) && a.getValue().equals("true")) {
        l.setShowID(true);
    } else {
        l.setShowID(false);
    }
    a = element.getAttribute("filter");
    if (a != null) {
        l.setFilter(a.getValue());
    }
    double sxScale = 0.;
    double syScale = 0.;
    int sxOrigin = 0;
    int syOrigin = 0;
    try {
        sxScale = element.getAttribute("sxscale").getDoubleValue();
        syScale = element.getAttribute("syscale").getDoubleValue();
        sxOrigin = element.getAttribute("sxorigin").getIntValue();
        syOrigin = element.getAttribute("syorigin").getIntValue();
    } catch (NullPointerException e1) {
        log.error("missing transform attribute");
    } catch (org.jdom2.DataConversionException e2) {
        log.error("failed to convert transform attributes");
    }
    l.setTransform(sxScale, syScale, sxOrigin, syOrigin);
    NamedIcon icon = loadIcon(l, "active", element, "RpsPositionIcon ", ed);
    if (icon != null) {
        l.setActiveIcon(icon);
    }
    icon = loadIcon(l, "error", element, "RpsPositionIcon ", ed);
    if (icon != null) {
        l.setErrorIcon(icon);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SENSORS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Editor(jmri.jmrit.display.Editor) RpsPositionIcon(jmri.jmrit.display.RpsPositionIcon)

Example 24 with Editor

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

the class MemoryIconXml method load.

/**
     * Load, starting with the memoryicon 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;
    MemoryIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.MemoryIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new MemoryIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
        log.error("incorrect information for a memory location; must use memory name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (m != null) {
        l.setMemory(name);
    } else {
        log.error("Memory 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);
    }
    a = element.getAttribute("updateBlockValue");
    if (a != null && a.getValue().equals("yes")) {
        l.updateBlockValueOnChange(true);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("memorystate");
    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) MemoryIcon(jmri.jmrit.display.MemoryIcon) Attribute(org.jdom2.Attribute) Memory(jmri.Memory) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Editor(jmri.jmrit.display.Editor)

Example 25 with Editor

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

the class MemoryInputIconXml method load.

/**
     * Load, starting with the memoryInputIcon 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;
    int nCol = 2;
    try {
        nCol = element.getAttribute("colWidth").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert colWidth attribute");
    }
    MemoryInputIcon l = new MemoryInputIcon(nCol, p);
    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);
    javax.swing.JComponent textField = l.getTextComponent();
    jmri.jmrit.display.PositionablePopupUtil util = l.getPopupUtility();
    if (util.hasBackground()) {
        textField.setBackground(util.getBackground());
    } else {
        textField.setBackground(null);
        textField.setOpaque(false);
    }
}
Also used : Attribute(org.jdom2.Attribute) Memory(jmri.Memory) MemoryInputIcon(jmri.jmrit.display.MemoryInputIcon) 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