use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class LinkingLabel method deepClone.
@Override
public Positionable deepClone() {
PositionableLabel pos;
if (_icon) {
NamedIcon icon = new NamedIcon((NamedIcon) getIcon());
pos = new LinkingLabel(icon, _editor, url);
} else {
pos = new LinkingLabel(_unRotatedText, _editor, url);
}
return finishClone(pos);
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class LocoIcon method init.
/**
* Called at load time to get "background" color
*/
public void init() {
NamedIcon icon = (NamedIcon) getIcon();
String name = icon.getURL();
if (name.endsWith("loco-white.gif")) {
_locoColor = Color.WHITE;
} else if (name.endsWith("loco-green.gif")) {
_locoColor = Color.GREEN;
} else if (name.endsWith("loco-gray.gif")) {
_locoColor = Color.GRAY;
} else if (name.endsWith("loco-red.gif")) {
_locoColor = Color.RED;
} else if (name.endsWith("loco-blue.gif")) {
_locoColor = COLOR_BLUE;
} else if (name.endsWith("loco-yellow.gif")) {
_locoColor = Color.YELLOW;
}
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class MemoryIcon method displayState.
protected void displayState(Object key) {
log.debug("displayState({})", key);
if (key != null) {
if (map == null) {
Object val = key;
// no map, attempt to show object directly
if (val instanceof jmri.jmrit.roster.RosterEntry) {
jmri.jmrit.roster.RosterEntry roster = (jmri.jmrit.roster.RosterEntry) val;
val = updateIconFromRosterVal(roster);
flipRosterIcon = false;
if (val == null) {
return;
}
}
if (val instanceof String) {
String str = (String) val;
_icon = false;
_text = true;
setText(str);
updateIcon(null);
if (log.isDebugEnabled()) {
log.debug("String str= \"" + str + "\" str.trim().length()= " + str.trim().length());
log.debug(" maxWidth()= " + maxWidth() + ", maxHeight()= " + maxHeight());
log.debug(" getBackground(): {}", getBackground());
log.debug(" _editor.getTargetPanel().getBackground(): {}", _editor.getTargetPanel().getBackground());
log.debug(" setAttributes to getPopupUtility({}) with", getPopupUtility());
log.debug(" hasBackground() {}", getPopupUtility().hasBackground());
log.debug(" getBackground() {}", getPopupUtility().getBackground());
log.debug(" on editor {}", _editor);
}
_editor.setAttributes(getPopupUtility(), this);
} else if (val instanceof javax.swing.ImageIcon) {
_icon = true;
_text = false;
setIcon((javax.swing.ImageIcon) val);
setText(null);
} else if (val instanceof Number) {
_icon = false;
_text = true;
setText(val.toString());
setIcon(null);
} else {
log.warn("can't display current value of " + getNameString() + ", val= " + val + " of Class " + val.getClass().getName());
}
} else {
// map exists, use it
NamedIcon newicon = map.get(key.toString());
if (newicon != null) {
setText(null);
super.setIcon(newicon);
} else {
// no match, use default
_icon = true;
_text = false;
setIcon(defaultIcon);
setText(null);
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("object null");
}
_icon = true;
_text = false;
setIcon(defaultIcon);
setText(null);
}
updateSize();
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class SignalHeadIcon method setIcons.
/**
* replace the icons in _iconMap with those from map, but preserve the scale
* and rotation.
*/
private void setIcons(Hashtable<String, NamedIcon> map) {
HashMap<String, NamedIcon> tempMap = new HashMap<String, NamedIcon>();
Iterator<Entry<String, NamedIcon>> it = map.entrySet().iterator();
while (it.hasNext()) {
Entry<String, NamedIcon> entry = it.next();
String name = entry.getKey();
NamedIcon icon = entry.getValue();
// setSignalHead() has cleared _iconMap
NamedIcon oldIcon = _saveMap.get(name);
if (log.isDebugEnabled()) {
log.debug("key= " + entry.getKey() + ", localKey= " + name + ", newIcon= " + icon + ", oldIcon= " + oldIcon);
}
if (oldIcon != null) {
icon.setLoad(oldIcon.getDegrees(), oldIcon.getScale(), this);
icon.setRotation(oldIcon.getRotation(), this);
}
tempMap.put(name, icon);
}
_iconMap = tempMap;
}
use of jmri.jmrit.catalog.NamedIcon in project JMRI by JMRI.
the class SignalHeadIcon method edit.
@Override
protected void edit() {
makeIconEditorFrame(this, "SignalHead", true, null);
_iconEditor.setPickList(jmri.jmrit.picker.PickListModel.signalHeadPickModelInstance());
Iterator<String> e = _iconMap.keySet().iterator();
int i = 0;
while (e.hasNext()) {
String key = e.next();
_iconEditor.setIcon(i++, key, new NamedIcon(_iconMap.get(key)));
}
_iconEditor.makeIconPanel(false);
ActionListener addIconAction = new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
updateSignal();
}
};
_iconEditor.complete(addIconAction, true, false, true);
_iconEditor.setSelection(getSignalHead());
}
Aggregations