Search in sources :

Example 56 with NamedIcon

use of jmri.jmrit.catalog.NamedIcon 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)

Example 57 with NamedIcon

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

the class ControlPanelEditorXml method loadIcon.

public NamedIcon loadIcon(String key, Element element, Editor ed) {
    Element elem = element.getChild(key);
    NamedIcon icon = null;
    if (elem != null) {
        Element e = elem.getChild("url");
        String iconName = e.getText();
        icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed(key, iconName);
            if (icon == null) {
                log.info("{} removed for url= {}", key, iconName);
            }
        }
    }
    return icon;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Element(org.jdom2.Element)

Example 58 with NamedIcon

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

the class ControlPanelEditorXml method load.

/**
     * Create a ControlPanelEditor object, then register and fill it, then pop
     * it in a JFrame
     *
     * @param shared Top level Element to unpack.
     * @return true if successful
     */
@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    // find coordinates
    int x = 0;
    int y = 0;
    int height = 400;
    int width = 300;
    try {
        x = shared.getAttribute("x").getIntValue();
        y = shared.getAttribute("y").getIntValue();
        height = shared.getAttribute("height").getIntValue();
        width = shared.getAttribute("width").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert ControlPanelEditor's attribute");
        result = false;
    }
    // find the name
    String name = "Control Panel";
    if (shared.getAttribute("name") != null) {
        name = shared.getAttribute("name").getValue();
    }
    // confirm that panel hasn't already been loaded
    if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
        log.warn("File contains a panel with the same name ({}) as an existing panel", name);
        result = false;
    }
    ControlPanelEditor panel = new ControlPanelEditor(name);
    // save painting until last
    panel.getTargetFrame().setVisible(false);
    jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
    // Load editor option flags. This has to be done before the content 
    // items are loaded, to preserve the individual item settings
    Attribute a;
    boolean value = true;
    if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllEditable(value);
    value = true;
    if ((a = shared.getAttribute("positionable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllPositionable(value);
    /*
         value = false;
         if ((a = element.getAttribute("showcoordinates"))!=null && a.getValue().equals("yes"))
         value = true;
         panel.setShowCoordinates(value);
         */
    value = true;
    if ((a = shared.getAttribute("showtooltips")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllShowTooltip(value);
    value = true;
    if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllControlling(value);
    value = false;
    if ((a = shared.getAttribute("hide")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    panel.setShowHidden(value);
    value = true;
    if ((a = shared.getAttribute("panelmenu")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setPanelMenuVisible(value);
    value = true;
    if ((a = shared.getAttribute("shapeSelect")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setShapeSelect(value);
    if ((a = shared.getAttribute("state")) != null) {
        try {
            int xState = a.getIntValue();
            panel.setExtendedState(xState);
        } catch (org.jdom2.DataConversionException e) {
            log.error("failed to convert ControlPanelEditor's extended State");
            result = false;
        }
    }
    String state = "both";
    if ((a = shared.getAttribute("scrollable")) != null) {
        state = a.getValue();
    }
    panel.setScroll(state);
    try {
        int red = shared.getAttribute("redBackground").getIntValue();
        int blue = shared.getAttribute("blueBackground").getIntValue();
        int green = shared.getAttribute("greenBackground").getIntValue();
        panel.setBackgroundColor(new Color(red, green, blue));
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse color attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    Element icons = shared.getChild("icons");
    /*        if (icons != null) {
            HashMap<String, NamedIcon> portalIconMap = new HashMap<String, NamedIcon>();
            portalIconMap.put(PortalIcon.VISIBLE, loadIcon("visible", icons, panel));
            portalIconMap.put(PortalIcon.PATH, loadIcon("path_edit", icons, panel));
            portalIconMap.put(PortalIcon.HIDDEN, loadIcon("hidden", icons, panel));
            portalIconMap.put(PortalIcon.TO_ARROW, loadIcon("to_arrow", icons, panel));
            portalIconMap.put(PortalIcon.FROM_ARROW, loadIcon("from_arrow", icons, panel));
            panel.setDefaultPortalIcons(portalIconMap);
        }*/
    shared.removeChild("icons");
    //set the (global) editor display widgets to their flag settings
    panel.initView();
    // load the contents
    List<Element> items = shared.getChildren();
    for (Element item : items) {
        String adapterName = item.getAttribute("class").getValue();
        log.debug("load via {}", adapterName);
        try {
            XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
            // and do it
            adapter.load(item, panel);
            if (!panel.loadOK()) {
                result = false;
            }
        } catch (Exception e) {
            log.error("Exception while loading {}: {}", item.getName(), e.getMessage(), e);
            result = false;
        }
    }
    if (icons != null) {
        HashMap<String, NamedIcon> portalIconMap = new HashMap<String, NamedIcon>();
        portalIconMap.put(PortalIcon.VISIBLE, loadIcon("visible", icons, panel));
        portalIconMap.put(PortalIcon.PATH, loadIcon("path_edit", icons, panel));
        portalIconMap.put(PortalIcon.HIDDEN, loadIcon("hidden", icons, panel));
        portalIconMap.put(PortalIcon.TO_ARROW, loadIcon("to_arrow", icons, panel));
        portalIconMap.put(PortalIcon.FROM_ARROW, loadIcon("from_arrow", icons, panel));
        panel.setDefaultPortalIcons(portalIconMap);
    }
    // dispose of url correction data
    panel.disposeLoadData();
    // display the results, with the editor in back
    panel.pack();
    panel.setAllEditable(panel.isEditable());
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(panel);
    }
    // reset the size and position, in case the display caused it to change
    panel.getTargetFrame().setLocation(x, y);
    panel.getTargetFrame().setSize(width, height);
    panel.setTitle();
    // always show the panel
    panel.getTargetFrame().setVisible(true);
    // do last to set putItem override - unused.
    panel.loadComplete();
    return result;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Attribute(org.jdom2.Attribute) HashMap(java.util.HashMap) Color(java.awt.Color) Element(org.jdom2.Element) Point(java.awt.Point) ConfigureManager(jmri.ConfigureManager) AbstractXmlAdapter(jmri.configurexml.AbstractXmlAdapter) XmlAdapter(jmri.configurexml.XmlAdapter)

Example 59 with NamedIcon

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

the class ControlPanelEditorXml method store.

/**
     * Default implementation for storing the contents of a ControlPanelEditor
     *
     * @param o Object to store, of type ControlPanelEditor
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    ControlPanelEditor p = (ControlPanelEditor) o;
    Element panel = new Element("paneleditor");
    JFrame frame = p.getTargetFrame();
    Dimension size = frame.getSize();
    Point posn = frame.getLocation();
    panel.setAttribute("class", "jmri.jmrit.display.controlPanelEditor.configurexml.ControlPanelEditorXml");
    panel.setAttribute("name", "" + frame.getName());
    panel.setAttribute("x", "" + posn.x);
    panel.setAttribute("y", "" + posn.y);
    panel.setAttribute("height", "" + size.height);
    panel.setAttribute("width", "" + size.width);
    panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
    panel.setAttribute("positionable", "" + (p.allPositionable() ? "yes" : "no"));
    //panel.setAttribute("showcoordinates", ""+(p.showCoordinates()?"yes":"no"));
    panel.setAttribute("showtooltips", "" + (p.showTooltip() ? "yes" : "no"));
    panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
    panel.setAttribute("hide", p.isVisible() ? "no" : "yes");
    panel.setAttribute("panelmenu", p.isPanelMenuVisible() ? "yes" : "no");
    panel.setAttribute("scrollable", p.getScrollable());
    if (p.getBackgroundColor() != null) {
        panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
        panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
        panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
    }
    panel.setAttribute("state", "" + p.getExtendedState());
    panel.setAttribute("shapeSelect", "" + (p.getShapeSelect() ? "yes" : "no"));
    Element elem = new Element("icons");
    HashMap<String, NamedIcon> map = p.getPortalIconMap();
    elem.addContent(storeIcon("visible", map.get(PortalIcon.VISIBLE)));
    elem.addContent(storeIcon("path_edit", map.get(PortalIcon.PATH)));
    elem.addContent(storeIcon("hidden", map.get(PortalIcon.HIDDEN)));
    elem.addContent(storeIcon("to_arrow", map.get(PortalIcon.TO_ARROW)));
    elem.addContent(storeIcon("from_arrow", map.get(PortalIcon.FROM_ARROW)));
    panel.addContent(elem);
    // include contents
    List<Positionable> contents = p.getContents();
    log.debug("N elements: {}", contents.size());
    for (Positionable sub : contents) {
        if (sub != null && sub.storeItem()) {
            try {
                Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
                if (e != null) {
                    panel.addContent(e);
                }
            } catch (Exception e) {
                log.error("Error storing panel element: {}", e.getMessage(), e);
            }
        }
    }
    return panel;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) Dimension(java.awt.Dimension) Point(java.awt.Point) Positionable(jmri.jmrit.display.Positionable)

Example 60 with NamedIcon

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

the class SignalMastItemPanel method getIconMap.

private void getIconMap(int row) {
    if (row < 0) {
        _currentIconMap = null;
        _family = null;
        return;
    }
    NamedBean bean = _model.getBeanAt(row);
    if (bean == null) {
        if (log.isDebugEnabled()) {
            log.debug("getIconMap: NamedBean is null at row " + row);
        }
        _currentIconMap = null;
        _family = null;
        return;
    }
    try {
        _mast = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(bean.getDisplayName());
    } catch (IllegalArgumentException ex) {
        log.error("getIconMap: No SignalMast called " + bean.getDisplayName());
        _currentIconMap = null;
        return;
    }
    _family = _mast.getSignalSystem().getSystemName();
    _currentIconMap = new HashMap<String, NamedIcon>();
    SignalAppearanceMap appMap = _mast.getAppearanceMap();
    Enumeration<String> e = _mast.getAppearanceMap().getAspects();
    while (e.hasMoreElements()) {
        String aspect = e.nextElement();
        String s = appMap.getImageLink(aspect, _family);
        if (s != null && !s.equals("")) {
            if (!s.contains("preference:")) {
                s = s.substring(s.indexOf("resources"));
            }
            NamedIcon n = new NamedIcon(s, s);
            _currentIconMap.put(aspect, n);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("getIconMap: for " + _family + " size= " + _currentIconMap.size());
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) NamedBean(jmri.NamedBean) SignalAppearanceMap(jmri.SignalAppearanceMap)

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