use of jmri.NamedBean in project JMRI by JMRI.
the class EntryExitPairs method setMultiPointRoute.
private void setMultiPointRoute(PointDetails fromPd, PointDetails toPd) {
boolean cleardown = false;
if (fromPd.isRouteFromPointSet() && toPd.isRouteToPointSet()) {
cleardown = true;
}
for (LayoutBlock pro : fromPd.getProtecting()) {
try {
jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class);
LayoutBlock toProt = null;
if (!toPd.getProtecting().isEmpty()) {
toProt = toPd.getProtecting().get(0);
}
boolean result = lbm.getLayoutBlockConnectivityTools().checkValidDest(fromPd.getFacing(), pro, toPd.getFacing(), toProt, LayoutBlockConnectivityTools.SENSORTOSENSOR);
if (result) {
ArrayList<LayoutBlock> blkList = lbm.getLayoutBlockConnectivityTools().getLayoutBlocks(fromPd.getFacing(), toPd.getFacing(), pro, cleardown, LayoutBlockConnectivityTools.NONE);
if (!blkList.isEmpty()) {
List<jmri.NamedBean> beanList = lbm.getLayoutBlockConnectivityTools().getBeansInPath(blkList, fromPd.getPanel(), jmri.Sensor.class);
PointDetails fromPoint = fromPd;
refCounter++;
if (!beanList.isEmpty()) {
for (int i = 1; i < beanList.size(); i++) {
NamedBean nb = beanList.get(i);
PointDetails cur = getPointDetails(nb, fromPd.getPanel());
Source s = nxpair.get(fromPoint);
if (s != null) {
routesToSet.add(new SourceToDest(s, s.getDestForPoint(cur), false, refCounter));
}
fromPoint = cur;
}
}
Source s = nxpair.get(fromPoint);
if (s != null) {
routesToSet.add(new SourceToDest(s, s.getDestForPoint(toPd), false, refCounter));
}
processRoutesToSet();
return;
}
}
} catch (jmri.JmriException e) {
//Can be considered normal if route is blocked
}
}
fromPd.setNXButtonState(NXBUTTONINACTIVE);
toPd.setNXButtonState(NXBUTTONINACTIVE);
}
use of jmri.NamedBean in project JMRI by JMRI.
the class AddEntryExitPairPanel method addPointToCombo.
void addPointToCombo(String signalMastName, String sensorName) {
if (sensorName != null && !sensorName.isEmpty()) {
String description = sensorName;
NamedBean source = InstanceManager.sensorManagerInstance().getSensor(sensorName);
if (signalMastName != null && !signalMastName.isEmpty()) {
description = sensorName + " (" + signalMastName + ")";
}
validPoints.add(new ValidPoints(source, description));
fromPoint.addItem(description);
toPoint.addItem(description);
}
}
use of jmri.NamedBean in project JMRI by JMRI.
the class DefaultRoute method vetoableChange.
@Override
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException {
NamedBean nb = (NamedBean) evt.getOldValue();
if ("CanDelete".equals(evt.getPropertyName())) {
// NOI18N
StringBuilder message = new StringBuilder();
// NOI18N
message.append("<b>").append(getDisplayName()).append("</b><ul>");
boolean found = false;
if (nb instanceof Turnout) {
if (isOutputTurnoutIncluded((Turnout) nb)) {
// NOI18N
message.append(Bundle.getMessage("InUseRouteOutputTurnout"));
found = true;
}
if (nb.equals(getCtlTurnout())) {
// NOI18N
message.append(Bundle.getMessage("InUseRouteControlTurnout"));
found = true;
}
if (nb.equals(getLockCtlTurnout())) {
// NOI18N
message.append(Bundle.getMessage("InUseRouteLockTurnout"));
found = true;
}
} else if (nb instanceof Sensor) {
if (isOutputSensorIncluded((Sensor) nb)) {
// NOI18N
message.append(Bundle.getMessage("InUseRouteOutputSensor"));
found = true;
}
if (nb.equals(getTurnoutsAlgdSensor())) {
// NOI18N
message.append(Bundle.getMessage("InUseRouteAlignSensor"));
found = true;
}
if (isRouteSensorIncluded((Sensor) nb)) {
// NOI18N
message.append(Bundle.getMessage("InUseRouteSensor"));
found = true;
}
}
if (found) {
message.append("</ul>");
throw new java.beans.PropertyVetoException(message.toString(), evt);
}
} else if ("DoDelete".equals(evt.getPropertyName())) {
// NOI18N
if (nb instanceof Turnout) {
if (isOutputTurnoutIncluded((Turnout) nb)) {
deActivateRoute();
deleteOutputTurnout((Turnout) evt.getOldValue());
}
if (nb.equals(getCtlTurnout())) {
deActivateRoute();
setControlTurnout(null);
}
if (nb.equals(getLockCtlTurnout())) {
deActivateRoute();
setLockControlTurnout(null);
}
} else if (nb instanceof Sensor) {
if (isOutputSensorIncluded((Sensor) nb)) {
deActivateRoute();
removeOutputSensor((Sensor) nb);
}
if (nb.equals(getTurnoutsAlgdSensor())) {
deActivateRoute();
setTurnoutsAlignedSensor(null);
}
if (isRouteSensorIncluded((Sensor) nb)) {
deActivateRoute();
removeRouteSensor((Sensor) nb);
}
}
activateRoute();
}
}
use of jmri.NamedBean in project JMRI by JMRI.
the class DefaultLogix method startListener.
/**
* Creates a listener of the required type and starts it
*/
private void startListener(JmriSimplePropertyListener listener) {
String msg = "(unknown type number " + listener.getType() + ")";
NamedBean nb;
NamedBeanHandle<?> namedBeanHandle;
switch(listener.getType()) {
case LISTENER_TYPE_FASTCLOCK:
Timebase tb = InstanceManager.getDefault(jmri.Timebase.class);
tb.addMinuteChangeListener(listener);
return;
default:
namedBeanHandle = listener.getNamedBean();
if (namedBeanHandle == null) {
switch(listener.getType()) {
case LISTENER_TYPE_SENSOR:
msg = "sensor";
break;
case LISTENER_TYPE_TURNOUT:
msg = "turnout";
break;
case LISTENER_TYPE_LIGHT:
msg = "light";
break;
case LISTENER_TYPE_CONDITIONAL:
msg = "conditional";
break;
case LISTENER_TYPE_SIGNALHEAD:
msg = "signalhead";
break;
case LISTENER_TYPE_SIGNALMAST:
msg = "signalmast";
break;
case LISTENER_TYPE_MEMORY:
msg = "memory";
break;
case LISTENER_TYPE_WARRANT:
msg = "warrant";
break;
case LISTENER_TYPE_OBLOCK:
msg = "oblock";
break;
case LISTENER_TYPE_ENTRYEXIT:
msg = "entry exit";
break;
default:
msg = "unknown";
}
break;
}
nb = namedBeanHandle.getBean();
nb.addPropertyChangeListener(listener, namedBeanHandle.getName(), "Logix " + getDisplayName());
return;
}
log.error("Bad name for " + msg + " \"" + listener.getDevName() + "\" when setting up Logix listener");
}
use of jmri.NamedBean in project JMRI by JMRI.
the class BeanSelectCreatePanel method createBean.
private NamedBean createBean() throws jmri.JmriException {
String prefix = ConnectionNameFromSystemName.getPrefixFromName((String) prefixBox.getSelectedItem());
NamedBean nBean = null;
if (_manager instanceof jmri.TurnoutManager) {
String sName = "";
try {
sName = InstanceManager.turnoutManagerInstance().createSystemName(hardwareAddress.getText(), prefix);
} catch (jmri.JmriException e) {
throw e;
}
try {
nBean = InstanceManager.turnoutManagerInstance().provideTurnout(sName);
} catch (IllegalArgumentException ex) {
// user input no good
throw new jmri.JmriException("ErrorTurnoutAddFailed");
}
} else if (_manager instanceof jmri.SensorManager) {
String sName = "";
try {
sName = InstanceManager.sensorManagerInstance().createSystemName(hardwareAddress.getText(), prefix);
} catch (jmri.JmriException e) {
throw e;
}
try {
nBean = InstanceManager.sensorManagerInstance().provideSensor(sName);
} catch (IllegalArgumentException ex) {
// user input no good
throw new jmri.JmriException("ErrorSensorAddFailed");
}
} else {
String sName = _manager.makeSystemName(hardwareAddress.getText());
if (_manager instanceof jmri.MemoryManager) {
try {
nBean = InstanceManager.memoryManagerInstance().provideMemory(sName);
} catch (IllegalArgumentException ex) {
// user input no good
throw new jmri.JmriException("ErrorMemoryAddFailed");
}
} else if (_manager instanceof jmri.Block) {
try {
nBean = InstanceManager.getDefault(jmri.BlockManager.class).provideBlock(sName);
} catch (IllegalArgumentException ex) {
// user input no good
throw new jmri.JmriException("ErrorBlockAddFailed");
}
}
}
if (nBean == null) {
throw new jmri.JmriException("Unable to create bean");
}
if ((_reference != null && !_reference.equals("")) && (nBean.getComment() == null || nBean.getComment().equals(""))) {
nBean.setComment(_reference);
}
setDefaultNamedBean(nBean);
return nBean;
}
Aggregations