use of jmri.Block in project JMRI by JMRI.
the class SectionTableAction method initializeEditInformation.
private void initializeEditInformation() {
userName.setText(curSection.getUserName());
switch(curSection.getSectionType()) {
case Section.USERDEFINED:
generationStateLabel.setText("");
break;
case Section.SIGNALMASTLOGIC:
generationStateLabel.setText(rbx.getString("SectionTypeSMLLabel"));
break;
case Section.DYNAMICADHOC:
generationStateLabel.setText(rbx.getString("SectionTypeDynLabel"));
break;
default:
generationStateLabel.setText("");
break;
}
deleteBlocksPressed(null);
int i = 0;
while (curSection.getBlockBySequenceNumber(i) != null) {
Block b = curSection.getBlockBySequenceNumber(i);
blockList.add(b);
i++;
if (blockList.size() == 1) {
beginBlock = b;
}
endBlock = b;
}
forwardSensorField.setText(curSection.getForwardBlockingSensorName());
reverseSensorField.setText(curSection.getReverseBlockingSensorName());
forwardStopSensorField.setText(curSection.getForwardStoppingSensorName());
reverseStopSensorField.setText(curSection.getReverseStoppingSensorName());
List<EntryPoint> list = curSection.getForwardEntryPointList();
if (list.size() > 0) {
for (int j = 0; j < list.size(); j++) {
entryPointList.add(list.get(j));
}
}
list = curSection.getReverseEntryPointList();
if (list.size() > 0) {
for (int j = 0; j < list.size(); j++) {
entryPointList.add(list.get(j));
}
}
}
use of jmri.Block in project JMRI by JMRI.
the class BlockEditAction method physcialDetails.
BeanItemPanel physcialDetails() {
defaultBlockSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + jmri.InstanceManager.getDefault(jmri.BlockManager.class).getDefaultSpeed());
speedList.add(defaultBlockSpeedText);
java.util.Vector<String> _speedMap = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames();
for (int i = 0; i < _speedMap.size(); i++) {
if (!speedList.contains(_speedMap.get(i))) {
speedList.add(_speedMap.get(i));
}
}
BeanItemPanel basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("BlockPhysicalProperties"));
basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("BlockPropertiesText")));
basic.addItem(new BeanEditItem(lengthField, Bundle.getMessage("BlockLengthColName"), Bundle.getMessage("BlockLengthText")));
lengthField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
String text = lengthField.getText();
// ensure data valid
try {
jmri.util.IntlUtilities.floatValue(text);
} catch (java.text.ParseException e) {
String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("BlockLengthColName") });
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "length", false, false);
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
ButtonGroup rg = new ButtonGroup();
rg.add(inch);
rg.add(cm);
JPanel p = new JPanel();
p.add(inch);
p.add(cm);
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
inch.setSelected(true);
inch.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cm.setSelected(!inch.isSelected());
updateLength();
}
});
cm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
inch.setSelected(!cm.isSelected());
updateLength();
}
});
basic.addItem(new BeanEditItem(p, Bundle.getMessage("BlockLengthUnits"), Bundle.getMessage("BlockLengthUnitsText")));
basic.addItem(new BeanEditItem(curvatureField, Bundle.getMessage("BlockCurveColName"), ""));
basic.addItem(new BeanEditItem(speedField = new JComboBox<String>(speedList), Bundle.getMessage("BlockSpeedColName"), Bundle.getMessage("BlockMaxSpeedText")));
basic.addItem(new BeanEditItem(permissiveField, Bundle.getMessage("BlockPermColName"), Bundle.getMessage("BlockPermissiveText")));
permissiveField.setSelected(((Block) bean).getPermissiveWorking());
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
String cName = (String) curvatureField.getSelectedItem();
if (cName.equals(noneText)) {
blk.setCurvature(Block.NONE);
} else if (cName.equals(gradualText)) {
blk.setCurvature(Block.GRADUAL);
} else if (cName.equals(tightText)) {
blk.setCurvature(Block.TIGHT);
} else if (cName.equals(severeText)) {
blk.setCurvature(Block.SEVERE);
}
String speed = (String) speedField.getSelectedItem();
try {
blk.setBlockSpeed(speed);
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
return;
}
if (!speedList.contains(speed) && !speed.contains("Global")) {
speedList.add(speed);
}
float len = 0.0f;
try {
len = jmri.util.IntlUtilities.floatValue(lengthField.getText());
} catch (java.text.ParseException ex2) {
log.error("Error parsing length value of \"{}\"", lengthField.getText());
}
if (inch.isSelected()) {
blk.setLength(len * 25.4f);
} else {
blk.setLength(len * 10.0f);
}
blk.setPermissiveWorking(permissiveField.isSelected());
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
lengthField.setText(twoDigit.format(((Block) bean).getLengthMm()));
if (blk.getCurvature() == Block.NONE) {
curvatureField.setSelectedItem(0);
} else if (blk.getCurvature() == Block.GRADUAL) {
curvatureField.setSelectedItem(gradualText);
} else if (blk.getCurvature() == Block.TIGHT) {
curvatureField.setSelectedItem(tightText);
} else if (blk.getCurvature() == Block.SEVERE) {
curvatureField.setSelectedItem(severeText);
}
String speed = blk.getBlockSpeed();
if (!speedList.contains(speed)) {
speedList.add(speed);
}
speedField.setEditable(true);
speedField.setSelectedItem(speed);
double len = 0.0;
if (inch.isSelected()) {
len = blk.getLengthIn();
} else {
len = blk.getLengthCm();
}
lengthField.setText(twoDigit.format(len));
permissiveField.setSelected(((Block) bean).getPermissiveWorking());
}
});
bei.add(basic);
return basic;
}
use of jmri.Block in project JMRI by JMRI.
the class BlockEditAction method sensor.
BeanItemPanel sensor() {
BeanItemPanel basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("BeanNameSensor"));
sensorComboBox = new JmriBeanComboBox(InstanceManager.sensorManagerInstance(), ((Block) bean).getSensor(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
sensorComboBox.setFirstItemBlank(true);
basic.addItem(new BeanEditItem(sensorComboBox, Bundle.getMessage("BeanNameSensor"), Bundle.getMessage("BlockAssignSensorText")));
final SensorDebounceEditAction debounce = new SensorDebounceEditAction();
//debounce.setBean(bean);
debounce.sensorDebounce(basic);
sensorComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
debounce.setBean(sensorComboBox.getSelectedBean());
debounce.resetDebounceItems(e);
}
});
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
jmri.jmrit.display.layoutEditor.LayoutBlock lBlk = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getLayoutBlock(blk);
//If the block is related to a layoutblock then set the sensor details there and allow that to propergate the changes down.
if (lBlk != null) {
lBlk.validateSensor(sensorComboBox.getSelectedDisplayName(), null);
} else {
blk.setSensor(sensorComboBox.getSelectedDisplayName());
}
debounce.saveDebounceItems(e);
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
//From basic details
sensorComboBox.setSelectedBean(blk.getSensor());
debounce.setBean(blk.getSensor());
debounce.resetDebounceItems(e);
}
});
bei.add(basic);
return basic;
}
use of jmri.Block in project JMRI by JMRI.
the class BlockEditAction method reporterDetails.
BeanItemPanel reporterDetails() {
BeanItemPanel reporter = new BeanItemPanel();
reporter.setName(Bundle.getMessage("BeanNameReporter"));
reporterComboBox = new JmriBeanComboBox(InstanceManager.getDefault(jmri.ReporterManager.class), ((Block) bean).getReporter(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
reporterComboBox.setFirstItemBlank(true);
reporter.addItem(new BeanEditItem(reporterComboBox, Bundle.getMessage("BeanNameReporter"), Bundle.getMessage("BlockReporterText")));
reporterComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (reporterComboBox.getSelectedBean() != null) {
useCurrent.setEnabled(true);
} else {
useCurrent.setEnabled(false);
}
}
});
reporter.addItem(new BeanEditItem(useCurrent, Bundle.getMessage("BlockReporterCurrent"), Bundle.getMessage("BlockUseCurrentText")));
if (reporterComboBox.getSelectedBean() == null) {
useCurrent.setEnabled(false);
}
reporter.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
reporterComboBox.setSelectedBean(((Block) bean).getReporter());
useCurrent.setSelected(((Block) bean).isReportingCurrent());
}
});
reporter.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
blk.setReporter((Reporter) reporterComboBox.getSelectedBean());
blk.setReportingCurrent(useCurrent.isSelected());
}
});
bei.add(reporter);
if (jmri.InstanceManager.getNullableDefault(jmri.ReporterManager.class) == null) {
setEnabled(false);
}
return reporter;
}
use of jmri.Block in project JMRI by JMRI.
the class AutoAllocate method isSignalHeldAtStartOfSection.
private boolean isSignalHeldAtStartOfSection(AllocationRequest ar) {
if (ar == null) {
return false;
}
Section sec = ar.getSection();
ActiveTrain mActiveTrain = ar.getActiveTrain();
if (sec == null || mActiveTrain == null) {
return false;
}
Section lastSec = mActiveTrain.getLastAllocatedSection();
if (lastSec == null) {
return false;
}
if (!sec.equals(mActiveTrain.getNextSectionToAllocate())) {
log.error("Allocation request section does not match active train next section to allocate");
log.error("Section to allocate " + sec.getDisplayName());
if (mActiveTrain.getNextSectionToAllocate() != null) {
log.error("Active Train expected " + mActiveTrain.getNextSectionToAllocate().getDisplayName());
}
return false;
}
Block facingBlock;
Block protectingBlock;
if (ar.getSectionDirection() == jmri.Section.FORWARD) {
protectingBlock = sec.getBlockBySequenceNumber(0);
facingBlock = lastSec.getBlockBySequenceNumber(lastSec.getNumBlocks() - 1);
} else {
//Reverse
protectingBlock = sec.getBlockBySequenceNumber(sec.getNumBlocks() - 1);
facingBlock = lastSec.getBlockBySequenceNumber(0);
}
if (protectingBlock == null || facingBlock == null) {
return false;
}
jmri.SignalMast sm = jmri.InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getFacingSignalMast(facingBlock, protectingBlock);
if (sm != null && sm.getHeld() && !_dispatcher.isMastHeldByDispatcher(sm, mActiveTrain)) {
ar.setWaitingForSignalMast(sm);
return true;
}
return false;
}
Aggregations