Search in sources :

Example 21 with NamedIcon

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

the class ItemPalette method store3levelMap.

static CatalogTreeNode store3levelMap(String type, HashMap<String, HashMap<String, NamedIcon>> familyMap) {
    CatalogTreeNode typeNode = new CatalogTreeNode(type);
    Iterator<Entry<String, HashMap<String, NamedIcon>>> iter = familyMap.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String, HashMap<String, NamedIcon>> ent = iter.next();
        String family = ent.getKey();
        CatalogTreeNode familyNode = new CatalogTreeNode(family);
        HashMap<String, NamedIcon> iconMap = ent.getValue();
        Iterator<Entry<String, NamedIcon>> iterat = iconMap.entrySet().iterator();
        while (iterat.hasNext()) {
            Entry<String, NamedIcon> e = iterat.next();
            String state = e.getKey();
            String path = e.getValue().getURL();
            familyNode.addLeaf(state, path);
        }
        typeNode.add(familyNode);
        if (log.isDebugEnabled()) {
            log.debug("Add familyNode " + familyNode);
        }
    }
    return typeNode;
}
Also used : Entry(java.util.Map.Entry) NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 22 with NamedIcon

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

the class ItemPalette method loadFamilyMap.

static HashMap<String, HashMap<String, NamedIcon>> loadFamilyMap(CatalogTreeNode node, Editor ed) {
    HashMap<String, HashMap<String, NamedIcon>> familyMap = new HashMap<String, HashMap<String, NamedIcon>>();
    // node.children() is still unchecked in JDOM2
    @SuppressWarnings("unchecked") Enumeration<CatalogTreeNode> ee = node.children();
    while (ee.hasMoreElements()) {
        CatalogTreeNode famNode = ee.nextElement();
        String familyName = (String) famNode.getUserObject();
        HashMap<String, NamedIcon> iconMap = new HashMap<String, NamedIcon>();
        List<CatalogTreeLeaf> list = famNode.getLeaves();
        for (int i = 0; i < list.size(); i++) {
            String iconName = list.get(i).getName();
            CatalogTreeLeaf leaf = list.get(i);
            String path = leaf.getPath();
            NamedIcon icon = NamedIcon.getIconByName(path);
            if (icon == null) {
                icon = ed.loadFailed(iconName, path);
                if (icon == null) {
                    log.info(iconName + " removed for url= " + path);
                } else {
                    ImageIndexEditor.indexChanged(true);
                }
            }
            if (icon != null) {
                iconMap.put(iconName, icon);
                if (log.isDebugEnabled()) {
                    log.debug("Add " + iconName + " icon to family " + familyName);
                }
            }
            Thread.yield();
        }
        familyMap.put(familyName, iconMap);
    }
    return familyMap;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) HashMap(java.util.HashMap) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 23 with NamedIcon

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

the class FamilyItemPanel method makeDndIconPanel.

protected void makeDndIconPanel(HashMap<String, NamedIcon> iconMap, String displayKey) {
    if (_supressDragging) {
        return;
    }
    if (!jmri.util.ThreadingUtil.isGUIThread())
        log.error("Not on GUI thread", new Exception("traceback"));
    _dragIconPanel.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
    if (iconMap != null) {
        if (iconMap.get(displayKey) == null) {
            displayKey = (String) iconMap.keySet().toArray()[0];
        }
        NamedIcon ic = iconMap.get(displayKey);
        if (ic != null) {
            NamedIcon icon = new NamedIcon(ic);
            JPanel panel = new JPanel(new FlowLayout());
            String borderName = ItemPalette.convertText("dragToPanel");
            panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), borderName));
            JLabel label;
            try {
                label = getDragger(new DataFlavor(Editor.POSITIONABLE_FLAVOR), iconMap, icon);
                if (label != null) {
                    label.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
                    //                        label.setIcon(icon);
                    label.setName(borderName);
                    panel.add(label);
                }
            } catch (java.lang.ClassNotFoundException cnfe) {
                log.warn("no DndIconPanel {} created", borderName, cnfe);
            }
            int width = Math.max(100, panel.getPreferredSize().width);
            panel.setPreferredSize(new java.awt.Dimension(width, panel.getPreferredSize().height));
            panel.setToolTipText(Bundle.getMessage("ToolTipDragIcon"));
            _dragIconPanel.add(panel);
            return;
        }
    } else {
        log.error("No iconMap for makeDndIconPanel");
    }
}
Also used : JPanel(javax.swing.JPanel) NamedIcon(jmri.jmrit.catalog.NamedIcon) FlowLayout(java.awt.FlowLayout) JLabel(javax.swing.JLabel) DataFlavor(java.awt.datatransfer.DataFlavor)

Example 24 with NamedIcon

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

the class FamilyItemPanel method setFamily.

/**
     * Action of family radio button MultisensorItemPanel {@literal &}
     * IndicatorTOItem must overrides
     */
protected void setFamily(String family) {
    _family = family;
    if (log.isDebugEnabled()) {
        log.debug("setFamily: for type \"" + _itemType + "\", family \"" + family + "\"");
    }
    _iconFamilyPanel.remove(_iconPanel);
    _iconPanel = new JPanel(new FlowLayout());
    _iconFamilyPanel.add(_iconPanel, 0);
    HashMap<String, NamedIcon> map = ItemPalette.getIconMap(_itemType, _family);
    if (map != null) {
        _currentIconMap = map;
    }
    if (!_supressDragging) {
        _iconFamilyPanel.remove(_dragIconPanel);
        _dragIconPanel = new JPanel(new FlowLayout());
        _iconFamilyPanel.add(_dragIconPanel, 0);
        makeDndIconPanel(_currentIconMap, "BeanStateUnknown");
    }
    addIconsToPanel(_currentIconMap);
    _iconFamilyPanel.invalidate();
    hideIcons();
    Enumeration<AbstractButton> en = _familyButtonGroup.getElements();
    while (en.hasMoreElements()) {
        JRadioButton but = (JRadioButton) en.nextElement();
        if (_family != null && _family.equals(but.getText())) {
            but.setSelected(true);
            break;
        }
    }
}
Also used : JPanel(javax.swing.JPanel) NamedIcon(jmri.jmrit.catalog.NamedIcon) FlowLayout(java.awt.FlowLayout) AbstractButton(javax.swing.AbstractButton) JRadioButton(javax.swing.JRadioButton)

Example 25 with NamedIcon

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

the class IconAdder method setIcon.

/**
     * @param order -the index to Sensor's name and the inverse order that icons
     *              are drawn in doIconPanel()
     * @param label -the Sensor's name displayed in the icon panel and the key
     *              to the icon button in _iconMap
     * @param icon  -the icon displayed in the icon button
     */
protected void setIcon(int order, String label, NamedIcon icon) {
    // make a button to change that icon
    if (log.isDebugEnabled()) {
        log.debug("setIcon at order= " + order + ", key= " + label);
    }
    JToggleButton button = new IconButton(label, icon);
    if (icon == null || icon.getIconWidth() < 1 || icon.getIconHeight() < 1) {
        button.setText(Bundle.getMessage("invisibleIcon"));
        button.setForeground(Color.lightGray);
    } else {
        icon.reduceTo(CatalogPanel.ICON_WIDTH, CatalogPanel.ICON_HEIGHT, CatalogPanel.ICON_SCALE);
        button.setToolTipText(icon.getName());
    }
    if (_allowDeletes) {
        String fileName = "resources/icons/misc/X-red.gif";
        button.setSelectedIcon(new jmri.jmrit.catalog.NamedIcon(fileName, fileName));
    }
    if (icon != null) {
        icon.reduceTo(CatalogPanel.ICON_WIDTH, CatalogPanel.ICON_HEIGHT, CatalogPanel.ICON_SCALE);
    }
    _iconMap.put(label, button);
    // calls may not be in ascending order, so pad array
    if (order > _order.size()) {
        for (int i = _order.size(); i < order; i++) {
            _order.add(i, "placeHolder");
        }
    } else {
        if (order < _order.size()) {
            _order.remove(order);
        }
    }
    _order.add(order, label);
}
Also used : JToggleButton(javax.swing.JToggleButton) NamedIcon(jmri.jmrit.catalog.NamedIcon)

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