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/random/AudioFeedback.java,v 1.5 2004/07/01 05:50:20 tj_willis Exp $
019     */ 
020    package net.sourceforge.pavlov.pluglets.feedback.random;
021    
022    import javax.swing.*;
023    
024    import net.sourceforge.pavlov.event.*;
025    import net.sourceforge.pavlov.feedback.old.*;
026    import net.sourceforge.pavlov.randommedia.RandomRightWrongAudioFactory;
027    import net.sourceforge.pavlov.randommedia.ImageIconUtilities;
028    import net.sourceforge.pavlov.event.MediaRootChangedListener;
029    
030    /**
031     * <code>AudioFeedback</code> is an old-style feedback module.  It shouldn't
032     * be used.
033     * @author <a href="mailto:"></a>
034     * @version $Revision: 1.5 $
035     */
036    public class AudioFeedback extends AbstractFeedbackPanel
037            implements AnswerListener, MediaRootChangedListener {
038            /**
039             * Describe variable <code>rights</code> here.
040             *
041             */
042            protected  int rights = 0;
043            /**
044             * Describe variable <code>ifac</code> here.
045             *
046             */
047            protected  RandomRightWrongAudioFactory ifac;
048            public static final String PLUGLET_FEEDBACK_AUDIO = "pluglet.feedback.audio";
049            public static final String PLUGLET_FEEDBACK_AUDIO_DESCRIPTION = "pluglet.feedback.audio.description";
050            private String correct;
051            private String incorrect;
052    
053            /**
054             * Describe <code>getName</code> method here.
055             *
056             * @return a <code>String</code> value
057             */
058            public String getName(){ return rb.getString(PLUGLET_FEEDBACK_AUDIO,"Audio Feedback"); }
059    
060            /**
061             * Describe <code>getDescription</code> method here.
062             *
063             * @return a <code>String</code> value
064             */
065            public String getDescription() { return rb.getString(PLUGLET_FEEDBACK_AUDIO_DESCRIPTION,"Old style audio-feedback"); }
066    
067            /**
068             * Creates a new <code>AudioFeedback</code> instance.
069             *
070             */
071            public AudioFeedback() {
072                    super();
073                    
074                    correct = rb.getString(rb.CORRECT);
075                    incorrect = rb.getString(rb.INCORRECT);
076                    
077                    ifac = new RandomRightWrongAudioFactory(); //.getInstance();
078                    //ifac.addMediaRootChangedListener(this);
079                    setNumberOfActiveItems(ifac.getNumberOfEnabledItems());
080    
081                    //setBackground(java.awt.Color.white);
082                    // FIXME: should use an abstract getLogoName()
083                    ImageIcon la = ImageIconUtilities.getNamedImageIcon("file:resources/audioLogo.jpg");
084                    setMessage("");
085                    jLabel4.setVisible(false);
086                    jCheckBox1.setVisible(false);
087                    // FIXME: should use an abstract getDirectoryName()
088                    setDirectoryName("resources/audio/");
089                    imageLabel.setIcon(la);
090                    pack();
091            }
092    
093            /**
094             * Describe <code>makeTitle</code> method here.
095             *
096             * @deprecated Broken in 1.0 push.
097             *
098             */
099            @Deprecated protected void makeTitle() {
100                    String x = null;
101                    // display sound's url
102                    //    if(cacheObject!=null)
103                    //  x = cacheObject.getFileShortName();
104    
105                    if (x != null){
106                            super.setTitle( x);
107                    }
108            }
109    
110            /**
111             * Describe <code>answerEvent</code> method here.
112             *
113             * @param e an <code>AnswerEvent</code> value
114             */
115            public void answerEvent(AnswerEvent e) {
116                    if(!isVisible()) return;
117                    String msg = correct;//"Correct!";
118                    if(e.isCorrect()){
119                            ifac.playRandomRightClip();
120                    } else {
121                            ifac.playRandomWrongClip();
122                            msg = incorrect;//"Incorrect.";
123                    }
124                    //String msg = "<HTML>";
125                    //msg += mode.getMessage();
126                    setMessage(msg);
127                    pack();
128            }
129    
130            /**
131             * Describe <code>setMessage</code> method here.
132             *
133             * @param pre a <code>String</code> value
134             * @deprecated Broken in 1.0 push.
135             */
136            @Deprecated protected void setMessage(String pre)
137            {
138            }
139    
140    
141            /**
142             * Describe <code>mediaRootChanged</code> method here.
143             *
144             */
145            public void mediaRootChanged()
146            {
147                    // FIXME: This doesn't appear to be registered as a mediarootchangedlistener with ifac.
148                    setNumberOfActiveItems(ifac.getNumberOfEnabledItems());
149            }
150    
151    }
152    
153    
154    
155    
156    
157    
158    
159