001 /*
002 * $Id: McvSplash.java,v 1.22 2012/02/19 17:35:50 davep Exp $
003 *
004 * This file is part of McIDAS-V
005 *
006 * Copyright 2007-2012
007 * Space Science and Engineering Center (SSEC)
008 * University of Wisconsin - Madison
009 * 1225 W. Dayton Street, Madison, WI 53706, USA
010 * https://www.ssec.wisc.edu/mcidas
011 *
012 * All Rights Reserved
013 *
014 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
015 * some McIDAS-V source code is based on IDV and VisAD source code.
016 *
017 * McIDAS-V is free software; you can redistribute it and/or modify
018 * it under the terms of the GNU Lesser Public License as published by
019 * the Free Software Foundation; either version 3 of the License, or
020 * (at your option) any later version.
021 *
022 * McIDAS-V is distributed in the hope that it will be useful,
023 * but WITHOUT ANY WARRANTY; without even the implied warranty of
024 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
025 * GNU Lesser Public License for more details.
026 *
027 * You should have received a copy of the GNU Lesser Public License
028 * along with this program. If not, see http://www.gnu.org/licenses.
029 */
030
031 package edu.wisc.ssec.mcidasv.ui;
032
033 import java.awt.BorderLayout;
034 import java.awt.Color;
035 import java.awt.Dimension;
036 import java.awt.Insets;
037 import java.awt.Toolkit;
038 import java.awt.event.ActionEvent;
039 import java.awt.event.ActionListener;
040 import java.awt.event.MouseEvent;
041
042 import javax.swing.BorderFactory;
043 import javax.swing.ImageIcon;
044 import javax.swing.JButton;
045 import javax.swing.JDialog;
046 import javax.swing.JLabel;
047 import javax.swing.JPanel;
048 import javax.swing.JWindow;
049 import javax.swing.border.BevelBorder;
050
051 import edu.wisc.ssec.mcidasv.Constants;
052 import edu.wisc.ssec.mcidasv.McIDASV;
053 import edu.wisc.ssec.mcidasv.servermanager.EntryStore;
054 import edu.wisc.ssec.mcidasv.util.McVGuiUtils;
055
056 import ucar.unidata.idv.IntegratedDataViewer;
057 import ucar.unidata.ui.RovingProgress;
058 import ucar.unidata.util.GuiUtils;
059 import ucar.unidata.util.Msg;
060 import ucar.unidata.util.ObjectListener;
061 import ucar.unidata.util.Resource;
062 import ucar.unidata.util.StringUtil;
063
064 /**
065 * <p>This is a straight up copy of {@link ucar.unidata.idv.ui.IdvSplash} with
066 * the easter egg taken out.</p>
067 *
068 * <p>Control+double click isn't enough with all the OS X users here at SSEC ;)</p>
069 *
070 * @author IDV development team
071 */
072 public class McvSplash extends JWindow {
073
074 private IntegratedDataViewer idv;
075
076 /** The JLabel to show messages */
077 private JLabel splashLbl;
078
079 /** The text to use in the splash screen */
080 private String splashTitle = null;
081
082 /** The icon to use in the splash screen */
083 private ImageIcon splashIcon;
084
085 /** The icon to use when the mouse rolls over the splash icon */
086 private ImageIcon splashRolloverIcon;
087
088 /**
089 * Keep the splash progress bar around to tell it to stop.
090 */
091 private RovingProgress splashProgressBar;
092
093 /**
094 * Create the splash screen
095 *
096 * @param idv The IDV
097 *
098 */
099 public McvSplash(IntegratedDataViewer idv) {
100 this.idv = idv;
101 init();
102 }
103
104 /**
105 * Show a message in the splash screen (if it exists)
106 *
107 * @param m The message
108 */
109 public void splashMsg(String m) {
110 if (splashLbl != null) {
111 splashLbl.setText(" " + Msg.msg(m) + " ");
112 }
113 }
114
115 /**
116 * Close and dispose of the splash window (if it has been created).
117 */
118 public void doClose() {
119 if (splashProgressBar != null) {
120 splashProgressBar.stop();
121 }
122 setVisible(false);
123 dispose();
124 }
125
126 /**
127 * Create and return (if not in test mode) the splash screen.
128 */
129 private void init() {
130
131 try {
132 splashTitle = idv.getProperty("idv.ui.splash.title", "");
133
134 splashTitle =
135 idv.getResourceManager().getResourcePath(splashTitle);
136
137 splashTitle =
138 StringUtil.replace(splashTitle, "%IDV.TITLE%",
139 (String) idv.getProperty("idv.title",
140 "McIDAS-V"));
141
142 splashIcon =
143 GuiUtils.getImageIcon(idv.getProperty("idv.ui.splash.icon",
144 "/edu/wisc/ssec/mcidasv/images/mcidasv_logo.gif"));
145 splashRolloverIcon = GuiUtils.getImageIcon(
146 idv.getProperty(
147 "idv.ui.splash.iconroll",
148 "/edu/wisc/ssec/mcidasv/images/mcidasv_logo.gif"));
149 } catch (Exception exc) {}
150
151 JLabel image = ((splashIcon != null)
152 ? new JLabel(splashIcon)
153 : new JLabel("McIDAS-V Nightly"));
154
155 if ((splashIcon != null) && (splashRolloverIcon != null)) {
156 int width = Math.max(splashIcon.getIconWidth(),
157 splashRolloverIcon.getIconWidth());
158 int height = Math.max(splashIcon.getIconHeight(),
159 splashRolloverIcon.getIconHeight());
160 image.setPreferredSize(new Dimension(width, height));
161 }
162
163 image.addMouseListener(new ObjectListener(image) {
164 public void mouseEntered(MouseEvent e) {
165 if (splashRolloverIcon != null) {
166 ((JLabel) e.getSource()).setIcon(splashRolloverIcon);
167 }
168 }
169
170 public void mouseExited(MouseEvent e) {
171 if (splashIcon != null) {
172 ((JLabel) e.getSource()).setIcon(splashIcon);
173 }
174 }
175 });
176
177 splashLbl = GuiUtils.cLabel(" ");
178 splashLbl.setForeground(Color.gray);
179
180 splashProgressBar = new RovingProgress(Constants.MCV_BLUE);
181 splashProgressBar.start();
182 splashProgressBar.setBorder(
183 BorderFactory.createLineBorder(Color.gray));
184
185 JButton cancelButton = McVGuiUtils.makePrettyButton("Cancel");
186 cancelButton.addActionListener(new ActionListener() {
187 public void actionPerformed(ActionEvent ae) {
188 EntryStore serverManager = (EntryStore)(((McIDASV)idv).getServerManager());
189 if (serverManager != null) {
190 serverManager.stopLocalServer();
191 }
192 ((McIDASV)idv).exitMcIDASV(0);
193 }
194 });
195 if ((splashTitle == null) || splashTitle.trim().equals("")) {
196 String version = idv.getStateManager().getVersion();
197 String title = idv.getStateManager().getTitle();
198 splashTitle = title + " " + version;
199 }
200
201 JLabel versionLabel = GuiUtils.cLabel("<html><center><b>"
202 + hiliteRevision(splashTitle) + "</center></b></html>");
203
204 JPanel imagePanel = GuiUtils.inset(image, new Insets(4, 35, 0, 35));
205 JPanel titlePanel = GuiUtils.center(versionLabel);
206
207 JPanel barPanel = GuiUtils.inset(splashProgressBar,
208 new Insets(4, 4, 1, 4));
209
210 JPanel topPanel = GuiUtils.vbox(imagePanel, titlePanel, barPanel);
211 topPanel = GuiUtils.centerBottom(topPanel, splashLbl);
212 JPanel contents =
213 GuiUtils.topCenter(topPanel,
214 GuiUtils.inset(GuiUtils.wrap(cancelButton),
215 4));
216 JPanel outer = GuiUtils.center(contents);
217 // contents.setBorder(
218 // BorderFactory.createBevelBorder(BevelBorder.RAISED));
219 outer.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,
220 Color.gray, Color.gray));
221 getContentPane().add(outer);
222 pack();
223 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
224 setLocation(screenSize.width / 2 - getWidth() / 2,
225 screenSize.height / 2 - getHeight() / 2);
226
227 ucar.unidata.util.Msg.translateTree(this);
228
229 //show();
230 setVisible(true);
231 toFront();
232 }
233
234 /**
235 * Highlight the minor version number if it exists
236 *
237 * @param version
238 * @return
239 */
240 private String hiliteRevision(String version) {
241 String hilited = version;
242 if (version == null) return null;
243
244 try {
245 int p = version.indexOf('b');
246 if (p > 0) {
247 hilited += "<br><font color=red>THIS IS BETA SOFTWARE</font>";
248 }
249 else {
250 p = version.indexOf('a');
251 if (p > 0) {
252 hilited += "<br><font color=red>THIS IS ALPHA SOFTWARE</font>";
253 }
254 }
255 } catch (Exception e) {}
256
257 return hilited;
258 }
259 }