Search in sources :

Example 1 with NamedIcon

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

the class MultiIconEditor method setIcon.

public void setIcon(int iconNum, String label, String name) {
    iconList[iconNum] = new NamedIcon(name, name);
    // make a button to change that icon
    JButton j = new IconButton(iconNum, iconList[iconNum]);
    j.setToolTipText(iconList[iconNum].getName());
    buttonList[iconNum] = j;
    // and add it to this panel
    JPanel p = new JPanel();
    p.add(new JLabel(label));
    p.add(j);
    this.add(p);
}
Also used : JPanel(javax.swing.JPanel) NamedIcon(jmri.jmrit.catalog.NamedIcon) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel)

Example 2 with NamedIcon

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

the class MultiSensorIcon method updateSensor.

void updateSensor() {
    MultiSensorIconAdder iconEditor = (MultiSensorIconAdder) _iconEditor;
    setInactiveIcon(iconEditor.getIcon("SensorStateInactive"));
    setInconsistentIcon(iconEditor.getIcon("BeanStateInconsistent"));
    setUnknownIcon(iconEditor.getIcon("BeanStateUnknown"));
    for (int i = 0; i < entries.size(); i++) {
        entries.get(i).namedSensor.getBean().removePropertyChangeListener(this);
    }
    int numPositions = iconEditor.getNumIcons();
    entries = new ArrayList<>(numPositions);
    for (int i = 3; i < numPositions; i++) {
        NamedIcon icon = iconEditor.getIcon(i);
        NamedBeanHandle<Sensor> namedSensor = iconEditor.getSensor(i);
        addEntry(namedSensor, icon);
    }
    setUpDown(iconEditor.getUpDown());
    _iconEditorFrame.dispose();
    _iconEditorFrame = null;
    _iconEditor = null;
    invalidate();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Sensor(jmri.Sensor)

Example 3 with NamedIcon

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

the class MultiSensorIcon method editItem.

protected void editItem() {
    makePaletteFrame(Bundle.getMessage("EditItem", Bundle.getMessage("MultiSensor")));
    _itemPanel = new MultiSensorItemPanel(_paletteFrame, "MultiSensor", _iconFamily, PickListModel.multiSensorPickModelInstance(), _editor);
    ActionListener updateAction = (ActionEvent a) -> {
        updateItem();
    };
    // duplicate _iconMap map with unscaled and unrotated icons
    HashMap<String, NamedIcon> map = new HashMap<>();
    map.put("SensorStateInactive", inactive);
    map.put("BeanStateInconsistent", inconsistent);
    map.put("BeanStateUnknown", unknown);
    for (int i = 0; i < entries.size(); i++) {
        map.put(MultiSensorItemPanel.getPositionName(i), entries.get(i).icon);
    }
    _itemPanel.init(updateAction, map);
    for (int i = 0; i < entries.size(); i++) {
        _itemPanel.setSelection(entries.get(i).namedSensor.getBean());
    }
    _itemPanel.setUpDown(getUpDown());
    _paletteFrame.add(_itemPanel);
    _paletteFrame.pack();
    _paletteFrame.setVisible(true);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ActionListener(java.awt.event.ActionListener) HashMap(java.util.HashMap) ActionEvent(java.awt.event.ActionEvent) MultiSensorItemPanel(jmri.jmrit.display.palette.MultiSensorItemPanel)

Example 4 with NamedIcon

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

the class PositionableLabel method rotate.

@Override
public void rotate(int deg) {
    if (log.isDebugEnabled()) {
        log.debug("rotate({}) with _rotateText {}, _text {}, _icon {}", deg, _rotateText, _text, _icon);
    }
    _degrees = deg;
    if (_rotateText || deg == 0) {
        if (deg == 0) {
            // restore unrotated whatever
            _rotateText = false;
            if (_text) {
                if (log.isDebugEnabled()) {
                    log.debug("   super.setText(\"{}\");", _unRotatedText);
                }
                super.setText(_unRotatedText);
                if (_popupUtil != null) {
                    setOpaque(_popupUtil.hasBackground());
                    _popupUtil.setBorder(true);
                }
                if (_namedIcon != null) {
                    String url = _namedIcon.getURL();
                    _namedIcon = new NamedIcon(url, url);
                }
                super.setIcon(_namedIcon);
            } else {
                if (_namedIcon != null) {
                    _namedIcon.rotate(deg, this);
                }
                super.setIcon(_namedIcon);
            }
        } else {
            if (_text & _icon) {
                // update text over icon
                _namedIcon = makeTextOverlaidIcon(_unRotatedText, _namedIcon);
            } else if (_text) {
                // update text only icon image
                _namedIcon = makeTextIcon(_unRotatedText);
            }
            _namedIcon.rotate(deg, this);
            super.setIcon(_namedIcon);
            // rotations cannot be opaque
            setOpaque(false);
        }
    } else {
        // first time text or icon is rotated from horizontal
        if (_text && _icon) {
            // text overlays icon  e.g. LocoIcon
            _namedIcon = makeTextOverlaidIcon(_unRotatedText, _namedIcon);
            super.setText(null);
            _rotateText = true;
            setOpaque(false);
        } else if (_text) {
            _namedIcon = makeTextIcon(_unRotatedText);
            super.setText(null);
            _rotateText = true;
            setOpaque(false);
        }
        if (_popupUtil != null) {
            _popupUtil.setBorder(false);
        }
        _namedIcon.rotate(deg, this);
        super.setIcon(_namedIcon);
    }
    updateSize();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 5 with NamedIcon

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

the class MultiSensorIcon method setScale.

@Override
public void setScale(double s) {
    for (int i = 0; i < entries.size(); i++) {
        NamedIcon icon = entries.get(i).icon;
        icon.scale(s, this);
    }
    inactive.scale(s, this);
    unknown.scale(s, this);
    inconsistent.scale(s, this);
    displayState();
}
Also used : 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