001 /* PAVLOV -- Multiple Choice Study System 002 * Copyright (C) 2000 - 2004 T.J. Willis 003 * 004 * This program is free software; you can redistribute it and/or 005 * modify it under the terms of the GNU General Public License 006 * as published by the Free Software Foundation; either version 2 007 * of the License, or (at your option) any later version. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, write to the Free Software 016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. 017 * 018 * $Header: /cvsroot/pavlov/net/sourceforge/pavlov/startup/StartupWindow.java,v 1.5 2004/06/11 06:17:34 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.startup; 021 import javax.swing.*; 022 import java.awt.*; 023 import java.awt.event.*; 024 import net.sourceforge.pavlov.randommedia.*; 025 import org.apache.log4j.*; 026 027 028 /** 029 * Shows an unbordered window with an image that closes itself when the main 030 * application becomes visible. 031 * @author <a href="mailto:tj_willis@users.sourceforge.net"></a> 032 * @version $Revision: 1.5 $ 033 */ 034 public class StartupWindow 035 extends Window 036 implements AbstractStartupWindow, WindowListener 037 { 038 /** Image to show.*/ 039 private ImageIcon aboutImage; 040 /** JLabel to show image in. */ 041 private JLabel label; 042 private JFrame mainapp; 043 /** 044 * Progress status message text. 045 * 046 */ 047 protected String text = "Starting PAVLOV."; 048 /** 049 * Describe variable <code>pbar</code> here. 050 * 051 */ 052 protected JProgressBar pbar; 053 /** 054 * Describe variable <code>progress</code> here. 055 * 056 */ 057 protected int progress = 0; 058 059 060 /** 061 * Describe <code>setText</code> method here. 062 * 063 * @param msg a <code>String</code> value 064 * FIXME: should be protected 065 */ 066 public void setText(String msg) { 067 pbar.setStringPainted(true); 068 pbar.setString(msg); 069 } 070 071 /** 072 * Sets the progress bar value to i. 073 * 074 * @param i an <code>int</code> value 075 */ 076 public void setProgress(int i) { 077 pbar.setValue(i); 078 //pbar.repaint(); 079 } 080 /** 081 * Sets progress bar value and message. 082 * 083 * @param i an <code>int</code> value 084 * @param msg a <code>String</code> value 085 */ 086 public void setStatus(int i,String msg) { 087 setProgress(i); 088 setText(msg); 089 } 090 091 /** 092 * Increments progress bar value by i and sets message. 093 * 094 * @param i an <code>int</code> value 095 * @param msg a <code>String</code> value 096 */ 097 public void incrementStatus(int i,String msg) { 098 progress+=i; 099 setProgress(i); 100 } 101 102 /** 103 * Creates a new <code>StartupWindow</code> instance. 104 * 105 * @param imageURL a <code>String</code> value 106 * @param who a <code>Frame</code> value 107 */ 108 public StartupWindow(String imageURL, JFrame who) 109 { 110 super(who); 111 setMainApp(who); 112 //Box bx = Box.createVerticalBox(); 113 JPanel bx = new JPanel(); 114 BorderLayout b = new BorderLayout(); 115 bx.setLayout(b); 116 b.setHgap(0); 117 b.setVgap(0); 118 119 aboutImage = ImageIconUtilities.getNamedImageIcon(imageURL); 120 label = new JLabel(aboutImage); 121 bx.add(label); 122 123 pbar = new JProgressBar(0,100); 124 pbar.setBackground(java.awt.Color.blue); 125 setText(text); 126 127 Dimension psize = new Dimension(aboutImage.getIconWidth(),24); 128 pbar.setPreferredSize( psize ); 129 pbar.setMaximumSize( psize ); 130 131 bx.add(pbar,BorderLayout.SOUTH ); 132 133 add(bx); 134 pack(); 135 136 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 137 138 setBounds( 139 screenSize.width/2 - getWidth()/2, 140 screenSize.height/2 - getHeight()/2, 141 bx.getWidth(), 142 bx.getHeight()); 143 setVisible(true); 144 145 } 146 147 /** 148 * Describe <code>setMainApp</code> method here. 149 * 150 * @param mainApp a <code>JFrame</code> value 151 */ 152 public void setMainApp(JFrame mainApp) 153 { 154 //Quit this app when the big window closes. 155 mainApp.addWindowListener(this); 156 mainapp = mainApp; 157 } 158 159 160 161 // /** 162 // * Describe <code>main</code> method here. 163 // * 164 // * @param args[] a <code>String</code> value 165 // * @deprecated tests my functionality 166 // */ 167 // public static void main(String args[]) 168 // { 169 // JFrame la = new JFrame(); 170 // StartupWindow tst = new StartupWindow("file:resources/AboutPavlov.jpg",la); 171 // tst.setMainApp(la); 172 // tst.setStatus(10,"Now"); 173 // tst.setStatus(20,"is"); 174 // tst.setStatus(30,"the"); 175 // tst.setStatus(40,"time"); 176 177 // tst.setVisible(true); 178 // la.pack(); 179 // la.setVisible(true); 180 // } 181 182 /** 183 * Close the window and free up my resources. 184 * 185 */ 186 public void killme() 187 { 188 if(mainapp!=null)mainapp.removeWindowListener(this); 189 //System.out.println("Window closing"); 190 setVisible(false); 191 //hide(); 192 //finalize(); 193 dispose(); 194 } 195 196 197 /** 198 * Called when main application is activated. I call die(). 199 * 200 * @param e a <code>WindowEvent</code> value 201 */ 202 public void windowActivated(WindowEvent e) {killme();} 203 204 205 /** 206 * Describe <code>windowClosed</code> method here. 207 * 208 * @param e a <code>WindowEvent</code> value 209 */ 210 public void windowClosed(WindowEvent e) {} 211 212 213 /** 214 * Describe <code>windowClosing</code> method here. 215 * 216 * @param e a <code>WindowEvent</code> value 217 */ 218 public void windowClosing(WindowEvent e) {} 219 220 221 /** 222 * Describe <code>windowDeactivated</code> method here. 223 * 224 * @param e a <code>WindowEvent</code> value 225 */ 226 public void windowDeactivated(WindowEvent e) {} 227 228 229 /** 230 * Describe <code>windowDeiconified</code> method here. 231 * 232 * @param e a <code>WindowEvent</code> value 233 */ 234 public void windowDeiconified(WindowEvent e) {} 235 236 237 /** 238 * Describe <code>windowIconified</code> method here. 239 * 240 * @param e a <code>WindowEvent</code> value 241 */ 242 public void windowIconified(WindowEvent e) {} 243 244 245 /** 246 * Called when main application is opened. I call die(). 247 * 248 * @param e a <code>WindowEvent</code> value 249 */ 250 public void windowOpened(WindowEvent e) {killme();} 251 252 } 253 254 255 256