001/* 002 * This file is part of McIDAS-V 003 * 004 * Copyright 2007-2016 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 029package edu.wisc.ssec.mcidasv.ui; 030 031import java.awt.BorderLayout; 032import java.awt.Color; 033import java.awt.Dimension; 034import java.awt.Insets; 035import java.awt.Toolkit; 036import java.awt.event.ActionEvent; 037import java.awt.event.ActionListener; 038import java.awt.event.MouseEvent; 039 040import javax.swing.BorderFactory; 041import javax.swing.ImageIcon; 042import javax.swing.JButton; 043import javax.swing.JDialog; 044import javax.swing.JLabel; 045import javax.swing.JPanel; 046import javax.swing.JWindow; 047import javax.swing.border.BevelBorder; 048 049import edu.wisc.ssec.mcidasv.Constants; 050import edu.wisc.ssec.mcidasv.McIDASV; 051import edu.wisc.ssec.mcidasv.servermanager.EntryStore; 052import edu.wisc.ssec.mcidasv.util.McVGuiUtils; 053 054import ucar.unidata.idv.IntegratedDataViewer; 055import ucar.unidata.ui.RovingProgress; 056import ucar.unidata.util.GuiUtils; 057import ucar.unidata.util.Msg; 058import ucar.unidata.util.ObjectListener; 059import ucar.unidata.util.Resource; 060import 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 */ 070public 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 Version string. {@code null} is allowed. 236 * 237 * @return {@code null} if {@code version} is {@code null}, otherwise 238 * a {@code String} containing HTML markup. 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("beta"); 246 if (p > 0) { 247 hilited += "<br><font color=red>THIS IS BETA SOFTWARE</font>"; 248 } 249 else { 250 p = version.indexOf("alpha"); 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}