001package apps.DecoderPro;
002
003import apps.Apps;
004
005import java.awt.Component;
006import java.awt.FlowLayout;
007import java.awt.event.ActionEvent;
008
009import javax.swing.AbstractAction;
010import javax.swing.Action;
011import javax.swing.BoxLayout;
012import javax.swing.JButton;
013import javax.swing.JPanel;
014
015import jmri.InstanceManager;
016import jmri.jmrit.roster.swing.RosterFrameAction;
017import jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgAction;
018import jmri.jmrit.symbolicprog.tabbedframe.PaneProgAction;
019import jmri.util.JmriJFrame;
020
021/**
022 * The JMRI application for configuring DCC decoders.
023 * <p>
024 * If an argument is provided at startup, it will be used as the name of the
025 * configuration file. Note that this is just the name, not the path; the file
026 * is searched for in the usual way, first in the preferences tree and then in
027 * xml/
028 *
029 * <hr>
030 * This file is part of JMRI.
031 * <p>
032 * JMRI is free software; you can redistribute it and/or modify it under the
033 * terms of version 2 of the GNU General Public License as published by the Free
034 * Software Foundation. See the "COPYING" file for a copy of this license.
035 * <p>
036 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
037 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
038 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
039 *
040 * @author Bob Jacobsen Copyright 2003, 2004, 2007
041 */
042public class DecoderPro extends Apps {
043
044    DecoderPro() {
045        super();
046    }
047
048    @Override
049    protected String logo() {
050        return "resources/decoderpro.gif";
051    }
052
053    @Override
054    protected String mainWindowHelpID() {
055        return "package.apps.DecoderPro.DecoderPro";
056    }
057
058    @Override
059    protected String line1() {
060        return Bundle.getMessage("DecoderProVersionCredit", jmri.Version.name());
061    }
062
063    @Override
064    protected String line2() {
065        return "https://jmri.org/DecoderPro";
066    }
067
068    /**
069     * JPanel displayed as DecoderPro v2 main screen.
070     */
071    @Override
072    protected JPanel statusPanel() {
073        JPanel j = new JPanel();
074        j.setLayout(new BoxLayout(j, BoxLayout.Y_AXIS));
075        j.add(super.statusPanel());
076
077        // Buttons
078        Action serviceprog = new PaneProgAction(Bundle.getMessage("DpButtonUseProgrammingTrack"));
079        Action opsprog = new PaneOpsProgAction(Bundle.getMessage("DpButtonProgramOnMainTrack"));
080        Action quit = new AbstractAction(Bundle.getMessage("MenuItemQuit")) {
081            @Override
082            public void actionPerformed(ActionEvent e) {
083                Apps.handleQuit();
084            }
085        };
086
087        JButton roster = new JButton(new RosterFrameAction());
088        roster.setAlignmentX(Component.CENTER_ALIGNMENT);
089        j.add(roster);
090        JButton b1 = new JButton(Bundle.getMessage("DpButtonUseProgrammingTrack"));
091        b1.addActionListener(serviceprog);
092        b1.setAlignmentX(Component.CENTER_ALIGNMENT);
093        j.add(b1);
094        if (InstanceManager.getNullableDefault(jmri.GlobalProgrammerManager.class) == null
095                || !InstanceManager.getDefault(jmri.GlobalProgrammerManager.class).isGlobalProgrammerAvailable()) {
096            b1.setEnabled(false);
097            b1.setToolTipText(Bundle.getMessage("MsgServiceButtonDisabled"));
098        }
099        JButton m1 = new JButton(Bundle.getMessage("DpButtonProgramOnMainTrack"));
100        m1.addActionListener(opsprog);
101        m1.setAlignmentX(Component.CENTER_ALIGNMENT);
102        j.add(m1);
103        if (InstanceManager.getNullableDefault(jmri.AddressedProgrammerManager.class) == null
104                || !InstanceManager.getDefault(jmri.AddressedProgrammerManager.class).isAddressedModePossible()) {
105            m1.setEnabled(false);
106            m1.setToolTipText(Bundle.getMessage("MsgOpsButtonDisabled"));
107        }
108
109        JPanel p3 = new JPanel();
110        p3.setLayout(new FlowLayout());
111        h1 = new JButton(Bundle.getMessage("ButtonHelp"));
112        // as globalHelpBroker is still null, wait to attach help target after help menu is created
113        h1.setAlignmentX(Component.CENTER_ALIGNMENT);
114        p3.add(h1);
115        JButton q1 = new JButton(Bundle.getMessage("ButtonQuit"));
116        q1.addActionListener(quit);
117        q1.setAlignmentX(Component.CENTER_ALIGNMENT);
118        p3.add(q1);
119        j.add(p3);
120
121        return j;
122    }
123
124    /**
125     * Help button on Main Screen.
126     */
127    private JButton h1;
128
129    /**
130     * {@inheritDoc}
131     */
132    @Override
133    protected void attachHelp() {
134        if (h1 != null) {
135            jmri.util.HelpUtil.addHelpToComponent(h1, "html.apps.DecoderPro.index");
136        }
137    }
138
139    // Main entry point
140    public static void main(String args[]) {
141
142        // Set up system properties that needs to be loaded early
143        jmri.util.EarlyInitializationPreferences.getInstance().loadAndSetPreferences();
144
145        // show splash screen early
146        splash(true);
147
148        Apps.setStartupInfo("DecoderPro");
149
150        setConfigFilename("DecoderProConfig2.xml", args);
151        DecoderPro dp = new DecoderPro();
152        JmriJFrame f = new JmriJFrame(jmri.Application.getApplicationName());
153        createFrame(dp, f);
154
155        log.debug("main initialization done");
156        splash(false);
157    }
158
159    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(DecoderPro.class);
160}