Search in sources :

Example 21 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class LayoutBlockConnectivityTools method getBeansInPath.

/**
     * Returns a list of NamedBeans (Signalhead, Signalmast or Sensor) that are
     * assinged to block boundaries in a given list
     *
     * @param blocklist The list of block in order that need to be checked.
     * @param panel     (Optional) panel that the blocks need to be checked
     *                  against
     * @param T         (Optional) the class that we want to check against,
     *                  either Sensor, SignalMast or SignalHead, set null will
     *                  return any.
     */
public List<NamedBean> getBeansInPath(List<LayoutBlock> blocklist, LayoutEditor panel, Class<?> T) {
    ArrayList<NamedBean> beansInPath = new ArrayList<NamedBean>();
    if (blocklist.size() >= 2) {
        LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
        for (int x = 1; x < blocklist.size(); x++) {
            LayoutBlock facingBlock = blocklist.get(x - 1);
            LayoutBlock protectingBlock = blocklist.get(x);
            NamedBean nb = null;
            if (T == null) {
                nb = lbm.getFacingNamedBean(facingBlock.getBlock(), protectingBlock.getBlock(), panel);
            } else if (T.equals(jmri.SignalMast.class)) {
                nb = lbm.getFacingSignalMast(facingBlock.getBlock(), protectingBlock.getBlock(), panel);
            } else if (T.equals(jmri.Sensor.class)) {
                nb = lbm.getFacingSensor(facingBlock.getBlock(), protectingBlock.getBlock(), panel);
            } else if (T.equals(jmri.SignalHead.class)) {
                nb = lbm.getFacingSignalHead(facingBlock.getBlock(), protectingBlock.getBlock());
            }
            if (nb != null) {
                beansInPath.add(nb);
            }
        }
    }
    return beansInPath;
}
Also used : NamedBean(jmri.NamedBean) ArrayList(java.util.ArrayList) SignalMast(jmri.SignalMast)

Example 22 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class LayoutBlockConnectivityTools method discoverPairDest.

ArrayList<NamedBean> discoverPairDest(NamedBean source, LayoutBlock lProtecting, LayoutBlock lFacing, ArrayList<FacingProtecting> blockList, int pathMethod) throws JmriException {
    LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
    if (!lbm.isAdvancedRoutingEnabled()) {
        throw new JmriException("advanced routing not enabled");
    }
    if (!lbm.routingStablised()) {
        throw new JmriException("routing not stabilised");
    }
    ArrayList<NamedBean> validDestBean = new ArrayList<NamedBean>();
    for (int j = 0; j < blockList.size(); j++) {
        if (blockList.get(j).getBean() != source) {
            NamedBean destObj = blockList.get(j).getBean();
            if (log.isDebugEnabled()) {
                log.debug("looking for pair " + source.getDisplayName() + " " + destObj.getDisplayName());
            }
            try {
                if (checkValidDest(lFacing, lProtecting, blockList.get(j), pathMethod)) {
                    if (log.isDebugEnabled()) {
                        log.debug("Valid pair " + source.getDisplayName() + " " + destObj.getDisplayName());
                    }
                    LayoutBlock ldstBlock = lbm.getLayoutBlock(blockList.get(j).getFacing());
                    try {
                        ArrayList<LayoutBlock> lblks = getLayoutBlocks(lFacing, ldstBlock, lProtecting, true, pathMethod);
                        if (log.isDebugEnabled()) {
                            log.debug("Adding block " + destObj.getDisplayName() + " to paths, current size " + lblks.size());
                        }
                        validDestBean.add(destObj);
                    } catch (jmri.JmriException e) {
                        // Considered normal if route not found.
                        log.debug("not a valid route through " + source.getDisplayName() + " - " + destObj.getDisplayName());
                    }
                }
            } catch (jmri.JmriException ex) {
                log.debug(ex.toString());
            }
        }
    }
    return validDestBean;
}
Also used : NamedBean(jmri.NamedBean) JmriException(jmri.JmriException) ArrayList(java.util.ArrayList) JmriException(jmri.JmriException)

Example 23 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class LayoutBlockConnectivityTools method generateBlocksWithBeans.

ArrayList<FacingProtecting> generateBlocksWithBeans(LayoutEditor editor, Class<?> T) {
    LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
    ArrayList<FacingProtecting> beanList = new ArrayList<FacingProtecting>();
    List<String> lblksSysName = lbm.getSystemNameList();
    for (int i = 0; i < lblksSysName.size(); i++) {
        LayoutBlock curLblk = lbm.getLayoutBlock(lblksSysName.get(i));
        Block curBlk = curLblk.getBlock();
        LayoutEditor useEdit = editor;
        if (editor == null) {
            useEdit = curLblk.getMaxConnectedPanel();
        }
        if (curBlk != null) {
            int noNeigh = curLblk.getNumberOfNeighbours();
            for (int x = 0; x < noNeigh; x++) {
                Block blk = curLblk.getNeighbourAtIndex(x);
                ArrayList<Block> proBlk = new ArrayList<Block>();
                NamedBean bean = null;
                if (T == null) {
                    proBlk.add(blk);
                    bean = lbm.getFacingNamedBean(curBlk, blk, useEdit);
                } else if (T.equals(SignalMast.class)) {
                    bean = lbm.getFacingSignalMast(curBlk, blk, useEdit);
                    if (bean != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Get list of protecting blocks for " + bean.getDisplayName() + " facing " + curBlk.getDisplayName());
                        }
                        List<LayoutBlock> lProBlk = lbm.getProtectingBlocksByNamedBean(bean, useEdit);
                        for (LayoutBlock lb : lProBlk) {
                            if (lb != null) {
                                proBlk.add(lb.getBlock());
                            }
                        }
                    }
                } else if (T.equals(Sensor.class)) {
                    bean = lbm.getFacingSensor(curBlk, blk, useEdit);
                    if (bean != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Get list of protecting blocks for " + bean.getDisplayName());
                        }
                        List<LayoutBlock> lProBlk = lbm.getProtectingBlocksByNamedBean(bean, useEdit);
                        for (LayoutBlock lb : lProBlk) {
                            if (lb != null) {
                                proBlk.add(lb.getBlock());
                            }
                        }
                    }
                } else {
                    log.error("Past bean type is unknown " + T);
                }
                if (bean != null) {
                    FacingProtecting toadd = new FacingProtecting(curBlk, proBlk, bean);
                    boolean found = false;
                    for (FacingProtecting fp : beanList) {
                        if (fp.equals(toadd)) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        beanList.add(toadd);
                    }
                }
            }
            if (noNeigh == 1) {
                NamedBean bean = null;
                if (log.isDebugEnabled()) {
                    log.debug("We have a dead end " + curBlk.getDisplayName());
                }
                if (T == null) {
                    bean = lbm.getNamedBeanAtEndBumper(curBlk, useEdit);
                } else if (T.equals(SignalMast.class)) {
                    bean = lbm.getSignalMastAtEndBumper(curBlk, useEdit);
                } else if (T.equals(Sensor.class)) {
                    bean = lbm.getSensorAtEndBumper(curBlk, useEdit);
                } else {
                    log.error("Past bean type is unknown " + T);
                }
                if (bean != null) {
                    FacingProtecting toadd = new FacingProtecting(curBlk, null, bean);
                    boolean found = false;
                    for (FacingProtecting fp : beanList) {
                        if (fp.equals(toadd)) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        beanList.add(toadd);
                    }
                }
            }
        }
    }
    return beanList;
}
Also used : NamedBean(jmri.NamedBean) ArrayList(java.util.ArrayList) Block(jmri.Block) SignalMast(jmri.SignalMast) List(java.util.List) ArrayList(java.util.ArrayList)

Example 24 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class MemoryItemPanel method valueChanged.

/**
     * ListSelectionListener action from table
     */
@Override
public void valueChanged(ListSelectionEvent e) {
    if (_table == null) {
        return;
    }
    int row = _table.getSelectedRow();
    if (log.isDebugEnabled()) {
        log.debug("Table valueChanged: row= " + row);
    }
    if (row >= 0) {
        if (_updateButton != null) {
            _updateButton.setEnabled(true);
            _updateButton.setToolTipText(null);
        }
        NamedBean bean = getDeviceNamedBean();
        _readMem.setMemory(bean.getDisplayName());
        _writeMem.setMemory(bean.getDisplayName());
        _spinMem.setMemory(bean.getDisplayName());
        _comboMem.setMemory(bean.getDisplayName());
    } else {
        if (_updateButton != null) {
            _updateButton.setEnabled(false);
            _updateButton.setToolTipText(Bundle.getMessage("ToolTipPickFromTable"));
        }
    }
    validate();
}
Also used : NamedBean(jmri.NamedBean)

Example 25 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class ReporterItemPanel method valueChanged.

/**
     * ListSelectionListener action from table
     */
@Override
public void valueChanged(ListSelectionEvent e) {
    if (_table == null) {
        return;
    }
    int row = _table.getSelectedRow();
    if (log.isDebugEnabled()) {
        log.debug("Table valueChanged: row= " + row);
    }
    if (row >= 0) {
        if (_updateButton != null) {
            _updateButton.setEnabled(true);
            _updateButton.setToolTipText(null);
        }
        NamedBean bean = getDeviceNamedBean();
        _reporter.setReporter(bean.getDisplayName());
    } else {
        if (_updateButton != null) {
            _updateButton.setEnabled(false);
            _updateButton.setToolTipText(Bundle.getMessage("ToolTipPickFromTable"));
        }
    }
    validate();
}
Also used : NamedBean(jmri.NamedBean)

Aggregations

NamedBean (jmri.NamedBean)104 ArrayList (java.util.ArrayList)18 JTextField (javax.swing.JTextField)12 JmriException (jmri.JmriException)12 SignalMast (jmri.SignalMast)12 JTable (javax.swing.JTable)11 Manager (jmri.Manager)9 Sensor (jmri.Sensor)9 JButton (javax.swing.JButton)8 InstanceManager (jmri.InstanceManager)8 JComboBox (javax.swing.JComboBox)7 MouseEvent (java.awt.event.MouseEvent)6 Hashtable (java.util.Hashtable)6 SignalHead (jmri.SignalHead)6 Turnout (jmri.Turnout)6 OBlock (jmri.jmrit.logix.OBlock)5 File (java.io.File)4 JLabel (javax.swing.JLabel)4 TableCellEditor (javax.swing.table.TableCellEditor)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4