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/SequencedImagePluglet.java,v 1.1 2004/05/10 15:29:16 tj_willis Exp $
019     */
020    package net.sourceforge.pavlov.pluglets.feedback;
021    
022    import java.net.URL;
023    import java.io.File;
024    import net.sourceforge.pavlov.event.*;
025    import net.sourceforge.pavlov.randommedia.*;
026    import net.sourceforge.pavlov.zipUtilities.*;
027    
028    /**
029     * A base class to facilitate writing pluglets that use sequenced images.
030     *
031     * @author <a href="mailto:"></a>
032     * @version 1.0
033     */
034    public abstract class SequencedImagePluglet
035        extends AbstractFeedbackPluglet
036    {
037        /**
038         * The directory containing the sequence of images.
039         *
040         */
041        protected  SequencedMediaDirectory rights;
042    
043        /**
044         * Returns the FileFilter to use to accept image files.
045         *
046         * @return a <code>ZipCapableFileFilter</code> value
047         */
048        public abstract ZipCapableFileFilter getFileFilter();
049        /**
050         * Returns the name of the directory containing the sequence of images.
051         *
052         * @return a <code>String</code> value
053         */
054        public abstract String getDirectory();
055        /**
056         * What to do with the URL of the current image in the sequence.
057         *
058         * @param url an <code>URL</code> value
059         */
060        public abstract void handleURL(URL url);
061    
062        /**
063         * Describe <code>init</code> method here.
064         *
065         */
066        public void init(){
067            ZipCapableFileFilter filt = getFileFilter();
068            String p = getResourcePath(getDirectory());
069            if(p!=null)
070                {
071                    File me = new File(p);
072                    rights = new SequencedMediaDirectory(me,filt);
073                }
074        }
075    
076        /**
077         * Describe <code>getResourcePath</code> method here.
078         *
079         * @param in a <code>String</code> value
080         * @return a <code>String</code> value
081         */
082        public abstract String getResourcePath(String in);
083    
084        /**
085         * Updates the sequence cursor and calls handleURL to display the new
086         * image.  Implemented to only increment the cursor if answer is correct.
087         *
088         * @param e an <code>AnswerEvent</code> value
089         */
090        public void answerEvent(AnswerEvent e)
091        {
092            if(!isVisible()) return;
093            URL next = null;
094            // FIXME: NPE if no files in directory
095            if(e.isCorrect()) {
096                next = rights.getCurrentURL();
097                handleURL(next);
098            }
099        }
100    }