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/pluglets/feedback/velocity/VelocityPluglet.java,v 1.2 2004/05/13 06:07:08 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.pluglets.feedback.velocity; 021 022 import java.awt.event.*; 023 import java.io.File; 024 import java.net.URL; 025 import javax.swing.*; 026 import net.sourceforge.pavlov.event.*; 027 import net.sourceforge.pavlov.pluglets.*; 028 import net.sourceforge.sillyview.*; 029 030 031 /** 032 * A base class for Pavlov feedback pluglets. 033 * 034 * @author <a href="mailto:"></a> 035 * @version 1.0 036 */ 037 public class VelocityPluglet 038 extends JFrameView 039 implements ActionListener, AnswerListener, Pluglet 040 { 041 public static final String ANSWER_EVENT = "ANSWER_EVENT"; 042 public static final String QUIZ_DATA = "QUIZ_DATA"; 043 private String name; 044 private URL baseURL; 045 046 /** 047 * Creates a new <code>VelocityPluglet</code> instance. 048 * 049 */ 050 public VelocityPluglet(VelocityModel mod,File directory) 051 throws Exception 052 { 053 super(mod, JPanelView.JEDITORPANE); 054 // confirm directory is a directory, readable 055 name = directory.getName(); 056 baseURL = directory.toURL(); 057 setToken("BASE_URL",baseURL); 058 setTitle(getName()); 059 pack(); 060 setDefaultLookAndFeelDecorated(true); 061 init(); 062 } 063 064 public String getBaseURL() { return baseURL.toString(); } 065 066 public void setName(String name) { 067 this.name = name; 068 } 069 070 public String getName() { return name; } 071 072 // FIXME: where to get descriptions? 073 public String getDescription() { return "Velocity Pluglet"; } 074 075 /** 076 * Called when the pluglet is loaded. 077 * 078 */ 079 public void init(){}; 080 /** 081 * Called when the pluglet is opened/started by the user. 082 * 083 */ 084 public void start(){}; 085 /** 086 * Called when the pluglet is closed/stopped by the user. 087 * 088 */ 089 public void stop(){}; 090 091 /** 092 * Describe <code>actionPerformed</code> method here. 093 * 094 * @param e an <code>ActionEvent</code> value 095 */ 096 public void actionPerformed(ActionEvent e) 097 { 098 JCheckBoxMenuItem mi = (JCheckBoxMenuItem)e.getSource(); 099 if(mi.getState()) 100 { 101 start(); 102 setVisible(true); 103 } 104 else 105 { 106 setVisible(false); 107 stop(); 108 } 109 } 110 111 /** 112 * Called when the user answers a question. 113 * 114 * @param e an <code>AnswerEvent</code> value 115 */ 116 public void answerEvent(AnswerEvent e){ 117 //setToken(ANSWER_EVENT,e); 118 //setToken(QUIZ_DATA,e.getQuizData()); 119 //setToken("right",e.isCorrect()); 120 121 } 122 123 }