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/rightWrong/MediaDirectoryPluglet.java,v 1.4 2004/05/10 15:25:17 tj_willis Exp $
019     */
020    package net.sourceforge.pavlov.pluglets.feedback.rightWrong;
021    
022    import java.net.URL;
023    import java.io.File;
024    import net.sourceforge.pavlov.event.*;
025    import net.sourceforge.pavlov.pluglets.feedback.*;
026    import net.sourceforge.pavlov.randommedia.*;
027    import net.sourceforge.pavlov.zipUtilities.*;
028    
029    /**
030     * This class pulls media items from two directories, a "right" directory
031     * and a "wrong" directory.  The items are pulled sequentially, with cursors
032     * maintained in both directories.  Implement the handleURL() method to 
033     * use the resulting URL's to respond to the user's response.
034     *
035     * @author <a href="mailto:"></a>
036     * @version 1.0
037     */
038    public abstract class MediaDirectoryPluglet
039    extends AbstractFeedbackPluglet
040    {
041        /**
042         * Directory containing sequenced media for correct responses.
043         *
044         */
045        protected  SequencedMediaDirectory rights;
046        /**
047         * Directory containing sequenced media for incorrect responses.
048         *
049         */
050        protected  SequencedMediaDirectory wrongs;
051    
052        /**
053         * Describe <code>getFileFilter</code> method here.
054         *
055         * @return a <code>ZipCapableFileFilter</code> value
056         */
057        public abstract ZipCapableFileFilter getFileFilter();
058        /**
059         * Describe <code>getRightDirectory</code> method here.
060         *
061         * @return a <code>String</code> value
062         */
063        public abstract String getRightDirectory();
064        /**
065         * Describe <code>getWrongDirectory</code> method here.
066         *
067         * @return a <code>String</code> value
068         */
069        public abstract String getWrongDirectory();
070        /**
071         * Implement this method to present the media at the given URL to
072         * the user.
073         *
074         * @param url an <code>URL</code> value
075         */
076        public abstract void handleURL(URL url);
077    
078        /**
079         * Describe <code>init</code> method here.
080         *
081         */
082        public void init(){
083    
084        ZipCapableFileFilter filt = getFileFilter();
085        String p = getResourcePath(getRightDirectory());
086        if(p!=null)
087          {
088            File me = new File(p);
089            rights = new SequencedMediaDirectory(me,filt);
090          }
091        p = getResourcePath(getWrongDirectory());
092        if( p!=null)
093          {
094            File me2 = new File(p);
095            wrongs = new SequencedMediaDirectory(me2,filt);
096          }
097      }
098    
099        /**
100         * Describe <code>getResourcePath</code> method here.
101         *
102         * @param in a <code>String</code> value
103         * @return a <code>String</code> value
104         */
105        public abstract String getResourcePath(String in);
106    
107    
108        /**
109         * User has answered a question, if correct, get the next URL from the
110         * rights directory, if incorrect, get URL from wrongs directory.  Call
111         * handleURL on the resulting URL.
112         *
113         * @param e an <code>AnswerEvent</code> value
114         */
115        public void answerEvent(AnswerEvent e)
116      {
117        if(!isVisible()) return;
118        URL next = null;
119        // NPE if no files in directory
120        if(e.isCorrect()) next = rights.getCurrentURL();
121        else next = wrongs.getCurrentURL();
122        handleURL(next);
123      }
124    
125    
126    }