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/main/standalone/Pavlov.java,v 1.8 2004/07/01 05:50:20 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.main.standalone; 021 022 import java.awt.*; 023 import java.awt.event.*; 024 025 import javax.swing.*; 026 027 import net.sourceforge.pavlov.main.*; 028 import net.sourceforge.pavlov.pluglets.*; 029 import net.sourceforge.pavlov.pluglets.feedback.velocity.*; 030 import net.sourceforge.pavlov.pluglets.strategy.*; 031 032 import org.apache.log4j.*; 033 /** 034 * Description of the Class 035 * 036 *@author Haus 037 *@created June 26, 2004 038 */ 039 public class Pavlov 040 extends AbstractPavlovApplication 041 { 042 private JFrame frame; 043 private SwingUIFactory uiFactory; 044 private static Category cat = Category.getInstance(Pavlov.class.getName()); 045 046 047 /** 048 * Constructor for the Pavlov object 049 * 050 *@param args Description of the Parameter 051 */ 052 public Pavlov(String args[]) 053 { 054 //FIXED: finally single-document-interface 055 super(args); 056 makeFrame(); 057 makeUIFactory(); 058 // this must be done before pluglet loading starts 059 frame.setJMenuBar(uiFactory.createMenuBar(frame.getRootPane())); 060 061 setup(); 062 cat.info("Build date: " + rb.getString("BuildDate", "Unknown")); 063 064 ImageIcon logo = uiFactory.makeImageIcon("WindowIconFile", 065 "file:resources/P.png", 066 50); 067 068 069 if (logo != null) { 070 java.awt.Image imm = logo.getImage(); 071 frame.setIconImage(imm); 072 } 073 074 //JLabel lab = new JLabel("Foo"); 075 //frame.add(lab); 076 077 //Quit this app when the big window closes. 078 frame.addWindowListener( 079 new WindowAdapter() 080 { 081 public void windowClosing(WindowEvent event) 082 { 083 niceQuit(false); 084 } 085 }); 086 javax.swing.ToolTipManager.sharedInstance().setEnabled(true); 087 088 frame.add(uiFactory.getMain()); 089 sizeFrame(); 090 //frame.pack(); 091 } 092 093 094 /** 095 * Description of the Method 096 */ 097 private void makeFrame() 098 { 099 if (frame != null) { 100 return; 101 } 102 frame = new JFrame(rb.getString(rb.TITLE,"Pavlov")); 103 //frame.pack(); 104 //frame.setVisible(true); 105 } 106 107 108 /* 109 * Gets the frame attribute of the Pavlov object 110 * 111 *@return The frame value 112 *@deprecated to be removed soon 113 * 114 public JFrame getFrame() 115 { 116 return frame; 117 }*/ 118 119 120 /** 121 * Description of the Method 122 */ 123 private void makeUIFactory() 124 { 125 if (uiFactory != null) { 126 return; 127 } 128 uiFactory = new SwingUIFactory(this, frame); 129 } 130 131 /** 132 * Description of the Method 133 * 134 *@param abs Description of the Parameter 135 */ 136 protected void showLoginController(AbstractPavlovApplication abs) 137 { 138 //System.out.println("In showLoginController"); 139 uiFactory.showLoginController(abs); 140 } 141 142 143 /** 144 * Shows the user startup status, delegates to getUIBuilder()'s setStatus. 145 * 146 *@param pos an <code>int</code> value 147 *@param msg a <code>String</code> value 148 */ 149 public final void setStatus(final int pos, final String msg) 150 { 151 uiFactory.setStatus(pos, msg); 152 } 153 154 155 /** 156 * Sets status using a key to query the resource broker. 157 * 158 *@param pos Description of the Parameter 159 *@param key Description of the Parameter 160 */ 161 public final void newSetStatus(final int pos, final String key) 162 { 163 String msg = rb.getString(key); 164 setStatus(pos, msg); 165 } 166 167 168 /** 169 * Description of the Method 170 */ 171 protected final void showSplashScreen() 172 { 173 uiFactory.showSplashScreen(frame); 174 } 175 176 177 /** 178 * Description of the Method 179 */ 180 protected final void closeSplashScreen() 181 { 182 uiFactory.closeSplashScreen(); 183 } 184 185 186 /** 187 * Description of the Method 188 * 189 *@return Description of the Return Value 190 */ 191 protected boolean confirmQuit() 192 { 193 return uiFactory.confirmQuit(); 194 } 195 196 197 /** 198 * Description of the Method 199 * 200 *@param msg Description of the Parameter 201 */ 202 public final void showIncorrectDialog(String msg) 203 { 204 uiFactory.showIncorrectDialog(msg); 205 } 206 207 208 /** 209 * Description of the Method 210 */ 211 public void loadPluglets() 212 { 213 //Load java feedback pluglets 214 String superClass 215 = "net.sourceforge.pavlov.pluglets.feedback.AbstractFeedbackPluglet"; 216 new fbLoader().start(); 217 /* 218 feedbackPlugins = new PlugletLoader(superClass,"pluglets/feedback/"); 219 //feedbackPlugins.addToContainer(desktopPane); 220 uiFactory.setFeedbackPluglets(feedbackPlugins); 221 */ 222 223 //Load velocity feedback pluglets 224 new vpLoader().start(); 225 /* 226 velocityPlugins = new VelocityPlugletLoader("pluglets/velocity"); 227 uiFactory.setVelocityPluglets(velocityPlugins); 228 */ 229 230 //Load strategy pluglets 231 new stLoader().start(); 232 /* 233 String sc1 = "net.sourceforge.pavlov.user.AbstractStrategy"; 234 strategyPlugins = new StrategyLoader(sc1,"pluglets/strategy/"); 235 uiFactory.setStrategyPluglets(strategyPlugins); 236 */ 237 238 239 //Load tool pluglets 240 new tLoader().start(); 241 /* 242 toolPluglets = new PlugletLoader(superClass,"pluglets/tools/"); 243 //toolPluglets.addToContainer(desktopPane); 244 uiFactory.setToolPluglets(toolPluglets); 245 */ 246 } 247 248 private final class fbLoader extends Thread{ 249 public fbLoader(){ 250 super(); 251 } 252 253 public void run(){ 254 String superClass 255 = "net.sourceforge.pavlov.pluglets.feedback.AbstractFeedbackPluglet"; 256 String dir = Pavlov.this.rb.getString(rb.FEEDBACK_PLUGLET_DIRECTORY); 257 Pavlov.this.feedbackPlugins = new PlugletLoader(superClass,dir);//"pluglets/feedback/"); 258 //feedbackPlugins.addToContainer(desktopPane); 259 Pavlov.this.uiFactory.setFeedbackPluglets(feedbackPlugins); 260 } 261 } 262 private final class vpLoader extends Thread{ 263 public vpLoader(){ 264 super(); 265 } 266 267 public void run(){ 268 String dir = Pavlov.this.rb.getString(rb.VELOCITY_PLUGLET_DIRECTORY); 269 Pavlov.this.velocityPlugins = new VelocityPlugletLoader(dir);//"pluglets/velocity"); 270 Pavlov.this.uiFactory.setVelocityPluglets(velocityPlugins); 271 } 272 } 273 274 275 private final class stLoader extends Thread{ 276 public stLoader(){ 277 super(); 278 } 279 280 public void run(){ 281 String sc1 = "net.sourceforge.pavlov.user.AbstractStrategy"; 282 String dir = Pavlov.this.rb.getString(rb.STRATEGY_PLUGLET_DIRECTORY); 283 Pavlov.this.strategyPlugins = new StrategyLoader(sc1,dir);//"pluglets/strategy/"); 284 Pavlov.this.uiFactory.setStrategyPluglets(strategyPlugins); 285 } 286 } 287 288 private final class tLoader extends Thread{ 289 public tLoader(){ 290 super(); 291 } 292 293 public void run(){ 294 String superClass 295 = "net.sourceforge.pavlov.pluglets.feedback.AbstractFeedbackPluglet"; 296 String dir = Pavlov.this.rb.getString(rb.TOOL_PLUGLET_DIRECTORY); 297 Pavlov.this.toolPluglets = new PlugletLoader(superClass,dir);//"pluglets/tools/"); 298 //toolPluglets.addToContainer(desktopPane); 299 Pavlov.this.uiFactory.setToolPluglets(toolPluglets); 300 } 301 } 302 303 /** 304 * Description of the Method 305 */ 306 public void createQuizSelector() 307 { 308 uiFactory.createQuizSelector(user, library); 309 } 310 311 312 /** 313 * Gets the uIBuilder attribute of the Pavlov object 314 * 315 *@return The uIBuilder value 316 */ 317 public AbstractUIFactory getUIBuilder() 318 { 319 // these 2 methods do nothing if frame, uiFactory already exist 320 makeFrame(); 321 makeUIFactory(); 322 return uiFactory; 323 } 324 325 326 /** 327 * Description of the Method 328 */ 329 public void loginFinished() 330 { 331 //FIXED: 800 X 600 was ghetto 332 sizeFrame(); 333 } 334 335 private void sizeFrame(){ 336 Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); 337 frame.setSize(new java.awt.Dimension( (int)(size.width*.8), (int)(size.height*.8))); 338 frame.setVisible(true); 339 } 340 341 /** 342 * Description of the Method 343 * 344 *@param args Description of the Parameter 345 */ 346 public static void main(String args[]) 347 { 348 try { 349 new Pavlov(args); 350 } catch (Throwable t) { 351 cat.error("Uncaught Throwable",t); 352 } 353 } 354 } 355