001    /*
002     * This file is part of McIDAS-V
003     *
004     * Copyright 2007-2013
005     * Space Science and Engineering Center (SSEC)
006     * University of Wisconsin - Madison
007     * 1225 W. Dayton Street, Madison, WI 53706, USA
008     * https://www.ssec.wisc.edu/mcidas
009     * 
010     * All Rights Reserved
011     * 
012     * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013     * some McIDAS-V source code is based on IDV and VisAD source code.  
014     * 
015     * McIDAS-V is free software; you can redistribute it and/or modify
016     * it under the terms of the GNU Lesser Public License as published by
017     * the Free Software Foundation; either version 3 of the License, or
018     * (at your option) any later version.
019     * 
020     * McIDAS-V is distributed in the hope that it will be useful,
021     * but WITHOUT ANY WARRANTY; without even the implied warranty of
022     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023     * GNU Lesser Public License for more details.
024     * 
025     * You should have received a copy of the GNU Lesser Public License
026     * along with this program.  If not, see http://www.gnu.org/licenses.
027     */
028    package edu.wisc.ssec.mcidasv.util;
029    
030    import static edu.wisc.ssec.mcidasv.util.McVGuiUtils.setButtonImage;
031    
032    import java.awt.Dimension;
033    
034    import javax.swing.JButton;
035    import javax.swing.JLabel;
036    import javax.swing.JPanel;
037    import javax.swing.JScrollPane;
038    import javax.swing.JTextPane;
039    import javax.swing.event.HyperlinkEvent;
040    
041    /**
042     * {@code WelcomeWindow} is really just intended to <i>try</i> to detect known
043     * hardware problems and inform the user about any problems.
044     *
045     * <p>The current implementation does not perform <i>any</i> detection, but
046     * expect this to change.
047     */
048    // NOTE TO MCV CODERS:
049    // **DOCUMENT WHAT CHECKS AND/OR DETECTION ARE BEING PERFORMED**
050    public class WelcomeWindow extends javax.swing.JFrame {
051    
052        /** Path to {@literal "header"} image. */
053        private static final String LOGO_PATH = 
054            "/edu/wisc/ssec/mcidasv/images/mcidasv_logo.gif";
055    
056        /** Path to the HTML to display within {@link #textPane}. */
057        private static final String WELCOME_HTML =
058            "/edu/wisc/ssec/mcidasv/resources/welcome.html";
059    
060        /**
061         * Message to display if there was a problem loading
062         * {@link #WELCOME_HTML}.
063         */
064        private static final String ERROR_MESSAGE =
065            "McIDAS-V had a problem displaying its welcome message. Please"
066            + " contact the McIDAS Help Desk for assistance.";
067    
068        /** Dimensions of the welcome window frame. */
069        private static final Dimension WINDOW_SIZE = new Dimension(495, 431);
070    
071        /** Java-friendly location of the path to the welcome message. */
072        private final java.net.URL contents;
073    
074        /** 
075         * Creates new form WelcomeWindow
076         */
077        public WelcomeWindow() {
078            this.contents = WelcomeWindow.class.getResource(WELCOME_HTML);
079            initComponents();
080        }
081    
082        /** 
083         * This method is called from within the constructor to
084         * initialize the form.
085         * WARNING: Do NOT modify this code. The content of this method is
086         * always regenerated by the Form Editor.
087         */
088        // <editor-fold defaultstate="collapsed" desc="Generated Code">
089        private void initComponents() {
090    
091            setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
092            setTitle("Welcome to McIDAS-V");
093            setLocationByPlatform(true);
094            addWindowListener(new java.awt.event.WindowAdapter() {
095                public void windowClosing(java.awt.event.WindowEvent evt) {
096                    formWindowClosing(evt);
097                }
098            });
099    
100            logoPanel.setLayout(new java.awt.GridBagLayout());
101    
102            logoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource(LOGO_PATH))); // NOI18N
103            logoPanel.add(logoLabel, new java.awt.GridBagConstraints());
104    
105            textPane.setEditable(false);
106            try {
107                textPane.setPage(contents);
108            } catch (java.io.IOException e) {
109                textPane.setText(ERROR_MESSAGE);
110                e.printStackTrace();
111            }
112            textPane.addHyperlinkListener(new javax.swing.event.HyperlinkListener() {
113                public void hyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
114                    textPaneHyperlinkUpdate(evt);
115                }
116            });
117            scrollPane.setViewportView(textPane);
118    
119            javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
120            mainPanel.setLayout(mainPanelLayout);
121            mainPanelLayout.setHorizontalGroup(
122                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
123                .addComponent(scrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
124            );
125            mainPanelLayout.setVerticalGroup(
126                mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127                .addComponent(scrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 273, Short.MAX_VALUE)
128            );
129    
130            setButtonImage(startButton, McVGuiUtils.ICON_APPLY_SMALL);
131            startButton.addActionListener(new java.awt.event.ActionListener() {
132                public void actionPerformed(java.awt.event.ActionEvent evt) {
133                    startButtonActionPerformed(evt);
134                }
135            });
136    
137            setButtonImage(quitButton, McVGuiUtils.ICON_CANCEL_SMALL);
138            quitButton.addActionListener(new java.awt.event.ActionListener() {
139                public void actionPerformed(java.awt.event.ActionEvent evt) {
140                    quitButtonActionPerformed(evt);
141                }
142            });
143    
144            javax.swing.GroupLayout buttonPanelLayout = new javax.swing.GroupLayout(buttonPanel);
145            buttonPanel.setLayout(buttonPanelLayout);
146            buttonPanelLayout.setHorizontalGroup(
147                buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
148                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
149                    .addContainerGap(144, Short.MAX_VALUE)
150                    .addComponent(quitButton)
151                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
152                    .addComponent(startButton))
153            );
154            buttonPanelLayout.setVerticalGroup(
155                buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
156                .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
157                    .addComponent(startButton)
158                    .addComponent(quitButton))
159            );
160    
161            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
162            getContentPane().setLayout(layout);
163            layout.setHorizontalGroup(
164                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
165                .addGroup(layout.createSequentialGroup()
166                    .addContainerGap()
167                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
168                        .addComponent(mainPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
169                        .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
170                        .addComponent(logoPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
171                    .addContainerGap())
172            );
173            layout.setVerticalGroup(
174                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175                .addGroup(layout.createSequentialGroup()
176                    .addContainerGap()
177                    .addComponent(logoPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
178                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
179                    .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
180                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
181                    .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182                    .addContainerGap())
183            );
184    
185            pack();
186            setSize(WINDOW_SIZE);
187        }// </editor-fold>
188    
189        /**
190         * Handles the user clicking on {@link #startButton}. 
191         * Executes {@code System.exit(0)} in an effort to signal to the startup
192         * scripts that the window terminated {@literal "normally"}.
193         * 
194         * @param evt Event to handle. Currently ignored.
195         */
196        private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
197            System.exit(0);
198        }
199    
200        /**
201         * Handles the user clicking on {@link #quitButton}. Doesn't do anything
202         * aside from handing off things to
203         * {@link #formWindowClosing(java.awt.event.WindowEvent)}
204         *
205         * @param evt Event to handle. Currently ignored.
206         *
207         * @see #formWindowClosing(java.awt.event.WindowEvent)
208         */
209        private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {
210            formWindowClosing(null);
211        }
212    
213        /**
214         * Handles the user opting to close the welcome window
215         * {@link javax.swing.JFrame}. Executes {@code System.exit(1)} in an 
216         * effort to signal to the startup scripts that window terminated 
217         * {@literal "abnormally"}.
218         * 
219         * <p>An abnormal termination will result in the startup script 
220         * terminating the launch of McIDAS-V.
221         * 
222         * @param evt Note that this parameter is currently ignored.
223         */
224        private void formWindowClosing(java.awt.event.WindowEvent evt) {
225            System.exit(1);
226        }
227    
228        /**
229         * Listens to {@link #textPane} in order to handle the user clicking on
230         * HTML links.
231         *
232         * @param evt Event to handle. Anything other than
233         * {@link javax.swing.event.HyperlinkEvent.EventType#ACTIVATED} is ignored.
234         *
235         * @see WebBrowser#browse(String)
236         */
237        private void textPaneHyperlinkUpdate(javax.swing.event.HyperlinkEvent evt) {
238            if (evt.getEventType() != HyperlinkEvent.EventType.ACTIVATED)
239                return;
240    
241            String url = null;
242            if (evt.getURL() == null)
243                url = evt.getDescription();
244            else
245                url = evt.getURL().toString();
246    
247            WebBrowser.browse(url);
248        }
249    
250        /**
251         * @param args the command line arguments
252         */
253        public static void main(String args[]) {
254            java.awt.EventQueue.invokeLater(new Runnable() {
255                public void run() {
256                    new WelcomeWindow().setVisible(true);
257                }
258            });
259        }
260    
261        // boring gui components
262        private final JPanel buttonPanel = new JPanel();
263        private final JLabel logoLabel = new JLabel();
264        private final JPanel logoPanel = new JPanel();
265        private final JPanel mainPanel = new JPanel();
266        private final JButton quitButton = new JButton("Quit");
267        private final JScrollPane scrollPane = new JScrollPane();
268        private final JButton startButton = new JButton("Start McIDAS-V");
269        private final JTextPane textPane = new JTextPane();
270    }