Search in sources :

Example 6 with Transit

use of jmri.Transit in project JMRI by JMRI.

the class ActivateTrainFrame method initiateTrain.

/**
     * Open up a new train window for a given roster entry located in a
     * specific block.
     * 
     * @param e the action event triggering the new window
     * @param re the roster entry to open the new window for
     * @param b the block where the train is located
     */
public void initiateTrain(ActionEvent e, RosterEntry re, Block b) {
    initiateTrain(e);
    if (_TrainsFromRoster && re != null) {
        setComboBox(trainSelectBox, re.getId());
    //Add in some bits of code as some point to filter down the transits that can be used.
    }
    if (b != null && selectedTransit != null) {
        ArrayList<Transit> transitList = _TransitManager.getListUsingBlock(b);
        ArrayList<Transit> transitEntryList = _TransitManager.getListEntryBlock(b);
        for (Transit t : transitEntryList) {
            if (!transitList.contains(t)) {
                transitList.add(t);
            }
        }
        transitsFromSpecificBlock = true;
        initializeFreeTransitsCombo(transitList);
        ArrayList<Block> tmpBlkList = new ArrayList<Block>();
        if (selectedTransit.getEntryBlocksList().contains(b)) {
            tmpBlkList = selectedTransit.getEntryBlocksList();
            inTransitBox.setSelected(false);
        } else if (selectedTransit.containsBlock(b)) {
            tmpBlkList = selectedTransit.getInternalBlocksList();
            inTransitBox.setSelected(true);
        }
        ArrayList<Integer> tmpSeqList = selectedTransit.getBlockSeqList();
        for (int i = 0; i < tmpBlkList.size(); i++) {
            if (tmpBlkList.get(i) == b) {
                setComboBox(startingBlockBox, getBlockName(b) + "-" + tmpSeqList.get(i));
                break;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Block(jmri.Block) Transit(jmri.Transit)

Example 7 with Transit

use of jmri.Transit in project JMRI by JMRI.

the class TransitCreationTool method createTransit.

public Transit createTransit() throws JmriException {
    TransitManager tm = InstanceManager.getDefault(jmri.TransitManager.class);
    String transitName = "From " + list.get(0).getDisplayName() + " to " + list.get(list.size() - 1).getDisplayName();
    Transit t = tm.createNewTransit(transitName);
    if (t == null) {
        log.error("Unable to create transit " + transitName);
        throw new JmriException(Bundle.getMessage("TCTErrorUnableToCreate", transitName));
    }
    if (list.get(0) instanceof SignalMast) {
        jmri.SignalMastLogicManager smlm = InstanceManager.getDefault(jmri.SignalMastLogicManager.class);
        for (int i = 1; i <= list.size() - 1; i++) {
            jmri.SignalMastLogic sml = smlm.getSignalMastLogic((SignalMast) list.get(i - 1));
            Section sec = sml.getAssociatedSection((SignalMast) list.get(i));
            //In theory sec being null would already have been tested when the signal was added.
            if (sec == null) {
                String error = Bundle.getMessage("TCTErrorMastPairsNoSection", list.get(i - 1).getDisplayName(), list.get(i).getDisplayName());
                log.error(error);
                tm.deregister(t);
                t.dispose();
                cancelTransitCreate();
                throw new JmriException(error);
            }
            t.addTransitSection(new jmri.TransitSection(sec, i, Section.FORWARD));
        }
    }
    //Once created clear the list for a fresh start.
    list = new ArrayList<NamedBean>();
    return t;
}
Also used : NamedBean(jmri.NamedBean) JmriException(jmri.JmriException) Transit(jmri.Transit) Section(jmri.Section) TransitManager(jmri.TransitManager) SignalMast(jmri.SignalMast)

Example 8 with Transit

use of jmri.Transit 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 9 with Transit

use of jmri.Transit 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 10 with Transit

use of jmri.Transit in project JMRI by JMRI.

the class TransitTableAction method updatePressed.

void updatePressed(ActionEvent e) {
    if (!checkTransitInformation()) {
        return;
    }
    // check if user name has been changed
    String uName = userName.getText();
    if (uName.equals("")) {
        uName = null;
    }
    if ((uName != null) && (!uName.equals(curTransit.getUserName()))) {
        // check that new user name is unique
        Transit tTransit = transitManager.getByUserName(uName);
        if (tTransit != null) {
            javax.swing.JOptionPane.showMessageDialog(addFrame, rbx.getString("Message22"), Bundle.getMessage("ErrorTitle"), javax.swing.JOptionPane.ERROR_MESSAGE);
            return;
        }
    }
    curTransit.setUserName(uName);
    if (setTransitInformation()) {
        // successful update
        addFrame.setVisible(false);
        // remove addFrame from Windows menu
        addFrame.dispose();
        addFrame = null;
    }
}
Also used : Transit(jmri.Transit)

Aggregations

Transit (jmri.Transit)14 EntryPoint (jmri.EntryPoint)5 Section (jmri.Section)4 TransitManager (jmri.TransitManager)4 ActionEvent (java.awt.event.ActionEvent)3 ArrayList (java.util.ArrayList)3 JButton (javax.swing.JButton)3 Block (jmri.Block)3 TransitSection (jmri.TransitSection)3 FlowLayout (java.awt.FlowLayout)2 ActionListener (java.awt.event.ActionListener)2 BoxLayout (javax.swing.BoxLayout)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 NamedBean (jmri.NamedBean)2 SectionManager (jmri.SectionManager)2 TransitSectionAction (jmri.TransitSectionAction)2 Element (org.jdom2.Element)2 AbstractAction (javax.swing.AbstractAction)1 JDialog (javax.swing.JDialog)1