use of jmri.jmrit.display.controlPanelEditor.shape.LocoLabel in project JMRI by JMRI.
the class LocoLabelXml method load.
/**
* Create a PositionableShape, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor ed = (Editor) o;
LocoLabel ll = new LocoLabel(ed);
Element elem = element.getChild("size");
ll.setWidth(getInt(elem, "width"));
ll.setHeight(getInt(elem, "height"));
if (elem != null && elem.getAttribute("systemName") != null) {
String name = elem.getAttribute("systemName").getValue();
OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
OBlock block = manager.getBySystemName(name);
ll.setBlock(block);
if (elem.getAttribute("trainName") != null && block != null) {
block.setValue(elem.getAttribute("trainName").getValue());
}
} else {
// don't put into editor's content list without
return;
}
ed.putItem(ll);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(ll, Editor.MARKERS, element);
}
use of jmri.jmrit.display.controlPanelEditor.shape.LocoLabel in project JMRI by JMRI.
the class IndicatorTrackPaths method setLocoIcon.
protected void setLocoIcon(OBlock block, Point pt, Dimension size, Editor ed) {
if (!_showTrain) {
removeLocoIcon();
return;
}
String trainName = (String) block.getValue();
if (trainName == null) {
removeLocoIcon();
return;
}
if (_loco != null) {
return;
}
trainName = trainName.trim();
_loco = new LocoLabel(ed);
Font font = block.getMarkerFont();
if (font == null) {
font = ed.getFont();
}
int width = ed.getFontMetrics(font).stringWidth(trainName);
// limit height to locoIcon height
int height = ed.getFontMetrics(ed.getFont()).getHeight();
_loco.setLineWidth(1);
_loco.setLineColor(Color.BLACK);
_loco.setFillColor(block.getMarkerBackground());
_loco.setBlock(block);
_loco.setWidth(width + height / 2);
_loco.setHeight(height + 2);
_loco.setCornerRadius(height);
_loco.makeShape();
_loco.setDisplayLevel(Editor.MARKERS);
_loco.updateSize();
pt.x = pt.x + (size.width - _loco.maxWidth()) / 2;
pt.y = pt.y + (size.height - _loco.maxHeight()) / 2;
_loco.setLocation(pt);
ed.putItem(_loco);
}
use of jmri.jmrit.display.controlPanelEditor.shape.LocoLabel in project JMRI by JMRI.
the class LocoLabelXml method store.
/**
* Default implementation for storing the contents of a PositionableShape
*
* @param o Object to store, of type PositionableShape
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LocoLabel p = (LocoLabel) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("LocoLabel");
storeCommonAttributes(p, element);
Element elem = new Element("size");
elem.setAttribute("width", "" + p.getWidth());
elem.setAttribute("height", "" + p.getHeight());
element.addContent(elem);
elem = new Element("OBlock");
OBlock block = p.getBlock();
elem.setAttribute("systemName", "" + block.getSystemName());
elem.setAttribute("trainName", "" + block.getValue());
element.addContent(elem);
element.setAttribute("class", "jmri.jmrit.display.controlPanelEditor.shape.configurexml.LocoLabelXml");
return element;
}