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 WARRNTY; 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/randommedia/RandomRightWrongAudioFactory.java,v 1.6 2004/05/10 14:58:54 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.randommedia; 021 022 import java.net.URL; 023 import java.io.File; 024 import org.apache.log4j.*; 025 026 /** 027 * FIXME: rewrite doc 028 * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a> 029 * @version $Revision: 1.6 $ 030 */ 031 public class RandomRightWrongAudioFactory 032 implements RandomURLProvider 033 { 034 private RandomAudioFactory rights; 035 private RandomAudioFactory wrongs; 036 //private volatile static RandomRightWrongAudioFactory instance; 037 038 // // FIXED: de-singleton this class 039 // /** 040 // * RandomRightWrongAudioFactory is implemented as a Singleton: only one 041 // * instance is available in a Java Virtual Machine. 042 // * 043 // * @return a <code>RandomRightWrongAudioFactory</code> value 044 // */ 045 // public synchronized static RandomRightWrongAudioFactory getInstance() { 046 // if (instance == null) 047 // instance = new RandomRightWrongAudioFactory(); 048 // return instance; 049 // } 050 051 /** 052 * Describe <code>clearCache</code> method here. 053 * 054 */ 055 public void clearCache() { 056 //FIXME: reimplement this 057 } 058 059 060 /** 061 * Creates a new <code>RandomRightWrongAudioFactory</code> instance. 062 * 063 */ 064 public RandomRightWrongAudioFactory() 065 { 066 File foo = new File("resources/audio/rights"); 067 File bar = new File("resources/audio/wrongs"); 068 init(foo,bar); 069 } 070 071 /** 072 * Creates a new <code>RandomRightWrongAudioFactory</code> instance. 073 * 074 */ 075 public RandomRightWrongAudioFactory(File rightDirectory, File wrongDirectory) 076 { 077 //File foo = new File("resources/audio/rights"); 078 //File bar = new File("resources/audio/wrongs"); 079 init(rightDirectory,wrongDirectory); 080 } 081 082 private void init(File rightDirectory, File wrongDirectory) 083 { 084 rights = new RandomAudioFactory(rightDirectory); 085 wrongs = new RandomAudioFactory(wrongDirectory); 086 } 087 088 /** 089 * Describe <code>playRandomRightClip</code> method here. 090 * 091 */ 092 public void playRandomRightClip() 093 { 094 rights.playRandomClip(); 095 } 096 097 /** 098 * Describe <code>playRandomWrongClip</code> method here. 099 * 100 */ 101 public void playRandomWrongClip() 102 { 103 wrongs.playRandomClip(); 104 } 105 /** 106 * Returns a count of items in enabled directories. 107 * 108 * @return an <code>int</code> value 109 */ 110 public int getNumberOfEnabledItems() { 111 return rights.getNumberOfEnabledItems() + wrongs.getNumberOfEnabledItems(); 112 } 113 114 /** 115 * Returns a count of items in enabled and disabled directories. 116 * 117 * @return an <code>int</code> value 118 */ 119 public int getNumberOfTotalItems() { 120 return rights.getNumberOfTotalItems() + wrongs.getNumberOfTotalItems(); 121 } 122 123 124 /** 125 * Returns a count of items in disabled directories. 126 * 127 * @return an <code>int</code> value 128 */ 129 public int getNumberOfDisabledItems() 130 { 131 return rights.getNumberOfDisabledItems() + wrongs.getNumberOfDisabledItems(); 132 } 133 134 135 /** 136 * Describe <code>getRandomURL</code> method here. 137 * 138 * @return an <code>URL</code> value 139 */ 140 public URL getRandomURL() 141 { 142 // flip a coin to see if it's from rights or wrongs 143 return rights.getRandomURL(); 144 } 145 146 } 147 148 149 150