001    /* BEE - Book Editing Environment for PAVLOV
002     * Copyright (C) 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/bee/InsertMultipleFrame.java,v 1.3 2004/07/01 05:50:19 tj_willis Exp $
019     */
020    package net.sourceforge.bee;
021    
022    import javax.swing.*;
023    import java.awt.*;
024    import java.awt.event.*;
025    import net.sourceforge.pavlov.library.*;
026    import java.util.*;
027    
028    /**
029     * Inserts multiple blank questions into the chapter being editied.
030     *
031     * @author <a href="mailto:"></a>
032     * @version $Id: InsertMultipleFrame.java,v 1.3 2004/07/01 05:50:19 tj_willis Exp $
033     */
034    public class InsertMultipleFrame 
035    extends JInternalFrame
036    implements ActionListener
037    {
038        private JLabel lNumber;//, lRandomAnswers;//lDefault
039        private JTextField fNumber;//, fDefault;
040      private JButton bGenerate;
041        //private JRadioButton rRandomAnswers;
042      private ChapterEditor cpan;
043    
044        /**
045         * Creates a new <code>InsertMultipleFrame</code> instance.
046         *
047         * @param cPan a <code>ChapterEditor</code> value
048         */
049        public InsertMultipleFrame(ChapterEditor cPan)
050        {
051          super("Add Blank Questions");
052          setClosable(true);
053          setDefaultCloseOperation(HIDE_ON_CLOSE);
054    
055          cpan = cPan;
056          Container content = getContentPane();
057          GridLayout g = new GridLayout(4,2);
058          content.setLayout(g);
059    
060          lNumber = new JLabel("Number of Questions:");
061          fNumber = new JTextField("1");
062          content.add(lNumber);
063          content.add(fNumber);
064    
065    //       lDefault = new JLabel("Default Question Text:");
066    //       fDefault = new JTextField();
067    //       content.add(lDefault);
068    //       content.add(fDefault);
069    
070    //       rRandomAnswers = new JRadioButton();
071    //       lRandomAnswers = new JLabel("Generate Random Wrong Answers");
072    //       content.add(rRandomAnswers);
073    //       content.add(lRandomAnswers);
074    
075          bGenerate= new JButton("Generate");
076          bGenerate.addActionListener(this);
077          content.add(bGenerate);
078            
079          pack();
080        }
081    
082      private void generate()
083      {
084        Vector<Question> generated = new Vector<Question>();
085        try {
086          String s = fNumber.getText();
087          int n = Integer.parseInt(s);
088          //String d = fDefault.getText();
089          for(int i=0;i<n;i++)
090            {
091              Question q = Question.makeBlankQuestion();
092              q.setText(new String(""));
093              q.setId(new String("NOID"));
094              q.setWrongAnswer(new String(""),0);
095              q.setWrongAnswer(new String(""),1);
096              q.setWrongAnswer(new String(""),2);
097              generated.add(q);
098            }
099          cpan.addGenerated(generated);
100        } catch (Exception e) {
101          System.out.println(e);
102          return;
103        }
104      }
105    
106    
107        /**
108         * Listens for the generate button.
109         *
110         * @param e an <code>ActionEvent</code> value
111         */
112        public void actionPerformed(ActionEvent e)
113      {
114        if(e.getSource().equals(bGenerate))
115          generate();
116      }
117    
118    }
119    
120    
121    
122    
123    
124    
125