Search in sources :

Example 36 with Block

use of jmri.Block in project JMRI by JMRI.

the class SignallingPanel method updatePressed.

/**
     * Update changes in SML when Update button is pressed in the Edit Logic - Add Logic pane.
     *
     * @param e the event heard
     */
void updatePressed(ActionEvent e) {
    sourceMast = (SignalMast) sourceMastBox.getSelectedBean();
    destMast = (SignalMast) destMastBox.getSelectedBean();
    boolean smlPairAdded = false;
    destOK = true;
    if (sourceMast == destMast || fixedSourceMastLabel.getText() == destMast.getDisplayName()) {
        JOptionPane.showMessageDialog(null, rb.getString("ErrorSignalMastIdentical"));
        destOK = false;
        log.debug("Destination Mast check failed, keep pane open");
        return;
    }
    if ((sml == null) && (useLayoutEditor.isSelected())) {
        boolean valid = false;
        try {
            valid = InstanceManager.getDefault(LayoutBlockManager.class).getLayoutBlockConnectivityTools().checkValidDest(sourceMast, destMast, LayoutBlockConnectivityTools.MASTTOMAST);
            if (!valid) {
                JOptionPane.showMessageDialog(null, rb.getString("ErrorUnReachableDestination"));
                return;
            }
        } catch (jmri.JmriException je) {
            JOptionPane.showMessageDialog(null, rb.getString("WarningUnabletoValidate"));
        }
    }
    if (sml == null) {
        // a new SML directly from the SML Table
        sml = InstanceManager.getDefault(jmri.SignalMastLogicManager.class).newSignalMastLogic(sourceMast);
        // check if a similar SML pair already exists when in Add New session
        if (!sml.getDestinationList().contains(destMast)) {
            // not yet defined as a pair
            smlPairAdded = true;
            sml.setDestinationMast(destMast);
        } else {
            // show replace/update dialog
            int mes = JOptionPane.showConfirmDialog(null, rb.getString("WarningExistingPair"), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION);
            if (mes == JOptionPane.NO_OPTION) {
                return;
            }
        }
        fixedSourceMastLabel.setText(sourceMast.getDisplayName());
        fixedDestMastLabel.setText(destMast.getDisplayName());
        sourceMastBox.setVisible(false);
        destMastBox.setVisible(false);
        fixedSourceMastLabel.setVisible(true);
        fixedDestMastLabel.setVisible(true);
        _autoTurnoutModel.smlValid();
        _autoBlockModel.smlValid();
        _autoSignalMastModel.smlValid();
    }
    initializeIncludedList();
    sml.allowAutoMaticSignalMastGeneration(allowAutoMastGeneration.isSelected(), destMast);
    boolean layouteditorgen = true;
    try {
        sml.useLayoutEditor(useLayoutEditor.isSelected(), destMast);
    } catch (jmri.JmriException je) {
        JOptionPane.showMessageDialog(null, je.toString());
        layouteditorgen = false;
    }
    try {
        if (useLayoutEditor.isSelected()) {
            sml.useLayoutEditorDetails(useLayoutEditorTurnout.isSelected(), useLayoutEditorBlock.isSelected(), destMast);
        }
    } catch (jmri.JmriException ji) {
        if (layouteditorgen) {
            JOptionPane.showMessageDialog(null, ji.toString());
        }
    }
    Hashtable<Block, Integer> hashBlocks = new Hashtable<Block, Integer>();
    for (int i = 0; i < _includedManualBlockList.size(); i++) {
        Block blk = jmri.InstanceManager.getDefault(jmri.BlockManager.class).getBlock(_includedManualBlockList.get(i).getSysName());
        hashBlocks.put(blk, _includedManualBlockList.get(i).getState());
    }
    sml.setBlocks(hashBlocks, destMast);
    Hashtable<NamedBeanHandle<Turnout>, Integer> hashTurnouts = new Hashtable<NamedBeanHandle<Turnout>, Integer>();
    for (int i = 0; i < _includedManualTurnoutList.size(); i++) {
        String turnoutName = _includedManualTurnoutList.get(i).getDisplayName();
        Turnout turnout = jmri.InstanceManager.turnoutManagerInstance().getTurnout(_includedManualTurnoutList.get(i).getDisplayName());
        NamedBeanHandle<Turnout> namedTurnout = nbhm.getNamedBeanHandle(turnoutName, turnout);
        hashTurnouts.put(namedTurnout, _includedManualTurnoutList.get(i).getState());
    // no specific value, just show the current turnout state as selection in comboBox.
    // for existing SML pair, will be updated to show present setting by editDetails()
    }
    sml.setTurnouts(hashTurnouts, destMast);
    Hashtable<NamedBeanHandle<Sensor>, Integer> hashSensors = new Hashtable<NamedBeanHandle<Sensor>, Integer>();
    for (int i = 0; i < _includedManualSensorList.size(); i++) {
        String sensorName = _includedManualSensorList.get(i).getDisplayName();
        Sensor sensor = jmri.InstanceManager.sensorManagerInstance().getSensor(_includedManualSensorList.get(i).getDisplayName());
        NamedBeanHandle<Sensor> namedSensor = nbhm.getNamedBeanHandle(sensorName, sensor);
        hashSensors.put(namedSensor, _includedManualSensorList.get(i).getState());
    // no specific value, just show the current sensor state as selection in comboBox.
    // for existing SML pair, will be updated to show present setting by editDetails()
    }
    sml.setSensors(hashSensors, destMast);
    Hashtable<SignalMast, String> hashSignalMasts = new Hashtable<SignalMast, String>();
    for (int i = 0; i < _includedManualSignalMastList.size(); i++) {
        if (_includedManualSignalMastList.get(i).getMast() == sourceMast || _includedManualSignalMastList.get(i).getMast() == destMast) {
            // warn user that control mast is either source or destination mast of this pair, but allow as a valid choice
            int mes = JOptionPane.showConfirmDialog(null, java.text.MessageFormat.format(rb.getString("SignalMastCriteriaOwn"), new Object[] { _includedManualSignalMastList.get(i).getMast().getDisplayName() }), rb.getString("SignalMastCriteriaOwnTitle"), JOptionPane.YES_NO_OPTION);
            if (mes == 0) {
                // Yes
                hashSignalMasts.put(_includedManualSignalMastList.get(i).getMast(), _includedManualSignalMastList.get(i).getSetToState());
            } else {
                // No
                // deselect "Included" checkBox for signal mast in manualSignalList
                _includedManualSignalMastList.get(i).setIncluded(false);
                initializeIncludedList();
                _signalMastModel.fireTableDataChanged();
            }
        } else {
            hashSignalMasts.put(_includedManualSignalMastList.get(i).getMast(), _includedManualSignalMastList.get(i).getSetToState());
        }
    }
    sml.setMasts(hashSignalMasts, destMast);
    sml.allowTurnoutLock(lockTurnouts.isSelected(), destMast);
    sml.initialise(destMast);
    if (smlPairAdded) {
        log.debug("New SML");
        // to show new SML in underlying table
        firePropertyChange("newDestination", null, destMastBox.getSelectedBean());
    }
}
Also used : Hashtable(java.util.Hashtable) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Block(jmri.Block) SignalMast(jmri.SignalMast) Turnout(jmri.Turnout) NamedBeanHandle(jmri.NamedBeanHandle) Sensor(jmri.Sensor)

Example 37 with Block

use of jmri.Block in project JMRI by JMRI.

the class SignallingPanel method initializeIncludedList.

/**
     * Create new lists of control items configured as part of an SML.
     */
void initializeIncludedList() {
    _includedManualBlockList = new ArrayList<ManualBlockList>();
    for (int i = 0; i < _manualBlockList.size(); i++) {
        if (_manualBlockList.get(i).isIncluded()) {
            _includedManualBlockList.add(_manualBlockList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Block> blkList = sml.getAutoBlocks(destMast);
        _automaticBlockList = new ArrayList<AutoBlockList>(blkList.size());
        Iterator<Block> iter = blkList.iterator();
        while (iter.hasNext()) {
            Block blk = iter.next();
            AutoBlockList newABlk = new AutoBlockList(blk);
            _automaticBlockList.add(newABlk);
            newABlk.setState(sml.getAutoBlockState(blk, destMast));
        }
    }
    _includedManualTurnoutList = new ArrayList<ManualTurnoutList>();
    for (int i = 0; i < _manualTurnoutList.size(); i++) {
        if (_manualTurnoutList.get(i).isIncluded()) {
            _includedManualTurnoutList.add(_manualTurnoutList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Turnout> turnList = sml.getAutoTurnouts(destMast);
        _automaticTurnoutList = new ArrayList<AutoTurnoutList>(turnList.size());
        Iterator<Turnout> iter = turnList.iterator();
        while (iter.hasNext()) {
            Turnout turn = iter.next();
            String systemName = turn.getSystemName();
            String userName = turn.getUserName();
            AutoTurnoutList newAturn = new AutoTurnoutList(systemName, userName);
            _automaticTurnoutList.add(newAturn);
            newAturn.setState(sml.getAutoTurnoutState(turn, destMast));
        }
    }
    _includedManualSensorList = new ArrayList<ManualSensorList>();
    for (int i = 0; i < _manualSensorList.size(); i++) {
        if (_manualSensorList.get(i).isIncluded()) {
            _includedManualSensorList.add(_manualSensorList.get(i));
        }
    }
    _includedManualSignalMastList = new ArrayList<ManualSignalMastList>();
    for (int i = 0; i < _manualSignalMastList.size(); i++) {
        if (_manualSignalMastList.get(i).isIncluded()) {
            _includedManualSignalMastList.add(_manualSignalMastList.get(i));
        }
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<SignalMast> mastList = sml.getAutoMasts(destMast);
        _automaticSignalMastList = new ArrayList<AutoSignalMastList>(mastList.size());
        Iterator<SignalMast> iter = mastList.iterator();
        while (iter.hasNext()) {
            SignalMast mast = iter.next();
            AutoSignalMastList newAmast = new AutoSignalMastList(mast);
            _automaticSignalMastList.add(newAmast);
            newAmast.setState(sml.getAutoSignalMastState(mast, destMast));
        }
    }
}
Also used : SignalMast(jmri.SignalMast) Block(jmri.Block) Turnout(jmri.Turnout)

Example 38 with Block

use of jmri.Block in project JMRI by JMRI.

the class SignallingPanel method editDetails.

/**
     * Fill in existing SML configuration on the edit panel
     */
void editDetails() {
    int setRow = 0;
    for (int i = _manualBlockList.size() - 1; i >= 0; i--) {
        ManualBlockList block = _manualBlockList.get(i);
        String tSysName = block.getSysName();
        Block blk = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(tSysName);
        if (sml.isBlockIncluded(blk, destMast)) {
            block.setIncluded(true);
            block.setState(sml.getBlockState(blk, destMast));
            setRow = i;
        } else {
            block.setIncluded(false);
            block.setState(Block.UNOCCUPIED);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualBlockScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _blockModel.fireTableDataChanged();
    setRow = 0;
    for (int i = _manualTurnoutList.size() - 1; i >= 0; i--) {
        ManualTurnoutList turnout = _manualTurnoutList.get(i);
        String tSysName = turnout.getSysName();
        Turnout turn = InstanceManager.turnoutManagerInstance().getTurnout(tSysName);
        if (sml.isTurnoutIncluded(turn, destMast)) {
            turnout.setIncluded(true);
            turnout.setState(sml.getTurnoutState(turn, destMast));
            setRow = i;
        } else {
            turnout.setIncluded(false);
            turnout.setState(Turnout.CLOSED);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualSensorScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _sensorModel.fireTableDataChanged();
    setRow = 0;
    for (int i = _manualSensorList.size() - 1; i >= 0; i--) {
        ManualSensorList sensor = _manualSensorList.get(i);
        String tSysName = sensor.getSysName();
        Sensor sen = InstanceManager.sensorManagerInstance().getSensor(tSysName);
        if (sml.isSensorIncluded(sen, destMast)) {
            sensor.setIncluded(true);
            sensor.setState(sml.getSensorState(sen, destMast));
            setRow = i;
        } else {
            sensor.setIncluded(false);
            sensor.setState(Sensor.INACTIVE);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualSensorScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _sensorModel.fireTableDataChanged();
    setRow = 0;
    for (int i = _manualSignalMastList.size() - 1; i >= 0; i--) {
        ManualSignalMastList mast = _manualSignalMastList.get(i);
        SignalMast sigMast = _manualSignalMastList.get(i).getMast();
        if (sml.isSignalMastIncluded(sigMast, destMast)) {
            mast.setIncluded(true);
            mast.setSetToState(sml.getSignalMastState(sigMast, destMast));
            setRow = i;
        } else {
            mast.setIncluded(false);
        }
    }
    setRow -= 1;
    if (setRow < 0) {
        setRow = 0;
    }
    _manualSignalMastScrollPane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
    _signalMastModel.fireTableDataChanged();
}
Also used : LayoutBlockManager(jmri.jmrit.display.layoutEditor.LayoutBlockManager) Block(jmri.Block) SignalMast(jmri.SignalMast) Turnout(jmri.Turnout) Sensor(jmri.Sensor)

Example 39 with Block

use of jmri.Block in project JMRI by JMRI.

the class SignallingPanel method buildBlocksPanel.

/**
     * Compose GUI for setting up Blocks tab for an SML.
     *
     * @return a JPanel containing the SML control blocks configuration interface
     */
JPanel buildBlocksPanel() {
    JPanel blockPanel = new JPanel();
    blockPanel.setLayout(new BoxLayout(blockPanel, BoxLayout.Y_AXIS));
    jmri.BlockManager bm = jmri.InstanceManager.getDefault(jmri.BlockManager.class);
    List<String> systemNameList = bm.getSystemNameList();
    _manualBlockList = new ArrayList<ManualBlockList>(systemNameList.size());
    Iterator<String> iter = systemNameList.iterator();
    while (iter.hasNext()) {
        String systemName = iter.next();
        _manualBlockList.add(new ManualBlockList(bm.getBySystemName(systemName)));
    }
    if ((sml != null) && (destMast != null)) {
        ArrayList<Block> blkList = sml.getAutoBlocks(destMast);
        _automaticBlockList = new ArrayList<AutoBlockList>(blkList.size());
        Iterator<Block> iterBlk = blkList.iterator();
        while (iterBlk.hasNext()) {
            Block blk = iterBlk.next();
            AutoBlockList blockitem = new AutoBlockList(blk);
            blockitem.setState(sml.getAutoBlockState(blk, destMast));
            _automaticBlockList.add(blockitem);
        }
    }
    // this hides a field
    JPanel p2xc = new JPanel();
    JPanel p2xcSpace = new JPanel();
    p2xcSpace.setLayout(new BoxLayout(p2xcSpace, BoxLayout.Y_AXIS));
    p2xcSpace.add(new JLabel("XXX"));
    p2xc.add(p2xcSpace);
    JPanel p21c = new JPanel();
    p21c.setLayout(new BoxLayout(p21c, BoxLayout.Y_AXIS));
    p21c.add(new JLabel(Bundle.getMessage("LabelSelectChecked", Bundle.getMessage("Blocks"))));
    p2xc.add(p21c);
    _blockModel = new BlockModel();
    JTable manualBlockTable = new JTable(_blockModel);
    TableRowSorter<BlockModel> manualBlockSorter = new TableRowSorter<>(_blockModel);
    // configure row height for comboBox
    // row height has to be greater than for plain tables
    manualBlockTable.setRowHeight(Sizer.getPreferredSize().height - 2);
    manualBlockSorter.setComparator(BlockModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(manualBlockSorter, BlockModel.SNAME_COLUMN, SortOrder.ASCENDING);
    // create static comboBox in State column
    _blockModel.configStateColumn(manualBlockTable);
    manualBlockTable.setRowSorter(manualBlockSorter);
    manualBlockTable.setRowSelectionAllowed(false);
    manualBlockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    // JComboBox<String> stateCCombo = new JComboBox<>(); // moved to ManualBlockTable class
    TableColumnModel _manualBlockColumnModel = manualBlockTable.getColumnModel();
    TableColumn includeColumnC = _manualBlockColumnModel.getColumn(BlockModel.INCLUDE_COLUMN);
    includeColumnC.setResizable(false);
    // was fixed 60
    includeColumnC.setMinWidth(9 * Bundle.getMessage("Include").length());
    includeColumnC.setMaxWidth(includeColumnC.getMinWidth() + 5);
    TableColumn sNameColumnC = _manualBlockColumnModel.getColumn(BlockModel.SNAME_COLUMN);
    sNameColumnC.setResizable(true);
    sNameColumnC.setMinWidth(75);
    sNameColumnC.setMaxWidth(95);
    TableColumn stateColumnC = _manualBlockColumnModel.getColumn(BlockModel.STATE_COLUMN);
    //stateColumnC.setCellEditor(new DefaultCellEditor(stateCCombo)); // moved to ManualBlockTable class
    stateColumnC.setResizable(false);
    stateColumnC.setMinWidth(9 * Math.max(SET_TO_UNOCCUPIED.length(), SET_TO_OCCUPIED.length()) + 40);
    // was fixed 100
    stateColumnC.setMaxWidth(stateColumnC.getMinWidth() + 10);
    // remaining space is filled by UserName
    _manualBlockScrollPane = new JScrollPane(manualBlockTable);
    p2xc.add(_manualBlockScrollPane, BorderLayout.CENTER);
    blockPanel.add(p2xc);
    p2xc.setVisible(true);
    ROW_HEIGHT = manualBlockTable.getRowHeight();
    p2xcSpace.setVisible(false);
    JPanel p2xaSpace = new JPanel();
    p2xaSpace.setLayout(new BoxLayout(p2xaSpace, BoxLayout.Y_AXIS));
    p2xaSpace.add(new JLabel("XXX"));
    p2xb.add(p2xaSpace);
    JPanel p21a = new JPanel();
    p21a.setLayout(new BoxLayout(p21a, BoxLayout.Y_AXIS));
    p21a.add(new JLabel(Bundle.getMessage("LabelAutogenerated", Bundle.getMessage("Blocks"))));
    p2xb.add(p21a);
    _autoBlockModel = new AutoBlockModel();
    JTable autoBlockTable = new JTable(_autoBlockModel);
    TableRowSorter<AutoBlockModel> autoBlockSorter = new TableRowSorter<>(_autoBlockModel);
    autoBlockSorter.setComparator(AutoBlockModel.SNAME_COLUMN, new SystemNameComparator());
    RowSorterUtil.setSortOrder(autoBlockSorter, AutoBlockModel.SNAME_COLUMN, SortOrder.ASCENDING);
    autoBlockTable.setRowSorter(autoBlockSorter);
    autoBlockTable.setRowSelectionAllowed(false);
    autoBlockTable.setPreferredScrollableViewportSize(new java.awt.Dimension(480, 100));
    TableColumnModel _autoBlockColumnModel = autoBlockTable.getColumnModel();
    TableColumn sNameColumnA = _autoBlockColumnModel.getColumn(AutoBlockModel.SNAME_COLUMN);
    sNameColumnA.setResizable(true);
    sNameColumnA.setMinWidth(75);
    sNameColumnA.setMaxWidth(95);
    TableColumn stateColumnA = _autoBlockColumnModel.getColumn(AutoBlockModel.STATE_COLUMN);
    stateColumnA.setResizable(false);
    stateColumnA.setMinWidth(90);
    stateColumnA.setMaxWidth(100);
    _autoBlockScrollPane = new JScrollPane(autoBlockTable);
    p2xb.add(_autoBlockScrollPane, BorderLayout.CENTER);
    blockPanel.add(p2xb);
    p2xb.setVisible(true);
    ROW_HEIGHT = autoBlockTable.getRowHeight();
    p2xaSpace.setVisible(false);
    return blockPanel;
}
Also used : JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) TableColumnModel(javax.swing.table.TableColumnModel) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) TableColumn(javax.swing.table.TableColumn) JTable(javax.swing.JTable) Block(jmri.Block) SystemNameComparator(jmri.util.SystemNameComparator)

Example 40 with Block

use of jmri.Block in project JMRI by JMRI.

the class DestinationPoints method blockStateUpdated.

protected void blockStateUpdated(PropertyChangeEvent e) {
    Block blk = (Block) e.getSource();
    if (e.getPropertyName().equals("state")) {
        if (log.isDebugEnabled()) {
            log.debug(mUserName + "  We have a change of state on the block " + blk.getDisplayName());
        }
        int now = ((Integer) e.getNewValue()).intValue();
        if (now == Block.OCCUPIED) {
            LayoutBlock lBlock = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getLayoutBlock(blk);
            //If the block was previously active or inactive then we will 
            //reset the useExtraColor, but not if it was previously unknown or inconsistent.
            lBlock.setUseExtraColor(false);
            //was this
            blk.removePropertyChangeListener(propertyBlockListener);
            removeBlockFromRoute(lBlock);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("state was " + now + " and did not go through reset");
            }
        }
    }
}
Also used : LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock) Block(jmri.Block) LayoutBlock(jmri.jmrit.display.layoutEditor.LayoutBlock)

Aggregations

Block (jmri.Block)84 ArrayList (java.util.ArrayList)19 EntryPoint (jmri.EntryPoint)16 Sensor (jmri.Sensor)10 Element (org.jdom2.Element)9 BlockManager (jmri.BlockManager)8 SignalMast (jmri.SignalMast)8 Turnout (jmri.Turnout)8 Test (org.junit.Test)7 Path (jmri.Path)6 Reporter (jmri.Reporter)6 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 Section (jmri.Section)5 Hashtable (java.util.Hashtable)4 NamedBean (jmri.NamedBean)4 SignalHead (jmri.SignalHead)4 LayoutBlockManager (jmri.jmrit.display.layoutEditor.LayoutBlockManager)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)3 PropertyChangeListener (java.beans.PropertyChangeListener)3