Search in sources :

Example 91 with NamedIcon

use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.

the class PositionableLabelXml method store.

/**
     * Default implementation for storing the contents of a PositionableLabel
     *
     * @param o Object to store, of type PositionableLabel
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    PositionableLabel p = (PositionableLabel) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("positionablelabel");
    storeCommonAttributes(p, element);
    if (p.isText()) {
        if (p.getUnRotatedText() != null) {
            element.setAttribute("text", p.getUnRotatedText());
        }
        storeTextInfo(p, element);
    }
    if (p.isIcon() && p.getIcon() != null) {
        element.setAttribute("icon", "yes");
        element.addContent(storeIcon("icon", (NamedIcon) p.getIcon()));
    }
    element.setAttribute("class", "jmri.jmrit.display.configurexml.PositionableLabelXml");
    return element;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Element(org.jdom2.Element) PositionableLabel(jmri.jmrit.display.PositionableLabel)

Example 92 with NamedIcon

use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.

the class PositionableLabelXml 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
    PositionableLabel l = null;
    // get object class and determine editor being used
    Editor editor = (Editor) o;
    if (element.getAttribute("icon") != null) {
        NamedIcon icon;
        String name = element.getAttribute("icon").getValue();
        //            if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
        if (name.equals("yes")) {
            icon = getNamedIcon("icon", element, "PositionableLabel ", editor);
        } else {
            icon = NamedIcon.getIconByName(name);
            if (icon == null) {
                icon = editor.loadFailed("PositionableLabel", name);
                if (icon == null) {
                    log.info("PositionableLabel icon removed for url= " + name);
                    return;
                }
            }
        }
        // abort if name != yes and have null icon
        if (icon == null && !name.equals("yes")) {
            log.info("PositionableLabel icon removed for url= " + name);
            return;
        }
        l = new PositionableLabel(icon, editor);
        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, "PositionableLabel ", editor);
            if (nIcon != null) {
                l.updateIcon(nIcon);
            } else {
                log.info("PositionableLabel icon removed for url= " + name);
                return;
            }
        } else {
            l.updateIcon(icon);
        }
    }
    if (element.getAttribute("text") != null) {
        if (l == null) {
            l = new PositionableLabel(element.getAttribute("text").getValue(), editor);
        }
        loadTextInfo(l, element);
    } else if (l == null) {
        log.error("PositionableLabel 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) Element(org.jdom2.Element) PositionableLabel(jmri.jmrit.display.PositionableLabel) DataConversionException(org.jdom2.DataConversionException) Editor(jmri.jmrit.display.Editor)

Example 93 with NamedIcon

use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.

the class MemoryIconXml method store.

/**
     * Default implementation for storing the contents of a MemoryIcon
     *
     * @param o Object to store, of type MemoryIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    MemoryIcon p = (MemoryIcon) o;
    Element element = new Element("memoryicon");
    // include attributes
    element.setAttribute("memory", p.getNamedMemory().getName());
    storeCommonAttributes(p, element);
    storeTextInfo(p, element);
    //Then we need to replace the x, y values with the original ones.
    if (p.getPopupUtility().getFixedWidth() == 0 && p.getPopupUtility().getJustification() != 0) {
        element.setAttribute("x", "" + p.getOriginalX());
        element.setAttribute("y", "" + p.getOriginalY());
    }
    element.setAttribute("selectable", (p.isSelectable() ? "yes" : "no"));
    if (p.updateBlockValueOnChange()) {
        element.setAttribute("updateBlockValue", (p.updateBlockValueOnChange() ? "yes" : "no"));
    }
    element.setAttribute("class", "jmri.jmrit.display.configurexml.MemoryIconXml");
    if (p.getDefaultIcon() != null) {
        element.setAttribute("defaulticon", p.getDefaultIcon().getURL());
    }
    // include contents
    java.util.HashMap<String, NamedIcon> map = p.getMap();
    if (map != null) {
        java.util.Iterator<java.util.Map.Entry<String, NamedIcon>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            java.util.Map.Entry<String, NamedIcon> mi = iterator.next();
            String key = mi.getKey();
            String value = mi.getValue().getName();
            Element e2 = new Element("memorystate");
            e2.setAttribute("value", key);
            e2.setAttribute("icon", value);
            element.addContent(e2);
        }
    }
    return element;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) MemoryIcon(jmri.jmrit.display.MemoryIcon) Element(org.jdom2.Element)

Example 94 with NamedIcon

use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.

the class SensorIconXml method loadSensorIcon.

private NamedIcon loadSensorIcon(String state, int rotation, SensorIcon l, Element element, String name, Editor ed) {
    String msg = "SensorIcon \"" + name + "\": icon \"" + state + "\" ";
    // loadIcon gets icon as an element
    NamedIcon icon = loadIcon(l, state, element, msg, ed);
    if (icon == null && _icon) {
        // old config files may define icons as attributes
        String iconName;
        if (element.getAttribute(state) != null && !(iconName = element.getAttribute(state).getValue()).equals("")) {
            icon = NamedIcon.getIconByName(iconName);
            if (icon == null) {
                icon = ed.loadFailed(msg, iconName);
                if (icon == null) {
                    log.info(msg + " removed for url= " + iconName);
                }
            } else {
                icon.setRotation(rotation, l);
            }
        } else {
            log.warn("did not locate " + state + " icon file for " + name);
        }
    }
    if (icon == null) {
        log.info(msg + " removed");
    } else {
        l.setIcon(_nameMap.get(state), icon);
    }
    return icon;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 95 with NamedIcon

use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.

the class EditPortalFrame method makeDndIconPanel.

/**
     * ******************** DnD ****************************
     */
protected JPanel makeDndIconPanel() {
    _dndPanel = new JPanel();
    String fileName = "resources/icons/throttles/RoundRedCircle20.png";
    NamedIcon icon = new NamedIcon(fileName, fileName);
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), Bundle.getMessage("BeanNamePortal")));
    try {
        JLabel label = new IconDragJLabel(new DataFlavor(Editor.POSITIONABLE_FLAVOR));
        label.setIcon(icon);
        label.setName(Bundle.getMessage("BeanNamePortal"));
        panel.add(label);
    } catch (java.lang.ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
    }
    _dndPanel.add(panel);
    return _dndPanel;
}
Also used : JPanel(javax.swing.JPanel) NamedIcon(jmri.jmrit.catalog.NamedIcon) JLabel(javax.swing.JLabel) DragJLabel(jmri.jmrit.catalog.DragJLabel) DataFlavor(java.awt.datatransfer.DataFlavor)

Aggregations

NamedIcon (jmri.jmrit.catalog.NamedIcon)128 Entry (java.util.Map.Entry)28 Element (org.jdom2.Element)27 HashMap (java.util.HashMap)23 JPanel (javax.swing.JPanel)13 Editor (jmri.jmrit.display.Editor)13 Attribute (org.jdom2.Attribute)13 ActionEvent (java.awt.event.ActionEvent)12 ActionListener (java.awt.event.ActionListener)12 JLabel (javax.swing.JLabel)11 JButton (javax.swing.JButton)10 DataFlavor (java.awt.datatransfer.DataFlavor)6 CatalogTreeNode (jmri.jmrit.catalog.CatalogTreeNode)6 DragJLabel (jmri.jmrit.catalog.DragJLabel)6 Sensor (jmri.Sensor)5 CatalogTreeLeaf (jmri.jmrit.catalog.CatalogTreeLeaf)5 RosterEntry (jmri.jmrit.roster.RosterEntry)5 Point (java.awt.Point)4 JComponent (javax.swing.JComponent)4 JDialog (javax.swing.JDialog)4