Search in sources :

Example 1 with LocoLabel

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);
}
Also used : LocoLabel(jmri.jmrit.display.controlPanelEditor.shape.LocoLabel) Element(org.jdom2.Element) OBlockManager(jmri.jmrit.logix.OBlockManager) Editor(jmri.jmrit.display.Editor) OBlock(jmri.jmrit.logix.OBlock)

Example 2 with LocoLabel

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);
}
Also used : LocoLabel(jmri.jmrit.display.controlPanelEditor.shape.LocoLabel) Font(java.awt.Font) Point(java.awt.Point)

Example 3 with LocoLabel

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;
}
Also used : LocoLabel(jmri.jmrit.display.controlPanelEditor.shape.LocoLabel) Element(org.jdom2.Element) OBlock(jmri.jmrit.logix.OBlock)

Aggregations

LocoLabel (jmri.jmrit.display.controlPanelEditor.shape.LocoLabel)3 OBlock (jmri.jmrit.logix.OBlock)2 Element (org.jdom2.Element)2 Font (java.awt.Font)1 Point (java.awt.Point)1 Editor (jmri.jmrit.display.Editor)1 OBlockManager (jmri.jmrit.logix.OBlockManager)1