use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class SignalHeadIconXml method store.
/**
* Default implementation for storing the contents of a SignalHeadIcon
*
* @param o Object to store, of type SignalHeadIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
SignalHeadIcon p = (SignalHeadIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("signalheadicon");
element.setAttribute("signalhead", "" + p.getNamedSignalHead().getName());
storeCommonAttributes(p, element);
element.setAttribute("clickmode", "" + p.getClickMode());
element.setAttribute("litmode", "" + p.getLitMode());
Element elem = new Element("icons");
NamedIcon icon = p.getIcon(rbean.getString("SignalHeadStateHeld"));
if (icon != null) {
elem.addContent(storeIcon("held", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateDark"));
if (icon != null) {
elem.addContent(storeIcon("dark", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateRed"));
if (icon != null) {
elem.addContent(storeIcon("red", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateYellow"));
if (icon != null) {
elem.addContent(storeIcon("yellow", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateGreen"));
if (icon != null) {
elem.addContent(storeIcon("green", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateLunar"));
if (icon != null) {
elem.addContent(storeIcon("lunar", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingRed"));
if (icon != null) {
elem.addContent(storeIcon("flashred", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingYellow"));
if (icon != null) {
elem.addContent(storeIcon("flashyellow", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingGreen"));
if (icon != null) {
elem.addContent(storeIcon("flashgreen", icon));
}
icon = p.getIcon(rbean.getString("SignalHeadStateFlashingLunar"));
if (icon != null) {
elem.addContent(storeIcon("flashlunar", icon));
}
element.addContent(elem);
elem = new Element("iconmaps");
String family = p.getFamily();
if (family != null) {
elem.setAttribute("family", family);
}
element.addContent(elem);
element.setAttribute("class", "jmri.jmrit.display.configurexml.SignalHeadIconXml");
return element;
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class ControlPanelEditor method drop.
@SuppressWarnings("unchecked")
@Override
public void drop(DropTargetDropEvent evt) {
try {
//Point pt = evt.getLocation(); coords relative to entire window
Point pt = _targetPanel.getMousePosition(true);
Transferable tr = evt.getTransferable();
if (log.isDebugEnabled()) {
// avoid string building if not debug
DataFlavor[] flavors = tr.getTransferDataFlavors();
StringBuilder flavor = new StringBuilder();
for (DataFlavor flavor1 : flavors) {
flavor.append(flavor1.getRepresentationClass().getName()).append(", ");
}
log.debug("Editor Drop: flavor classes={}", flavor);
}
if (tr.isDataFlavorSupported(_positionableDataFlavor)) {
Positionable item = (Positionable) tr.getTransferData(_positionableDataFlavor);
if (item == null) {
return;
}
item.setLocation(pt.x, pt.y);
// now set display level in the pane.
item.setDisplayLevel(item.getDisplayLevel());
item.setEditor(this);
putItem(item);
item.updateSize();
//if (_debug) log.debug("Drop positionable "+item.getNameString()+
// " as "+item.getClass().getName()+
// ", w= "+item.maxWidth()+", h= "+item.maxHeight());
evt.dropComplete(true);
return;
} else if (tr.isDataFlavorSupported(_namedIconDataFlavor)) {
NamedIcon newIcon = new NamedIcon((NamedIcon) tr.getTransferData(_namedIconDataFlavor));
String url = newIcon.getURL();
NamedIcon icon = NamedIcon.getIconByName(url);
PositionableLabel ni = new PositionableLabel(icon, this);
// infer a background icon from the size
if (icon.getIconHeight() > 500 || icon.getIconWidth() > 600) {
ni.setDisplayLevel(BKG);
} else {
ni.setDisplayLevel(ICONS);
}
ni.setLocation(pt.x, pt.y);
ni.setEditor(this);
putItem(ni);
ni.updateSize();
evt.dropComplete(true);
return;
} else if (tr.isDataFlavorSupported(DataFlavor.stringFlavor)) {
String text = (String) tr.getTransferData(DataFlavor.stringFlavor);
PositionableLabel l = new PositionableLabel(text, this);
l.setSize(l.getPreferredSize().width, l.getPreferredSize().height);
l.setDisplayLevel(LABELS);
l.setLocation(pt.x, pt.y);
l.setEditor(this);
putItem(l);
evt.dropComplete(true);
} else if (tr.isDataFlavorSupported(_positionableListDataFlavor)) {
List<Positionable> dragGroup = (List<Positionable>) tr.getTransferData(_positionableListDataFlavor);
for (Positionable pos : dragGroup) {
pos.setEditor(this);
putItem(pos);
pos.updateSize();
log.debug("DnD Add {}", pos.getNameString());
}
} else {
log.warn("Editor DropTargetListener supported DataFlavors not avaialable at drop from " + tr.getClass().getName());
}
} catch (IOException ioe) {
log.warn("Editor DropTarget caught IOException", ioe);
} catch (UnsupportedFlavorException ufe) {
log.warn("Editor DropTarget caught UnsupportedFlavorException", ufe);
}
log.debug("Editor DropTargetListener drop REJECTED!");
evt.rejectDrop();
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class ClockItemPanel method addIconsToPanel.
@Override
protected void addIconsToPanel(HashMap<String, NamedIcon> iconMap) {
_iconPanel = new JPanel();
Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
while (it.hasNext()) {
Entry<String, NamedIcon> entry = it.next();
// make copy for possible reduction
NamedIcon icon = new NamedIcon(entry.getValue());
JPanel panel = new JPanel();
String borderName = ItemPalette.convertText(entry.getKey());
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), borderName));
try {
JLabel label = new ClockDragJLabel(new DataFlavor(Editor.POSITIONABLE_FLAVOR));
if (icon.getIconWidth() < 1 || icon.getIconHeight() < 1) {
label.setText(Bundle.getMessage("invisibleIcon"));
label.setForeground(Color.lightGray);
} else {
icon.reduceTo(100, 100, 0.2);
}
label.setIcon(icon);
label.setName(borderName);
panel.add(label);
} catch (java.lang.ClassNotFoundException cnfe) {
cnfe.printStackTrace();
}
_iconPanel.add(panel);
}
add(_iconPanel, 1);
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class FamilyItemPanel method addIconsToPanel.
protected void addIconsToPanel(HashMap<String, NamedIcon> iconMap) {
if (iconMap == null) {
log.warn("iconMap is null for type " + _itemType + " family " + _family);
return;
}
GridBagLayout gridbag = new GridBagLayout();
_iconPanel.setLayout(gridbag);
int numCol = 4;
GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 1;
c.gridheight = 1;
c.gridx = -1;
c.gridy = 0;
int cnt = iconMap.size();
Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
while (it.hasNext()) {
Entry<String, NamedIcon> entry = it.next();
// make copy for possible reduction
NamedIcon icon = new NamedIcon(entry.getValue());
icon.reduceTo(100, 100, 0.2);
JPanel panel = new JPanel(new FlowLayout());
// I18N use existing NamedBeanBundle keys
String borderName = getIconBorderName(entry.getKey());
panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), borderName));
JLabel image = new JLabel(icon);
if (icon.getIconWidth() < 1 || icon.getIconHeight() < 1) {
image.setText(Bundle.getMessage("invisibleIcon"));
image.setForeground(Color.lightGray);
}
image.setToolTipText(icon.getName());
panel.add(image);
int width = getFontMetrics(getFont()).stringWidth(borderName);
width = Math.max(100, Math.max(width, icon.getIconWidth()) + 10);
panel.setPreferredSize(new java.awt.Dimension(width, panel.getPreferredSize().height));
c.gridx += 1;
if (c.gridx >= numCol) {
//start next row
c.gridy++;
c.gridx = 0;
if (cnt < numCol - 1) {
// last row
JPanel p = new JPanel(new FlowLayout());
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(Box.createHorizontalStrut(100));
gridbag.setConstraints(p, c);
//if (log.isDebugEnabled()) log.debug("addIconsToPanel: gridx= "+c.gridx+" gridy= "+c.gridy);
_iconPanel.add(p);
c.gridx = 1;
}
}
cnt--;
gridbag.setConstraints(panel, c);
_iconPanel.add(panel);
}
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class ItemPanel method checkIconMap.
protected static void checkIconMap(String type, HashMap<String, NamedIcon> map) {
String[] names = getNames(type);
for (int i = 0; i < names.length; i++) {
if (map.get(names[i]) == null) {
NamedIcon icon = new jmri.jmrit.catalog.NamedIcon(redX, redX);
// store RedX as default icon if icon not set
map.put(names[i], icon);
}
}
}
Aggregations