Search in sources :

Example 6 with OBlockManager

use of jmri.jmrit.logix.OBlockManager in project JMRI by JMRI.

the class TableFrames method errorCheck.

private void errorCheck() {
    WarrantTableAction.initPathPortalCheck();
    OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    String[] sysNames = manager.getSystemNameArray();
    for (int i = 0; i < sysNames.length; i++) {
        WarrantTableAction.checkPathPortals(manager.getBySystemName(sysNames[i]));
    }
    if (_showWarnings) {
        WarrantTableAction.showPathPortalErrors();
    }
}
Also used : OBlockManager(jmri.jmrit.logix.OBlockManager) Point(java.awt.Point)

Example 7 with OBlockManager

use of jmri.jmrit.logix.OBlockManager in project JMRI by JMRI.

the class TableFrames method updateOpenMenu.

protected void updateOpenMenu() {
    _openMenu.removeAll();
    JMenuItem openBlock = new JMenuItem(Bundle.getMessage("OpenBlockMenu"));
    _openMenu.add(openBlock);
    openBlock.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _blockTableFrame.setVisible(true);
            try {
                _blockTableFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("Block Table Frame vetoed setIcon " + pve.toString());
            }
            _blockTableFrame.moveToFront();
        }
    });
    JMenuItem openPortal = new JMenuItem(Bundle.getMessage("OpenPortalMenu"));
    _openMenu.add(openPortal);
    openPortal.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _portalTableFrame.setVisible(true);
            try {
                _portalTableFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("Portal Table Frame vetoed setIcon " + pve.toString());
            }
            _portalTableFrame.moveToFront();
        }
    });
    JMenuItem openXRef = new JMenuItem(Bundle.getMessage("OpenXRefMenu"));
    _openMenu.add(openXRef);
    openXRef.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _blockPortalXRefFrame.setVisible(true);
            try {
                _blockPortalXRefFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("XRef Table Frame vetoed setIcon " + pve.toString());
            }
            _blockPortalXRefFrame.moveToFront();
        }
    });
    JMenuItem openSignal = new JMenuItem(Bundle.getMessage("OpenSignalMenu"));
    _openMenu.add(openSignal);
    openSignal.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            _signalTableFrame.setVisible(true);
            try {
                _signalTableFrame.setIcon(false);
            } catch (PropertyVetoException pve) {
                log.warn("Signal Table Frame vetoed setIcon " + pve.toString());
            }
            _signalTableFrame.moveToFront();
        }
    });
    JMenu openBlockPath = new JMenu(Bundle.getMessage("OpenBlockPathMenu"));
    ActionListener openFrameAction = new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            String sysName = e.getActionCommand();
            openBlockPathFrame(sysName);
        }
    };
    OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    String[] sysNames = manager.getSystemNameArray();
    for (int i = 0; i < sysNames.length; i++) {
        OBlock block = manager.getBySystemName(sysNames[i]);
        JMenuItem mi = new JMenuItem(Bundle.getMessage("OpenPathMenu", block.getDisplayName()));
        mi.setActionCommand(sysNames[i]);
        mi.addActionListener(openFrameAction);
        openBlockPath.add(mi);
    }
    _openMenu.add(openBlockPath);
    JMenu openTurnoutPath = new JMenu(Bundle.getMessage("OpenBlockPathTurnoutMenu"));
    sysNames = manager.getSystemNameArray();
    for (int i = 0; i < sysNames.length; i++) {
        OBlock block = manager.getBySystemName(sysNames[i]);
        JMenu openTurnoutMenu = new JMenu(Bundle.getMessage("OpenTurnoutMenu", block.getDisplayName()));
        openTurnoutPath.add(openTurnoutMenu);
        openFrameAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                String pathTurnoutName = e.getActionCommand();
                openPathTurnoutFrame(pathTurnoutName);
            }
        };
        Iterator<Path> iter = block.getPaths().iterator();
        while (iter.hasNext()) {
            OPath path = (OPath) iter.next();
            JMenuItem mi = new JMenuItem(Bundle.getMessage("OpenPathTurnoutMenu", path.getName()));
            mi.setActionCommand(makePathTurnoutName(sysNames[i], path.getName()));
            mi.addActionListener(openFrameAction);
            openTurnoutMenu.add(mi);
        }
    }
    _openMenu.add(openTurnoutPath);
}
Also used : OPath(jmri.jmrit.logix.OPath) Path(jmri.Path) ActionEvent(java.awt.event.ActionEvent) OBlockManager(jmri.jmrit.logix.OBlockManager) OPath(jmri.jmrit.logix.OPath) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) ActionListener(java.awt.event.ActionListener) TransferActionListener(jmri.util.com.sun.TransferActionListener) JMenuItem(javax.swing.JMenuItem) OBlock(jmri.jmrit.logix.OBlock) JMenu(javax.swing.JMenu)

Example 8 with OBlockManager

use of jmri.jmrit.logix.OBlockManager in project JMRI by JMRI.

the class OBlockManagerXml method store.

/**
     * Store the contents of a OBlockManager.
     *
     * @param o Object to store, of type BlockManager
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    Element blocks = new Element("oblocks");
    blocks.setAttribute("class", "jmri.jmrit.logix.configurexml.OBlockManagerXml");
    OBlockManager manager = (OBlockManager) o;
    Iterator<String> iter = manager.getSystemNameList().iterator();
    while (iter.hasNext()) {
        String sname = iter.next();
        OBlock block = manager.getBySystemName(sname);
        String uname = block.getUserName();
        if (log.isDebugEnabled()) {
            log.debug("OBlock: sysName= " + sname + ", userName= " + uname);
        }
        Element elem = new Element("oblock");
        elem.setAttribute("systemName", sname);
        if (uname != null && uname.length() > 0) {
            // doing this for compatibility during 2.9.* series
            elem.setAttribute("userName", uname);
            elem.addContent(new Element("userName").addContent(uname));
        }
        String comment = block.getComment();
        if (comment != null) {
            Element c = new Element("comment");
            c.addContent(comment);
            elem.addContent(c);
        }
        elem.setAttribute("length", "" + block.getLengthMm());
        elem.setAttribute("units", block.isMetric() ? "true" : "false");
        elem.setAttribute("curve", "" + block.getCurvature());
        if (block.getNamedSensor() != null) {
            Element se = new Element("sensor");
            se.setAttribute("systemName", block.getNamedSensor().getName());
            elem.addContent(se);
        }
        if (block.getNamedErrorSensor() != null) {
            Element se = new Element("errorSensor");
            se.setAttribute("systemName", block.getNamedErrorSensor().getName());
            elem.addContent(se);
        }
        if (block.getReporter() != null) {
            Element se = new Element("reporter");
            se.setAttribute("systemName", block.getReporter().getSystemName());
            se.setAttribute("reportCurrent", block.isReportingCurrent() ? "true" : "false");
            elem.addContent(se);
        }
        elem.setAttribute("permissive", block.getPermissiveWorking() ? "true" : "false");
        elem.setAttribute("speedNotch", block.getBlockSpeed());
        List<Path> paths = block.getPaths();
        for (int j = 0; j < paths.size(); j++) {
            elem.addContent(storePath((OPath) paths.get(j)));
        }
        List<Portal> portals = block.getPortals();
        for (int i = 0; i < portals.size(); i++) {
            elem.addContent(storePortal(portals.get(i)));
        }
        // and put this element out
        blocks.addContent(elem);
    }
    return blocks;
}
Also used : OPath(jmri.jmrit.logix.OPath) Path(jmri.Path) Element(org.jdom2.Element) Portal(jmri.jmrit.logix.Portal) OBlockManager(jmri.jmrit.logix.OBlockManager) OPath(jmri.jmrit.logix.OPath) OBlock(jmri.jmrit.logix.OBlock)

Example 9 with OBlockManager

use of jmri.jmrit.logix.OBlockManager in project JMRI by JMRI.

the class InstanceManagerTest method testOBlockManager.

public void testOBlockManager() {
    OBlockManager obj = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    Assert.assertNotNull(obj);
    Assert.assertEquals(obj, InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class));
    Assert.assertEquals(obj, InstanceManager.getDefault(OBlockManager.class));
    Assert.assertEquals(obj, InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class));
}
Also used : OBlockManager(jmri.jmrit.logix.OBlockManager)

Example 10 with OBlockManager

use of jmri.jmrit.logix.OBlockManager 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)

Aggregations

OBlockManager (jmri.jmrit.logix.OBlockManager)12 OBlock (jmri.jmrit.logix.OBlock)8 Portal (jmri.jmrit.logix.Portal)4 Point (java.awt.Point)3 ArrayList (java.util.ArrayList)3 JMenu (javax.swing.JMenu)2 NamedBean (jmri.NamedBean)2 Path (jmri.Path)2 Positionable (jmri.jmrit.display.Positionable)2 OPath (jmri.jmrit.logix.OPath)2 Element (org.jdom2.Element)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyVetoException (java.beans.PropertyVetoException)1 ParseException (java.text.ParseException)1 Iterator (java.util.Iterator)1 Entry (java.util.Map.Entry)1 JMenuItem (javax.swing.JMenuItem)1 Editor (jmri.jmrit.display.Editor)1 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)1