Search in sources :

Example 1 with IndicatorTurnoutIcon

use of jmri.jmrit.display.IndicatorTurnoutIcon 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 IndicatorTurnoutIcon

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

the class IndicatorTurnoutIconXml method store.

/**
     * Default implementation for storing the contents of a IndicatorTurnoutIcon
     *
     * @param o Object to store, of type IndicatorTurnoutIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    IndicatorTurnoutIcon p = (IndicatorTurnoutIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("indicatorturnouticon");
    storeCommonAttributes(p, element);
    NamedBeanHandle<Turnout> t = p.getNamedTurnout();
    if (t != null) {
        element.addContent(storeNamedBean("turnout", t));
    }
    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
        element.addContent(storeNamedBean("occupancysensor", s));
    }
    Element elem = new Element("showTrainName");
    String show = "no";
    if (p.showTrain()) {
        show = "yes";
    }
    elem.addContent(show);
    element.addContent(elem);
    HashMap<String, HashMap<Integer, NamedIcon>> iconMaps = p.getIconMaps();
    Iterator<Entry<String, HashMap<Integer, NamedIcon>>> it = iconMaps.entrySet().iterator();
    Element el = new Element("iconmaps");
    String family = p.getFamily();
    if (family != null) {
        el.setAttribute("family", family);
    }
    while (it.hasNext()) {
        Entry<String, HashMap<Integer, NamedIcon>> ent = it.next();
        elem = new Element(ent.getKey());
        Iterator<Entry<Integer, NamedIcon>> iter = ent.getValue().entrySet().iterator();
        while (iter.hasNext()) {
            Entry<Integer, NamedIcon> entry = iter.next();
            elem.addContent(storeIcon(p.getStateName(entry.getKey()), entry.getValue()));
        }
        el.addContent(elem);
    }
    element.addContent(el);
    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.IndicatorTurnoutIconXml");
    return element;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) Element(org.jdom2.Element) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Entry(java.util.Map.Entry) Turnout(jmri.Turnout) OBlock(jmri.jmrit.logix.OBlock) Sensor(jmri.Sensor)

Example 3 with IndicatorTurnoutIcon

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

the class CircuitBuilder method convertTO.

private void convertTO() {
    IndicatorTurnoutIcon t = new IndicatorTurnoutIcon(_editor);
    t.setOccBlockHandle(InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(_currentBlock.getSystemName(), _currentBlock));
    t.setTurnout(((TurnoutIcon) _oldIcon).getNamedTurnout());
    t.setFamily(_trackTOPanel.getFamilyName());
    HashMap<String, HashMap<String, NamedIcon>> iconMap = _trackTOPanel.getIconMaps();
    Iterator<Entry<String, HashMap<String, NamedIcon>>> it = iconMap.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, HashMap<String, NamedIcon>> entry = it.next();
        String status = entry.getKey();
        Iterator<Entry<String, NamedIcon>> iter = entry.getValue().entrySet().iterator();
        while (iter.hasNext()) {
            Entry<String, NamedIcon> ent = iter.next();
            t.setIcon(status, ent.getKey(), new NamedIcon(ent.getValue()));
        }
    }
    t.setLevel(Editor.TURNOUTS);
    t.setScale(_oldIcon.getScale());
    t.rotate(_oldIcon.getDegrees());
    finishConvert(t);
}
Also used : Entry(java.util.Map.Entry) NamedIcon(jmri.jmrit.catalog.NamedIcon) HashMap(java.util.HashMap) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon)

Example 4 with IndicatorTurnoutIcon

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

the class IndicatorTurnoutIconXml method load.

/**
     * Create a IndicatorTurnoutIcon, 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;
    IndicatorTurnoutIcon l = new IndicatorTurnoutIcon(p);
    Element name = element.getChild("turnout");
    if (name == null) {
        log.error("incorrect information for turnout; must use turnout name");
    } else {
        l.setTurnout(name.getText());
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        List<Element> maps = elem.getChildren();
        if (maps.size() > 0) {
            for (int i = 0; i < maps.size(); i++) {
                String status = maps.get(i).getName();
                List<Element> states = maps.get(i).getChildren();
                for (int k = 0; k < states.size(); k++) {
                    String msg = "IndicatorTurnout \"" + l.getNameString() + "\" icon \"" + states.get(k).getName() + "\" ";
                    NamedIcon icon = loadIcon(l, states.get(k).getName(), maps.get(i), msg, p);
                    if (icon != null) {
                        l.setIcon(status, states.get(k).getName(), icon);
                    } else {
                        log.info(msg + " removed for url= " + name);
                        return;
                    }
                }
            }
        }
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    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.updateSize();
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Editor(jmri.jmrit.display.Editor)

Example 5 with IndicatorTurnoutIcon

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

the class EditCircuitPaths method makeOPath.

/**
     * Make the OPath from the icons in the Iterator
     */
private OPath makeOPath(String name, ArrayList<Positionable> pathGp, boolean showMsg) {
    if (pathGp.size() == 0) {
        if (showMsg) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
        }
        return null;
    }
    Iterator<Positionable> it = pathGp.iterator();
    ArrayList<BeanSetting> settings = new ArrayList<BeanSetting>();
    Portal fromPortal = null;
    Portal toPortal = null;
    boolean hasTrack = false;
    int portalIconCount = 0;
    while (it.hasNext()) {
        Positionable pos = it.next();
        if (pos instanceof IndicatorTurnoutIcon) {
            jmri.Turnout t = ((IndicatorTurnoutIcon) pos).getTurnout();
            String turnoutName = ((IndicatorTurnoutIcon) pos).getNamedTurnout().getName();
            int state = t.getKnownState();
            if (state != Turnout.CLOSED && state != Turnout.THROWN) {
                if (showMsg) {
                    JOptionPane.showMessageDialog(this, Bundle.getMessage("turnoutNotSet", t.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
                }
                return null;
            }
            settings.add(new BeanSetting(t, turnoutName, state));
            hasTrack = true;
        } else if (pos instanceof PortalIcon) {
            if (toPortal == null) {
                toPortal = ((PortalIcon) pos).getPortal();
            } else if (fromPortal == null) {
                fromPortal = ((PortalIcon) pos).getPortal();
            }
            portalIconCount++;
        } else if (pos instanceof IndicatorTrack) {
            hasTrack = true;
        }
    }
    if (showMsg) {
        if (!hasTrack) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
        if (toPortal == null && fromPortal == null) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("tooFewPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
        if (portalIconCount == 0) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("noPortalIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
        }
        if (portalIconCount > 2) {
            JOptionPane.showMessageDialog(this, Bundle.getMessage("tooManyPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
            return null;
        }
    }
    if (hasTrack && portalIconCount > 0 && portalIconCount < 3) {
        return new OPath(name, _block, fromPortal, toPortal, settings);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Turnout(jmri.Turnout) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point) BeanSetting(jmri.BeanSetting) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable)

Aggregations

IndicatorTurnoutIcon (jmri.jmrit.display.IndicatorTurnoutIcon)5 NamedIcon (jmri.jmrit.catalog.NamedIcon)3 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Entry (java.util.Map.Entry)2 Turnout (jmri.Turnout)2 Positionable (jmri.jmrit.display.Positionable)2 Element (org.jdom2.Element)2 BeanSetting (jmri.BeanSetting)1 Sensor (jmri.Sensor)1 Editor (jmri.jmrit.display.Editor)1 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)1 IndicatorTrackIcon (jmri.jmrit.display.IndicatorTrackIcon)1 TurnoutIcon (jmri.jmrit.display.TurnoutIcon)1 OBlock (jmri.jmrit.logix.OBlock)1 OPath (jmri.jmrit.logix.OPath)1 Portal (jmri.jmrit.logix.Portal)1 Attribute (org.jdom2.Attribute)1