Search in sources :

Example 26 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class PaneProgAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (log.isDebugEnabled()) {
        log.debug("Pane programmer requested");
    }
    // create the initial frame that steers
    final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameServiceProgrammerSetup"));
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    // ensure status line is cleared on close so it is normal if re-opened
    f.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent we) {
            statusLabel.setText(SymbolicProgBundle.getMessage("StateIdle"));
            f.windowClosing(we);
        }
    });
    // add the Roster menu
    JMenuBar menuBar = new JMenuBar();
    // menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
    JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
    j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
    j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
    menuBar.add(j);
    menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
    f.setJMenuBar(menuBar);
    // new Loco on programming track
    JPanel pane1 = new CombinedLocoSelTreePane(statusLabel, modePane) {

        @Override
        protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
            String title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { "new decoder" });
            if (re != null) {
                title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { re.getId() });
            }
            JFrame p = new PaneServiceProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", modePane.getProgrammer());
            p.pack();
            p.setVisible(true);
        // f.setVisible(false);
        // f.dispose();
        }
    };
    // load primary frame
    JPanel tempPane = new JPanel();
    tempPane.add(modePane);
    f.getContentPane().add(tempPane);
    f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
    pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    f.getContentPane().add(pane1);
    f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
    statusLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    f.getContentPane().add(statusLabel);
    f.pack();
    if (log.isDebugEnabled()) {
        log.debug("Tab-Programmer setup created");
    }
    f.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) BoxLayout(javax.swing.BoxLayout) WindowAdapter(java.awt.event.WindowAdapter) JSeparator(javax.swing.JSeparator) JmriJFrame(jmri.util.JmriJFrame) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) RosterEntry(jmri.jmrit.roster.RosterEntry) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) CombinedLocoSelTreePane(jmri.jmrit.symbolicprog.CombinedLocoSelTreePane)

Example 27 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class PaneOpsProgAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (log.isDebugEnabled()) {
        log.debug("Pane programmer requested");
    }
    // create the initial frame that steers
    final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameOpsProgrammerSetup"));
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    // add the Roster menu
    JMenuBar menuBar = new JMenuBar();
    // menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
    menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
    f.setJMenuBar(menuBar);
    // known loco on main track
    JPanel pane1 = new // no ident in ops mode yet
    KnownLocoSelPane(// no ident in ops mode yet
    false) {

        @Override
        protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
            String title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameOpsProgrammerTitle"), new Object[] { re.getId() });
            // find the ops-mode programmer
            int address = Integer.parseInt(re.getDccAddress());
            boolean longAddr = re.isLongAddress();
            Programmer programmer = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(longAddr, address);
            // and created the frame
            JFrame p = new PaneOpsProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", programmer);
            p.pack();
            p.setVisible(true);
        // f.setVisible(false);
        // f.dispose();
        }
    };
    // load primary frame
    pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    f.getContentPane().add(pane1);
    f.pack();
    if (log.isDebugEnabled()) {
        log.debug("Tab-Programmer setup created");
    }
    f.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) BoxLayout(javax.swing.BoxLayout) KnownLocoSelPane(jmri.jmrit.symbolicprog.KnownLocoSelPane) JmriJFrame(jmri.util.JmriJFrame) Programmer(jmri.Programmer) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) RosterEntry(jmri.jmrit.roster.RosterEntry) JMenuBar(javax.swing.JMenuBar)

Example 28 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class ThrottleFrame method saveRosterChanges.

public void saveRosterChanges() {
    RosterEntry rosterEntry = addressPanel.getRosterEntry();
    if (rosterEntry == null) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("ThrottleFrameNoRosterItemMessageDialog"), Bundle.getMessage("ThrottleFrameNoRosterItemTitleDialog"), JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (JOptionPane.showConfirmDialog(this, Bundle.getMessage("ThrottleFrameRosterChangeMesageDialog"), Bundle.getMessage("ThrottleFrameRosterChangeTitleDialog"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
        return;
    }
    functionPanel.saveFunctionButtonsToRoster(rosterEntry);
    controlPanel.saveToRoster(rosterEntry);
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 29 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class VSDConfigPanel method rosterSaveButtonAction.

// rosterSaveButtonAction()
//
// ActionEventListener method for rosterSaveButton
// Writes VSDecoder info to the RosterEntry.
private void rosterSaveButtonAction(ActionEvent e) {
    log.debug("rosterSaveButton pressed");
    if (rosterSelector.getSelectedRosterEntries().length != 0) {
        RosterEntry r = rosterSelector.getSelectedRosterEntries()[0];
        String path = main_pane.getDecoder().getVSDFilePath();
        String profile = profileComboBox.getSelectedItem().toString();
        if ((path == null) || (profile == null)) {
            log.debug("Path and/or Profile not selected.  Ignore Save button press.");
            return;
        } else {
            r.setOpen(true);
            r.putAttribute("VSDecoder_Path", main_pane.getDecoder().getVSDFilePath());
            r.putAttribute("VSDecoder_Profile", profileComboBox.getSelectedItem().toString());
            int value = JOptionPane.showConfirmDialog(null, MessageFormat.format(Bundle.getMessage("UpdateRoster"), new Object[] { r.titleString() }), Bundle.getMessage("SaveRoster?"), JOptionPane.YES_NO_OPTION);
            if (value == JOptionPane.YES_OPTION) {
                storeFile(r);
            }
            r.setOpen(false);
        }
    // Need to write RosterEntry to file.
    }
}
Also used : RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 30 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class EcosLocoAddressManager method checkLocoList.

/* This is used after an event update form the ecos informing us of a change in the 
     * loco list, we have to determine if it is an addition or delete.
     * We should only ever do either a remove or an add in one go, if we are adding the loco
     * to the roster otherwise this causes a problem with the roster list.
     */
void checkLocoList(String[] ecoslines) {
    log.info("Checking loco list");
    String loco;
    for (int i = 0; i < ecoslines.length; i++) {
        loco = ecoslines[i];
        loco = loco.replaceAll("[\\n\\r]", "");
        if (getByEcosObject(loco) == null) {
            log.debug("We are to add loco " + loco + " to the Ecos Loco List");
            EcosMessage mout = new EcosMessage("get(" + loco + ", addr, name, protocol)");
            tc.sendEcosMessage(mout, this);
        }
    }
    String[] jmrilist = getEcosObjectArray();
    boolean nomatch = true;
    for (int i = 0; i < jmrilist.length; i++) {
        nomatch = true;
        for (int k = 0; k < ecoslines.length; k++) {
            loco = ecoslines[k];
            loco = loco.replaceAll("[\\n\\r]", "");
            if (loco.equals(jmrilist[i])) {
                nomatch = false;
                break;
            }
        }
        if (nomatch) {
            //System.out.println("We do not have a match, therefore this should be deleted from the Ecos loco Manager " + jmrilist[i]);
            log.debug("Loco not found so need to remove from register");
            if (getByEcosObject(jmrilist[i]).getRosterId() != null) {
                final String rosterid = getByEcosObject(jmrilist[i]).getRosterId();
                final Roster _roster = Roster.getDefault();
                final RosterEntry re = _roster.entryFromTitle(rosterid);
                re.deleteAttribute(p.getRosterAttribute());
                re.writeFile(null, null, null);
                Roster.getDefault().writeRoster();
                if (p.getRemoveLocoFromJMRI() == EcosPreferences.YES) {
                    _roster.removeEntry(re);
                    Roster.getDefault().writeRoster();
                } else if (p.getRemoveLocoFromJMRI() == EcosPreferences.ASK) {
                    try {
                        final JDialog dialog = new JDialog();
                        dialog.setTitle("Remove Roster Entry From JMRI?");
                        dialog.setLocation(300, 200);
                        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(rosterid + " has been removed from the Ecos do you want to remove it from 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) {
                                if (remember.isSelected()) {
                                    p.setRemoveLocoFromJMRI(EcosPreferences.ASK);
                                }
                                dialog.dispose();
                            }
                        });
                        yesButton.addActionListener(new ActionListener() {

                            @Override
                            public void actionPerformed(ActionEvent e) {
                                if (remember.isSelected()) {
                                    p.setRemoveLocoFromJMRI(EcosPreferences.YES);
                                }
                                setLocoToRoster();
                                _roster.removeEntry(re);
                                Roster.getDefault().writeRoster();
                                dialog.dispose();
                            }
                        });
                        container.add(remember);
                        container.setAlignmentX(Component.CENTER_ALIGNMENT);
                        container.setAlignmentY(Component.CENTER_ALIGNMENT);
                        dialog.getContentPane().add(container);
                        dialog.pack();
                        dialog.setModal(true);
                        dialog.setVisible(true);
                    } catch (HeadlessException he) {
                    // silently ignore inability to display dialog
                    }
                }
            }
            //Even if we do not delete the loco from the roster, we need to remove it from the ecos list.
            deregister(getByEcosObject(jmrilist[i]));
        }
    }
}
Also used : JPanel(javax.swing.JPanel) HeadlessException(java.awt.HeadlessException) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) Roster(jmri.jmrit.roster.Roster) EcosLocoToRoster(jmri.jmrix.ecos.utilities.EcosLocoToRoster) ActionListener(java.awt.event.ActionListener) RosterEntry(jmri.jmrit.roster.RosterEntry) JDialog(javax.swing.JDialog)

Aggregations

RosterEntry (jmri.jmrit.roster.RosterEntry)77 DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)12 JPanel (javax.swing.JPanel)11 Element (org.jdom2.Element)11 JFrame (javax.swing.JFrame)9 BoxLayout (javax.swing.BoxLayout)8 JLabel (javax.swing.JLabel)8 Test (org.junit.Test)7 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 JMenuBar (javax.swing.JMenuBar)6 CvTableModel (jmri.jmrit.symbolicprog.CvTableModel)6 IndexedCvTableModel (jmri.jmrit.symbolicprog.IndexedCvTableModel)6 VariableTableModel (jmri.jmrit.symbolicprog.VariableTableModel)6 ArrayList (java.util.ArrayList)5 JmriJFrame (jmri.util.JmriJFrame)5 File (java.io.File)4 JButton (javax.swing.JButton)3 JMenu (javax.swing.JMenu)3 NamedIcon (jmri.jmrit.catalog.NamedIcon)3