Search in sources :

Example 16 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class SignalTableModel method makeList.

private void makeList() {
    ArrayList<SignalRow> tempList = new ArrayList<SignalRow>();
    // collect signals entered into Portals
    String[] sysNames = _portalMgr.getSystemNameArray();
    for (int i = 0; i < sysNames.length; i++) {
        Portal portal = _portalMgr.getBySystemName(sysNames[i]);
        NamedBean signal = portal.getFromSignal();
        SignalRow sr = null;
        if (signal != null) {
            sr = new SignalRow(signal, portal.getFromBlock(), portal, portal.getToBlock(), portal.getFromSignalOffset(), portal.getToBlock().isMetric());
            addToList(tempList, sr);
        }
        signal = portal.getToSignal();
        if (signal != null) {
            sr = new SignalRow(signal, portal.getToBlock(), portal, portal.getFromBlock(), portal.getToSignalOffset(), portal.getFromBlock().isMetric());
            addToList(tempList, sr);
        }
    }
    _signalList = tempList;
    if (log.isDebugEnabled()) {
        log.debug("makeList exit: _signalList has " + _signalList.size() + " rows.");
    }
}
Also used : NamedBean(jmri.NamedBean) ArrayList(java.util.ArrayList) Portal(jmri.jmrit.logix.Portal)

Example 17 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class BlockPortalTableModel method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    List<NamedBean> list = _oBlockModel.getBeanList();
    if (list.size() > 0) {
        int count = 0;
        //accumulated row count
        int idx = 0;
        OBlock block = null;
        NamedBean[] array = new NamedBean[list.size()];
        array = list.toArray(array);
        Arrays.sort(array, new jmri.util.NamedBeanComparator());
        while (count <= row) {
            count += ((OBlock) array[idx++]).getPortals().size();
        }
        block = (OBlock) array[--idx];
        idx = row - (count - block.getPortals().size());
        if (col == BLOCK_NAME_COLUMN) {
            if (idx == 0) {
                return block.getDisplayName();
            }
            return "";
        }
        return block.getPortals().get(idx).getName();
    /*           
             while (count <= row)  {
             count += ((OBlock)list.get(idx++)).getPortals().size();
             }
             block = (OBlock)list.get(--idx);
             idx = row - (count - block.getPortals().size());
             if (col==BLOCK_NAME_COLUMN) {
             if (idx==0) {
             return block.getDisplayName();
             }
             return "";
             }
             return block.getPortals().get(idx).getName();
             */
    }
    return null;
}
Also used : NamedBean(jmri.NamedBean) OBlock(jmri.jmrit.logix.OBlock)

Example 18 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class SignalTableModel method setValueAt.

@Override
public void setValueAt(Object value, int row, int col) {
    String msg = null;
    if (_signalList.size() == row) {
        if (col == DELETE_COL) {
            initTempRow();
            fireTableRowsUpdated(row, row);
            return;
        } else if (col == UNITSCOL) {
            if (((Boolean) value).booleanValue()) {
                tempRow[UNITSCOL] = Bundle.getMessage("cm");
            } else {
                tempRow[UNITSCOL] = Bundle.getMessage("in");
            }
            fireTableRowsUpdated(row, row);
            return;
        } else if (col == LENGTHCOL) {
            try {
                _tempLen = IntlUtilities.floatValue(value.toString());
                if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) {
                    _tempLen *= 10f;
                } else {
                    _tempLen *= 25.4f;
                }
            } catch (ParseException e) {
                JOptionPane.showMessageDialog(null, Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
            }
            return;
        }
        String str = (String) value;
        if (str == null || str.trim().length() == 0) {
            tempRow[col] = null;
            return;
        }
        tempRow[col] = str.trim();
        OBlock fromBlock = null;
        OBlock toBlock = null;
        Portal portal = null;
        NamedBean signal = null;
        OBlockManager OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
        if (tempRow[FROM_BLOCK_COLUMN] != null) {
            fromBlock = OBlockMgr.getOBlock(tempRow[FROM_BLOCK_COLUMN]);
            if (fromBlock == null) {
                msg = Bundle.getMessage("NoSuchBlock", tempRow[FROM_BLOCK_COLUMN]);
            }
        }
        if (msg == null && tempRow[TO_BLOCK_COLUMN] != null) {
            toBlock = OBlockMgr.getOBlock(tempRow[TO_BLOCK_COLUMN]);
            if (toBlock == null) {
                msg = Bundle.getMessage("NoSuchBlock", tempRow[TO_BLOCK_COLUMN]);
            }
        }
        if (msg == null) {
            if (tempRow[PORTAL_COLUMN] != null) {
                portal = _portalMgr.getPortal(tempRow[PORTAL_COLUMN]);
                if (portal == null) {
                    msg = Bundle.getMessage("NoSuchPortalName", tempRow[PORTAL_COLUMN]);
                }
            } else {
                if (fromBlock != null && toBlock != null) {
                    portal = getPortalwithBlocks(fromBlock, toBlock);
                    if (portal == null) {
                        msg = Bundle.getMessage("NoSuchPortal", tempRow[FROM_BLOCK_COLUMN], tempRow[TO_BLOCK_COLUMN]);
                    } else {
                        tempRow[PORTAL_COLUMN] = portal.getName();
                    }
                }
            }
        }
        if (msg == null && tempRow[NAME_COLUMN] != null) {
            signal = Portal.getSignal(tempRow[NAME_COLUMN]);
            if (signal == null) {
                msg = Bundle.getMessage("NoSuchSignal", tempRow[NAME_COLUMN]);
            } else {
                msg = checkDuplicateSignal(signal);
            }
            if (msg == null) {
                if (fromBlock != null && toBlock != null) {
                    portal = getPortalwithBlocks(fromBlock, toBlock);
                    if (portal == null) {
                        msg = Bundle.getMessage("NoSuchPortal", tempRow[FROM_BLOCK_COLUMN], tempRow[TO_BLOCK_COLUMN]);
                    } else {
                        tempRow[PORTAL_COLUMN] = portal.getName();
                    }
                } else {
                    return;
                }
            }
            if (msg == null) {
                float length = 0.0f;
                boolean isMetric = tempRow[UNITSCOL].equals(Bundle.getMessage("cm"));
                try {
                    length = IntlUtilities.floatValue(tempRow[LENGTHCOL]);
                    if (isMetric) {
                        length *= 10f;
                    } else {
                        length *= 25.4f;
                    }
                } catch (ParseException e) {
                    msg = Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]);
                }
                if (isMetric) {
                    tempRow[UNITSCOL] = Bundle.getMessage("cm");
                } else {
                    tempRow[UNITSCOL] = Bundle.getMessage("in");
                }
                if (msg == null) {
                    SignalRow signalRow = new SignalRow(signal, fromBlock, portal, toBlock, length, isMetric);
                    msg = setSignal(signalRow, false);
                    if (msg == null) {
                        _signalList.add(signalRow);
                    }
                    initTempRow();
                    fireTableDataChanged();
                }
            }
        }
    } else {
        // Editing existing signal configurations
        SignalRow signalRow = _signalList.get(row);
        OBlockManager OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
        switch(col) {
            case NAME_COLUMN:
                NamedBean signal = Portal.getSignal((String) value);
                if (signal == null) {
                    msg = Bundle.getMessage("NoSuchSignal", (String) value);
                    //                        signalRow.setSignal(null);                              
                    break;
                }
                Portal portal = signalRow.getPortal();
                if (portal != null && signalRow.getToBlock() != null) {
                    NamedBean oldSignal = signalRow.getSignal();
                    signalRow.setSignal(signal);
                    msg = checkDuplicateSignal(signalRow);
                    if (msg == null) {
                        // delete old
                        deleteSignal(signalRow);
                        msg = setSignal(signalRow, false);
                        fireTableRowsUpdated(row, row);
                    } else {
                        signalRow.setSignal(oldSignal);
                    }
                }
                break;
            case FROM_BLOCK_COLUMN:
                OBlock block = OBlockMgr.getOBlock((String) value);
                if (block == null) {
                    msg = Bundle.getMessage("NoSuchBlock", (String) value);
                    break;
                }
                if (block.equals(signalRow.getFromBlock())) {
                    // no change
                    break;
                }
                // delete old
                deleteSignal(signalRow);
                signalRow.setFromBlock(block);
                portal = signalRow.getPortal();
                if (checkPortalBlock(portal, block)) {
                    signalRow.setToBlock(null);
                } else {
                    // get new portal
                    portal = getPortalwithBlocks(block, signalRow.getToBlock());
                    signalRow.setPortal(portal);
                }
                msg = checkSignalRow(signalRow);
                if (msg == null) {
                    msg = checkDuplicateProtection(signalRow);
                } else {
                    signalRow.setPortal(null);
                    break;
                }
                if (msg == null && signalRow.getPortal() != null) {
                    msg = setSignal(signalRow, true);
                } else {
                    signalRow.setPortal(null);
                }
                fireTableRowsUpdated(row, row);
                break;
            case PORTAL_COLUMN:
                portal = _portalMgr.getPortal((String) value);
                if (portal == null) {
                    msg = Bundle.getMessage("NoSuchPortalName", (String) value);
                    break;
                }
                // delete old
                deleteSignal(signalRow);
                signalRow.setPortal(portal);
                block = signalRow.getToBlock();
                if (checkPortalBlock(portal, block)) {
                    signalRow.setFromBlock(null);
                } else {
                    block = signalRow.getFromBlock();
                    if (checkPortalBlock(portal, block)) {
                        signalRow.setToBlock(null);
                    }
                }
                msg = checkSignalRow(signalRow);
                if (msg == null) {
                    msg = checkDuplicateProtection(signalRow);
                } else {
                    signalRow.setToBlock(null);
                    break;
                }
                if (msg == null) {
                    signalRow.setPortal(portal);
                    msg = setSignal(signalRow, false);
                    fireTableRowsUpdated(row, row);
                }
                break;
            case TO_BLOCK_COLUMN:
                block = OBlockMgr.getOBlock((String) value);
                if (block == null) {
                    msg = Bundle.getMessage("NoSuchBlock", (String) value);
                    break;
                }
                if (block.equals(signalRow.getToBlock())) {
                    // no change
                    break;
                }
                // delete old
                deleteSignal(signalRow);
                signalRow.setToBlock(block);
                portal = signalRow.getPortal();
                if (checkPortalBlock(portal, block)) {
                    signalRow.setFromBlock(null);
                } else {
                    // get new portal
                    portal = getPortalwithBlocks(signalRow.getFromBlock(), block);
                    signalRow.setPortal(portal);
                }
                msg = checkSignalRow(signalRow);
                if (msg == null) {
                    msg = checkDuplicateProtection(signalRow);
                } else {
                    signalRow.setPortal(null);
                    break;
                }
                if (msg == null && signalRow.getPortal() != null) {
                    msg = setSignal(signalRow, true);
                } else {
                    signalRow.setPortal(null);
                }
                fireTableRowsUpdated(row, row);
                break;
            case LENGTHCOL:
                try {
                    float len = IntlUtilities.floatValue(value.toString());
                    if (signalRow.isMetric()) {
                        signalRow.setLength(len * 10.0f);
                    } else {
                        signalRow.setLength(len * 25.4f);
                    }
                    fireTableRowsUpdated(row, row);
                } catch (ParseException e) {
                    msg = Bundle.getMessage("BadNumber", value);
                }
                if (msg == null && signalRow.getPortal() != null) {
                    msg = setSignal(signalRow, false);
                } else {
                    signalRow.setPortal(null);
                }
                fireTableRowsUpdated(row, row);
                break;
            case UNITSCOL:
                signalRow.setMetric((Boolean) value);
                fireTableRowsUpdated(row, row);
                break;
            case DELETE_COL:
                deleteSignal(signalRow);
                _signalList.remove(signalRow);
                fireTableDataChanged();
                break;
            default:
                // fall through
                break;
        }
    }
    if (msg != null) {
        JOptionPane.showMessageDialog(null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
    }
}
Also used : NamedBean(jmri.NamedBean) Portal(jmri.jmrit.logix.Portal) OBlockManager(jmri.jmrit.logix.OBlockManager) ParseException(java.text.ParseException) OBlock(jmri.jmrit.logix.OBlock)

Example 19 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class IconAdder method getTableSelection.

/**
     * Used by Panel Editor to make the final installation of the icon(s) into
     * the user's Panel.
     * <P>
     * Note! the selection is cleared. When two successive calls are made, the
     * 2nd will always return null, regardless of the 1st return.
     *
     * @return the selected item
     */
public NamedBean getTableSelection() {
    if (ImageIndexEditor.isIndexChanged()) {
        checkIconSizes();
    }
    int row = _table.getSelectedRow();
    row = _table.convertRowIndexToModel(row);
    if (row >= 0) {
        NamedBean b = _pickListModel.getBeanAt(row);
        _table.clearSelection();
        _addButton.setEnabled(false);
        _addButton.setToolTipText(null);
        this.revalidate();
        if (log.isDebugEnabled()) {
            log.debug("getTableSelection: row= " + row + ", bean= " + b.getDisplayName());
        }
        return b;
    } else if (log.isDebugEnabled()) {
        log.debug("getTableSelection: row=0");
    }
    return null;
}
Also used : NamedBean(jmri.NamedBean)

Example 20 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class IconAdder method addToTable.

void addToTable() {
    String name = _sysNametext.getText();
    if (name != null && name.length() > 0) {
        NamedBean bean = _pickListModel.addBean(name);
        int setRow = _pickListModel.getIndexOf(bean);
        _table.setRowSelectionInterval(setRow, setRow);
        _pickTablePane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    }
    _sysNametext.setText("");
    _addTableButton.setEnabled(false);
    _addTableButton.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
}
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