Search in sources :

Example 66 with NamedIcon

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

the class Editor method putIcon.

/**
     * Add an icon to the target.
     *
     * @return The icon that was added to the target.
     */
protected Positionable putIcon() {
    IconAdder iconEditor = getIconEditor("Icon");
    String url = iconEditor.getIcon("plainIcon").getURL();
    NamedIcon icon = NamedIcon.getIconByName(url);
    if (log.isDebugEnabled()) {
        log.debug("putIcon: {} url= {}", (icon == null ? "null" : "icon"), url);
    }
    PositionableLabel l = new PositionableLabel(icon, this);
    //        l.setPopupUtility(null);        // no text
    l.setDisplayLevel(ICONS);
    setNextLocation(l);
    putItem(l);
    l.updateSize();
    return l;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 67 with NamedIcon

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

the class IconAdder method makeIcons.

/**
     * Build iconMap and orderArray from user's choice of defaults.
     *
     * @param n the root in a catalog from which icons are made
     */
protected void makeIcons(CatalogTreeNode n) {
    if (log.isDebugEnabled()) {
        log.debug("makeIcons from node= {}, numChildren= {}, NumLeaves= {}", n.toString(), n.getChildCount(), n.getNumLeaves());
    }
    _iconMap = new HashMap<>(10);
    _order = new ArrayList<>();
    ArrayList<CatalogTreeLeaf> list = n.getLeaves();
    // adjust order of icons
    int k = list.size() - 1;
    for (int i = list.size() - 1; i >= 0; i--) {
        CatalogTreeLeaf leaf = list.get(i);
        String name = leaf.getName();
        String path = leaf.getPath();
        switch(name) {
            case "BeanStateInconsistent":
                this.setIcon(0, name, new NamedIcon(path, path));
                break;
            case "BeanStateUnknown":
                this.setIcon(1, name, new NamedIcon(path, path));
                break;
            default:
                this.setIcon(k, name, new NamedIcon(path, path));
                k--;
                break;
        }
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf)

Example 68 with NamedIcon

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

the class IconAdder method getDefaultIconNodeFromMap.

private CatalogTreeNode getDefaultIconNodeFromMap() {
    if (log.isDebugEnabled()) {
        log.debug("getDefaultIconNodeFromMap for node= " + _type + ", _order.size()= " + _order.size());
    }
    _defaultIcons = new CatalogTreeNode(_type);
    Iterator<Entry<String, JToggleButton>> it = _iconMap.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, JToggleButton> e = it.next();
        NamedIcon icon = (NamedIcon) e.getValue().getIcon();
        _defaultIcons.addLeaf(new CatalogTreeLeaf(e.getKey(), icon.getURL(), _order.indexOf(e.getKey())));
    }
    return _defaultIcons;
}
Also used : Entry(java.util.Map.Entry) NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) JToggleButton(javax.swing.JToggleButton) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

Example 69 with NamedIcon

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

the class IndicatorTrackIcon method displayState.

/*
     * Drive the current state of the display from the status.
     */
public void displayState(String status) {
    if (log.isDebugEnabled()) {
        log.debug(getNameString() + " displayStatus " + _status);
    }
    NamedIcon icon = getIcon(status);
    if (icon != null) {
        super.setIcon(icon);
    }
    updateSize();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 70 with NamedIcon

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

the class IndicatorTurnoutIcon method updateItem.

@Override
void updateItem() {
    if (log.isDebugEnabled()) {
        log.debug("updateItem: " + getNameString() + " family= " + _TOPanel.getFamilyName());
    }
    setTurnout(_TOPanel.getTableSelection().getSystemName());
    setOccSensor(_TOPanel.getOccSensor());
    setOccBlock(_TOPanel.getOccBlock());
    _pathUtil.setShowTrain(_TOPanel.getShowTrainName());
    _iconFamily = _TOPanel.getFamilyName();
    _pathUtil.setPaths(_TOPanel.getPaths());
    HashMap<String, HashMap<String, NamedIcon>> iconMap = _TOPanel.getIconMaps();
    if (iconMap != null) {
        Iterator<Entry<String, HashMap<String, NamedIcon>>> it = iconMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, HashMap<String, NamedIcon>> entry = it.next();
            String status = entry.getKey();
            HashMap<Integer, NamedIcon> oldMap = _iconMaps.get(entry.getKey());
            Iterator<Entry<String, NamedIcon>> iter = entry.getValue().entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, NamedIcon> ent = iter.next();
                if (log.isDebugEnabled()) {
                    log.debug("key= " + ent.getKey());
                }
                NamedIcon newIcon = cloneIcon(ent.getValue(), this);
                NamedIcon oldIcon = oldMap.get(_name2stateMap.get(ent.getKey()));
                newIcon.setLoad(oldIcon.getDegrees(), oldIcon.getScale(), this);
                newIcon.setRotation(oldIcon.getRotation(), this);
                setIcon(status, ent.getKey(), newIcon);
            }
        }
    }
    // otherwise retain current map
    //        jmri.jmrit.catalog.ImageIndexEditor.checkImageIndex();
    _paletteFrame.dispose();
    _paletteFrame = null;
    _TOPanel.dispose();
    _TOPanel = null;
    displayState(turnoutState());
}
Also used : Entry(java.util.Map.Entry) NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap)

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