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;
}
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"), "");
}
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();
}
}
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);
}
}
}
}
}
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));
}
Aggregations