use of jmri.ConditionalAction in project JMRI by JMRI.
the class DefaultConditionalActionTest method testBasicBeanOperations.
public void testBasicBeanOperations() {
ConditionalAction ix1 = new DefaultConditionalAction(1, 2, "3", 4, "5");
ConditionalAction ix2 = new DefaultConditionalAction(1, 2, "3", 4, "5");
ConditionalAction ix3 = new DefaultConditionalAction(0, 2, "3", 4, "5");
ConditionalAction ix4 = new DefaultConditionalAction(1, 0, "3", 4, "5");
ConditionalAction ix5 = new DefaultConditionalAction(1, 2, "0", 4, "5");
ConditionalAction ix6 = new DefaultConditionalAction(1, 2, "3", 0, "5");
ConditionalAction ix7 = new DefaultConditionalAction(1, 2, "3", 4, "0");
Assert.assertTrue(!ix1.equals(null));
Assert.assertTrue(ix1.equals(ix1));
Assert.assertTrue(ix1.equals(ix2));
Assert.assertTrue(!ix1.equals(ix3));
Assert.assertTrue(!ix1.equals(ix4));
Assert.assertTrue(!ix1.equals(ix5));
Assert.assertTrue(!ix1.equals(ix6));
Assert.assertTrue(!ix1.equals(ix7));
Assert.assertTrue(ix1.hashCode() == ix2.hashCode());
}
use of jmri.ConditionalAction in project JMRI by JMRI.
the class Maintenance method search.
/**
* Search if a given string is used as the name of a NamedBean.
*
* @param name the string to look for
* @param text body of the message to be displayed reporting the result
* @return true if name is found at least once as a bean name
*/
static boolean search(String name, JTextArea text) {
String[] names = getTypeAndNames(name);
if (log.isDebugEnabled()) {
log.debug("search for " + name + " as " + names[0] + " \"" + names[1] + "\" (" + names[2] + ")");
}
if (names[0].length() == 0) {
if (text != null) {
text.append(MessageFormat.format(rbm.getString("ElementNotFound"), (Object[]) names));
return false;
}
}
if (text != null) {
text.append(MessageFormat.format(rbm.getString("ReferenceFollows"), (Object[]) names));
}
String sysName = names[2];
String userName = names[1];
int referenceCount = 0;
StringBuilder tempText = new StringBuilder();
boolean found = false;
boolean empty = true;
// search for references among each class known to be listeners
Iterator<String> iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
if (x == null) {
log.error("Error getting Logix - " + sName);
break;
}
tempText = new StringBuilder();
String uName = x.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "", Bundle.getMessage("BeanNameLogix"), uName, sName });
for (int i = 0; i < x.getNumConditionals(); i++) {
sName = x.getConditionalByNumberOrder(i);
if (sName == null) {
log.error("Null conditional system name");
break;
}
Conditional c = InstanceManager.getDefault(jmri.ConditionalManager.class).getBySystemName(sName);
if (c == null) {
log.error("Invalid conditional system name - " + sName);
break;
}
uName = c.getUserName();
String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameConditional"), uName, sName });
String line = MessageFormat.format(rbm.getString("ConditionalReference"), "\t");
if (sysName.equals(sName) || (userName != null && userName.length() > 0 && userName.equals(uName))) {
if (testName(sysName, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
for (int k = 0; k < variableList.size(); k++) {
ConditionalVariable v = variableList.get(k);
line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
if (testName(v.getName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
for (int k = 0; k < actionList.size(); k++) {
ConditionalAction a = actionList.get(k);
line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
if (testName(a.getDeviceName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append("\t" + MessageFormat.format(rbm.getString("NoReference"), "Logix"));
// cannot put escaped tab char at start of getString
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.jmrit.logix.OBlockManager oBlockManager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
iter1 = oBlockManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.jmrit.logix.OBlock block = oBlockManager.getBySystemName(sName);
String uName = block.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameOBlock"), uName, sName });
Sensor sensor = block.getSensor();
if (sensor != null) {
String line = MessageFormat.format(rbm.getString("OBlockSensor"), "\t");
if (testName(sensor.getSystemName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "OBlock"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.RouteManager routeManager = InstanceManager.getDefault(jmri.RouteManager.class);
iter1 = routeManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Route r = routeManager.getBySystemName(sName);
if (r == null) {
log.error("Error getting Route - " + sName);
break;
}
String uName = r.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameRoute"), uName, sName });
for (int i = 0; i < jmri.Route.MAX_CONTROL_SENSORS; i++) {
String line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameSensor"));
if (testName(r.getRouteSensorName(i), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
String line = MessageFormat.format("TurnoutsAlignedSensor", Bundle.getMessage("BeanNameSensor"));
if (testName(r.getTurnoutsAlignedSensor(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = "\t" + MessageFormat.format(rbm.getString("ControlReference"), Bundle.getMessage("BeanNameTurnout"));
if (testName(r.getControlTurnout(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format("LockControlTurnout", Bundle.getMessage("BeanNameTurnout"));
if (testName(r.getLockControlTurnout(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
for (int i = 0; i < r.getNumOutputTurnouts(); i++) {
line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameTurnout"));
if (testName(r.getOutputTurnoutByIndex(i), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
for (int i = 0; i < r.getNumOutputSensors(); i++) {
line = "\t" + MessageFormat.format(rbm.getString("OutputReference"), Bundle.getMessage("BeanNameSensor"));
if (testName(r.getOutputSensorByIndex(i), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Route"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.TransitManager transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
iter1 = transitManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Transit transit = transitManager.getBySystemName(sName);
if (transit == null) {
log.error("Error getting Transit - " + sName);
break;
}
String uName = transit.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameTransit"), uName, sName });
ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
for (int i = 0; i < sectionList.size(); i++) {
jmri.TransitSection transitSection = sectionList.get(i);
jmri.Section section = transitSection.getSection();
uName = section.getUserName();
sName = section.getSystemName();
String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", rbm.getString("TransitSection"), uName, sName });
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(line1);
tempText.append(line2);
tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t\t"));
found = true;
referenceCount++;
}
String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t\t");
if (testName(section.getForwardBlockingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t\t");
if (testName(section.getForwardStoppingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t\t");
if (testName(section.getReverseBlockingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t\t");
if (testName(section.getReverseStoppingSensorName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
ArrayList<jmri.Block> blockList = section.getBlockList();
for (int k = 0; k < blockList.size(); k++) {
jmri.Block block = blockList.get(k);
sName = block.getSystemName();
uName = block.getUserName();
tempText.append(MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t\t", Bundle.getMessage("BeanNameBlock"), uName, sName }));
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t\t"));
found = true;
referenceCount++;
}
Sensor sensor = block.getSensor();
if (sensor != null) {
line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Transit"));
} else {
text.append("\n");
}
}
// if (text != null) {
// text.append(rbm.getString("NestMessage"));
// }
tempText = new StringBuilder();
found = false;
empty = true;
jmri.SectionManager sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
java.util.List<String> sysNameList = sectionManager.getSystemNameList();
transitManager = InstanceManager.getDefault(jmri.TransitManager.class);
iter1 = transitManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Transit transit = transitManager.getBySystemName(sName);
if (transit != null) {
ArrayList<jmri.TransitSection> sectionList = transit.getTransitSectionList();
for (int i = 0; i < sectionList.size(); i++) {
jmri.TransitSection transitSection = sectionList.get(i);
jmri.Section section = transitSection.getSection();
sysNameList.remove(section.getSystemName());
}
}
}
iter1 = sysNameList.iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Section section = sectionManager.getBySystemName(sName);
if (section == null) {
log.error("Error getting Section - " + sName);
break;
}
String uName = section.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameSection"), uName, sName });
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(MessageFormat.format(rbm.getString("SectionReference"), "\t"));
found = true;
referenceCount++;
}
String line = MessageFormat.format(rbm.getString("ForwardBlocking"), "\t");
if (testName(section.getForwardBlockingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ForwardStopping"), "\t");
if (testName(section.getForwardStoppingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseBlocking"), "\t");
if (testName(section.getReverseBlockingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("ReverseStopping"), "\t");
if (testName(section.getReverseStoppingSensorName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
ArrayList<jmri.Block> blockList = section.getBlockList();
for (int k = 0; k < blockList.size(); k++) {
jmri.Block block = blockList.get(k);
sName = block.getSystemName();
uName = block.getUserName();
String line2 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { "\t", Bundle.getMessage("BeanNameBlock"), uName, sName });
if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
tempText.append(line2);
tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
found = true;
referenceCount++;
}
Sensor sensor = block.getSensor();
if (sensor != null) {
line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
if (testName(sensor.getSystemName(), found, names, line1, line2, line, tempText)) {
found = true;
referenceCount++;
}
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Section"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.BlockManager blockManager = InstanceManager.getDefault(jmri.BlockManager.class);
sysNameList = blockManager.getSystemNameList();
sectionManager = InstanceManager.getDefault(jmri.SectionManager.class);
iter1 = sectionManager.getSystemNameList().iterator();
while (iter1.hasNext()) {
String sName = iter1.next();
jmri.Section section = sectionManager.getBySystemName(sName);
if (section != null) {
for (Block block : section.getBlockList()) {
sysNameList.remove(block.getSystemName());
}
}
}
iter1 = sysNameList.iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Block b = blockManager.getBySystemName(sName);
String uName = b.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameBlock"), uName, sName });
if (sName.equals(sysName) || (uName != null && uName.equals(userName))) {
tempText.append(line1);
tempText.append(MessageFormat.format(rbm.getString("BlockReference"), "\t"));
found = true;
referenceCount++;
}
jmri.Sensor s = b.getSensor();
if (s != null) {
String line = MessageFormat.format(rbm.getString("BlockSensor"), "\t\t");
if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Block"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.jmrit.display.layoutEditor.LayoutBlockManager lbm = InstanceManager.getDefault(LayoutBlockManager.class);
iter1 = lbm.getSystemNameList().iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.jmrit.display.layoutEditor.LayoutBlock lb = lbm.getBySystemName(sName);
if (lb == null) {
log.error("Error getting LayoutBlock - " + sName);
break;
}
String uName = lb.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("LayoutBlock"), uName, sName });
jmri.Sensor s = lb.getOccupancySensor();
if (s != null) {
String line = MessageFormat.format(rbm.getString("OccupancySensor"), "\t\t");
if (testName(s.getSystemName(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "LayoutBlock"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
java.util.Enumeration<BlockBossLogic> enumeration = BlockBossLogic.entries();
while (enumeration.hasMoreElements()) {
// get the next Logix
BlockBossLogic bbl = enumeration.nextElement();
String sName = bbl.getName();
String uName = bbl.getDrivenSignal();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("BlockBossLogic"), uName, sName });
if (uName.equals(sysName) || uName.equals(userName) || sName.equals(sysName) || sName.equals(userName)) {
tempText.append(line1);
tempText.append(MessageFormat.format(rbm.getString("SignalReference"), "\t"));
found = true;
referenceCount++;
}
String line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
if (testName(bbl.getSensor1(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
if (testName(bbl.getSensor2(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "3\t");
if (testName(bbl.getSensor3(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "4\t");
if (testName(bbl.getSensor4(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "5\t");
if (testName(bbl.getSensor5(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "\t");
if (testName(bbl.getTurnout(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSignalReference"), "1\t");
if (testName(bbl.getWatchedSignal1(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "1Alt\t");
if (testName(bbl.getWatchedSignal1Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2\t");
if (testName(bbl.getWatchedSignal2(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchTurnoutReference"), "2Alt\t");
if (testName(bbl.getWatchedSignal2Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1\t");
if (testName(bbl.getWatchedSensor1(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "1Alt\t");
if (testName(bbl.getWatchedSensor1Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2\t");
if (testName(bbl.getWatchedSensor2(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
line = MessageFormat.format(rbm.getString("WatchSensorReference"), "2Alt\t");
if (testName(bbl.getWatchedSensor2Alt(), found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "BlockBossLogic"));
} else {
text.append("\n");
}
}
tempText = new StringBuilder();
found = false;
empty = true;
jmri.ConditionalManager conditionalManager = InstanceManager.getDefault(jmri.ConditionalManager.class);
sysNameList = conditionalManager.getSystemNameList();
iter1 = InstanceManager.getDefault(jmri.LogixManager.class).getSystemNameList().iterator();
while (iter1.hasNext()) {
String sName = iter1.next();
Logix x = InstanceManager.getDefault(jmri.LogixManager.class).getBySystemName(sName);
for (int i = 0; i < x.getNumConditionals(); i++) {
sName = x.getConditionalByNumberOrder(i);
sysNameList.remove(sName);
}
}
iter1 = sysNameList.iterator();
while (iter1.hasNext()) {
// get the next Logix
String sName = iter1.next();
jmri.Conditional c = conditionalManager.getBySystemName(sName);
if (c == null) {
log.error("Error getting Condition - " + sName);
break;
}
String uName = c.getUserName();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", Bundle.getMessage("BeanNameConditional"), uName, sName });
if (sName.equals(sysName) || uName.equals(userName)) {
tempText.append(line1);
tempText.append(MessageFormat.format(rbm.getString("ConditionalReference"), "\t"));
found = true;
//referenceCount++; Don't count, this conditional is orphaned by logix(es)
}
ArrayList<ConditionalVariable> variableList = c.getCopyOfStateVariables();
for (int k = 0; k < variableList.size(); k++) {
ConditionalVariable v = variableList.get(k);
String line = MessageFormat.format(rbm.getString("VariableReference"), new Object[] { "\t\t", v.getTestTypeString(), v.getDataString() });
if (testName(v.getName(), found, names, line1, null, line, tempText)) {
found = true;
//referenceCount++; Don't count, this conditional is orphaned by logix(es)
}
}
ArrayList<ConditionalAction> actionList = c.getCopyOfActions();
for (int k = 0; k < actionList.size(); k++) {
ConditionalAction a = actionList.get(k);
String line = MessageFormat.format(rbm.getString("ActionReference"), new Object[] { "\t\t", a.getTypeString(), a.getOptionString(false), a.getActionDataString() });
if (testName(a.getDeviceName(), found, names, line1, null, line, tempText)) {
found = true;
//referenceCount++; Don't count, this conditional is orphaned by logix(es)
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Conditional"));
}
text.append("\n");
}
found = false;
empty = true;
ArrayList<jmri.jmrit.display.Editor> panelList = jmri.jmrit.display.PanelMenu.instance().getEditorPanelList();
for (int i = 0; i < panelList.size(); i++) {
jmri.jmrit.display.Editor panelEditor = panelList.get(i);
name = panelEditor.getTitle();
String line1 = MessageFormat.format(rbm.getString("ReferenceTitle"), new Object[] { " ", rbm.getString("Panel"), name, name });
List<Positionable> contents = panelEditor.getContents();
for (int k = 0; k < contents.size(); k++) {
Positionable o = contents.get(k);
if (o.getClass().getName().equals("jmri.jmrit.display.SensorIcon")) {
name = ((jmri.jmrit.display.SensorIcon) o).getSensor().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSensor") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.TurnoutIcon")) {
name = ((jmri.jmrit.display.TurnoutIcon) o).getTurnout().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameTurnout") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.SignalHeadIcon")) {
name = ((jmri.jmrit.display.SignalHeadIcon) o).getSignalHead().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("BeanNameSignalHead") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.MultiSensorIcon")) {
jmri.jmrit.display.MultiSensorIcon msi = (jmri.jmrit.display.MultiSensorIcon) o;
for (int j = 0; j < msi.getNumEntries(); j++) {
name = msi.getSensorName(j);
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("MultiSensor") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTurnoutIcon")) {
jmri.jmrit.display.IndicatorTurnoutIcon ito = (jmri.jmrit.display.IndicatorTurnoutIcon) o;
name = ito.getTurnout().getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
Sensor sensor = ito.getOccSensor();
if (sensor != null) {
name = sensor.getSystemName();
line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
jmri.jmrit.logix.OBlock block = ito.getOccBlock();
if (block != null) {
sensor = block.getSensor();
if (sensor != null) {
name = sensor.getSystemName();
line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTO") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
}
} else if (o.getClass().getName().equals("jmri.jmrit.display.IndicatorTrackIcon")) {
jmri.jmrit.display.IndicatorTrackIcon track = (jmri.jmrit.display.IndicatorTrackIcon) o;
Sensor sensor = track.getOccSensor();
if (sensor != null) {
name = sensor.getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
jmri.jmrit.logix.OBlock block = track.getOccBlock();
if (block != null) {
sensor = block.getSensor();
if (sensor != null) {
name = sensor.getSystemName();
String line = MessageFormat.format(rbm.getString("PanelReference"), new Object[] { "\t", Bundle.getMessage("IndicatorTrack") });
if (testName(name, found, names, line1, null, line, tempText)) {
found = true;
referenceCount++;
}
}
}
}
if (text != null && found) {
text.append(tempText.toString());
tempText = new StringBuilder();
found = false;
empty = false;
line1 = null;
}
}
if (text != null) {
if (empty) {
text.append(MessageFormat.format(rbm.getString("NoReference"), "Panel"));
}
}
}
if (text != null) {
if (referenceCount == 0) {
text.append(MessageFormat.format(rbm.getString("Orphan"), (Object[]) names));
} else {
text.append(MessageFormat.format(rbm.getString("ReferenceFound"), new Object[] { Integer.valueOf(referenceCount), userName, sysName }));
}
}
if (names[0] != null) {
// The manager is always a listener
int numListeners = Integer.parseInt(names[3]) - 1;
// PickLists are also listeners
numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances(names[0]);
if (names[0].equals("Sensor")) {
// NOI18N
numListeners = numListeners - jmri.jmrit.picker.PickListModel.getNumInstances("MultiSensor");
}
if (numListeners > referenceCount) {
if (names[0].length() == 0) {
names[0] = "Unknown Type?";
}
/*
JOptionPane.showMessageDialog(null,
MessageFormat.format(rbm.getString("OrphanName"), (Object[])names)+" has "+numListeners+
" listeners installed and only "+referenceCount+
" references found.\n"+names[0]+
" Tables are listeneners. Check that the table is closed.",
rbm.getString("infoTitle"), JOptionPane.INFORMATION_MESSAGE);
*/
if (text != null) {
text.append(MessageFormat.format(rbm.getString("OrphanName"), (Object[]) names) + " has " + numListeners + " listeners installed and only " + referenceCount + " references found.\n" + names[0] + " Tables are listeneners. Check that the table is closed.");
}
}
}
return (referenceCount > 0);
}
use of jmri.ConditionalAction in project JMRI by JMRI.
the class LogixTableAction method buildConditionalListing.
/**
* Builds the text representing the current conditionals for the selected
* Logix statement
*/
void buildConditionalListing() {
String showSystemName, showCondName, condName, operand, tStr;
ConditionalVariable variable;
ConditionalAction action;
numConditionals = _curLogix.getNumConditionals();
showSystemName = _curLogix.getSystemName();
condText.setText(null);
for (int rx = 0; rx < numConditionals; rx++) {
conditionalRowNumber = rx;
_curConditional = _conditionalManager.getBySystemName(_curLogix.getConditionalByNumberOrder(rx));
_variableList = _curConditional.getCopyOfStateVariables();
_logixSysName = _curConditional.getSystemName();
_actionList = _curConditional.getCopyOfActions();
showCondName = _curConditional.getUserName();
if (showCondName == null) {
showCondName = "";
}
showSystemName = _curConditional.getSystemName();
// If no user name for a conditional, create one using C + row number
if (showCondName.equals("")) {
showCondName = "C" + (rx + 1);
}
condText.append("\n " + showSystemName + " " + showCondName + "\n");
if (_curConditional.getLogicType() == Conditional.MIXED) {
_antecedent = _curConditional.getAntecedentExpression();
condText.append(" " + rbx.getString("BrowserAntecedent") + " " + _antecedent + "\n");
}
for (int i = 0; i < _variableList.size(); i++) {
variable = _variableList.get(i);
tStr = " ";
// Makes {Rx}bb or {Rxx}b
tStr = tStr + " R" + (i + 1) + (i > 9 ? "" : " ");
condText.append(tStr);
operand = variable.getOpernString();
if (i == 0) {
// add the IF to the first conditional
condText.append(rbx.getString("BrowserIF") + " " + operand + " ");
} else {
condText.append(" " + operand + " ");
}
if (variable.isNegated()) {
condText.append(rbx.getString("LogicNOT") + " ");
}
condText.append(variable.toString() + "\n");
}
if (_actionList.size() > 0) {
condText.append(" " + rbx.getString("BrowserTHEN") + "\n");
for (int i = 0; i < _actionList.size(); i++) {
action = _actionList.get(i);
condName = action.description(false);
condText.append(" " + condName + "\n");
}
// for _actionList
} else {
condText.append(" " + rbx.getString("BrowserNoAction") + "\n");
}
}
// for numConditionals
condText.setCaretPosition(0);
}
use of jmri.ConditionalAction in project JMRI by JMRI.
the class SensorGroupConditional method calculate.
@SuppressWarnings("null")
@Override
public int calculate(boolean enabled, PropertyChangeEvent evt) {
int currentState = super.calculate(false, evt);
if (!enabled || evt == null) {
return currentState;
}
String listener = ((Sensor) evt.getSource()).getSystemName();
log.debug("SGConditional \"" + getUserName() + "\" (" + getSystemName() + ") has event from \"" + listener + "\"");
if (Sensor.INACTIVE == ((Integer) evt.getNewValue()).intValue()) {
return currentState;
}
for (int i = 0; i < _actionList.size(); i++) {
ConditionalAction action = _actionList.get(i);
Sensor sn = InstanceManager.sensorManagerInstance().getSensor(action.getDeviceName());
if (sn == null) {
log.error("invalid sensor name in action - " + action.getDeviceName());
}
if (// don't change who triggered the action
!listener.equals(action.getDeviceName())) {
// find the old one and reset it
if (sn.getState() != action.getActionData()) {
try {
sn.setKnownState(action.getActionData());
} catch (JmriException e) {
log.warn("Exception setting sensor " + action.getDeviceName() + " in action");
}
}
}
}
log.debug("SGConditional \"" + getUserName() + "\" (" + getSystemName() + "), state= " + currentState + "has set the group actions for " + listener);
return currentState;
}
use of jmri.ConditionalAction in project JMRI by JMRI.
the class RouteTableAction method cloneActionList.
ArrayList<ConditionalAction> cloneActionList(ArrayList<ConditionalAction> actionList, int option) {
ArrayList<ConditionalAction> list = new ArrayList<>();
for (int i = 0; i < actionList.size(); i++) {
ConditionalAction action = actionList.get(i);
ConditionalAction clone = new DefaultConditionalAction();
clone.setType(action.getType());
clone.setOption(option);
clone.setDeviceName(action.getDeviceName());
clone.setActionData(action.getActionData());
clone.setActionString(action.getActionString());
list.add(clone);
}
return list;
}
Aggregations