use of jmri.TransitSectionAction in project JMRI by JMRI.
the class TransitManagerXml method store.
/**
* Default implementation for storing the contents of a TransitManager
*
* @param o Object to store, of type TransitManager
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
Element transits = new Element("transits");
setStoreElementClass(transits);
TransitManager tm = (TransitManager) o;
if (tm != null) {
java.util.Iterator<String> iter = tm.getSystemNameList().iterator();
// don't return an element if there are not Transits to include
if (!iter.hasNext()) {
return null;
}
// store the Transit
while (iter.hasNext()) {
String sname = iter.next();
if (sname == null) {
log.error("System name null during store");
} else {
log.debug("Transit system name is " + sname);
Transit x = tm.getBySystemName(sname);
Element elem = new Element("transit");
elem.addContent(new Element("systemName").addContent(sname));
// store common part
storeCommon(x, elem);
// save child transitsection entries
ArrayList<TransitSection> tsList = x.getTransitSectionList();
Element tsElem = null;
for (int k = 0; k < tsList.size(); k++) {
TransitSection ts = tsList.get(k);
if (ts != null && !ts.isTemporary()) {
tsElem = new Element("transitsection");
Section tSection = ts.getSection();
if (tSection != null) {
tsElem.setAttribute("sectionname", tSection.getSystemName());
} else {
tsElem.setAttribute("sectionname", "null");
}
tsElem.setAttribute("sequence", Integer.toString(ts.getSequenceNumber()));
tsElem.setAttribute("direction", Integer.toString(ts.getDirection()));
tsElem.setAttribute("alternate", "" + (ts.isAlternate() ? "yes" : "no"));
// save child transitsectionaction entries if any
ArrayList<TransitSectionAction> tsaList = ts.getTransitSectionActionList();
if (tsaList.size() > 0) {
Element tsaElem = null;
for (int m = 0; m < tsaList.size(); m++) {
TransitSectionAction tsa = tsaList.get(m);
if (tsa != null) {
tsaElem = new Element("transitsectionaction");
tsaElem.setAttribute("whencode", Integer.toString(tsa.getWhenCode()));
tsaElem.setAttribute("whatcode", Integer.toString(tsa.getWhatCode()));
tsaElem.setAttribute("whendata", Integer.toString(tsa.getDataWhen()));
tsaElem.setAttribute("whenstring", tsa.getStringWhen());
tsaElem.setAttribute("whatdata1", Integer.toString(tsa.getDataWhat1()));
tsaElem.setAttribute("whatdata2", Integer.toString(tsa.getDataWhat2()));
tsaElem.setAttribute("whatstring", tsa.getStringWhat());
tsElem.addContent(tsaElem);
}
}
}
elem.addContent(tsElem);
}
}
transits.addContent(elem);
}
}
}
return (transits);
}
use of jmri.TransitSectionAction in project JMRI by JMRI.
the class AutoTrainAction method handleBlockStateChange.
// this method is called when the state of a Block in an Allocated Section changes
protected synchronized void handleBlockStateChange(AllocatedSection as, Block b) {
// Ignore call if not waiting on Block state change
for (int i = 0; i < _activeActionList.size(); i++) {
if (_activeActionList.get(i).getWaitingForBlock()) {
TransitSectionAction tsa = _activeActionList.get(i);
Block target = InstanceManager.getDefault(jmri.BlockManager.class).getBlock(tsa.getStringWhen());
if (b == target) {
// waiting on state change for this block
if (((b.getState() == Block.OCCUPIED) && (tsa.getWhenCode() == TransitSectionAction.BLOCKENTRY)) || ((b.getState() == Block.UNOCCUPIED) && (tsa.getWhenCode() == TransitSectionAction.BLOCKEXIT))) {
checkDelay(tsa);
}
}
}
}
}
use of jmri.TransitSectionAction in project JMRI by JMRI.
the class TransitTableAction method deleteAction.
private void deleteAction(int r) {
TransitSectionAction tsa = action[activeRow].get(r);
action[activeRow].remove(r);
tsa.dispose();
actionTableModel.fireTableDataChanged();
}
use of jmri.TransitSectionAction in project JMRI by JMRI.
the class AutoTrainAction method clearRemainingActions.
/**
* This method is called to clear any actions that have not been completed
*/
protected synchronized void clearRemainingActions() {
for (int i = _activeActionList.size() - 1; i >= 0; i--) {
TransitSectionAction tsa = _activeActionList.get(i);
Thread t = tsa.getWaitingThread();
if (t != null) {
// interrupting an Action thread will cause it to terminate
t.interrupt();
}
if (tsa.getWaitingForSensor()) {
// remove a sensor listener if one is present
tsa.disposeSensorListener();
}
tsa.initialize();
_activeActionList.remove(i);
}
}
Aggregations