use of jmri.NamedBean in project JMRI by JMRI.
the class OBlockTableModel method getBeanList.
protected List<NamedBean> getBeanList() {
TreeSet<NamedBean> ts = new TreeSet<NamedBean>(new NamedBeanComparator());
Iterator<String> iter = sysNameList.iterator();
while (iter.hasNext()) {
ts.add(getBySystemName(iter.next()));
}
ArrayList<NamedBean> list = new ArrayList<NamedBean>(sysNameList.size());
Iterator<NamedBean> it = ts.iterator();
while (it.hasNext()) {
NamedBean elt = it.next();
list.add(elt);
}
return list;
}
use of jmri.NamedBean in project JMRI by JMRI.
the class BlockBossLogic method vetoableChange.
@Override
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {
NamedBean nb = (NamedBean) evt.getOldValue();
if ("CanDelete".equals(evt.getPropertyName())) {
//IN18N
StringBuilder message = new StringBuilder();
//IN18N
message.append(Bundle.getMessage("InUseBlockBossHeader", getDrivenSignal()));
boolean found = false;
if (nb instanceof SignalHead) {
if (getDrivenSignalNamedBean() != null && getDrivenSignalNamedBean().getBean().equals(nb)) {
message.append("<br><b>This SSL will be deleted</b>");
throw new java.beans.PropertyVetoException(message.toString(), evt);
}
if ((watchedSignal1 != null && watchedSignal1.getBean().equals(nb)) || (watchedSignal1Alt != null && watchedSignal1Alt.getBean().equals(nb)) || (watchedSignal2 != null && watchedSignal2.getBean().equals(nb)) || (watchedSignal2Alt != null && watchedSignal2Alt.getBean().equals(nb))) {
message.append("<ul>");
message.append(Bundle.getMessage("InUseWatchedSignal"));
message.append("</ul>");
found = true;
}
} else if (nb instanceof Turnout) {
if (watchTurnout != null && watchTurnout.getBean().equals(nb)) {
found = true;
message.append("<ul>");
message.append(Bundle.getMessage("InUseWatchedTurnout"));
message.append("</ul>");
}
} else if (nb instanceof Sensor) {
message.append("<ul>");
if ((watchSensor1 != null && watchSensor1.getBean().equals(nb)) || (watchSensor2 != null && watchSensor2.getBean().equals(nb)) || (watchSensor3 != null && watchSensor3.getBean().equals(nb)) || (watchSensor4 != null && watchSensor4.getBean().equals(nb)) || (watchSensor5 != null && watchSensor5.getBean().equals(nb))) {
message.append("<li>");
message.append(Bundle.getMessage("InUseWatchedSensor"));
message.append("</li>");
found = true;
}
if ((watchedSensor1 != null && watchedSensor1.getBean().equals(nb)) || (watchedSensor2 != null && watchedSensor2.getBean().equals(nb)) || (watchedSensor1Alt != null && watchedSensor1Alt.getBean().equals(nb)) || (watchedSensor2Alt != null && watchedSensor2Alt.getBean().equals(nb))) {
message.append("<li>");
message.append(Bundle.getMessage("InUseWatchedSensor"));
message.append("</li>");
found = true;
}
if (approachSensor1 != null && approachSensor1.getBean().equals(nb)) {
found = true;
message.append("<li>");
message.append(Bundle.getMessage("InUseApproachSensor"));
message.append("</li>");
}
message.append("</ul>");
}
if (found) {
//IN18N
message.append(Bundle.getMessage("InUseBlockBossFooter"));
throw new java.beans.PropertyVetoException(message.toString(), evt);
}
} else if ("DoDelete".equals(evt.getPropertyName())) {
//IN18N
if (nb instanceof SignalHead) {
if (getDrivenSignalNamedBean() != null && getDrivenSignalNamedBean().getBean().equals(nb)) {
stop();
bblList.remove(this);
}
if (watchedSignal1 != null && watchedSignal1.getBean().equals(nb)) {
stop();
setWatchedSignal1(null, false);
start();
}
if (watchedSignal1Alt != null && watchedSignal1Alt.getBean().equals(nb)) {
stop();
setWatchedSignal1Alt(null);
start();
}
if (watchedSignal2 != null && watchedSignal2.getBean().equals(nb)) {
stop();
setWatchedSignal2(null);
start();
}
if (watchedSignal2Alt != null && watchedSignal2Alt.getBean().equals(nb)) {
stop();
setWatchedSignal2Alt(null);
start();
}
} else if (nb instanceof Turnout) {
if (watchTurnout != null && watchTurnout.getBean().equals(nb)) {
stop();
setTurnout(null);
start();
}
} else if (nb instanceof Sensor) {
if (watchSensor1 != null && watchSensor1.getBean().equals(nb)) {
stop();
setSensor1(null);
start();
}
if (watchSensor2 != null && watchSensor2.getBean().equals(nb)) {
stop();
setSensor2(null);
start();
}
if (watchSensor3 != null && watchSensor3.getBean().equals(nb)) {
stop();
setSensor3(null);
start();
}
if (watchSensor4 != null && watchSensor4.getBean().equals(nb)) {
stop();
setSensor4(null);
start();
}
if (watchSensor5 != null && watchSensor5.getBean().equals(nb)) {
stop();
setSensor5(null);
start();
}
if (watchedSensor1 != null && watchedSensor1.getBean().equals(nb)) {
stop();
setWatchedSensor1(null);
start();
}
if (watchedSensor2 != null && watchedSensor2.getBean().equals(nb)) {
stop();
setWatchedSensor2(null);
start();
}
if (watchedSensor1Alt != null && watchedSensor1Alt.getBean().equals(nb)) {
stop();
setWatchedSensor1Alt(null);
start();
}
if (watchedSensor2Alt != null && watchedSensor2Alt.getBean().equals(nb)) {
stop();
setWatchedSensor2Alt(null);
start();
}
if (approachSensor1 != null && approachSensor1.getBean().equals(nb)) {
stop();
setApproachSensor1(null);
start();
}
}
}
}
use of jmri.NamedBean in project JMRI by JMRI.
the class PickListModel method propertyChange.
/**
* Handle additions and deletions in the table and changes to beans within
* the table.
*
* @param e the change
*/
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
if (e.getPropertyName().equals("length")) {
// a NamedBean added or deleted
makePickList();
fireTableDataChanged();
}
if (e.getSource() instanceof NamedBean) {
NamedBean bean = (NamedBean) e.getSource();
for (int i = 0; i < _pickList.size(); i++) {
if (bean.equals(_pickList.get(i))) {
fireTableRowsUpdated(i, i);
break;
}
}
}
if (log.isDebugEnabled()) {
log.debug("propertyChange of \"" + e.getPropertyName() + "\" for " + e.getSource().toString());
}
}
use of jmri.NamedBean in project JMRI by JMRI.
the class PickListModel method makePickList.
private void makePickList() {
// Don't know who is added or deleted so remove all name change listeners
if (_pickList != null) {
for (int i = 0; i < _pickList.size(); i++) {
_pickList.get(i).removePropertyChangeListener(this);
}
}
List<String> systemNameList = getManager().getSystemNameList();
TreeSet<NamedBean> ts = new TreeSet<>(new NamedBeanComparator());
Iterator<String> iter = systemNameList.iterator();
while (iter.hasNext()) {
ts.add(getBySystemName(iter.next()));
}
_pickList = new ArrayList<>(systemNameList.size());
Iterator<NamedBean> it = ts.iterator();
while (it.hasNext()) {
NamedBean elt = it.next();
_pickList.add(elt);
}
// add name change listeners
for (int i = 0; i < _pickList.size(); i++) {
_pickList.get(i).addPropertyChangeListener(this);
}
if (log.isDebugEnabled()) {
log.debug("_pickList has " + _pickList.size() + " beans");
}
}
use of jmri.NamedBean in project JMRI by JMRI.
the class EntryExitPairsXml method load.
/**
* Load, starting with the layoutBlock element, then all the value-icon
* pairs.
*
* @param shared Top level Element to unpack
* @param perNode ignored in this application
*/
@Override
public boolean load(Element shared, Element perNode) {
// create the objects
EntryExitPairs eep = jmri.InstanceManager.getDefault(jmri.jmrit.signalling.EntryExitPairs.class);
try {
String clearoption = shared.getChild("cleardown").getText();
eep.setClearDownOption(Integer.parseInt(clearoption));
} catch (java.lang.NullPointerException e) {
//Considered normal if it doesn't exist
}
// get attributes
ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
ArrayList<Object> loadedPanel;
if (cm != null) {
loadedPanel = cm.getInstanceList(LayoutEditor.class);
} else {
log.error("Failed getting optional default config manager");
loadedPanel = new ArrayList<Object>();
}
if (shared.getChild("dispatcherintegration") != null && shared.getChild("dispatcherintegration").getText().equals("yes")) {
eep.setDispatcherIntegration(true);
}
if (shared.getChild("colourwhilesetting") != null) {
eep.setSettingRouteColor(stringToColor(shared.getChild("colourwhilesetting").getText()));
int settingTimer = 2000;
try {
settingTimer = Integer.parseInt(shared.getChild("settingTimer").getText());
} catch (Exception e) {
log.error("Error in converting timer to int " + shared.getChild("settingTimer"));
}
eep.setSettingTimer(settingTimer);
}
List<Element> panelList = shared.getChildren("layoutPanel");
for (int k = 0; k < panelList.size(); k++) {
String panelName = panelList.get(k).getAttribute("name").getValue();
LayoutEditor panel = null;
for (int i = 0; i < loadedPanel.size(); i++) {
LayoutEditor tmp = (LayoutEditor) loadedPanel.get(i);
if (tmp.getLayoutName().equals(panelName)) {
panel = tmp;
break;
}
}
if (panel != null) {
List<Element> sourceList = panelList.get(k).getChildren("source");
for (int i = 0; i < sourceList.size(); i++) {
String sourceType = sourceList.get(i).getAttribute("type").getValue();
String sourceItem = sourceList.get(i).getAttribute("item").getValue();
NamedBean source = null;
if (sourceType.equals("signalMast")) {
source = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(sourceItem);
} else if (sourceType.equals("sensor")) {
source = jmri.InstanceManager.sensorManagerInstance().getSensor(sourceItem);
} else if (sourceType.equals("signalHead")) {
source = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(sourceItem);
}
//These two could be subbed off.
List<Element> destinationList = sourceList.get(i).getChildren("destination");
if (destinationList.size() > 0) {
eep.addNXSourcePoint(source, panel);
}
for (int j = 0; j < destinationList.size(); j++) {
String id = null;
if (destinationList.get(j).getAttribute("uniqueid") != null) {
id = destinationList.get(j).getAttribute("uniqueid").getValue();
}
String destType = destinationList.get(j).getAttribute("type").getValue();
String destItem = destinationList.get(j).getAttribute("item").getValue();
NamedBean dest = null;
if (destType.equals("signalMast")) {
dest = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(destItem);
} else if (destType.equals("sensor")) {
dest = jmri.InstanceManager.sensorManagerInstance().getSensor(destItem);
} else if (destType.equals("signalHead")) {
dest = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(destItem);
}
try {
eep.addNXDestination(source, dest, panel, id);
} catch (java.lang.NullPointerException e) {
log.error("An error occured while trying to add a point");
}
if ((destinationList.get(j).getAttribute("uniDirection") != null) && (destinationList.get(j).getAttribute("uniDirection").getValue().equals("no"))) {
eep.setUniDirection(source, panel, dest, false);
}
if ((destinationList.get(j).getAttribute("enabled") != null) && (destinationList.get(j).getAttribute("enabled").getValue().equals("no"))) {
eep.setEnabled(source, panel, dest, false);
}
if (destinationList.get(j).getAttribute("nxType") != null) {
String nxType = destinationList.get(j).getAttribute("nxType").getValue();
if (nxType.equals("turnoutsetting")) {
eep.setEntryExitType(source, panel, dest, 0x00);
} else if (nxType.equals("signalmastlogic")) {
eep.setEntryExitType(source, panel, dest, 0x01);
} else if (nxType.equals("fullinterlocking")) {
eep.setEntryExitType(source, panel, dest, 0x02);
}
}
}
}
} else {
log.error("Panel has not been loaded");
}
}
return true;
}
Aggregations