use of jmri.NamedBean in project JMRI by JMRI.
the class SignalTableModel method makeList.
private void makeList() {
ArrayList<SignalRow> tempList = new ArrayList<SignalRow>();
// collect signals entered into Portals
String[] sysNames = _portalMgr.getSystemNameArray();
for (int i = 0; i < sysNames.length; i++) {
Portal portal = _portalMgr.getBySystemName(sysNames[i]);
NamedBean signal = portal.getFromSignal();
SignalRow sr = null;
if (signal != null) {
sr = new SignalRow(signal, portal.getFromBlock(), portal, portal.getToBlock(), portal.getFromSignalOffset(), portal.getToBlock().isMetric());
addToList(tempList, sr);
}
signal = portal.getToSignal();
if (signal != null) {
sr = new SignalRow(signal, portal.getToBlock(), portal, portal.getFromBlock(), portal.getToSignalOffset(), portal.getFromBlock().isMetric());
addToList(tempList, sr);
}
}
_signalList = tempList;
if (log.isDebugEnabled()) {
log.debug("makeList exit: _signalList has " + _signalList.size() + " rows.");
}
}
use of jmri.NamedBean 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.NamedBean 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.NamedBean in project JMRI by JMRI.
the class IconAdder method getTableSelection.
/**
* Used by Panel Editor to make the final installation of the icon(s) into
* the user's Panel.
* <P>
* Note! the selection is cleared. When two successive calls are made, the
* 2nd will always return null, regardless of the 1st return.
*
* @return the selected item
*/
public NamedBean getTableSelection() {
if (ImageIndexEditor.isIndexChanged()) {
checkIconSizes();
}
int row = _table.getSelectedRow();
row = _table.convertRowIndexToModel(row);
if (row >= 0) {
NamedBean b = _pickListModel.getBeanAt(row);
_table.clearSelection();
_addButton.setEnabled(false);
_addButton.setToolTipText(null);
this.revalidate();
if (log.isDebugEnabled()) {
log.debug("getTableSelection: row= " + row + ", bean= " + b.getDisplayName());
}
return b;
} else if (log.isDebugEnabled()) {
log.debug("getTableSelection: row=0");
}
return null;
}
use of jmri.NamedBean in project JMRI by JMRI.
the class IconAdder method addToTable.
void addToTable() {
String name = _sysNametext.getText();
if (name != null && name.length() > 0) {
NamedBean bean = _pickListModel.addBean(name);
int setRow = _pickListModel.getIndexOf(bean);
_table.setRowSelectionInterval(setRow, setRow);
_pickTablePane.getVerticalScrollBar().setValue(setRow * ROW_HEIGHT);
}
_sysNametext.setText("");
_addTableButton.setEnabled(false);
_addTableButton.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
}
Aggregations