Search in sources :

Example 6 with IndicatorTrack

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

the class EditCircuitPaths method makePathGroup.

/**
     * Construct the array of icons that displays the path
     *
     */
private ArrayList<Positionable> makePathGroup(OPath path) {
    Portal fromPortal = path.getFromPortal();
    Portal toPortal = path.getToPortal();
    String name = path.getName();
    java.util.List<Positionable> list = _parent.getCircuitGroup();
    if (log.isDebugEnabled()) {
        log.debug("makePathGroup for " + name + " CircuitGroup size= " + list.size());
    }
    ArrayList<Positionable> pathGroup = new ArrayList<Positionable>();
    for (int i = 0; i < list.size(); i++) {
        Positionable pos = list.get(i);
        if (pos instanceof IndicatorTrack) {
            ArrayList<String> paths = ((IndicatorTrack) pos).getPaths();
            if (paths != null) {
                for (int j = 0; j < paths.size(); j++) {
                    if (name.equals(paths.get(j))) {
                        ((IndicatorTrack) pos).setControlling(true);
                        pathGroup.add(pos);
                    }
                }
            }
        } else {
            PortalIcon icon = (PortalIcon) pos;
            Portal portal = icon.getPortal();
            if (portal.equals(fromPortal)) {
                pathGroup.add(icon);
            } else if (portal.equals(toPortal)) {
                pathGroup.add(icon);
            }
        }
    }
    return pathGroup;
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) ArrayList(java.util.ArrayList) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) Point(java.awt.Point)

Example 7 with IndicatorTrack

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

the class CircuitBuilder method checkCircuits.

/**
     * ************** end closing frames *******************
     */
/**
     * Find the blocks with no icons and the blocks with icons that need
     * conversion Setup for main Frame - used in both initialization and close
     * of an editing frame Build Lists that are used to create menu items
     */
private void checkCircuits() {
    _portalIconMap.clear();
    _darkTrack.clear();
    _unconvertedTrack.clear();
    PortalManager portalMgr = InstanceManager.getDefault(jmri.jmrit.logix.PortalManager.class);
    Iterator<Positionable> it = _editor.getContents().iterator();
    while (it.hasNext()) {
        Positionable pos = it.next();
        //            if (log.isDebugEnabled()) log.debug("class: "+pos.getClass().getName());
        if (pos instanceof IndicatorTrack) {
            OBlock block = ((IndicatorTrack) pos).getOccBlock();
            ((IndicatorTrack) pos).removePath(EditCircuitPaths.TEST_PATH);
            if (block != null) {
                addIcon(block, pos);
            } else {
                _darkTrack.add(pos);
            }
        } else if (pos instanceof PortalIcon) {
            PortalIcon pIcon = (PortalIcon) pos;
            String name = pIcon.getName();
            Portal portal = portalMgr.getByUserName(name);
            if (portal == null) {
                log.error("No Portal for PortalIcon called \"" + name + "\". Discarding icon.");
                pIcon.remove();
            } else {
                PortalIcon pi = _portalIconMap.get(name);
                if (pi != null) {
                    log.error("Removing duplicate PortalIcon for Portal \"" + name + "\".");
                    pi.remove();
                }
                _portalIconMap.put(name, pIcon);
            }
        }
    }
    Iterator<Entry<OBlock, ArrayList<Positionable>>> iters = _circuitMap.entrySet().iterator();
    while (iters.hasNext()) {
        Entry<OBlock, ArrayList<Positionable>> entry = iters.next();
        Iterator<Positionable> iter = entry.getValue().iterator();
        while (iter.hasNext()) {
            Positionable pos = iter.next();
            if (isUnconvertedTrack(pos)) {
                if (!_unconvertedTrack.contains(pos)) {
                    _unconvertedTrack.add(pos);
                }
            }
        }
    }
    _bareBlock.clear();
    _convertBlock.clear();
    _badPortalIcon.clear();
    OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    String[] sysNames = manager.getSystemNameArray();
    hasOBlocks = (sysNames.length > 0);
    for (int i = 0; i < sysNames.length; i++) {
        OBlock block = manager.getBySystemName(sysNames[i]);
        java.util.List<Portal> list = block.getPortals();
        if (list != null) {
            Iterator<Portal> iter = list.iterator();
            while (iter.hasNext()) {
                Portal portal = iter.next();
                // update circuitMap
                PortalIcon pi = _portalIconMap.get(portal.getName());
                if (pi != null) {
                    addIcon(block, pi);
                }
            }
        }
        java.util.List<Positionable> icons = _circuitMap.get(block);
        if (log.isDebugEnabled()) {
            log.debug("checkCircuits: block " + block.getDisplayName() + " has " + icons.size() + " icons.");
        }
        if (icons == null || icons.size() == 0) {
            _bareBlock.add(block);
        } else {
            _bareBlock.remove(block);
            for (int k = 0; k < icons.size(); k++) {
                Positionable pos = icons.get(k);
                if (!(pos instanceof IndicatorTrack) && !(pos instanceof PortalIcon)) {
                    if (!_convertBlock.contains(block)) {
                        _convertBlock.add(block);
                        break;
                    }
                }
            }
        }
    }
    List<NamedBean> list = portalMgr.getNamedBeanList();
    Iterator<NamedBean> iter = list.iterator();
    while (iter.hasNext()) {
        Portal portal = (Portal) iter.next();
        String name = portal.getName();
        PortalIcon pi = _portalIconMap.get(name);
        if (pi != null) {
            if (!checkPortalIcon(portal, pi)) {
                _badPortalIcon.put(name, portal);
            }
        } else {
            // no icon for this Portal
            _badPortalIcon.put(name, portal);
        }
    }
    makeToDoMenu();
}
Also used : NamedBean(jmri.NamedBean) PortalManager(jmri.jmrit.logix.PortalManager) ArrayList(java.util.ArrayList) OBlockManager(jmri.jmrit.logix.OBlockManager) Entry(java.util.Map.Entry) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

Example 8 with IndicatorTrack

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

the class CircuitBuilder method convertIcons.

protected void convertIcons(ArrayList<Positionable> iconList) {
    if (iconList == null || iconList.size() == 0) {
        return;
    }
    // use global member for finishConvert to remove and add converted icons,
    _circuitIcons = iconList;
    // since iconList will be modified, use a copy to find unconverted icons
    ArrayList<Positionable> list = new ArrayList<Positionable>();
    for (int i = 0; i < iconList.size(); i++) {
        list.add(iconList.get(i));
    }
    if (list.size() > 0) {
        TargetPane targetPane = (TargetPane) _editor.getTargetPanel();
        targetPane.setHighlightColor(_highlightColor);
        for (int i = 0; i < list.size(); i++) {
            Positionable pos = list.get(i);
            if (!(pos instanceof IndicatorTrack) && !(pos instanceof PortalIcon)) {
                if (log.isDebugEnabled()) {
                    log.debug("convertIcons: #" + i + " pos= " + pos.getClass().getName());
                }
                convertIcon(pos);
            }
        }
        targetPane.setHighlightColor(_editGroupColor);
        _editor.highlight(null);
    }
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) ArrayList(java.util.ArrayList) TargetPane(jmri.jmrit.display.Editor.TargetPane) Positionable(jmri.jmrit.display.Positionable)

Example 9 with IndicatorTrack

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

the class CircuitBuilder method okToAdd.

/**
     * Can this track icon be added to the circuit? N.B. Be sure Positionable
     * pos passes isTrack() call
     */
private boolean okToAdd(Positionable pos, OBlock editBlock) {
    if (pos instanceof IndicatorTrack) {
        OBlock block = ((IndicatorTrack) pos).getOccBlock();
        if (block != null) {
            if (!block.equals(editBlock)) {
                int result = JOptionPane.showConfirmDialog(_editor, java.text.MessageFormat.format(Bundle.getMessage("iconBlockConflict"), block.getDisplayName(), editBlock.getDisplayName()), Bundle.getMessage("whichCircuit"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (result == JOptionPane.YES_OPTION) {
                    // move icon from block to editBlock 
                    java.util.List<Positionable> ic = _circuitMap.get(block);
                    ic.remove(pos);
                    ((IndicatorTrack) pos).setOccBlockHandle(InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(editBlock.getSystemName(), editBlock));
                    return true;
                }
                return false;
            }
        }
    }
    return true;
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

Example 10 with IndicatorTrack

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

the class EditCircuitPaths method updatePath.

/**
     * Sets the path icons for display
     *
     */
protected void updatePath(boolean pathChanged) {
    // to avoid ConcurrentModificationException now set data
    Iterator<Positionable> iter = _pathGroup.iterator();
    while (iter.hasNext()) {
        Positionable pos = iter.next();
        if (pos instanceof IndicatorTrack) {
            ((IndicatorTrack) pos).addPath(TEST_PATH);
        } else {
            ((PortalIcon) pos).setStatus(PortalIcon.PATH);
        }
    }
    _pathChange = pathChanged;
    String name = _pathName.getText();
    if (name == null || name.length() == 0) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("needPathName"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
    } else {
    }
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Positionable(jmri.jmrit.display.Positionable)

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