use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class BlockPortalTableModel method getValueAt.
@Override
public Object getValueAt(int row, int col) {
List<NamedBean> list = _oBlockModel.getBeanList();
if (list.size() > 0) {
int count = 0;
//accumulated row count
int idx = 0;
OBlock block = null;
NamedBean[] array = new NamedBean[list.size()];
array = list.toArray(array);
Arrays.sort(array, new jmri.util.NamedBeanComparator());
while (count <= row) {
count += ((OBlock) array[idx++]).getPortals().size();
}
block = (OBlock) array[--idx];
idx = row - (count - block.getPortals().size());
if (col == BLOCK_NAME_COLUMN) {
if (idx == 0) {
return block.getDisplayName();
}
return "";
}
return block.getPortals().get(idx).getName();
/*
while (count <= row) {
count += ((OBlock)list.get(idx++)).getPortals().size();
}
block = (OBlock)list.get(--idx);
idx = row - (count - block.getPortals().size());
if (col==BLOCK_NAME_COLUMN) {
if (idx==0) {
return block.getDisplayName();
}
return "";
}
return block.getPortals().get(idx).getName();
*/
}
return null;
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class SignalTableModel method setValueAt.
@Override
public void setValueAt(Object value, int row, int col) {
String msg = null;
if (_signalList.size() == row) {
if (col == DELETE_COL) {
initTempRow();
fireTableRowsUpdated(row, row);
return;
} else if (col == UNITSCOL) {
if (((Boolean) value).booleanValue()) {
tempRow[UNITSCOL] = Bundle.getMessage("cm");
} else {
tempRow[UNITSCOL] = Bundle.getMessage("in");
}
fireTableRowsUpdated(row, row);
return;
} else if (col == 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;
}
String str = (String) value;
if (str == null || str.trim().length() == 0) {
tempRow[col] = null;
return;
}
tempRow[col] = str.trim();
OBlock fromBlock = null;
OBlock toBlock = null;
Portal portal = null;
NamedBean signal = null;
OBlockManager OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
if (tempRow[FROM_BLOCK_COLUMN] != null) {
fromBlock = OBlockMgr.getOBlock(tempRow[FROM_BLOCK_COLUMN]);
if (fromBlock == null) {
msg = Bundle.getMessage("NoSuchBlock", tempRow[FROM_BLOCK_COLUMN]);
}
}
if (msg == null && tempRow[TO_BLOCK_COLUMN] != null) {
toBlock = OBlockMgr.getOBlock(tempRow[TO_BLOCK_COLUMN]);
if (toBlock == null) {
msg = Bundle.getMessage("NoSuchBlock", tempRow[TO_BLOCK_COLUMN]);
}
}
if (msg == null) {
if (tempRow[PORTAL_COLUMN] != null) {
portal = _portalMgr.getPortal(tempRow[PORTAL_COLUMN]);
if (portal == null) {
msg = Bundle.getMessage("NoSuchPortalName", tempRow[PORTAL_COLUMN]);
}
} else {
if (fromBlock != null && toBlock != null) {
portal = getPortalwithBlocks(fromBlock, toBlock);
if (portal == null) {
msg = Bundle.getMessage("NoSuchPortal", tempRow[FROM_BLOCK_COLUMN], tempRow[TO_BLOCK_COLUMN]);
} else {
tempRow[PORTAL_COLUMN] = portal.getName();
}
}
}
}
if (msg == null && tempRow[NAME_COLUMN] != null) {
signal = Portal.getSignal(tempRow[NAME_COLUMN]);
if (signal == null) {
msg = Bundle.getMessage("NoSuchSignal", tempRow[NAME_COLUMN]);
} else {
msg = checkDuplicateSignal(signal);
}
if (msg == null) {
if (fromBlock != null && toBlock != null) {
portal = getPortalwithBlocks(fromBlock, toBlock);
if (portal == null) {
msg = Bundle.getMessage("NoSuchPortal", tempRow[FROM_BLOCK_COLUMN], tempRow[TO_BLOCK_COLUMN]);
} else {
tempRow[PORTAL_COLUMN] = portal.getName();
}
} else {
return;
}
}
if (msg == null) {
float length = 0.0f;
boolean isMetric = tempRow[UNITSCOL].equals(Bundle.getMessage("cm"));
try {
length = IntlUtilities.floatValue(tempRow[LENGTHCOL]);
if (isMetric) {
length *= 10f;
} else {
length *= 25.4f;
}
} catch (ParseException e) {
msg = Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]);
}
if (isMetric) {
tempRow[UNITSCOL] = Bundle.getMessage("cm");
} else {
tempRow[UNITSCOL] = Bundle.getMessage("in");
}
if (msg == null) {
SignalRow signalRow = new SignalRow(signal, fromBlock, portal, toBlock, length, isMetric);
msg = setSignal(signalRow, false);
if (msg == null) {
_signalList.add(signalRow);
}
initTempRow();
fireTableDataChanged();
}
}
}
} else {
// Editing existing signal configurations
SignalRow signalRow = _signalList.get(row);
OBlockManager OBlockMgr = InstanceManager.getDefault(OBlockManager.class);
switch(col) {
case NAME_COLUMN:
NamedBean signal = Portal.getSignal((String) value);
if (signal == null) {
msg = Bundle.getMessage("NoSuchSignal", (String) value);
// signalRow.setSignal(null);
break;
}
Portal portal = signalRow.getPortal();
if (portal != null && signalRow.getToBlock() != null) {
NamedBean oldSignal = signalRow.getSignal();
signalRow.setSignal(signal);
msg = checkDuplicateSignal(signalRow);
if (msg == null) {
// delete old
deleteSignal(signalRow);
msg = setSignal(signalRow, false);
fireTableRowsUpdated(row, row);
} else {
signalRow.setSignal(oldSignal);
}
}
break;
case FROM_BLOCK_COLUMN:
OBlock block = OBlockMgr.getOBlock((String) value);
if (block == null) {
msg = Bundle.getMessage("NoSuchBlock", (String) value);
break;
}
if (block.equals(signalRow.getFromBlock())) {
// no change
break;
}
// delete old
deleteSignal(signalRow);
signalRow.setFromBlock(block);
portal = signalRow.getPortal();
if (checkPortalBlock(portal, block)) {
signalRow.setToBlock(null);
} else {
// get new portal
portal = getPortalwithBlocks(block, signalRow.getToBlock());
signalRow.setPortal(portal);
}
msg = checkSignalRow(signalRow);
if (msg == null) {
msg = checkDuplicateProtection(signalRow);
} else {
signalRow.setPortal(null);
break;
}
if (msg == null && signalRow.getPortal() != null) {
msg = setSignal(signalRow, true);
} else {
signalRow.setPortal(null);
}
fireTableRowsUpdated(row, row);
break;
case PORTAL_COLUMN:
portal = _portalMgr.getPortal((String) value);
if (portal == null) {
msg = Bundle.getMessage("NoSuchPortalName", (String) value);
break;
}
// delete old
deleteSignal(signalRow);
signalRow.setPortal(portal);
block = signalRow.getToBlock();
if (checkPortalBlock(portal, block)) {
signalRow.setFromBlock(null);
} else {
block = signalRow.getFromBlock();
if (checkPortalBlock(portal, block)) {
signalRow.setToBlock(null);
}
}
msg = checkSignalRow(signalRow);
if (msg == null) {
msg = checkDuplicateProtection(signalRow);
} else {
signalRow.setToBlock(null);
break;
}
if (msg == null) {
signalRow.setPortal(portal);
msg = setSignal(signalRow, false);
fireTableRowsUpdated(row, row);
}
break;
case TO_BLOCK_COLUMN:
block = OBlockMgr.getOBlock((String) value);
if (block == null) {
msg = Bundle.getMessage("NoSuchBlock", (String) value);
break;
}
if (block.equals(signalRow.getToBlock())) {
// no change
break;
}
// delete old
deleteSignal(signalRow);
signalRow.setToBlock(block);
portal = signalRow.getPortal();
if (checkPortalBlock(portal, block)) {
signalRow.setFromBlock(null);
} else {
// get new portal
portal = getPortalwithBlocks(signalRow.getFromBlock(), block);
signalRow.setPortal(portal);
}
msg = checkSignalRow(signalRow);
if (msg == null) {
msg = checkDuplicateProtection(signalRow);
} else {
signalRow.setPortal(null);
break;
}
if (msg == null && signalRow.getPortal() != null) {
msg = setSignal(signalRow, true);
} else {
signalRow.setPortal(null);
}
fireTableRowsUpdated(row, row);
break;
case LENGTHCOL:
try {
float len = IntlUtilities.floatValue(value.toString());
if (signalRow.isMetric()) {
signalRow.setLength(len * 10.0f);
} else {
signalRow.setLength(len * 25.4f);
}
fireTableRowsUpdated(row, row);
} catch (ParseException e) {
msg = Bundle.getMessage("BadNumber", value);
}
if (msg == null && signalRow.getPortal() != null) {
msg = setSignal(signalRow, false);
} else {
signalRow.setPortal(null);
}
fireTableRowsUpdated(row, row);
break;
case UNITSCOL:
signalRow.setMetric((Boolean) value);
fireTableRowsUpdated(row, row);
break;
case DELETE_COL:
deleteSignal(signalRow);
_signalList.remove(signalRow);
fireTableDataChanged();
break;
default:
// fall through
break;
}
}
if (msg != null) {
JOptionPane.showMessageDialog(null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
}
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class PortalTableModel method setValueAt.
@Override
public void setValueAt(Object value, int row, int col) {
String msg = null;
if (super.getRowCount() == row) {
if (col == DELETE_COL) {
initTempRow();
fireTableRowsUpdated(row, row);
return;
} else {
String str = (String) value;
if (str == null || str.trim().length() == 0) {
tempRow[col] = null;
return;
} else {
tempRow[col] = str.trim();
}
}
OBlockManager OBlockMgr = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
OBlock fromBlock = null;
OBlock toBlock = null;
if (tempRow[FROM_BLOCK_COLUMN] != null) {
fromBlock = OBlockMgr.getOBlock(tempRow[FROM_BLOCK_COLUMN]);
if (fromBlock == null) {
msg = Bundle.getMessage("NoSuchBlock", tempRow[FROM_BLOCK_COLUMN]);
}
}
if (msg == null && tempRow[TO_BLOCK_COLUMN] != null) {
toBlock = OBlockMgr.getOBlock(tempRow[TO_BLOCK_COLUMN]);
if (toBlock == null) {
msg = Bundle.getMessage("NoSuchBlock", tempRow[TO_BLOCK_COLUMN]);
}
}
if (msg == null && tempRow[NAME_COLUMN] != null) {
if (fromBlock == null || toBlock == null) {
msg = Bundle.getMessage("PortalNeedsBlock", tempRow[NAME_COLUMN]);
} else if (fromBlock.equals(toBlock)) {
msg = Bundle.getMessage("SametoFromBlock", fromBlock.getDisplayName());
}
if (msg == null) {
Portal portal = _manager.createNewPortal(null, tempRow[NAME_COLUMN]);
if (portal != null) {
portal.setToBlock(toBlock, false);
portal.setFromBlock(fromBlock, false);
initTempRow();
fireTableDataChanged();
} else {
msg = Bundle.getMessage("DuplPortalName", (String) value);
}
}
}
if (msg != null) {
JOptionPane.showMessageDialog(null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
}
return;
}
String name = sysNameList.get(row);
Portal portal = _manager.getBySystemName(name);
if (portal == null) {
log.error("Portal null, getValueAt row= " + row + ", col= " + col + ", " + "portalListSize= " + _manager.getSystemNameArray().length);
return;
}
switch(col) {
case FROM_BLOCK_COLUMN:
OBlock block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock((String) value);
if (block == null) {
msg = Bundle.getMessage("NoSuchBlock", (String) value);
break;
}
if (block.equals(portal.getToBlock())) {
msg = Bundle.getMessage("SametoFromBlock", block.getDisplayName());
break;
}
if (!portal.setFromBlock(block, false)) {
int response = JOptionPane.showConfirmDialog(null, Bundle.getMessage("BlockPathsConflict", value, portal.getFromBlockName()), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.NO_OPTION) {
break;
}
}
portal.setFromBlock(block, true);
fireTableRowsUpdated(row, row);
break;
case NAME_COLUMN:
if (_manager.getPortal((String) value) != null) {
msg = Bundle.getMessage("DuplPortalName", (String) value);
break;
}
if (_manager.getPortal((String) value) != null) {
msg = Bundle.getMessage("PortalNameConflict", (String) value);
} else {
portal.setName((String) value);
fireTableRowsUpdated(row, row);
}
break;
case TO_BLOCK_COLUMN:
block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock((String) value);
if (block == null) {
msg = Bundle.getMessage("NoSuchBlock", (String) value);
break;
}
if (block.equals(portal.getFromBlock())) {
msg = Bundle.getMessage("SametoFromBlock", block.getDisplayName());
break;
}
if (!portal.setToBlock(block, false)) {
int response = JOptionPane.showConfirmDialog(null, Bundle.getMessage("BlockPathsConflict", value, portal.getToBlockName()), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (response == JOptionPane.NO_OPTION) {
break;
}
}
portal.setToBlock(block, true);
fireTableRowsUpdated(row, row);
break;
case DELETE_COL:
if (deletePortal(portal)) {
fireTableDataChanged();
}
break;
default:
log.warn("Unhandled column: {}", col);
break;
}
if (msg != null) {
JOptionPane.showMessageDialog(null, msg, Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
}
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class OBlockTableModel method getValueAt.
@Override
public Object getValueAt(int row, int col) {
if (row > sysNameList.size()) {
return "";
}
OBlock b = null;
if (row < sysNameList.size()) {
String name = sysNameList.get(row);
b = _manager.getBySystemName(name);
}
switch(col) {
case SYSNAMECOL:
if (b != null) {
return b.getSystemName();
}
return tempRow[col];
case USERNAMECOL:
if (b != null) {
return b.getUserName();
}
return tempRow[col];
case COMMENTCOL:
if (b != null) {
return b.getComment();
}
return tempRow[col];
case STATECOL:
if (b != null) {
int state = b.getState();
int num = Integer.numberOfLeadingZeros(state) - 23;
if (num >= 0) {
return ZEROS.substring(0, num) + Integer.toBinaryString(state);
}
}
return ZEROS;
case SENSORCOL:
if (b != null) {
Sensor s = b.getSensor();
if (s == null) {
return "";
}
return s.getDisplayName();
}
return tempRow[col];
case LENGTHCOL:
if (b != null) {
if (b.isMetric()) {
return (twoDigit.format(b.getLengthCm()));
}
return (twoDigit.format(b.getLengthIn()));
}
if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) {
return (twoDigit.format(_tempLen / 10));
}
return (twoDigit.format(_tempLen / 25.4f));
case UNITSCOL:
if (b != null) {
if (log.isDebugEnabled()) {
log.debug("getValueAt: row= {}, col= {}, \"{}\" isMetric= {}", row, col, b.getDisplayName(), b.isMetric());
}
return b.isMetric();
}
if (log.isDebugEnabled()) {
log.debug("getValueAt: row= {}, col= {}, isMetric= {}", row, col, tempRow[UNITSCOL].equals(Bundle.getMessage("cm")));
}
return Boolean.valueOf(tempRow[UNITSCOL].equals(Bundle.getMessage("cm")));
case CURVECOL:
if (b != null) {
String c = "";
if (b.getCurvature() == Block.NONE) {
c = noneText;
} else if (b.getCurvature() == Block.GRADUAL) {
c = gradualText;
} else if (b.getCurvature() == Block.TIGHT) {
c = tightText;
} else if (b.getCurvature() == Block.SEVERE) {
c = severeText;
}
return c;
}
return tempRow[col];
case ERR_SENSORCOL:
if (b != null) {
Sensor s = b.getErrorSensor();
if (s == null) {
return "";
}
return s.getDisplayName();
}
return tempRow[col];
case REPORTERCOL:
if (b != null) {
Reporter r = b.getReporter();
if (r == null) {
return "";
}
return r.getDisplayName();
}
return tempRow[col];
case REPORT_CURRENTCOL:
if (b != null) {
if (b.getReporter() != null) {
return b.isReportingCurrent();
}
return "";
}
return Boolean.valueOf(tempRow[REPORT_CURRENTCOL].equals(Bundle.getMessage("Current")));
case PERMISSIONCOL:
if (b != null) {
return b.getPermissiveWorking();
}
return Boolean.valueOf(tempRow[PERMISSIONCOL].equals(Bundle.getMessage("Permissive")));
case SPEEDCOL:
if (b != null) {
return b.getBlockSpeed();
}
return tempRow[col];
case EDIT_COL:
if (b != null) {
return Bundle.getMessage("ButtonEditPath");
}
return "";
case DELETE_COL:
if (b != null) {
return Bundle.getMessage("ButtonDelete");
}
return Bundle.getMessage("ButtonClear");
default:
// fall through
break;
}
return super.getValueAt(row, col);
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class LocoLabelXml method load.
/**
* Create a PositionableShape, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor ed = (Editor) o;
LocoLabel ll = new LocoLabel(ed);
Element elem = element.getChild("size");
ll.setWidth(getInt(elem, "width"));
ll.setHeight(getInt(elem, "height"));
if (elem != null && elem.getAttribute("systemName") != null) {
String name = elem.getAttribute("systemName").getValue();
OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
OBlock block = manager.getBySystemName(name);
ll.setBlock(block);
if (elem.getAttribute("trainName") != null && block != null) {
block.setValue(elem.getAttribute("trainName").getValue());
}
} else {
// don't put into editor's content list without
return;
}
ed.putItem(ll);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(ll, Editor.MARKERS, element);
}
Aggregations