Search in sources :

Example 26 with Section

use of jmri.Section in project JMRI by JMRI.

the class TransitTableAction method addAlternateForSeqPressed.

void addAlternateForSeqPressed(ActionEvent e) {
    if (sectionList.size() > maxSections) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message23"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    int seq = getSeqNum();
    if (seq == 0) {
        return;
    }
    Section primarySection = null;
    ArrayList<Section> altOldList = new ArrayList<>();
    Section beforeSection = null;
    int beforeSectionDirection = 0;
    Section afterSection = null;
    int afterSectionDirection = 0;
    int index = -1;
    for (int i = 0; i < sectionList.size(); i++) {
        if ((sequence[i] == seq) && (!alternate[i])) {
            primarySection = sectionList.get(i);
            index = i;
        }
        if ((sequence[i] == seq) && alternate[i]) {
            altOldList.add(sectionList.get(i));
        }
        if ((sequence[i] == (seq - 1)) && (!alternate[i])) {
            beforeSection = sectionList.get(i);
            beforeSectionDirection = direction[i];
        }
        if ((sequence[i] == (seq + 1)) && (!alternate[i])) {
            afterSection = sectionList.get(i);
            afterSectionDirection = Section.FORWARD;
            if (afterSectionDirection == direction[i]) {
                afterSectionDirection = Section.REVERSE;
            }
        }
    }
    if (primarySection == null) {
        log.error("Missing primary Section for seq = " + seq);
        return;
    }
    ArrayList<Section> possibles = new ArrayList<>();
    int[] possiblesDirection = new int[150];
    ArrayList<String> possibleNames = new ArrayList<>();
    List<String> allSections = sectionManager.getSystemNameList();
    for (int i = 0; i < allSections.size(); i++) {
        Section mayBeSection = null;
        String mayBeName = allSections.get(i);
        int mayBeDirection = 0;
        Section s = sectionManager.getBySystemName(mayBeName);
        if ((s != null) && (s != primarySection) && (s != beforeSection) && (s != afterSection) && (!inSectionList(s, altOldList))) {
            if (beforeSection != null) {
                if (forwardConnected(s, beforeSection, beforeSectionDirection)) {
                    String uname = s.getUserName();
                    if ((uname != null) && (!uname.equals(""))) {
                        mayBeName = mayBeName + "( " + uname + " )";
                    }
                    mayBeSection = s;
                    mayBeDirection = Section.FORWARD;
                } else if (reverseConnected(s, beforeSection, beforeSectionDirection)) {
                    String uname = s.getUserName();
                    if ((uname != null) && (!uname.equals(""))) {
                        mayBeName = mayBeName + "( " + uname + " )";
                    }
                    mayBeSection = s;
                    mayBeDirection = Section.REVERSE;
                }
                if ((mayBeSection != null) && (afterSection != null)) {
                    if (mayBeDirection == Section.REVERSE) {
                        if (!forwardConnected(s, afterSection, afterSectionDirection)) {
                            mayBeSection = null;
                        }
                    } else {
                        if (!reverseConnected(s, afterSection, afterSectionDirection)) {
                            mayBeSection = null;
                        }
                    }
                }
            } else if (afterSection != null) {
                if (forwardConnected(s, afterSection, afterSectionDirection)) {
                    String uname = s.getUserName();
                    if ((uname != null) && (!uname.equals(""))) {
                        mayBeName = mayBeName + "( " + uname + " )";
                    }
                    mayBeSection = s;
                    mayBeDirection = Section.REVERSE;
                } else if (reverseConnected(s, afterSection, afterSectionDirection)) {
                    String uname = s.getUserName();
                    if ((uname != null) && (!uname.equals(""))) {
                        mayBeName = mayBeName + "( " + uname + " )";
                    }
                    mayBeSection = s;
                    mayBeDirection = Section.FORWARD;
                }
            } else {
                mayBeSection = s;
                mayBeDirection = Section.FORWARD;
            }
            if (mayBeSection != null) {
                possibles.add(mayBeSection);
                possiblesDirection[possibles.size() - 1] = mayBeDirection;
                possibleNames.add(mayBeName);
            }
        }
    }
    if (possibles.size() == 0) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, java.text.MessageFormat.format(rbx.getString("Message37"), new Object[] { "" + seq }), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    int k = 0;
    if (possibles.size() > 1) {
        Object[] choices = new Object[possibles.size()];
        for (int j = 0; j < possibles.size(); j++) {
            choices[j] = possibleNames.get(j);
        }
        Object selName = JOptionPane.showInputDialog(addFrame, rbx.getString("AddAlternateChoice"), rbx.getString("AddAlternateTitle"), JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);
        if (selName == null) {
            return;
        }
        for (int j = 0; j < possibles.size(); j++) {
            if (selName.equals(choices[j])) {
                k = j;
            }
        }
    }
    index = index + 1 + altOldList.size();
    sectionList.add(index, possibles.get(k));
    for (int i = sectionList.size() - 2; i >= index; i--) {
        direction[i + 1] = direction[i];
        alternate[i + 1] = alternate[i];
        action[i + 1] = action[i];
        sequence[i + 1] = sequence[i];
    }
    direction[index] = possiblesDirection[k];
    sequence[index] = sequence[index - 1];
    alternate[index] = true;
    action[index] = new ArrayList<>();
    initializeSectionCombos();
    sectionTableModel.fireTableDataChanged();
}
Also used : ArrayList(java.util.ArrayList) Section(jmri.Section) TransitSection(jmri.TransitSection) EntryPoint(jmri.EntryPoint)

Example 27 with Section

use of jmri.Section in project JMRI by JMRI.

the class TransitTableAction method addNextSectionPressed.

void addNextSectionPressed(ActionEvent e) {
    if (sectionList.size() > maxSections) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message23"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (primarySectionBoxList.size() == 0) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message25"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    int index = primarySectionBox.getSelectedIndex();
    Section s = primarySectionBoxList.get(index);
    if (s != null) {
        int j = sectionList.size();
        sectionList.add(s);
        direction[j] = priSectionDirection[index];
        curSequenceNum++;
        sequence[j] = curSequenceNum;
        action[j] = new ArrayList<>();
        alternate[j] = false;
        if ((sectionList.size() == 2) && (curSection != null)) {
            if (forwardConnected(curSection, s, 0)) {
                direction[0] = Section.REVERSE;
            }
            curSectionDirection = direction[0];
        }
        prevSection = curSection;
        prevSectionDirection = curSectionDirection;
        curSection = s;
        if (prevSection != null) {
            curSectionDirection = direction[j];
        }
        initializeSectionCombos();
    }
    sectionTableModel.fireTableDataChanged();
}
Also used : Section(jmri.Section) TransitSection(jmri.TransitSection) EntryPoint(jmri.EntryPoint)

Example 28 with Section

use of jmri.Section in project JMRI by JMRI.

the class TransitTableAction method addAlternateSectionPressed.

void addAlternateSectionPressed(ActionEvent e) {
    if (sectionList.size() > maxSections) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message23"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (alternateSectionBoxList.size() == 0) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message24"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    int index = alternateSectionBox.getSelectedIndex();
    Section s = alternateSectionBoxList.get(index);
    if (s != null) {
        int j = sectionList.size();
        sectionList.add(s);
        direction[j] = altSectionDirection[index];
        sequence[j] = curSequenceNum;
        action[j] = new ArrayList<>();
        alternate[j] = true;
        initializeSectionCombos();
    }
    sectionTableModel.fireTableDataChanged();
}
Also used : Section(jmri.Section) TransitSection(jmri.TransitSection) EntryPoint(jmri.EntryPoint)

Example 29 with Section

use of jmri.Section in project JMRI by JMRI.

the class TransitTableAction method insertAtBeginningPressed.

void insertAtBeginningPressed(ActionEvent e) {
    if (sectionList.size() > maxSections) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message23"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (insertAtBeginningBoxList.size() == 0) {
        javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message35"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
        return;
    }
    int index = insertAtBeginningBox.getSelectedIndex();
    Section s = insertAtBeginningBoxList.get(index);
    if (s != null) {
        sectionList.add(0, s);
        for (int i = sectionList.size() - 2; i > 0; i--) {
            direction[i + 1] = direction[i];
            alternate[i + 1] = alternate[i];
            action[i + 1] = action[i];
            sequence[i + 1] = sequence[i] + 1;
        }
        direction[0] = insertAtBeginningDirection[index];
        curSequenceNum++;
        sequence[0] = 1;
        alternate[0] = false;
        action[0] = new ArrayList<>();
        if (curSequenceNum == 2) {
            prevSectionDirection = direction[0];
            prevSection = s;
        }
        initializeSectionCombos();
    }
    sectionTableModel.fireTableDataChanged();
}
Also used : Section(jmri.Section) TransitSection(jmri.TransitSection) EntryPoint(jmri.EntryPoint)

Example 30 with Section

use of jmri.Section in project JMRI by JMRI.

the class AutoActiveTrain method addAllocatedSection.

private void addAllocatedSection(AllocatedSection as) {
    _allocatedSectionList.add(as);
    if (!_initialized) {
        // this is first allocated section, get things started
        _initialized = true;
        _nextSection = as.getSection();
        _currentBlock = _activeTrain.getStartBlock();
        if (as.getSection().containsBlock(_currentBlock)) {
            // starting Block is in this allocated section - find next Block
            setNewCurrentSection(as);
            _nextBlock = getNextBlock(_currentBlock, as);
        } else if (as.getSection().connectsToBlock(_currentBlock)) {
            // starting Block is connected to a Block in this allocated section
            EntryPoint ep = as.getSection().getEntryPointFromBlock(_currentBlock, as.getDirection());
            if (ep != null) {
                _nextBlock = ep.getBlock();
            } else {
                log.error("failure to get entry point to Transit from Block " + _currentBlock.getSystemName());
            }
        }
        if (_nextBlock != null) {
            // set up new current signal
            setupNewCurrentSignal(as);
        }
    }
    // if train is stopping for lack of an allocation, set flag to restart it
    if (!_pausingActive && (_lastAllocatedSection == _currentAllocatedSection) && isStopping() && (_activeTrain.getStatus() == ActiveTrain.RUNNING)) {
        _needSetSpeed = true;
    }
    // request next allocation if appropriate--Dispatcher must decide whether to allocate it and when
    if ((!DispatcherFrame.instance().getAutoAllocate()) && ((_lastAllocatedSection == null) || (_lastAllocatedSection.getNextSection() == as.getSection()))) {
        // if AutoAllocate, this is now done in DispatcherFrame.java for all trains
        _lastAllocatedSection = as;
        if (as.getNextSection() != null) {
            Section nSection = as.getNextSection();
            int nextSeq = as.getNextSectionSequence();
            int nextDir = _activeTrain.getAllocationDirectionFromSectionAndSeq(nSection, nextSeq);
            DispatcherFrame.instance().requestAllocation(_activeTrain, nSection, nextDir, nextSeq, true, null);
        }
    }
}
Also used : EntryPoint(jmri.EntryPoint) Section(jmri.Section) EntryPoint(jmri.EntryPoint)

Aggregations

Section (jmri.Section)33 TransitSection (jmri.TransitSection)22 EntryPoint (jmri.EntryPoint)19 ArrayList (java.util.ArrayList)5 Block (jmri.Block)5 SectionManager (jmri.SectionManager)5 SignalMast (jmri.SignalMast)4 Transit (jmri.Transit)4 Element (org.jdom2.Element)4 NamedBean (jmri.NamedBean)3 Sensor (jmri.Sensor)3 SignalMastLogic (jmri.SignalMastLogic)2 TransitManager (jmri.TransitManager)2 FlowLayout (java.awt.FlowLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 Hashtable (java.util.Hashtable)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JDialog (javax.swing.JDialog)1