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();
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations