Search in sources :

Example 81 with NamedIcon

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

the class LinkingLabel method deepClone.

@Override
public Positionable deepClone() {
    PositionableLabel pos;
    if (_icon) {
        NamedIcon icon = new NamedIcon((NamedIcon) getIcon());
        pos = new LinkingLabel(icon, _editor, url);
    } else {
        pos = new LinkingLabel(_unRotatedText, _editor, url);
    }
    return finishClone(pos);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 82 with NamedIcon

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

the class LocoIcon method init.

/**
     * Called at load time to get "background" color
     */
public void init() {
    NamedIcon icon = (NamedIcon) getIcon();
    String name = icon.getURL();
    if (name.endsWith("loco-white.gif")) {
        _locoColor = Color.WHITE;
    } else if (name.endsWith("loco-green.gif")) {
        _locoColor = Color.GREEN;
    } else if (name.endsWith("loco-gray.gif")) {
        _locoColor = Color.GRAY;
    } else if (name.endsWith("loco-red.gif")) {
        _locoColor = Color.RED;
    } else if (name.endsWith("loco-blue.gif")) {
        _locoColor = COLOR_BLUE;
    } else if (name.endsWith("loco-yellow.gif")) {
        _locoColor = Color.YELLOW;
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 83 with NamedIcon

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

the class MemoryIcon method displayState.

protected void displayState(Object key) {
    log.debug("displayState({})", key);
    if (key != null) {
        if (map == null) {
            Object val = key;
            // no map, attempt to show object directly
            if (val instanceof jmri.jmrit.roster.RosterEntry) {
                jmri.jmrit.roster.RosterEntry roster = (jmri.jmrit.roster.RosterEntry) val;
                val = updateIconFromRosterVal(roster);
                flipRosterIcon = false;
                if (val == null) {
                    return;
                }
            }
            if (val instanceof String) {
                String str = (String) val;
                _icon = false;
                _text = true;
                setText(str);
                updateIcon(null);
                if (log.isDebugEnabled()) {
                    log.debug("String str= \"" + str + "\" str.trim().length()= " + str.trim().length());
                    log.debug("  maxWidth()= " + maxWidth() + ", maxHeight()= " + maxHeight());
                    log.debug("  getBackground(): {}", getBackground());
                    log.debug("  _editor.getTargetPanel().getBackground(): {}", _editor.getTargetPanel().getBackground());
                    log.debug("  setAttributes to getPopupUtility({}) with", getPopupUtility());
                    log.debug("     hasBackground() {}", getPopupUtility().hasBackground());
                    log.debug("     getBackground() {}", getPopupUtility().getBackground());
                    log.debug("    on editor {}", _editor);
                }
                _editor.setAttributes(getPopupUtility(), this);
            } else if (val instanceof javax.swing.ImageIcon) {
                _icon = true;
                _text = false;
                setIcon((javax.swing.ImageIcon) val);
                setText(null);
            } else if (val instanceof Number) {
                _icon = false;
                _text = true;
                setText(val.toString());
                setIcon(null);
            } else {
                log.warn("can't display current value of " + getNameString() + ", val= " + val + " of Class " + val.getClass().getName());
            }
        } else {
            // map exists, use it
            NamedIcon newicon = map.get(key.toString());
            if (newicon != null) {
                setText(null);
                super.setIcon(newicon);
            } else {
                // no match, use default
                _icon = true;
                _text = false;
                setIcon(defaultIcon);
                setText(null);
            }
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("object null");
        }
        _icon = true;
        _text = false;
        setIcon(defaultIcon);
        setText(null);
    }
    updateSize();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) RosterEntry(jmri.jmrit.roster.RosterEntry) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 84 with NamedIcon

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

the class SignalHeadIcon method setIcons.

/**
     * replace the icons in _iconMap with those from map, but preserve the scale
     * and rotation.
     */
private void setIcons(Hashtable<String, NamedIcon> map) {
    HashMap<String, NamedIcon> tempMap = new HashMap<String, NamedIcon>();
    Iterator<Entry<String, NamedIcon>> it = map.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, NamedIcon> entry = it.next();
        String name = entry.getKey();
        NamedIcon icon = entry.getValue();
        // setSignalHead() has cleared _iconMap 
        NamedIcon oldIcon = _saveMap.get(name);
        if (log.isDebugEnabled()) {
            log.debug("key= " + entry.getKey() + ", localKey= " + name + ", newIcon= " + icon + ", oldIcon= " + oldIcon);
        }
        if (oldIcon != null) {
            icon.setLoad(oldIcon.getDegrees(), oldIcon.getScale(), this);
            icon.setRotation(oldIcon.getRotation(), this);
        }
        tempMap.put(name, icon);
    }
    _iconMap = tempMap;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Entry(java.util.Map.Entry) HashMap(java.util.HashMap)

Example 85 with NamedIcon

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

the class SignalHeadIcon method edit.

@Override
protected void edit() {
    makeIconEditorFrame(this, "SignalHead", true, null);
    _iconEditor.setPickList(jmri.jmrit.picker.PickListModel.signalHeadPickModelInstance());
    Iterator<String> e = _iconMap.keySet().iterator();
    int i = 0;
    while (e.hasNext()) {
        String key = e.next();
        _iconEditor.setIcon(i++, key, new NamedIcon(_iconMap.get(key)));
    }
    _iconEditor.makeIconPanel(false);
    ActionListener addIconAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            updateSignal();
        }
    };
    _iconEditor.complete(addIconAction, true, false, true);
    _iconEditor.setSelection(getSignalHead());
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

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