Search in sources :

Example 96 with NamedIcon

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

the class DropJLabel method drop.

@Override
public void drop(DropTargetDropEvent e) {
    try {
        Transferable tr = e.getTransferable();
        if (e.isDataFlavorSupported(_dataFlavor)) {
            NamedIcon newIcon = new NamedIcon((NamedIcon) tr.getTransferData(_dataFlavor));
            accept(e, newIcon);
        } else if (e.isDataFlavorSupported(DataFlavor.stringFlavor)) {
            String text = (String) tr.getTransferData(DataFlavor.stringFlavor);
            if (log.isDebugEnabled()) {
                log.debug("drop for stringFlavor " + text);
            }
            NamedIcon newIcon = new NamedIcon(text, text);
            accept(e, newIcon);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("DropJLabel.drop REJECTED!");
            }
            e.rejectDrop();
        }
    } catch (IOException ioe) {
        if (log.isDebugEnabled()) {
            log.debug("DropPanel.drop REJECTED!");
        }
        e.rejectDrop();
    } catch (UnsupportedFlavorException ufe) {
        if (log.isDebugEnabled()) {
            log.debug("DropJLabel.drop REJECTED!");
        }
        e.rejectDrop();
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Transferable(java.awt.datatransfer.Transferable) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException)

Example 97 with NamedIcon

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

the class FamilyItemPanel method mapsAreEqual.

protected boolean mapsAreEqual(HashMap<String, NamedIcon> map1, HashMap<String, NamedIcon> map2) {
    if (map1.size() != map2.size()) {
        return false;
    }
    Iterator<Entry<String, NamedIcon>> iter = map1.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String, NamedIcon> ent = iter.next();
        NamedIcon icon = map2.get(ent.getKey());
        if (log.isDebugEnabled()) {
            log.debug("key= " + ent.getKey() + ", url1= " + icon.getURL() + ", url2= " + ent.getValue().getURL());
        }
        if (icon == null || !icon.getURL().equals(ent.getValue().getURL())) {
            return false;
        }
    }
    return true;
}
Also used : Entry(java.util.Map.Entry) NamedIcon(jmri.jmrit.catalog.NamedIcon)

Example 98 with NamedIcon

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

the class MultiSensorItemPanel method initTablePanel.

@Override
protected JPanel initTablePanel(PickListModel model, Editor editor) {
    _table = model.makePickTable();
    ROW_HEIGHT = _table.getRowHeight();
    TableColumn column = new TableColumn(PickListModel.POSITION_COL);
    column.setHeaderValue("Position");
    _table.addColumn(column);
    _selectionModel = new MultiSensorSelectionModel(model);
    _table.setSelectionModel(_selectionModel);
    _table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    topPanel.add(new JLabel(model.getName(), SwingConstants.CENTER), BorderLayout.NORTH);
    _scrollPane = new JScrollPane(_table);
    topPanel.add(_scrollPane, BorderLayout.CENTER);
    topPanel.setToolTipText(Bundle.getMessage("ToolTipDragTableRow"));
    JPanel panel = new JPanel();
    _addTableButton = new JButton(Bundle.getMessage("CreateNewItem"));
    _addTableButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            makeAddToTableWindow();
        }
    });
    _addTableButton.setToolTipText(Bundle.getMessage("ToolTipAddToTable"));
    panel.add(_addTableButton);
    int size = 6;
    if (_family != null) {
        HashMap<String, NamedIcon> map = ItemPalette.getIconMap(_itemType, _family);
        size = map.size();
    }
    _selectionModel.setPositionRange(size - 3);
    JButton clearSelectionButton = new JButton(Bundle.getMessage("ClearSelection"));
    clearSelectionButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent a) {
            clearSelections();
        }
    });
    clearSelectionButton.setToolTipText(Bundle.getMessage("ToolTipClearSelection"));
    panel.add(clearSelectionButton);
    topPanel.add(panel, BorderLayout.SOUTH);
    _table.setToolTipText(Bundle.getMessage("ToolTipDragTableRow"));
    _scrollPane.setToolTipText(Bundle.getMessage("ToolTipDragTableRow"));
    topPanel.setToolTipText(Bundle.getMessage("ToolTipDragTableRow"));
    return topPanel;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) NamedIcon(jmri.jmrit.catalog.NamedIcon) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) DragJLabel(jmri.jmrit.catalog.DragJLabel) TableColumn(javax.swing.table.TableColumn) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener)

Example 99 with NamedIcon

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

the class SignalHeadItemPanel method getFilteredIconMap.

protected HashMap<String, NamedIcon> getFilteredIconMap(HashMap<String, NamedIcon> allIconsMap) {
    if (allIconsMap == null) {
        JOptionPane.showMessageDialog(_paletteFrame, Bundle.getMessage("FamilyNotFound", _itemType, _family), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
        return null;
    }
    if (_table == null || _table.getSelectedRow() < 0) {
        return allIconsMap;
    }
    SignalHead sh = (SignalHead) getDeviceNamedBean();
    if (sh != null) {
        String[] states = sh.getValidStateNames();
        if (states.length == 0) {
            return allIconsMap;
        }
        HashMap<String, NamedIcon> iconMap = new HashMap<String, NamedIcon>();
        Iterator<Entry<String, NamedIcon>> it = allIconsMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, NamedIcon> entry = it.next();
            String name = entry.getKey();
            String borderName = ItemPalette.convertText(name);
            for (int j = 0; j < states.length; j++) {
                if (borderName.equals(states[j]) || name.equals("SignalHeadStateDark") || name.equals("SignalHeadStateHeld")) {
                    iconMap.put(name, entry.getValue());
                    break;
                }
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("filteredMap size= " + iconMap.size());
        }
        return iconMap;
    }
    if (log.isDebugEnabled()) {
        log.debug("Map NOT filtered, size= " + allIconsMap.size());
    }
    return allIconsMap;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) SignalHead(jmri.SignalHead)

Example 100 with NamedIcon

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

the class ItemPalette method loadDefaultFamilyMap.

static HashMap<String, HashMap<String, NamedIcon>> loadDefaultFamilyMap(List<Element> families, Editor ed) {
    HashMap<String, HashMap<String, NamedIcon>> familyMap = new HashMap<String, HashMap<String, NamedIcon>>();
    for (int k = 0; k < families.size(); k++) {
        String familyName = families.get(k).getName();
        HashMap<String, NamedIcon> iconMap = // Map of all icons of in family, familyName
        new HashMap<String, NamedIcon>();
        List<Element> iconfiles = families.get(k).getChildren();
        for (int j = 0; j < iconfiles.size(); j++) {
            String iconName = iconfiles.get(j).getName();
            String fileName = iconfiles.get(j).getText().trim();
            if (fileName.length() == 0) {
                fileName = "resources/icons/misc/X-red.gif";
                log.warn("loadDefaultFamilyMap: iconName= " + iconName + " in family " + familyName + " has no image file.");
            }
            NamedIcon icon = NamedIcon.getIconByName(fileName);
            if (icon == null) {
                icon = ed.loadFailed(iconName, fileName);
                if (icon == null) {
                    log.info(iconName + " removed for url= " + fileName);
                }
            }
            if (icon != null) {
                iconMap.put(iconName, icon);
            }
        }
        familyMap.put(familyName, iconMap);
        if (log.isDebugEnabled()) {
            log.debug("Add " + iconMap.size() + " icons to family " + familyName);
        }
    }
    return familyMap;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) Element(org.jdom2.Element)

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