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/controllers/QuestionHistory.java,v 1.2 2004/07/01 09:03:41 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.controllers; 021 import java.text.SimpleDateFormat; 022 import javax.swing.text.DateFormatter; 023 import net.sourceforge.pavlov.user.QuestionData; 024 import net.sourceforge.pavlov.event.QuestionChangedListener; 025 import net.sourceforge.pavlov.library.Question; 026 import net.sourceforge.sillyview.*; 027 import java.net.URL; 028 import java.util.HashMap; 029 import org.apache.log4j.*; 030 031 /** 032 * Feedback panel that displays information about the user's 033 * history with the specified question. 034 * 035 * @since 1.1 036 * @version $Revision: 1.2 $ 037 */ 038 039 public final class QuestionHistory 040 extends Widget implements QuestionChangedListener { 041 //FIXED: rename to QuestionHistory(Controller) 042 //FIXED: moved from main to controllers 043 protected DateFormatter fmt; 044 protected SimpleDateFormat dateFormat; 045 public static final String LAST_ANSWERED = "LAST_ANSWERED"; 046 public static final String NUM_RIGHTS = "NUM_RIGHTS"; 047 public static final String TOTAL_ANSWERED = "TOTAL_ANSWERED"; 048 049 public QuestionHistory (WidgetView myView) { 050 super (myView); 051 URL u = null; 052 053 dateFormat = new SimpleDateFormat ("EEE d MMM yyyy 'at' h:mm a"); 054 fmt = new DateFormatter (dateFormat); 055 } 056 057 /** 058 * Generates some textual information about the user's history 059 * with this question and dumps it into the text JLabel. 060 */ 061 public void questionChanged (Question aQuestion, QuestionData aQuestionData) { 062 if (aQuestionData == null) 063 return; 064 065 int totalAsked = aQuestionData.getTotal (); 066 067 // Process date this question last asked 068 java.util.Date askedDate = aQuestionData.getLastAsked (); 069 070 Object lastAsked = null; 071 if (totalAsked < 1 || askedDate == null) { 072 lastAsked = null; //new NullObject (); //null;//"never"; 073 } else { 074 try { 075 lastAsked = fmt.valueToString (askedDate); //x.toString(); 076 } catch (Exception ex) { 077 lastAsked = null; //ex.toString(); 078 } 079 } 080 081 int numRights = aQuestionData.getRight (); 082 083 HashMap < Object, Object > h = new HashMap < Object, Object > (); 084 h.put (TOTAL_ANSWERED, new Integer (totalAsked).toString ()); 085 h.put (LAST_ANSWERED, lastAsked); 086 h.put (NUM_RIGHTS, new Integer (numRights).toString ()); 087 view.addTokens (h); 088 } 089 }