Search in sources :

Example 1 with TransitSectionAction

use of jmri.TransitSectionAction in project JMRI by JMRI.

the class TransitTableAction method createActionPressed.

// handle button presses in add/edit action window
private void createActionPressed(ActionEvent e) {
    if ((!validateWhenData()) || (!validateWhatData())) {
        return;
    }
    // entered data is OK, create a special action
    curTSA = new TransitSectionAction(tWhen, tWhat, tWhenData, tWhatData1, tWhatData2, tWhenString, tWhatString);
    ArrayList<TransitSectionAction> list = action[activeRow];
    list.add(curTSA);
    actionTableModel.fireTableDataChanged();
    addEditActionFrame.setVisible(false);
    addEditActionFrame.dispose();
    addEditActionFrame = null;
}
Also used : TransitSectionAction(jmri.TransitSectionAction)

Example 2 with TransitSectionAction

use of jmri.TransitSectionAction in project JMRI by JMRI.

the class TransitTableAction method setTransitInformation.

private boolean setTransitInformation() {
    if (curTransit == null) {
        return false;
    }
    curTransit.removeAllSections();
    for (int i = 0; i < sectionList.size(); i++) {
        TransitSection ts = new TransitSection(sectionList.get(i), sequence[i], direction[i], alternate[i]);
        ArrayList<TransitSectionAction> list = action[i];
        if (list != null) {
            for (int j = 0; j < list.size(); j++) {
                ts.addAction(list.get(j));
            }
        }
        curTransit.addTransitSection(ts);
    }
    return true;
}
Also used : TransitSection(jmri.TransitSection) TransitSectionAction(jmri.TransitSectionAction) EntryPoint(jmri.EntryPoint)

Example 3 with TransitSectionAction

use of jmri.TransitSectionAction in project JMRI by JMRI.

the class AutoTrainAction method handleSensorChange.

public void handleSensorChange(String sName) {
    // find waiting Transit Section Action
    for (int i = 0; i < _activeActionList.size(); i++) {
        if (_activeActionList.get(i).getWaitingForSensor()) {
            TransitSectionAction tsa = _activeActionList.get(i);
            if (tsa.getStringWhen().equals(sName)) {
                // have the waiting action
                tsa.setWaitingForSensor(false);
                if (tsa.getSensorListener() != null) {
                    tsa.getTriggerSensor().removePropertyChangeListener(tsa.getSensorListener());
                    tsa.setSensorListener(null);
                }
                executeAction(tsa);
                return;
            }
        }
    }
}
Also used : TransitSectionAction(jmri.TransitSectionAction)

Example 4 with TransitSectionAction

use of jmri.TransitSectionAction in project JMRI by JMRI.

the class AutoTrainAction method addTransitSection.

// this method is called when an AutoActiveTrain enters a Section 
protected synchronized void addTransitSection(TransitSection ts) {
    _activeTransitSectionList.add(ts);
    ArrayList<TransitSectionAction> tsaList = ts.getTransitSectionActionList();
    // set up / execute Transit Section Actions if there are any
    if (tsaList.size() > 0) {
        for (int i = 0; i < tsaList.size(); i++) {
            TransitSectionAction tsa = tsaList.get(i);
            // add to list if not already there
            boolean found = false;
            for (int j = 0; j < _activeActionList.size(); j++) {
                if (_activeActionList.get(j) == tsa) {
                    found = true;
                }
            }
            if (!found) {
                _activeActionList.add(tsa);
                tsa.initialize();
            }
            switch(tsa.getWhenCode()) {
                case TransitSectionAction.ENTRY:
                    // on entry to Section - if here Section was entered
                    checkDelay(tsa);
                    break;
                case TransitSectionAction.EXIT:
                    // on exit from Section
                    tsa.setWaitingForSectionExit(true);
                    tsa.setTargetTransitSection(ts);
                    break;
                case TransitSectionAction.BLOCKENTRY:
                    // on entry to specified Block in the Section
                    tsa.setWaitingForBlock(true);
                    break;
                case TransitSectionAction.BLOCKEXIT:
                    // on exit from specified Block in the Section
                    tsa.setWaitingForBlock(true);
                    break;
                case TransitSectionAction.TRAINSTOP:
                // when train stops - monitor in separate thread
                case TransitSectionAction.TRAINSTART:
                    // when train starts - monitor in separate thread
                    Runnable monTrain = new MonitorTrain(tsa);
                    Thread tMonTrain = new Thread(monTrain, "Monitor Train Transit Action " + _activeTrain.getDccAddress());
                    tsa.setWaitingThread(tMonTrain);
                    tMonTrain.start();
                    break;
                case TransitSectionAction.SENSORACTIVE:
                // when specified Sensor changes to Active
                case TransitSectionAction.SENSORINACTIVE:
                    // when specified Sensor changes to Inactive
                    if (!waitOnSensor(tsa)) {
                        // execute operation immediately -
                        //  no sensor found, or sensor already in requested state
                        executeAction(tsa);
                    } else {
                        tsa.setWaitingForSensor(true);
                    }
                    break;
                default:
                    break;
            }
        }
    }
}
Also used : TransitSectionAction(jmri.TransitSectionAction)

Example 5 with TransitSectionAction

use of jmri.TransitSectionAction in project JMRI by JMRI.

the class TransitManagerXml method loadTransits.

/**
     * Utility method to load the individual Transit objects. If there's no
     * additional info needed for a specific Transit type, invoke this with the
     * parent of the set of Transit elements.
     *
     * @param sharedTransits  Element containing the Transit elements to load.
     * @param perNodeTransits Per-node Element containing the Transit elements
     *                        to load.
     */
@SuppressWarnings("null")
public void loadTransits(Element sharedTransits, Element perNodeTransits) {
    List<Element> transitList = sharedTransits.getChildren("transit");
    if (log.isDebugEnabled()) {
        log.debug("Found " + transitList.size() + " transits");
    }
    TransitManager tm = InstanceManager.getDefault(jmri.TransitManager.class);
    for (int i = 0; i < transitList.size(); i++) {
        String sysName = getSystemName(transitList.get(i));
        String userName = getUserName(transitList.get(i));
        Transit x = tm.createNewTransit(sysName, userName);
        if (x != null) {
            // load common part
            loadCommon(x, transitList.get(i));
            // load transitsection children
            List<Element> transitTransitSectionList = transitList.get(i).getChildren("transitsection");
            for (int n = 0; n < transitTransitSectionList.size(); n++) {
                Element elem = transitTransitSectionList.get(n);
                int seq = 0;
                int dir = Section.UNKNOWN;
                boolean alt = false;
                String sectionName = elem.getAttribute("sectionname").getValue();
                if (sectionName.equals("null")) {
                    log.warn("When loading configuration - missing Section in Transit " + sysName);
                }
                try {
                    seq = elem.getAttribute("sequence").getIntValue();
                    dir = elem.getAttribute("direction").getIntValue();
                } catch (Exception e) {
                    log.error("Data Conversion Exception when loading direction of entry point - " + e);
                }
                if (elem.getAttribute("alternate").getValue().equals("yes")) {
                    alt = true;
                }
                TransitSection ts = new TransitSection(sectionName, seq, dir, alt);
                x.addTransitSection(ts);
                // load transitsectionaction children, if any
                List<Element> transitTransitSectionActionList = transitTransitSectionList.get(n).getChildren("transitsectionaction");
                for (int m = 0; m < transitTransitSectionActionList.size(); m++) {
                    Element elemx = transitTransitSectionActionList.get(m);
                    int tWhen = 1;
                    int tWhat = 1;
                    int tWhenData = 0;
                    String tWhenString = elemx.getAttribute("whenstring").getValue();
                    int tWhatData1 = 0;
                    int tWhatData2 = 0;
                    String tWhatString = elemx.getAttribute("whatstring").getValue();
                    try {
                        tWhen = elemx.getAttribute("whencode").getIntValue();
                        tWhat = elemx.getAttribute("whatcode").getIntValue();
                        tWhenData = elemx.getAttribute("whendata").getIntValue();
                        tWhatData1 = elemx.getAttribute("whatdata1").getIntValue();
                        tWhatData2 = elemx.getAttribute("whatdata2").getIntValue();
                    } catch (Exception e) {
                        log.error("Data Conversion Exception when loading transit section action - " + e);
                    }
                    TransitSectionAction tsa = new TransitSectionAction(tWhen, tWhat, tWhenData, tWhatData1, tWhatData2, tWhenString, tWhatString);
                    ts.addAction(tsa);
                }
            }
        }
    }
}
Also used : TransitSection(jmri.TransitSection) TransitManager(jmri.TransitManager) Element(org.jdom2.Element) TransitSectionAction(jmri.TransitSectionAction) Transit(jmri.Transit)

Aggregations

TransitSectionAction (jmri.TransitSectionAction)9 TransitSection (jmri.TransitSection)3 Transit (jmri.Transit)2 TransitManager (jmri.TransitManager)2 Element (org.jdom2.Element)2 Block (jmri.Block)1 EntryPoint (jmri.EntryPoint)1 Section (jmri.Section)1