001package apps.DecoderPro;
002
003import apps.Apps;
004import java.awt.FlowLayout;
005import java.awt.event.ActionEvent;
006import java.text.MessageFormat;
007import javax.swing.AbstractAction;
008import javax.swing.Action;
009import javax.swing.BoxLayout;
010import javax.swing.JButton;
011import javax.swing.JLabel;
012import javax.swing.JPanel;
013import jmri.InstanceManager;
014import jmri.jmrit.roster.swing.RosterFrameAction;
015import jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgAction;
016import jmri.jmrit.symbolicprog.tabbedframe.PaneProgAction;
017import jmri.util.JmriJFrame;
018import org.slf4j.Logger;
019import org.slf4j.LoggerFactory;
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 MessageFormat.format(Bundle.getMessage("DecoderProVersionCredit"),
061                new Object[]{jmri.Version.name()});
062    }
063
064    @Override
065    protected String line2() {
066        return "http://jmri.org/DecoderPro";
067    }
068
069    /**
070     * JPanel displayed as DecoderPro v2 main screen.
071     */
072    @Override
073    protected JPanel statusPanel() {
074        JPanel j = new JPanel();
075        j.setLayout(new BoxLayout(j, BoxLayout.Y_AXIS));
076        j.add(super.statusPanel());
077
078        // Buttons
079        Action serviceprog = new PaneProgAction(Bundle.getMessage("DpButtonUseProgrammingTrack"));
080        Action opsprog = new PaneOpsProgAction(Bundle.getMessage("DpButtonProgramOnMainTrack"));
081        Action quit = new AbstractAction(Bundle.getMessage("MenuItemQuit")) {
082            @Override
083            public void actionPerformed(ActionEvent e) {
084                Apps.handleQuit();
085            }
086        };
087
088        JButton roster = new JButton(new RosterFrameAction());
089        roster.setAlignmentX(JLabel.CENTER_ALIGNMENT);
090        j.add(roster);
091        JButton b1 = new JButton(Bundle.getMessage("DpButtonUseProgrammingTrack"));
092        b1.addActionListener(serviceprog);
093        b1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
094        j.add(b1);
095        if (InstanceManager.getNullableDefault(jmri.GlobalProgrammerManager.class) == null
096                || !InstanceManager.getDefault(jmri.GlobalProgrammerManager.class).isGlobalProgrammerAvailable()) {
097            b1.setEnabled(false);
098            b1.setToolTipText(Bundle.getMessage("MsgServiceButtonDisabled"));
099        }
100        JButton m1 = new JButton(Bundle.getMessage("DpButtonProgramOnMainTrack"));
101        m1.addActionListener(opsprog);
102        m1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
103        j.add(m1);
104        if (InstanceManager.getNullableDefault(jmri.AddressedProgrammerManager.class) == null
105                || !InstanceManager.getDefault(jmri.AddressedProgrammerManager.class).isAddressedModePossible()) {
106            m1.setEnabled(false);
107            m1.setToolTipText(Bundle.getMessage("MsgOpsButtonDisabled"));
108        }
109
110        JPanel p3 = new JPanel();
111        p3.setLayout(new FlowLayout());
112        h1 = new JButton(Bundle.getMessage("ButtonHelp"));
113        // as globalHelpBroker is still null, wait to attach help target after help menu is created
114        h1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
115        p3.add(h1);
116        JButton q1 = new JButton(Bundle.getMessage("ButtonQuit"));
117        q1.addActionListener(quit);
118        q1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
119        p3.add(q1);
120        j.add(p3);
121
122        return j;
123    }
124
125    /**
126     * Help button on Main Screen.
127     */
128    private JButton h1;
129
130    /**
131     * {@inheritDoc}
132     */
133    @Override
134    protected void attachHelp() {
135        if (h1 != null) {
136            jmri.util.HelpUtil.addHelpToComponent(h1, "html.apps.DecoderPro.index");
137        }
138    }
139
140    // Main entry point
141    public static void main(String args[]) {
142
143        // Set up system properties that needs to be loaded early
144        jmri.util.EarlyInitializationPreferences.getInstance().loadAndSetPreferences();
145
146        // show splash screen early
147        splash(true);
148
149        Apps.setStartupInfo("DecoderPro");
150
151        setConfigFilename("DecoderProConfig2.xml", args);
152        DecoderPro dp = new DecoderPro();
153        JmriJFrame f = new JmriJFrame(jmri.Application.getApplicationName());
154        createFrame(dp, f);
155
156        log.debug("main initialization done");
157        splash(false);
158    }
159
160    private final static Logger log = LoggerFactory.getLogger(DecoderPro.class);
161}