Search in sources :

Example 1 with IndicatorTrackIcon

use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.

the class EditCircuitFrame method updateIconList.

protected void updateIconList(java.util.List<Positionable> icons) {
    //if (log.isDebugEnabled()) log.debug( 
    int segments = 0;
    int turnouts = 0;
    if (icons != null) {
        if (log.isDebugEnabled()) {
            log.debug("updateIconList: icons.size()= {}", icons.size());
        }
        for (int i = 0; i < icons.size(); i++) {
            Positionable pos = icons.get(i);
            if (pos instanceof IndicatorTurnoutIcon) {
                turnouts++;
            } else if (pos instanceof IndicatorTrackIcon) {
                segments++;
            } else if (pos instanceof TurnoutIcon) {
                turnouts++;
            } else {
                segments++;
            }
        }
    }
    _numTrackSeg.setText(String.valueOf(segments));
    _numTurnouts.setText(String.valueOf(turnouts));
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Positionable(jmri.jmrit.display.Positionable) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) TurnoutIcon(jmri.jmrit.display.TurnoutIcon) Point(java.awt.Point)

Example 2 with IndicatorTrackIcon

use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.

the class IndicatorTrackIconXml method load.

/**
     * Create a IndicatorTrackIcon, 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 p = (Editor) o;
    IndicatorTrackIcon l = new IndicatorTrackIcon(p);
    Element elem = element.getChild("iconmap");
    if (elem != null) {
        List<Element> status = elem.getChildren();
        if (status.size() > 0) {
            for (int i = 0; i < status.size(); i++) {
                String msg = "IndicatorTrack \"" + l.getNameString() + "\" icon \"" + status.get(i).getName() + "\" ";
                NamedIcon icon = loadIcon(l, status.get(i).getName(), elem, msg, p);
                if (icon != null) {
                    l.setIcon(status.get(i).getName(), icon);
                } else {
                    log.info(msg + " removed for url= " + status.get(i).getName());
                    return;
                }
            }
        }
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    Element name = element.getChild("occupancyblock");
    if (name != null) {
        l.setOccBlock(name.getText());
    } else {
        // only write sensor if no OBlock, don't write double sensing
        name = element.getChild("occupancysensor");
        if (name != null) {
            l.setOccSensor(name.getText());
        }
    }
    l.setShowTrain(false);
    name = element.getChild("showTrainName");
    if (name != null) {
        if ("yes".equals(name.getText())) {
            l.setShowTrain(true);
        }
    }
    elem = element.getChild("paths");
    if (elem != null) {
        ArrayList<String> paths = new ArrayList<String>();
        List<Element> pth = elem.getChildren();
        for (int i = 0; i < pth.size(); i++) {
            paths.add(pth.get(i).getText());
        }
        l.setPaths(paths);
    }
    l.displayState(l.getStatus());
    l.updateSize();
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) Editor(jmri.jmrit.display.Editor)

Example 3 with IndicatorTrackIcon

use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.

the class CircuitBuilder method convertSeg.

private void convertSeg() {
    IndicatorTrackIcon t = new IndicatorTrackIcon(_editor);
    t.setOccBlockHandle(InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(_currentBlock.getSystemName(), _currentBlock));
    t.setFamily(_trackPanel.getFamilyName());
    HashMap<String, NamedIcon> iconMap = _trackPanel.getIconMap();
    if (iconMap != null) {
        Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
        while (it.hasNext()) {
            Entry<String, NamedIcon> entry = it.next();
            if (log.isDebugEnabled()) {
                log.debug("key= " + entry.getKey());
            }
            t.setIcon(entry.getKey(), new NamedIcon(entry.getValue()));
        }
    }
    t.setLevel(Editor.TURNOUTS);
    t.setScale(_oldIcon.getScale());
    t.rotate(_oldIcon.getDegrees());
    finishConvert(t);
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) NamedIcon(jmri.jmrit.catalog.NamedIcon) Entry(java.util.Map.Entry)

Example 4 with IndicatorTrackIcon

use of jmri.jmrit.display.IndicatorTrackIcon in project JMRI by JMRI.

the class IndicatorTrackIconXml method store.

/**
     * Default implementation for storing the contents of a IndicatorTrackIcon
     *
     * @param o Object to store, of type IndicatorTrackIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    IndicatorTrackIcon p = (IndicatorTrackIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("indicatortrackicon");
    storeCommonAttributes(p, element);
    NamedBeanHandle<OBlock> b = p.getNamedOccBlock();
    if (b != null) {
        element.addContent(storeNamedBean("occupancyblock", b));
    }
    NamedBeanHandle<Sensor> s = p.getNamedOccSensor();
    if (b == null && s != null) {
        // only write sensor if no OBlock, don't write double sensing
        element.addContent(storeNamedBean("occupancysensor", s));
    }
    /*
         s = p.getErrSensor();
         if (s!=null) {
         element.addContent(storeBean("errorsensor", s));
         }
         */
    Element elem = new Element("showTrainName");
    String show = "no";
    if (p.showTrain()) {
        show = "yes";
    }
    elem.addContent(show);
    element.addContent(elem);
    HashMap<String, NamedIcon> iconMap = p.getIconMap();
    Iterator<Entry<String, NamedIcon>> it = iconMap.entrySet().iterator();
    elem = new Element("iconmap");
    String family = p.getFamily();
    if (family != null) {
        elem.setAttribute("family", family);
    }
    while (it.hasNext()) {
        Entry<String, NamedIcon> entry = it.next();
        elem.addContent(storeIcon(entry.getKey(), entry.getValue()));
    }
    element.addContent(elem);
    elem = new Element("paths");
    ArrayList<String> paths = p.getPaths();
    if (paths != null) {
        for (int i = 0; i < paths.size(); i++) {
            Element e = new Element("path");
            e.addContent(paths.get(i));
            elem.addContent(e);
        }
        element.addContent(elem);
    }
    element.setAttribute("class", "jmri.jmrit.display.configurexml.IndicatorTrackIconXml");
    return element;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Element(org.jdom2.Element) IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) Entry(java.util.Map.Entry) OBlock(jmri.jmrit.logix.OBlock) Sensor(jmri.Sensor)

Aggregations

IndicatorTrackIcon (jmri.jmrit.display.IndicatorTrackIcon)4 NamedIcon (jmri.jmrit.catalog.NamedIcon)3 Entry (java.util.Map.Entry)2 Element (org.jdom2.Element)2 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 Sensor (jmri.Sensor)1 Editor (jmri.jmrit.display.Editor)1 IndicatorTurnoutIcon (jmri.jmrit.display.IndicatorTurnoutIcon)1 Positionable (jmri.jmrit.display.Positionable)1 TurnoutIcon (jmri.jmrit.display.TurnoutIcon)1 OBlock (jmri.jmrit.logix.OBlock)1 Attribute (org.jdom2.Attribute)1