Search in sources :

Example 1 with EcosLocoAddress

use of jmri.jmrix.ecos.EcosLocoAddress in project JMRI by JMRI.

the class AddRosterEntryToEcos method rosterEntryUpdate.

void rosterEntryUpdate() {
    if (rosterEntry != null) {
        rosterEntry.removeAllItems();
    }
    for (RosterEntry r : roster.getAllEntries()) {
        // Add only those locos to the drop-down list that are in the roster but not in the Ecos
        String DccAddress = r.getDccAddress();
        EcosLocoAddress EcosAddress = null;
        if (DccAddress != null) {
            log.debug("DccAddress=" + DccAddress);
            EcosAddress = objEcosLocoManager.getByDccAddress(Integer.parseInt(DccAddress));
        }
        if (EcosAddress == null) {
            // It is not possible to create MFX locomotives in the Ecos. They are auto-discovered.
            if (r.getProtocol() != jmri.LocoAddress.Protocol.MFX) {
                rosterEntry.addItem(r.titleString());
            }
        }
    }
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry) EcosLocoAddress(jmri.jmrix.ecos.EcosLocoAddress)

Example 2 with EcosLocoAddress

use of jmri.jmrix.ecos.EcosLocoAddress in project JMRI by JMRI.

the class EcosLocoToRoster method processQueue.

public void processQueue() {
    if (inProcess) {
        return;
    }
    suppressFurtherAdditions = false;
    inProcess = true;
    Runnable run = new Runnable() {

        @Override
        public void run() {
            while (locoList.size() != 0) {
                final EcosLocoAddress tmploco = locoList.get(0);
                waitingForComplete = false;
                if (p.getAddLocoToJMRI() == EcosPreferences.YES) {
                    adaptermemo.getLocoAddressManager().setLocoToRoster();
                    ecosLocoToRoster(tmploco.getEcosObject());
                } else if (!suppressFurtherAdditions && tmploco.addToRoster() && (tmploco.getRosterId() == null)) {
                    class WindowMaker implements Runnable {

                        EcosLocoAddress ecosObject;

                        WindowMaker(EcosLocoAddress o) {
                            ecosObject = o;
                        }

                        @Override
                        public void run() {
                            final JDialog dialog = new JDialog();
                            dialog.setTitle("Add Roster Entry From JMRI?");
                            //dialog.setLocationRelativeTo(null);
                            dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
                            JPanel container = new JPanel();
                            container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
                            container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
                            JLabel question = new JLabel("Loco " + ecosObject.getEcosDescription() + " has been add to the " + adaptermemo.getUserName());
                            question.setAlignmentX(Component.CENTER_ALIGNMENT);
                            container.add(question);
                            question = new JLabel("Do you want to add it to JMRI?");
                            question.setAlignmentX(Component.CENTER_ALIGNMENT);
                            container.add(question);
                            final JCheckBox remember = new JCheckBox("Remember this setting for next time?");
                            remember.setFont(remember.getFont().deriveFont(10f));
                            remember.setAlignmentX(Component.CENTER_ALIGNMENT);
                            //user preferences do not have the save option, but once complete the following line can be removed
                            //Need to get the method to save connection configuration.
                            remember.setVisible(true);
                            JButton yesButton = new JButton("Yes");
                            JButton noButton = new JButton("No");
                            JPanel button = new JPanel();
                            button.setAlignmentX(Component.CENTER_ALIGNMENT);
                            button.add(yesButton);
                            button.add(noButton);
                            container.add(button);
                            noButton.addActionListener(new ActionListener() {

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    ecosObject.doNotAddToRoster();
                                    waitingForComplete = true;
                                    if (remember.isSelected()) {
                                        suppressFurtherAdditions = true;
                                        p.setAddLocoToJMRI(EcosPreferences.NO);
                                    }
                                    dialog.dispose();
                                }
                            });
                            yesButton.addActionListener(new ActionListener() {

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    if (remember.isSelected()) {
                                        p.setAddLocoToJMRI(EcosPreferences.YES);
                                    }
                                    ecosLocoToRoster(ecosObject.getEcosObject());
                                    dialog.dispose();
                                }
                            });
                            container.add(remember);
                            container.setAlignmentX(Component.CENTER_ALIGNMENT);
                            container.setAlignmentY(Component.CENTER_ALIGNMENT);
                            dialog.getContentPane().add(container);
                            dialog.pack();
                            Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                            int w = dialog.getSize().width;
                            int h = dialog.getSize().height;
                            int x = (dim.width - w) / 2;
                            int y = (dim.height - h) / 2;
                            // Move the window
                            dialog.setLocation(x, y);
                            dialog.setModal(true);
                            dialog.setVisible(true);
                        }
                    }
                    try {
                        WindowMaker t = new WindowMaker(tmploco);
                        javax.swing.SwingUtilities.invokeAndWait(t);
                    } catch (Exception ex) {
                    // Thread.currentThread().interrupt();
                    }
                } else {
                    waitingForComplete = true;
                }
                Runnable r = new Runnable() {

                    @Override
                    public void run() {
                        try {
                            while (!waitingForComplete) {
                                Thread.sleep(500L);
                            }
                        } catch (InterruptedException ex) {
                            Thread.currentThread().interrupt();
                        }
                    }
                };
                Thread thr = new Thread(r);
                thr.start();
                thr.setName("Ecos Loco To Roster Inner thread");
                try {
                    thr.join();
                } catch (InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }
                locoList.remove(0);
            }
            inProcess = false;
        }
    };
    Thread thread = new Thread(run);
    thread.setName("Ecos Loco To Roster");
    thread.start();
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) EcosLocoAddress(jmri.jmrix.ecos.EcosLocoAddress) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) JDialog(javax.swing.JDialog)

Aggregations

EcosLocoAddress (jmri.jmrix.ecos.EcosLocoAddress)2 Dimension (java.awt.Dimension)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JDialog (javax.swing.JDialog)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 RosterEntry (jmri.jmrit.roster.RosterEntry)1