use of jmri.jmrit.logix.OBlockManager in project JMRI by JMRI.
the class PortalTableModel method deletePortal.
private static boolean deletePortal(Portal portal) {
if (JOptionPane.showConfirmDialog(null, Bundle.getMessage("DeletePortalConfirm", portal.getName()), Bundle.getMessage("WarningTitle"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
OBlockManager OBlockMgr = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
String[] sysNames = OBlockMgr.getSystemNameArray();
for (int i = 0; i < sysNames.length; i++) {
OBlockMgr.getBySystemName(sysNames[i]).removePortal(portal);
}
portal.dispose();
return true;
}
return false;
}
use of jmri.jmrit.logix.OBlockManager 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.OBlockManager 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.OBlockManager 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);
}
use of jmri.jmrit.logix.OBlockManager in project JMRI by JMRI.
the class EditPortalFrame method findAdjacentBlock.
/*
* If icon is on the home block, find another intersecting block
*/
private OBlock findAdjacentBlock(PortalIcon icon) {
ArrayList<OBlock> neighbors = new ArrayList<OBlock>();
OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
String[] sysNames = manager.getSystemNameArray();
for (int j = 0; j < sysNames.length; j++) {
OBlock block = manager.getBySystemName(sysNames[j]);
if (block.equals(_homeBlock)) {
continue;
}
if (iconIntersectsBlock(icon, block) == null) {
neighbors.add(block);
}
}
OBlock block = null;
if (neighbors.size() == 1) {
block = neighbors.get(0);
} else if (neighbors.size() > 1) {
// show list
String[] selects = new String[neighbors.size()];
Iterator<OBlock> iter = neighbors.iterator();
int i = 0;
while (iter.hasNext()) {
selects[i++] = iter.next().getDisplayName();
}
Object select = JOptionPane.showInputDialog(this, Bundle.getMessage("multipleBlockSelections", _homeBlock.getDisplayName()), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE, null, selects, null);
if (select != null) {
iter = neighbors.iterator();
while (iter.hasNext()) {
block = iter.next();
if (((String) select).equals(block.getDisplayName())) {
return block;
}
}
}
}
if (log.isDebugEnabled()) {
log.debug("findAdjacentBlock: neighbors.size()= " + neighbors.size() + " return " + (block == null ? "null" : block.getDisplayName()));
}
return block;
}
Aggregations