Search in sources :

Example 51 with Block

use of jmri.Block in project JMRI by JMRI.

the class VSDecoderManager method blockPropertyChange.

public void blockPropertyChange(PropertyChangeEvent event) {
    // Needs to check the ID on the event, look up the appropriate VSDecoder,
    // get the location of the event source, and update the decoder's location.
    // NOI18N
    @SuppressWarnings("cast") String eventName = (String) event.getPropertyName();
    if (event.getSource() instanceof PhysicalLocationReporter) {
        Block blk = (Block) event.getSource();
        String repVal = null;
        // "value" => Get loco address from event's newValue.
        if (eventName.equals("state")) {
            // to extract the address and the location.
            if ((Integer) event.getNewValue() == Block.OCCUPIED) {
                /// an idtag type reporter.
                if (blk.getReporter() == null) {
                    log.debug("Block " + blk.getSystemName() + " has no reporter!  Skipping state-type report.");
                    return;
                }
                if (blk.isReportingCurrent()) {
                    repVal = (String) blk.getReporter().getCurrentReport();
                } else {
                    repVal = (String) blk.getReporter().getLastReport();
                }
            } else {
                log.debug("Ignoring report. not an OCCUPIED event.");
                return;
            }
        } else if (eventName.equals("value")) {
            if (event.getNewValue() instanceof String) {
                repVal = event.getNewValue().toString();
            }
        // Else it will still be null from the declaration/assignment above.
        } else {
            log.debug("Not a supported Block event type.  Ignoring.");
            return;
        }
        // Set the decoder's position.
        if (repVal == null) {
            log.warn("Report from Block " + blk.getUserName() + " is null!");
        }
        if (blk.getDirection(repVal) == PhysicalLocationReporter.Direction.ENTER) {
            setDecoderPositionByAddr(blk.getLocoAddress(repVal), blk.getPhysicalLocation());
        }
        return;
    } else {
        log.debug("Reporter doesn't support physical location reporting.");
    }
    // Reporting object implements PhysicalLocationReporter
    return;
}
Also used : Block(jmri.Block) PhysicalLocationReporter(jmri.PhysicalLocationReporter)

Example 52 with Block

use of jmri.Block in project JMRI by JMRI.

the class MemoryTrackerTest method testDirectCreate.

public void testDirectCreate() {
    MemoryManager m = InstanceManager.memoryManagerInstance();
    jmri.InstanceManager.store(new jmri.NamedBeanHandleManager(), jmri.NamedBeanHandleManager.class);
    m.provideMemory("dummy");
    // check for exception in ctor
    new MemoryTracker(new Block("dummy"), "");
}
Also used : Block(jmri.Block) MemoryManager(jmri.MemoryManager)

Example 53 with Block

use of jmri.Block in project JMRI by JMRI.

the class SectionTableAction method addBlockPressed.

void addBlockPressed(ActionEvent e) {
    if (blockBoxList.size() == 0) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message5"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    int index = blockBox.getSelectedIndex();
    Block b = blockBoxList.get(index);
    if (b != null) {
        blockList.add(b);
        if (blockList.size() == 1) {
            beginBlock = b;
        }
        endBlock = b;
        initializeBlockCombo();
        initializeEntryPoints();
        blockTableModel.fireTableDataChanged();
    }
}
Also used : Block(jmri.Block) EntryPoint(jmri.EntryPoint)

Example 54 with Block

use of jmri.Block in project JMRI by JMRI.

the class SectionTableAction method initializeBlockCombo.

private void initializeBlockCombo() {
    List<String> allBlocks = blockManager.getSystemNameList();
    blockBox.removeAllItems();
    for (int j = blockBoxList.size(); j > 0; j--) {
        blockBoxList.remove(j - 1);
    }
    if (blockList.size() == 0) {
        // No blocks selected, all blocks are eligible
        for (int i = 0; i < allBlocks.size(); i++) {
            String bName = allBlocks.get(i);
            Block b = blockManager.getBySystemName(bName);
            if (b != null) {
                String uname = b.getUserName();
                if ((uname != null) && (!uname.equals(""))) {
                    bName = bName + "( " + uname + " )";
                }
                blockBox.addItem(bName);
                blockBoxList.add(b);
            }
        }
    } else {
        // limit to Blocks bonded to the current block that are not already in the Section
        for (int i = 0; i < allBlocks.size(); i++) {
            String bName = allBlocks.get(i);
            Block b = blockManager.getBySystemName(bName);
            if (b != null) {
                if ((!inSection(b)) && connected(b, endBlock)) {
                    String uname = b.getUserName();
                    if ((uname != null) && (!uname.equals(""))) {
                        bName = bName + "( " + uname + " )";
                    }
                    blockBox.addItem(bName);
                    blockBoxList.add(b);
                }
            }
        }
    }
}
Also used : Block(jmri.Block) EntryPoint(jmri.EntryPoint)

Example 55 with Block

use of jmri.Block in project JMRI by JMRI.

the class BlockEditAction method updateLength.

private void updateLength() {
    double len = 0.0;
    Block blk = (Block) bean;
    if (inch.isSelected()) {
        len = blk.getLengthIn();
    } else {
        len = blk.getLengthCm();
    }
    lengthField.setText(twoDigit.format(len));
}
Also used : Block(jmri.Block)

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