Search in sources :

Example 21 with Section

use of jmri.Section in project JMRI by JMRI.

the class SectionTableAction method deleteSectionPressed.

/**
     * Special processing when user requests deletion of a Section Standard
     * BeanTable processing results in misleading information
     */
private void deleteSectionPressed(String sName) {
    final Section s = jmri.InstanceManager.getDefault(jmri.SectionManager.class).getBySystemName(sName);
    String fullName = sName;
    String uname = s.getUserName();
    if (uname != null && uname.length() > 0) {
        fullName = fullName + "(" + uname + ")";
    }
    ArrayList<Transit> affectedTransits = jmri.InstanceManager.getDefault(jmri.TransitManager.class).getListUsingSection(s);
    final JDialog dialog = new JDialog();
    String msg = "";
    dialog.setTitle(Bundle.getMessage("WarningTitle"));
    dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
    dialog.getContentPane().setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    JPanel p1 = new JPanel();
    p1.setLayout(new FlowLayout());
    if (affectedTransits.size() > 0) {
        // special warning if Section is used in Transits
        JLabel iLabel = new JLabel(java.text.MessageFormat.format(rbx.getString("Message17"), fullName));
        p1.add(iLabel);
        dialog.add(p1);
        for (int i = 0; i < affectedTransits.size(); i++) {
            Transit aTransit = affectedTransits.get(i);
            String tFullName = aTransit.getSystemName();
            uname = aTransit.getUserName();
            if (uname != null && uname.length() > 0) {
                tFullName = tFullName + "(" + uname + ")";
            }
            p1 = new JPanel();
            p1.setLayout(new FlowLayout());
            iLabel = new JLabel("   " + tFullName);
            p1.add(iLabel);
            dialog.add(p1);
        }
        dialog.add(p1);
        JPanel p3 = new JPanel();
        p3.setLayout(new FlowLayout());
        JLabel question = new JLabel(rbx.getString("Message18"));
        JPanel p4 = new JPanel();
        p4.setLayout(new FlowLayout());
        question = new JLabel(rbx.getString("Message18a"));
        p4.add(question);
        dialog.add(p4);
    } else {
        msg = java.text.MessageFormat.format(rbx.getString("Message19"), fullName);
        JLabel question = new JLabel(msg);
        p1.add(question);
        dialog.add(p1);
    }
    JPanel p6 = new JPanel();
    p6.setLayout(new FlowLayout());
    JLabel quest = new JLabel(rbx.getString("Message20"));
    p6.add(quest);
    dialog.add(p6);
    JButton yesButton = new JButton(rbx.getString("YesDeleteIt"));
    JButton noButton = new JButton(rbx.getString("NoCancel"));
    JPanel button = new JPanel();
    button.add(yesButton);
    button.add(noButton);
    dialog.add(button);
    noButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // user cancelled delete request
            dialog.dispose();
        }
    });
    yesButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jmri.InstanceManager.getDefault(jmri.SectionManager.class).deregister(s);
            s.dispose();
            dialog.dispose();
        }
    });
    dialog.pack();
    dialog.setModal(true);
    dialog.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Section(jmri.Section) Transit(jmri.Transit) EntryPoint(jmri.EntryPoint) SectionManager(jmri.SectionManager) ActionListener(java.awt.event.ActionListener) JDialog(javax.swing.JDialog)

Example 22 with Section

use of jmri.Section in project JMRI by JMRI.

the class DispatcherFrame method addExtraRequested.

private void addExtraRequested(ActionEvent e) {
    int index = extraBox.getSelectedIndex();
    if ((atSelectedIndex < 0) || (index < 0)) {
        cancelExtraRequested(e);
        return;
    }
    ActiveTrain at = activeTrainsList.get(atSelectedIndex);
    Transit t = at.getTransit();
    Section s = extraBoxList.get(index);
    //Section ns = null;
    AllocationRequest ar = null;
    boolean requested = false;
    if (t.containsSection(s)) {
        if (s == at.getNextSectionToAllocate()) {
            // this is a request that the next section in the transit be allocated
            allocateNextRequested(atSelectedIndex);
            return;
        } else {
            // requesting allocation of a section in the Transit, but not the next Section
            int seq = -99;
            ArrayList<Integer> seqList = t.getSeqListBySection(s);
            if (seqList.size() > 0) {
                seq = seqList.get(0);
            }
            if (seqList.size() > 1) {
                // this section is in the Transit multiple times 
                int test = at.getNextSectionSeqNumber() - 1;
                int diff = java.lang.Math.abs(seq - test);
                for (int i = 1; i < seqList.size(); i++) {
                    if (diff > java.lang.Math.abs(test - seqList.get(i))) {
                        seq = seqList.get(i);
                        diff = java.lang.Math.abs(seq - test);
                    }
                }
            }
            requested = requestAllocation(at, s, at.getAllocationDirectionFromSectionAndSeq(s, seq), seq, true, extraFrame);
            ar = findAllocationRequestInQueue(s, seq, at.getAllocationDirectionFromSectionAndSeq(s, seq), at);
        }
    } else {
        // requesting allocation of a section outside of the Transit, direction set arbitrary
        requested = requestAllocation(at, s, Section.FORWARD, -99, true, extraFrame);
        ar = findAllocationRequestInQueue(s, -99, Section.FORWARD, at);
    }
    // if allocation request is OK, allocate the Section, if not already allocated
    if (requested && (ar != null)) {
        allocateSection(ar, null);
    }
    if (extraFrame != null) {
        extraFrame.setVisible(false);
        // prevent listing in the Window menu.
        extraFrame.dispose();
        extraFrame = null;
    }
}
Also used : Transit(jmri.Transit) Section(jmri.Section) TransitSection(jmri.TransitSection) EntryPoint(jmri.EntryPoint)

Example 23 with Section

use of jmri.Section in project JMRI by JMRI.

the class DispatcherFrame method initializeExtraComboBox.

private void initializeExtraComboBox() {
    extraBox.removeAllItems();
    extraBoxList.clear();
    if (atSelectedIndex < 0) {
        return;
    }
    ActiveTrain at = activeTrainsList.get(atSelectedIndex);
    //Transit t = at.getTransit();
    ArrayList<AllocatedSection> allocatedSectionList = at.getAllocatedSectionList();
    ArrayList<String> allSections = (ArrayList<String>) InstanceManager.getDefault(jmri.SectionManager.class).getSystemNameList();
    for (int j = 0; j < allSections.size(); j++) {
        Section s = InstanceManager.getDefault(jmri.SectionManager.class).getSection(allSections.get(j));
        if (s.getState() == Section.FREE) {
            // not already allocated, check connectivity to this train's allocated sections
            boolean connected = false;
            for (int k = 0; k < allocatedSectionList.size(); k++) {
                if (connected(s, allocatedSectionList.get(k).getSection())) {
                    connected = true;
                }
            }
            if (connected) {
                // add to the combo box, not allocated and connected to allocated
                extraBoxList.add(s);
                extraBox.addItem(getSectionName(s));
            }
        }
    }
    if (extraBoxList.size() > 0) {
        extraBox.setSelectedIndex(0);
    }
}
Also used : ArrayList(java.util.ArrayList) Section(jmri.Section) TransitSection(jmri.TransitSection) EntryPoint(jmri.EntryPoint)

Example 24 with Section

use of jmri.Section in project JMRI by JMRI.

the class DispatcherFrame method requestNextAllocation.

// submit an AllocationRequest for the next Section of an ActiveTrain
private void requestNextAllocation(ActiveTrain at) {
    // set up an Allocation Request
    Section next = at.getNextSectionToAllocate();
    if (next == null) {
        return;
    }
    int seqNext = at.getNextSectionSeqNumber();
    int dirNext = at.getAllocationDirectionFromSectionAndSeq(next, seqNext);
    requestAllocation(at, next, dirNext, seqNext, true, dispatcherFrame);
}
Also used : Section(jmri.Section) TransitSection(jmri.TransitSection) EntryPoint(jmri.EntryPoint)

Example 25 with Section

use of jmri.Section in project JMRI by JMRI.

the class DispatcherFrame method allocateNextRequested.

// allocate the next section for an ActiveTrain at dispatcher's request
void allocateNextRequested(int index) {
    // set up an Allocation Request
    ActiveTrain at = activeTrainsList.get(index);
    Section next = at.getNextSectionToAllocate();
    if (next == null) {
        return;
    }
    int seqNext = at.getNextSectionSeqNumber();
    int dirNext = at.getAllocationDirectionFromSectionAndSeq(next, seqNext);
    if (requestAllocation(at, next, dirNext, seqNext, true, dispatcherFrame)) {
        AllocationRequest ar = findAllocationRequestInQueue(next, seqNext, dirNext, at);
        if (ar == null) {
            return;
        }
        // attempt to allocate
        allocateSection(ar, null);
    }
}
Also used : Section(jmri.Section) TransitSection(jmri.TransitSection) 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