Search in sources :

Example 46 with NamedIcon

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

the class MemoryIcon method updateIconFromRosterVal.

protected Object updateIconFromRosterVal(RosterEntry roster) {
    re = roster;
    javax.swing.ImageIcon icon = jmri.InstanceManager.rosterIconFactoryInstance().getIcon(roster);
    if (icon == null || icon.getIconWidth() == -1 || icon.getIconHeight() == -1) {
        //the IconPath is still at default so no icon set
        return roster.titleString();
    } else {
        NamedIcon rosterIcon = new NamedIcon(roster.getIconPath(), roster.getIconPath());
        _text = false;
        _icon = true;
        updateIcon(rosterIcon);
        if (flipRosterIcon) {
            flipIcon(NamedIcon.HORIZONTALFLIP);
        }
        jmri.InstanceManager.throttleManagerInstance().attachListener(re.getDccLocoAddress(), this);
        Object isForward = jmri.InstanceManager.throttleManagerInstance().getThrottleInfo(re.getDccLocoAddress(), "IsForward");
        if (isForward != null) {
            if (!(Boolean) isForward) {
                flipIcon(NamedIcon.HORIZONTALFLIP);
            }
        }
        return null;
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 47 with NamedIcon

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

the class IndicatorTurnoutIcon method editItem.

@Override
protected void editItem() {
    makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("IndicatorTO")));
    _TOPanel = new IndicatorTOItemPanel(_paletteFrame, "IndicatorTO", _iconFamily, PickListModel.turnoutPickModelInstance(), _editor);
    ActionListener updateAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            updateItem();
        }
    };
    // Convert _iconMaps state (ints) to Palette's bean names
    HashMap<String, HashMap<String, NamedIcon>> iconMaps = new HashMap<String, HashMap<String, NamedIcon>>();
    iconMaps.put("ClearTrack", new HashMap<String, NamedIcon>());
    iconMaps.put("OccupiedTrack", new HashMap<String, NamedIcon>());
    iconMaps.put("PositionTrack", new HashMap<String, NamedIcon>());
    iconMaps.put("AllocatedTrack", new HashMap<String, NamedIcon>());
    iconMaps.put("DontUseTrack", new HashMap<String, NamedIcon>());
    iconMaps.put("ErrorTrack", new HashMap<String, NamedIcon>());
    Iterator<Entry<String, HashMap<Integer, NamedIcon>>> it = _iconMaps.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, HashMap<Integer, NamedIcon>> entry = it.next();
        HashMap<String, NamedIcon> clone = iconMaps.get(entry.getKey());
        Iterator<Entry<Integer, NamedIcon>> iter = entry.getValue().entrySet().iterator();
        while (iter.hasNext()) {
            Entry<Integer, NamedIcon> ent = iter.next();
            NamedIcon oldIcon = ent.getValue();
            NamedIcon newIcon = cloneIcon(oldIcon, this);
            newIcon.rotate(0, this);
            newIcon.scale(1.0, this);
            newIcon.setRotation(4, this);
            clone.put(_state2nameMap.get(ent.getKey()), newIcon);
        }
    }
    _TOPanel.initUpdate(updateAction, iconMaps);
    _TOPanel.setSelection(getTurnout());
    if (namedOccSensor != null) {
        _TOPanel.setOccDetector(namedOccSensor.getBean().getDisplayName());
    }
    if (namedOccBlock != null) {
        _TOPanel.setOccDetector(namedOccBlock.getBean().getDisplayName());
    }
    _TOPanel.setShowTrainName(_pathUtil.showTrain());
    _TOPanel.setPaths(_pathUtil.getPaths());
    _paletteFrame.add(_TOPanel);
    _paletteFrame.pack();
    _paletteFrame.setVisible(true);
}
Also used : IndicatorTOItemPanel(jmri.jmrit.display.palette.IndicatorTOItemPanel) NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) ActionEvent(java.awt.event.ActionEvent) Entry(java.util.Map.Entry) ActionListener(java.awt.event.ActionListener)

Example 48 with NamedIcon

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

the class IndicatorTurnoutIcon method displayState.

/**
     * Drive the current state of the display from the state of the turnout and
     * status of track.
     */
@Override
public void displayState(int state) {
    if (getNamedTurnout() == null) {
        log.debug("Display state " + state + ", disconnected");
    } else {
        if (_status != null && _iconMaps != null) {
            NamedIcon icon = getIcon(_status, state);
            if (icon != null) {
                super.setIcon(icon);
            }
        }
    }
    super.displayState(state);
    updateSize();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 49 with NamedIcon

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

the class IndicatorTurnoutIcon method rotateOrthogonal.

/**
     * ****** popup AbstractAction.actionPerformed method overrides ********
     */
@Override
protected void rotateOrthogonal() {
    if (_iconMaps != null) {
        Iterator<HashMap<Integer, NamedIcon>> it = _iconMaps.values().iterator();
        while (it.hasNext()) {
            Iterator<NamedIcon> iter = it.next().values().iterator();
            while (iter.hasNext()) {
                NamedIcon icon = iter.next();
                icon.setRotation(icon.getRotation() + 1, this);
            }
        }
    }
    displayState(turnoutState());
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap)

Example 50 with NamedIcon

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

the class IndicatorTrackIcon method editItem.

protected void editItem() {
    makePaletteFrame(java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage("IndicatorTrack")));
    _trackPanel = new IndicatorItemPanel(_paletteFrame, "IndicatorTrack", _iconFamily, _editor);
    ActionListener updateAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            updateItem();
        }
    };
    // duplicate _iconMap map with unscaled and unrotated icons
    HashMap<String, NamedIcon> map = new HashMap<String, NamedIcon>();
    Iterator<Entry<String, NamedIcon>> it = _iconMap.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, NamedIcon> entry = it.next();
        NamedIcon oldIcon = entry.getValue();
        NamedIcon newIcon = cloneIcon(oldIcon, this);
        newIcon.rotate(0, this);
        newIcon.scale(1.0, this);
        newIcon.setRotation(4, this);
        map.put(entry.getKey(), newIcon);
    }
    _trackPanel.init(updateAction, map);
    if (namedOccSensor != null) {
        _trackPanel.setOccDetector(namedOccSensor.getBean().getDisplayName());
    }
    if (namedOccBlock != null) {
        _trackPanel.setOccDetector(namedOccBlock.getBean().getDisplayName());
    }
    _trackPanel.setShowTrainName(_pathUtil.showTrain());
    _trackPanel.setPaths(_pathUtil.getPaths());
    _paletteFrame.add(_trackPanel);
    _paletteFrame.setLocationRelativeTo(this);
    _paletteFrame.toFront();
    _paletteFrame.pack();
    _paletteFrame.setVisible(true);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Entry(java.util.Map.Entry) ActionListener(java.awt.event.ActionListener) HashMap(java.util.HashMap) ActionEvent(java.awt.event.ActionEvent) IndicatorItemPanel(jmri.jmrit.display.palette.IndicatorItemPanel)

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