Search in sources :

Example 11 with IndicatorTrack

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

Example 12 with IndicatorTrack

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

the class EditCircuitPaths method clearPath.

private void clearPath() {
    for (int i = 0; i < _pathGroup.size(); i++) {
        Positionable pos = _pathGroup.get(i);
        if (pos instanceof PortalIcon) {
            ((PortalIcon) pos).setStatus(PortalIcon.VISIBLE);
        } else {
            ((IndicatorTrack) pos).removePath(TEST_PATH);
        }
    }
    int state = _block.getState() & ~OBlock.ALLOCATED;
    _pathGroup = new ArrayList<Positionable>();
    _block.pseudoPropertyChange("state", Integer.valueOf(0), Integer.valueOf(state));
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Positionable(jmri.jmrit.display.Positionable) Point(java.awt.Point)

Aggregations

IndicatorTrack (jmri.jmrit.display.IndicatorTrack)12 Positionable (jmri.jmrit.display.Positionable)12 ArrayList (java.util.ArrayList)6 Portal (jmri.jmrit.logix.Portal)5 Point (java.awt.Point)4 OBlock (jmri.jmrit.logix.OBlock)3 OPath (jmri.jmrit.logix.OPath)2 Entry (java.util.Map.Entry)1 BeanSetting (jmri.BeanSetting)1 NamedBean (jmri.NamedBean)1 NamedBeanHandleManager (jmri.NamedBeanHandleManager)1 Turnout (jmri.Turnout)1 TargetPane (jmri.jmrit.display.Editor.TargetPane)1 IndicatorTurnoutIcon (jmri.jmrit.display.IndicatorTurnoutIcon)1 OBlockManager (jmri.jmrit.logix.OBlockManager)1 PortalManager (jmri.jmrit.logix.PortalManager)1