001package jmri.jmrit.symbolicprog.tabbedframe;
002
003import java.util.List;
004import javax.annotation.Nonnull;
005import javax.swing.JPanel;
006import javax.swing.JLabel;
007import jmri.Programmer;
008import jmri.ProgrammingMode;
009import jmri.jmrit.decoderdefn.DecoderFile;
010import jmri.jmrit.roster.RosterEntry;
011import org.jdom2.Element;
012import org.slf4j.Logger;
013import org.slf4j.LoggerFactory;
014
015/**
016 * Extend the PaneProgFrame to handle ops mode operations
017 *
018 * @author Bob Jacobsen Copyright (C) 2002, 2008
019 */
020public class PaneOpsProgFrame extends PaneProgFrame {
021
022    JPanel modePane;
023
024    /**
025     * Provide programming-mode panel to the parent class.
026     * <p>
027     * In this case, provide just an empty JPanel; we presently don't want a
028     * selection GUI to be present when in ops mode.
029     */
030    @Override
031    protected JPanel getModePane() {
032        if (modePane == null) {
033            modePane = new JPanel();
034            modePane.add(new JLabel(Bundle.getMessage("ProgrammingOnMain")));
035        }
036        return modePane;
037    }
038
039    /**
040     * This invokes the parent ctor to do the real work. That will call back to
041     * get the programming mode panel (none) and to hear if there is read mode
042     * (no)
043     *
044     * @param decoderFile XML file defining the decoder contents.
045     * @param r           RosterEntry for information on this locomotive.
046     * @param name        frame title.
047     * @param file        programmer file.
048     * @param p           Programmer object to be used.
049     */
050    public PaneOpsProgFrame(DecoderFile decoderFile, RosterEntry r,
051            String name, String file, Programmer p) {
052        super(decoderFile, r, name, file, p, true);
053
054        if (log.isDebugEnabled()) {
055            log.debug("PaneOpsProgFrame \"{}\" constructed", name);
056        }
057    }
058
059    @Override
060    void addHelp() {
061        addHelpMenu("package.jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgFrame", true);
062    }
063
064    @Override
065    protected void pickProgrammerMode(@Nonnull Element programming) {
066        // find an accepted mode to set it to
067        List<ProgrammingMode> modes = mProgrammer.getSupportedModes();
068
069        if (log.isDebugEnabled()) {
070            log.debug("Programmer supports:");
071            for (ProgrammingMode m : modes) {
072                log.debug("  mode: {} {}", m.getStandardName(), m.toString());
073            }
074        }
075
076        // first try specified modes
077        for (Element el1 : programming.getChildren("mode")) {
078            String name = el1.getText();
079            if (log.isDebugEnabled()) log.debug(" mode {} was specified", name);
080            for (ProgrammingMode m : modes) {
081                if (name.equals(m.getStandardName())) {
082                    log.info("Programming mode selected: {} ({})", m.toString(), m.getStandardName());
083                    mProgrammer.setMode(m);
084                    return;
085                }
086            }
087        }
088
089        // else leave as it is
090        log.debug("Leaving mode as is, supposed to be ops mode");
091    }
092
093    /**
094     * local dispose, which also invokes parent. Note that we remove the
095     * components (removeAll) before taking those apart.
096     */
097    @Override
098    public void dispose() {
099
100        if (log.isDebugEnabled()) {
101            log.debug("dispose local");
102        }
103
104        super.dispose();
105
106    }
107
108    private final static Logger log = LoggerFactory.getLogger(PaneOpsProgFrame.class);
109
110}