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/RandomAudioFactory.java,v 1.5 2004/05/10 14:58:54 tj_willis Exp $ 019 */ 020 package net.sourceforge.pavlov.randommedia; 021 022 import java.io.File; 023 import java.awt.event.*; 024 import net.sourceforge.pavlov.zipUtilities.*; 025 import java.applet.AudioClip; 026 import org.apache.log4j.*; 027 028 /** 029 * This is a base class for random media factories. A random media factory is 030 * supplied with a directory tree or JAR file or mixture of the two, and 031 * randomly supplies a media object (i.e. an image, a sound) from the files. 032 * Implementations often will require caching/preloading. 033 * @author <a href="mailto:tj_willis@users.sourceforge.net">T.J. Willis</a> 034 * @version $Revision: 1.5 $ 035 */ 036 public class RandomAudioFactory 037 extends AbstractRandomMediaFactory 038 implements ActionListener, RandomURLProvider 039 { 040 // FIXED: de-singleton this class 041 private ZipCapableFileFilter filter; 042 private SoundList list; 043 044 045 046 047 /** 048 * Describe <code>clearCache</code> method here. 049 * 050 */ 051 public void clearCache() { 052 // FIXME: implement this 053 } 054 055 public RandomAudioFactory(File myDir) 056 { 057 // super(myDir) would save a lot of processing 058 super(myDir.toString()); 059 zinit(myDir); 060 } 061 062 private void zinit(File rootDir){ 063 setRootDirectory(rootDir); 064 list = new SoundList(this,50); 065 list.loadObjects(10); 066 } 067 068 public RandomAudioFactory() 069 { 070 super(); 071 File foo = new File("resources/audio"); 072 zinit(foo); 073 } 074 075 void loadClips(int num) 076 { 077 list.loadObjects(num); 078 } 079 080 /** 081 * Describe <code>getFileFilter</code> method here. 082 * 083 * @return a <code>ZipCapableFileFilter</code> value 084 */ 085 protected ZipCapableFileFilter getFileFilter() 086 { 087 if (filter!=null) return filter; 088 filter = new SoundFileFilter(); 089 return filter; 090 } 091 092 093 public AudioClip getRandomClip() 094 { 095 return list.getClip(); 096 097 } 098 099 /** 100 * Describe <code>playRandomClip</code> method here. 101 * 102 */ 103 public void playRandomClip() 104 { 105 assert list!=null : "Audio List is null"; 106 107 list.playClip(); 108 //list.manageCache(); 109 } 110 111 } 112 113 114 115