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    
029    package edu.wisc.ssec.mcidasv.ui;
030    
031    import java.awt.BorderLayout;
032    import java.awt.Color;
033    import java.awt.Dimension;
034    import java.awt.Insets;
035    import java.awt.Toolkit;
036    import java.awt.event.ActionEvent;
037    import java.awt.event.ActionListener;
038    import java.awt.event.MouseEvent;
039    
040    import javax.swing.BorderFactory;
041    import javax.swing.ImageIcon;
042    import javax.swing.JButton;
043    import javax.swing.JDialog;
044    import javax.swing.JLabel;
045    import javax.swing.JPanel;
046    import javax.swing.JWindow;
047    import javax.swing.border.BevelBorder;
048    
049    import edu.wisc.ssec.mcidasv.Constants;
050    import edu.wisc.ssec.mcidasv.McIDASV;
051    import edu.wisc.ssec.mcidasv.servermanager.EntryStore;
052    import edu.wisc.ssec.mcidasv.util.McVGuiUtils;
053    
054    import ucar.unidata.idv.IntegratedDataViewer;
055    import ucar.unidata.ui.RovingProgress;
056    import ucar.unidata.util.GuiUtils;
057    import ucar.unidata.util.Msg;
058    import ucar.unidata.util.ObjectListener;
059    import ucar.unidata.util.Resource;
060    import ucar.unidata.util.StringUtil;
061    
062    /**
063     * <p>This is a straight up copy of {@link ucar.unidata.idv.ui.IdvSplash} with
064     * the easter egg taken out.</p>
065     * 
066     * <p>Control+double click isn't enough with all the OS X users here at SSEC ;)</p>
067     * 
068     * @author IDV development team
069     */
070    public class McvSplash extends JWindow {
071        
072        private IntegratedDataViewer idv;
073    
074        /** The JLabel to show messages */
075        private JLabel splashLbl;
076    
077        /** The text to use in the splash screen */
078        private String splashTitle = null;
079    
080        /** The icon to use in the splash screen */
081        private ImageIcon splashIcon;
082    
083        /** The icon to use when the mouse rolls over the splash icon */
084        private ImageIcon splashRolloverIcon;
085    
086        /**
087         *  Keep the splash progress bar around to tell it to stop.
088         */
089        private RovingProgress splashProgressBar;
090    
091        /**
092         * Create the splash screen
093         *
094         * @param idv The IDV
095         *
096         */
097        public McvSplash(IntegratedDataViewer idv) {
098            this.idv = idv;
099            init();
100        }
101    
102        /**
103         *  Show a message in the splash screen (if it exists)
104         *
105         * @param m The message
106         */
107        public void splashMsg(String m) {
108            if (splashLbl != null) {
109                splashLbl.setText(" " + Msg.msg(m) + " ");
110            }
111        }
112    
113        /**
114         *  Close and dispose of the splash window (if it has been created).
115         */
116        public void doClose() {
117            if (splashProgressBar != null) {
118                splashProgressBar.stop();
119            }
120            setVisible(false);
121            dispose();
122        }
123    
124        /**
125         *  Create and return (if not in test mode) the splash screen.
126         */
127        private void init() {
128    
129            try {
130                splashTitle = idv.getProperty("idv.ui.splash.title", "");
131    
132                splashTitle =
133                    idv.getResourceManager().getResourcePath(splashTitle);
134    
135                splashTitle =
136                    StringUtil.replace(splashTitle, "%IDV.TITLE%",
137                                       (String) idv.getProperty("idv.title",
138                                           "McIDAS-V"));
139    
140                splashIcon =
141                    GuiUtils.getImageIcon(idv.getProperty("idv.ui.splash.icon",
142                        "/edu/wisc/ssec/mcidasv/images/mcidasv_logo.gif"));
143                splashRolloverIcon = GuiUtils.getImageIcon(
144                    idv.getProperty(
145                        "idv.ui.splash.iconroll",
146                        "/edu/wisc/ssec/mcidasv/images/mcidasv_logo.gif"));
147            } catch (Exception exc) {}
148    
149            JLabel image = ((splashIcon != null)
150                            ? new JLabel(splashIcon)
151                            : new JLabel("McIDAS-V Nightly"));
152    
153            if ((splashIcon != null) && (splashRolloverIcon != null)) {
154                int width = Math.max(splashIcon.getIconWidth(),
155                                     splashRolloverIcon.getIconWidth());
156                int height = Math.max(splashIcon.getIconHeight(),
157                                      splashRolloverIcon.getIconHeight());
158                image.setPreferredSize(new Dimension(width, height));
159            }
160    
161            image.addMouseListener(new ObjectListener(image) {
162                public void mouseEntered(MouseEvent e) {
163                    if (splashRolloverIcon != null) {
164                        ((JLabel) e.getSource()).setIcon(splashRolloverIcon);
165                    }
166                }
167    
168                public void mouseExited(MouseEvent e) {
169                    if (splashIcon != null) {
170                        ((JLabel) e.getSource()).setIcon(splashIcon);
171                    }
172                }
173            });
174    
175            splashLbl = GuiUtils.cLabel(" ");
176            splashLbl.setForeground(Color.gray);
177                    
178            splashProgressBar = new RovingProgress(Constants.MCV_BLUE);
179            splashProgressBar.start();
180            splashProgressBar.setBorder(
181                BorderFactory.createLineBorder(Color.gray));
182    
183            JButton cancelButton = McVGuiUtils.makePrettyButton("Cancel");
184            cancelButton.addActionListener(new ActionListener() {
185                public void actionPerformed(ActionEvent ae) {
186                    EntryStore serverManager = (EntryStore)(((McIDASV)idv).getServerManager());
187                    if (serverManager != null) {
188                        serverManager.stopLocalServer();
189                    }
190                    ((McIDASV)idv).exitMcIDASV(0);
191                }
192            });
193            if ((splashTitle == null) || splashTitle.trim().equals("")) {
194                String version = idv.getStateManager().getVersion();
195                String title   = idv.getStateManager().getTitle();
196                splashTitle = title + " " + version;
197            }
198    
199            JLabel versionLabel = GuiUtils.cLabel("<html><center><b>"
200                                      + hiliteRevision(splashTitle) + "</center></b></html>");
201    
202            JPanel imagePanel = GuiUtils.inset(image, new Insets(4, 35, 0, 35));
203            JPanel titlePanel = GuiUtils.center(versionLabel);
204    
205            JPanel barPanel = GuiUtils.inset(splashProgressBar,
206                                             new Insets(4, 4, 1, 4));
207    
208            JPanel topPanel = GuiUtils.vbox(imagePanel, titlePanel, barPanel);
209            topPanel = GuiUtils.centerBottom(topPanel, splashLbl);
210            JPanel contents =
211                GuiUtils.topCenter(topPanel,
212                                   GuiUtils.inset(GuiUtils.wrap(cancelButton),
213                                       4));
214            JPanel outer = GuiUtils.center(contents);
215    //        contents.setBorder(
216    //            BorderFactory.createBevelBorder(BevelBorder.RAISED));
217            outer.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,
218                    Color.gray, Color.gray));
219            getContentPane().add(outer);
220            pack();
221            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
222            setLocation(screenSize.width / 2 - getWidth() / 2,
223                        screenSize.height / 2 - getHeight() / 2);
224    
225            ucar.unidata.util.Msg.translateTree(this);
226    
227            //show();
228            setVisible(true);
229            toFront();
230        }
231        
232        /**
233         * Highlight the minor version number if it exists
234         * 
235         * @param version
236         * @return
237         */
238        private String hiliteRevision(String version) {
239                    String hilited = version;
240                    if (version == null) return null;
241                    
242                    try {
243                            int p = version.indexOf("beta");
244                            if (p > 0) {
245                                    hilited += "<br><font color=red>THIS IS BETA SOFTWARE</font>";
246                            }
247                            else {
248                                    p = version.indexOf("alpha");
249                                    if (p > 0) {
250                                            hilited += "<br><font color=red>THIS IS ALPHA SOFTWARE</font>";
251                                    }
252                            }
253                    } catch (Exception e) {}
254    
255                    return hilited;
256        }
257    }