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/AbstractFeedbackPluglet.java,v 1.8 2004/06/27 08:16:26 tj_willis Exp $
019     */
020    package net.sourceforge.pavlov.pluglets.feedback;
021    
022    import java.awt.event.*;
023    import javax.swing.*;
024    import net.sourceforge.pavlov.event.*;
025    import net.sourceforge.pavlov.pluglets.*;
026    import net.sourceforge.pavlov.main.standalone.ResourceBroker;
027    
028    /**
029     * A base class for Pavlov feedback pluglets.
030     *
031     * @author <a href="mailto:"></a>
032     * @version 1.0
033     */
034    public abstract class AbstractFeedbackPluglet 
035        extends JDialog
036        implements ActionListener, AnswerListener, Pluglet
037    {
038        private AnswerEvent last;
039        protected ResourceBroker rb;
040        private JCheckBoxMenuItem mi;
041        
042        /**
043         * Creates a new <code>AbstractFeedbackPluglet</code> instance.
044         *
045         */
046        public AbstractFeedbackPluglet()
047        {
048            super();
049            rb = ResourceBroker.getInstance();
050            last = null;
051            //setClosable(false);
052            setTitle(getName());
053            setDefaultLookAndFeelDecorated(true);
054            init();
055        }
056    
057        /**
058         * Called when the pluglet is loaded.
059         *
060         */
061        public void init(){};
062        /**
063         * Called when the pluglet is opened/started by the user.
064         *
065         */
066        public void start(){};
067        /**
068         * Called when the pluglet is closed/stopped by the user.
069         *
070         */
071        public void stop(){};
072    
073        /**
074         * Describe <code>actionPerformed</code> method here.
075         *
076         * @param e an <code>ActionEvent</code> value
077         */
078        public void actionPerformed(ActionEvent e)
079        {
080            mi = (JCheckBoxMenuItem)e.getSource();
081            if(mi.getState())
082            {
083                start();
084                setVisible(true);
085                //if(last!=null) answerEvent(last);
086            } else {
087                setVisible(false);
088                stop();
089            }
090        }
091    
092        public void setVisible(boolean flag)
093        {
094            super.setVisible(flag);
095            if(mi==null) return;
096            mi.setState(flag);          
097        }
098        
099        /**
100         * Called when the user answers a question.
101         *
102         * @param e an <code>AnswerEvent</code> value
103         */
104        public void answerEvent(AnswerEvent e){ 
105           //last = e;
106        }
107    
108        public String toString(){
109           return getName();
110        }
111    }