use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class EditPortalFrame method checkPortal.
/**
* ***************** end button actions **********
*/
private boolean checkPortal(PortalIcon icon) {
Portal portal = icon.getPortal();
if (portal == null) {
deletePortalIcon(icon);
} else {
boolean home = false;
OBlock block = portal.getToBlock();
if (block == null) {
_parent._editor.highlight(icon);
JOptionPane.showMessageDialog(this, Bundle.getMessage("portalNeedsBlock", portal.getDisplayName()), Bundle.getMessage("makePortal"), JOptionPane.INFORMATION_MESSAGE);
return false;
}
home = _homeBlock.equals(block);
block = portal.getFromBlock();
if (block == null) {
_parent._editor.highlight(icon);
JOptionPane.showMessageDialog(this, Bundle.getMessage("portalNeedsBlock", portal.getDisplayName()), Bundle.getMessage("makePortal"), JOptionPane.INFORMATION_MESSAGE);
return false;
} else if (!home) {
home = _homeBlock.equals(block);
}
if (!home) {
_parent._editor.highlight(icon);
JOptionPane.showMessageDialog(this, Bundle.getMessage("portalNotInCircuit", _homeBlock.getDisplayName()), Bundle.getMessage("makePortal"), JOptionPane.INFORMATION_MESSAGE);
return false;
}
}
return true;
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class OBlockTableModel method setValueAt.
@Override
public void setValueAt(Object value, int row, int col) {
if (log.isDebugEnabled()) {
log.debug("setValueAt: row= {}, col= {}, value= {}", row, col, value);
}
if (super.getRowCount() == row) {
switch(col) {
case SYSNAMECOL:
OBlock block = _manager.createNewOBlock((String) value, tempRow[USERNAMECOL]);
if (block == null) {
block = _manager.getOBlock(tempRow[USERNAMECOL]);
String name = (String) value + " / " + tempRow[USERNAMECOL];
if (block != null) {
name = block.getDisplayName();
} else {
block = _manager.getOBlock((String) value);
if (block != null) {
name = block.getDisplayName();
}
}
JOptionPane.showMessageDialog(null, Bundle.getMessage("CreateDuplBlockErr", name), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
return;
}
if (tempRow[SENSORCOL] != null) {
if (!sensorExists(tempRow[SENSORCOL])) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchSensorErr", tempRow[SENSORCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
}
block.setComment(tempRow[COMMENTCOL]);
float len = 0.0f;
try {
len = IntlUtilities.floatValue(tempRow[LENGTHCOL]);
} catch (ParseException e) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) {
block.setLength(len * 10.0f);
block.setMetricUnits(true);
} else {
block.setLength(len * 25.4f);
block.setMetricUnits(false);
}
if (tempRow[CURVECOL].equals(noneText)) {
block.setCurvature(Block.NONE);
} else if (tempRow[CURVECOL].equals(gradualText)) {
block.setCurvature(Block.GRADUAL);
} else if (tempRow[CURVECOL].equals(tightText)) {
block.setCurvature(Block.TIGHT);
} else if (tempRow[CURVECOL].equals(severeText)) {
block.setCurvature(Block.SEVERE);
}
block.setPermissiveWorking(tempRow[PERMISSIONCOL].equals(Bundle.getMessage("Permissive")));
block.setBlockSpeedName(tempRow[SPEEDCOL]);
if (tempRow[ERR_SENSORCOL] != null) {
if (tempRow[ERR_SENSORCOL].trim().length() > 0) {
if (!sensorExists(tempRow[ERR_SENSORCOL])) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchSensorErr", tempRow[ERR_SENSORCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
}
}
if (tempRow[REPORTERCOL] != null) {
Reporter rep = null;
try {
rep = InstanceManager.getDefault(jmri.ReporterManager.class).getReporter(tempRow[REPORTERCOL]);
if (rep != null) {
block.setReporter(rep);
block.setReportingCurrent(tempRow[REPORT_CURRENTCOL].equals(Bundle.getMessage("Current")));
}
} catch (Exception ex) {
log.error("No Reporter named \"" + tempRow[REPORTERCOL] + "\" found. threw exception: " + ex);
}
if (rep == null) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchReporterErr", tempRow[REPORTERCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
block.setReporter(rep);
}
initTempRow();
fireTableDataChanged();
return;
case // clear
DELETE_COL:
initTempRow();
fireTableRowsUpdated(row, row);
return;
case 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;
case UNITSCOL:
if ((((Boolean) value).booleanValue())) {
tempRow[UNITSCOL] = Bundle.getMessage("cm");
} else {
tempRow[UNITSCOL] = Bundle.getMessage("in");
}
fireTableRowsUpdated(row, row);
return;
case REPORT_CURRENTCOL:
if (((Boolean) value).booleanValue()) {
//toggle
tempRow[REPORT_CURRENTCOL] = Bundle.getMessage("Current");
} else {
tempRow[REPORT_CURRENTCOL] = Bundle.getMessage("Last");
}
return;
case PERMISSIONCOL:
if (((Boolean) value).booleanValue()) {
//toggle
tempRow[PERMISSIONCOL] = Bundle.getMessage("Permissive");
} else {
tempRow[PERMISSIONCOL] = Bundle.getMessage("Absolute");
}
return;
default:
// fall though
break;
}
tempRow[col] = (String) value;
return;
}
String name = sysNameList.get(row);
OBlock block = _manager.getBySystemName(name);
switch(col) {
case USERNAMECOL:
OBlock b = _manager.getOBlock((String) value);
if (b != null) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("CreateDuplBlockErr", block.getDisplayName()), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
return;
}
block.setUserName((String) value);
fireTableRowsUpdated(row, row);
return;
case COMMENTCOL:
block.setComment((String) value);
fireTableRowsUpdated(row, row);
return;
case STATECOL:
// STATECOL is not editable
return;
case SENSORCOL:
if (!block.setSensor((String) value)) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchSensorErr", (String) value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
fireTableRowsUpdated(row, row);
return;
case LENGTHCOL:
try {
float len = IntlUtilities.floatValue(value.toString());
if (block.isMetric()) {
block.setLength(len * 10.0f);
} else {
block.setLength(len * 25.4f);
}
fireTableRowsUpdated(row, row);
} catch (ParseException e) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("BadNumber", value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
return;
case UNITSCOL:
block.setMetricUnits(((Boolean) value).booleanValue());
fireTableRowsUpdated(row, row);
return;
case CURVECOL:
String cName = (String) value;
if (cName.equals(noneText)) {
block.setCurvature(Block.NONE);
} else if (cName.equals(gradualText)) {
block.setCurvature(Block.GRADUAL);
} else if (cName.equals(tightText)) {
block.setCurvature(Block.TIGHT);
} else if (cName.equals(severeText)) {
block.setCurvature(Block.SEVERE);
}
fireTableRowsUpdated(row, row);
return;
case ERR_SENSORCOL:
boolean ok = false;
try {
if (((String) value).trim().length() == 0) {
block.setErrorSensor(null);
ok = true;
} else {
ok = block.setErrorSensor((String) value);
fireTableRowsUpdated(row, row);
}
} catch (Exception ex) {
log.error("getSensor(" + (String) value + ") threw exception: " + ex);
}
if (!ok) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchSensorErr", (String) value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
fireTableRowsUpdated(row, row);
return;
case REPORTERCOL:
Reporter rep = null;
try {
rep = InstanceManager.getDefault(jmri.ReporterManager.class).getReporter((String) value);
if (rep != null) {
block.setReporter(rep);
fireTableRowsUpdated(row, row);
}
} catch (Exception ex) {
log.error("No Reporter named \"" + (String) value + "\" found. threw exception: " + ex);
}
if (rep == null) {
JOptionPane.showMessageDialog(null, Bundle.getMessage("NoSuchReporterErr", tempRow[REPORTERCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE);
}
block.setReporter(rep);
fireTableRowsUpdated(row, row);
return;
case REPORT_CURRENTCOL:
if (block.getReporter() != null) {
block.setReportingCurrent(((Boolean) value).booleanValue());
fireTableRowsUpdated(row, row);
}
return;
case PERMISSIONCOL:
block.setPermissiveWorking(((Boolean) value).booleanValue());
fireTableRowsUpdated(row, row);
return;
case SPEEDCOL:
block.setBlockSpeedName((String) value);
fireTableRowsUpdated(row, row);
return;
case EDIT_COL:
_parent.openBlockPathFrame(block.getSystemName());
return;
case DELETE_COL:
deleteBean(block);
block = null;
return;
default:
// fall through
break;
}
super.setValueAt(value, row, col);
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class SignalTableModel method checkSignalRow.
private String checkSignalRow(SignalRow sr) {
Portal portal = sr.getPortal();
OBlock fromBlock = sr.getFromBlock();
OBlock toBlock = sr.getToBlock();
String msg = null;
if (portal != null) {
if (toBlock == null && sr.getFromBlock() == null) {
msg = Bundle.getMessage("SignalDirection", portal.getName(), portal.getFromBlock().getDisplayName(), portal.getToBlock().getDisplayName());
return msg;
}
OBlock pToBlk = portal.getToBlock();
OBlock pFromBlk = portal.getFromBlock();
if (pToBlk.equals(toBlock)) {
if (fromBlock == null) {
sr.setFromBlock(pFromBlk);
/* } else if (!fromBlock.equals(pFromBlk)) {
msg = Bundle.getMessage("PortalBlockConflict", portal.getName(),
fromBlock.getDisplayName()); */
}
} else if (pFromBlk.equals(toBlock)) {
if (fromBlock == null) {
sr.setFromBlock(pToBlk);
/* } else if (!toBlock.equals(pToBlk)) {
msg = Bundle.getMessage("PortalBlockConflict", portal.getName(),
toBlock.getDisplayName()); */
}
} else if (pToBlk.equals(fromBlock)) {
if (toBlock == null) {
sr.setToBlock(pFromBlk);
}
} else if (pFromBlk.equals(fromBlock)) {
if (toBlock == null) {
sr.setToBlock(pToBlk);
}
} else {
msg = Bundle.getMessage("PortalBlockConflict", portal.getName(), (toBlock != null ? toBlock.getDisplayName() : "(null to-block reference)"));
}
} else if (fromBlock != null && toBlock != null) {
Portal p = getPortalwithBlocks(fromBlock, toBlock);
if (p == null) {
msg = Bundle.getMessage("NoSuchPortal", fromBlock.getDisplayName(), toBlock.getDisplayName());
} else {
sr.setPortal(p);
}
}
if (msg == null && fromBlock != null && fromBlock.equals(toBlock)) {
msg = Bundle.getMessage("SametoFromBlock", fromBlock.getDisplayName());
}
return msg;
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class SignalTableModel method checkDuplicateProtection.
private String checkDuplicateProtection(SignalRow row) {
Portal portal = row.getPortal();
OBlock block = row.getToBlock();
if (block == null || portal == null) {
return null;
}
for (int i = 0; i < _signalList.size(); i++) {
SignalRow srow = _signalList.get(i);
if (srow.equals(row)) {
continue;
}
if (block.equals(srow.getToBlock()) && portal.equals(srow.getPortal())) {
return Bundle.getMessage("DuplProtection", block.getDisplayName(), portal.getName(), srow.getFromBlock().getDisplayName(), srow.getSignal().getDisplayName());
}
}
return null;
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class SignalTableModel method getPortalwithBlocks.
private Portal getPortalwithBlocks(OBlock fromBlock, OBlock toBlock) {
String[] sysNames = _portalMgr.getSystemNameArray();
for (int i = 0; i < sysNames.length; i++) {
Portal portal = _portalMgr.getBySystemName(sysNames[i]);
OBlock fromBlk = portal.getFromBlock();
OBlock toBlk = portal.getToBlock();
if ((fromBlk.equals(fromBlock) && toBlk.equals(toBlock)) || (fromBlk.equals(toBlock) && toBlk.equals(fromBlock))) {
return portal;
}
}
return null;
}
Aggregations