[sword-cvs] r47 - trunk/app/src/org/crosswire/flashcards
Apache
apache at crosswire.org
Sun Sep 19 10:42:29 MST 2004
Author:
Date: 2004-09-19 10:42:28 -0700 (Sun, 19 Sep 2004)
New Revision: 47
Added:
trunk/app/src/org/crosswire/flashcards/EditPane.java
trunk/app/src/org/crosswire/flashcards/FlashCardColumns.java
trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java
trunk/app/src/org/crosswire/flashcards/FlashCardPane.java
trunk/app/src/org/crosswire/flashcards/FlashCardRep.java
trunk/app/src/org/crosswire/flashcards/LessonChangeEvent.java
trunk/app/src/org/crosswire/flashcards/LessonChangeEventListener.java
trunk/app/src/org/crosswire/flashcards/LessonPane.java
trunk/app/src/org/crosswire/flashcards/LessonSetPane.java
trunk/app/src/org/crosswire/flashcards/QuizPane.java
Modified:
trunk/app/src/org/crosswire/flashcards/Debug.java
trunk/app/src/org/crosswire/flashcards/Editor.java
trunk/app/src/org/crosswire/flashcards/EditorFrame.java
trunk/app/src/org/crosswire/flashcards/EditorFrame_AboutBox.java
trunk/app/src/org/crosswire/flashcards/FlashCard.java
trunk/app/src/org/crosswire/flashcards/Lesson.java
trunk/app/src/org/crosswire/flashcards/LessonManager.java
trunk/app/src/org/crosswire/flashcards/LessonSet.java
trunk/app/src/org/crosswire/flashcards/MainFrame.java
trunk/app/src/org/crosswire/flashcards/MainMenu.java
trunk/app/src/org/crosswire/flashcards/Quiz.java
trunk/app/src/org/crosswire/flashcards/SetupPane.java
Log:
edit tab and misc improvements
Modified: trunk/app/src/org/crosswire/flashcards/Debug.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/Debug.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/Debug.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -30,7 +30,7 @@
package org.crosswire.flashcards;
-import java.io.*;
+import java.io.PrintStream;
class Debug {
Added: trunk/app/src/org/crosswire/flashcards/EditPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/EditPane.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/EditPane.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,112 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JPanel;
+import javax.swing.JSplitPane;
+
+import org.crosswire.common.swing.FixedSplitPane;
+
+
+/**
+ * An EditPane consists of Lesson Sets, Lessons and Flash Cards.
+ *
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class EditPane extends JPanel
+{
+ //Construct the frame
+ public EditPane()
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private void jbInit() throws Exception
+ {
+ setLayout(new BorderLayout());
+ setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
+ "Create and modify Lesson Sets, Lessons and Flash Cards "));
+
+ LessonSetPane lessonSetPanel = new LessonSetPane(true);
+ LessonPane lessonPanel = new LessonPane(true);
+ FlashCardPane flashCardPanel = new FlashCardPane(true);
+ final JButton saveButton = new JButton("Save");
+
+ saveButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ System.err.println("do save");
+
+ }
+ });
+
+ LessonChangeEventListener changeListener = new LessonChangeEventListener()
+ {
+ public void lessonChanged(LessonChangeEvent event)
+ {
+ boolean modified = LessonManager.instance().isModified();
+ saveButton.setEnabled(modified);
+ }
+
+ };
+
+ boolean modified = LessonManager.instance().isModified();
+ saveButton.setEnabled(modified);
+
+ lessonSetPanel.addLessonChangeEvent(changeListener);
+ lessonPanel.addLessonChangeEvent(changeListener);
+ flashCardPanel.addLessonChangeEvent(changeListener);
+
+ lessonSetPanel.addListSelectionListener(lessonPanel);
+ lessonPanel.addListSelectionListener(flashCardPanel);
+
+ JSplitPane horizontalSplitPane = new FixedSplitPane();
+ horizontalSplitPane.setResizeWeight(0.3D);
+ horizontalSplitPane.setDividerLocation(0.3D);
+ horizontalSplitPane.setRightComponent(lessonPanel);
+ horizontalSplitPane.setLeftComponent(lessonSetPanel);
+
+ JSplitPane verticalSplitPane = new FixedSplitPane(JSplitPane.VERTICAL_SPLIT);
+ verticalSplitPane.setDividerLocation(0.5D);
+ verticalSplitPane.setResizeWeight(0.5D);
+ verticalSplitPane.setTopComponent(horizontalSplitPane);
+ verticalSplitPane.setBottomComponent(flashCardPanel);
+ add(verticalSplitPane, BorderLayout.CENTER);
+
+ JPanel buttonPane = new JPanel();
+ buttonPane.add(saveButton);
+ add(buttonPane, BorderLayout.SOUTH);
+ }
+}
Modified: trunk/app/src/org/crosswire/flashcards/Editor.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/Editor.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/Editor.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -30,9 +30,6 @@
package org.crosswire.flashcards;
-import java.awt.Dimension;
-import java.awt.Toolkit;
-
import javax.swing.UIManager;
public class Editor {
@@ -50,7 +47,7 @@
// ---------------
public Editor(LessonManager lessonManager, boolean standAlone ) {
- EditorFrame frame = new EditorFrame(lessonManager, standAlone );
+ EditorFrame frame = new EditorFrame( standAlone );
//Validate frames that have preset sizes
//Pack frames that have useful preferred size info, e.g. from their layout
@@ -108,7 +105,7 @@
}
- new Editor(new LessonManager(), true );
+ new Editor(LessonManager.instance(), true );
}
Modified: trunk/app/src/org/crosswire/flashcards/EditorFrame.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/EditorFrame.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/EditorFrame.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -65,7 +65,6 @@
public class EditorFrame extends JFrame {
- private LessonManager lessonManager;
//
// Attributes
//
@@ -122,8 +121,7 @@
//
// ---------------
- public EditorFrame(LessonManager lessonManager, boolean standAlone ) {
- this.lessonManager = lessonManager;
+ public EditorFrame( boolean standAlone ) {
this.standAlone = standAlone;
enableEvents( AWTEvent.WINDOW_EVENT_MASK );
Modified: trunk/app/src/org/crosswire/flashcards/EditorFrame_AboutBox.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/EditorFrame_AboutBox.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/EditorFrame_AboutBox.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -36,6 +36,10 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
+/**
+ *
+ * @author Troy A. Griffitts [scribe at crosswire dot org]
+ */
public class EditorFrame_AboutBox extends JDialog implements ActionListener {
JPanel panel1 = new JPanel();
Modified: trunk/app/src/org/crosswire/flashcards/FlashCard.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCard.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/FlashCard.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -34,9 +34,9 @@
* Create a partial FlashCard.
* @param front
*/
- public FlashCard(String front)
+ public FlashCard()
{
- this(front, "");
+ this("", "");
}
/**
@@ -46,9 +46,16 @@
*/
public FlashCard(String front, String back)
{
- this.front = front;
- this.back = back;
- modified = true;
+ original = new FlashCardRep(front, back);
+
+ try
+ {
+ copy = (FlashCardRep) original.clone();
+ }
+ catch (CloneNotSupportedException e)
+ {
+ assert false;
+ }
}
/**
@@ -57,9 +64,9 @@
* @param front
* @return the requested side
*/
- public String getSide(boolean front)
+ public String getSide(boolean frontside)
{
- if (front)
+ if (frontside)
{
return getFront();
}
@@ -71,7 +78,7 @@
*/
public String getBack()
{
- return back;
+ return copy.getBack();
}
/**
@@ -79,11 +86,7 @@
*/
public void setBack(String newBack)
{
- if (newBack != null && !newBack.equals(back))
- {
- modified = true;
- back = newBack;
- }
+ copy.setBack(newBack);
}
/**
@@ -91,7 +94,7 @@
*/
public String getFront()
{
- return front;
+ return copy.getFront();
}
/**
@@ -99,19 +102,40 @@
*/
public void setFront(String newFront)
{
- if (newFront != null && !newFront.equals(this.front))
- {
- modified = true;
- front = newFront;
- }
+ copy.setFront(newFront);
}
/**
+ * Method reset
+ */
+ public void reset()
+ {
+ copy.assign(original);
+ }
+
+ /**
+ * Method isIncomplete
+ * @return boolean
+ */
+ public boolean isIncomplete()
+ {
+ return copy.isIncomplete();
+ }
+
+ /**
+ * Method setOriginal
+ */
+ public void setOriginal()
+ {
+ original.assign(copy);
+ }
+
+ /**
* @return Returns whether this FlashCard has been modified.
*/
protected boolean isModified()
{
- return modified;
+ return !original.equals(copy);
}
/* (non-Javadoc)
@@ -132,8 +156,7 @@
if (!(obj instanceof FlashCard))
return false;
FlashCard otherCard = (FlashCard) obj;
- return front.equals(otherCard.front)
- && back.equals(otherCard.back);
+ return copy.equals(otherCard.copy);
}
/* (non-Javadoc)
@@ -141,9 +164,7 @@
*/
public int hashCode()
{
- int hashCode = 31 + front.hashCode();
- hashCode = 31 * hashCode + back.hashCode();
- return hashCode;
+ return copy.hashCode();
}
/* (non-Javadoc)
@@ -151,7 +172,7 @@
*/
public String toString()
{
- return front + " " + back;
+ return copy.toString();
}
/* (non-Javadoc)
@@ -160,15 +181,9 @@
public int compareTo(Object obj)
{
FlashCard otherCard = (FlashCard) obj;
- int result = front.compareTo(otherCard.front);
- if (result == 0)
- {
- result = back.compareTo(otherCard.back);
- }
- return result;
+ return copy.compareTo(otherCard.copy);
}
- private String front;
- private String back;
- private transient boolean modified;
-}
\ No newline at end of file
+ private FlashCardRep original;
+ private FlashCardRep copy;
+}
Added: trunk/app/src/org/crosswire/flashcards/FlashCardColumns.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardColumns.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardColumns.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,163 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import org.crosswire.common.swing.RowColumns;
+
+/**
+ * Defines the prototypes needed to display a FlashCard in a RowTable.
+ *
+ * @author DM Smith [ dmsmith555 at yahoo dot com]
+ */
+public class FlashCardColumns extends RowColumns
+{
+ /**
+ * Field HEADERS
+ * The names of the table column headers.
+ */
+ private static final String[] HEADERS =
+ {
+ "Front", "Back" //$NON-NLS-1$ //$NON-NLS-2$
+ };
+
+ /**
+ * Field HEADER_TOOLTIPS
+ * The tooltips for the table column headers.
+ */
+ private static final String[] HEADER_TOOLTIPS =
+ {
+ "Front of the FlashCard", "Back of the FlashCard" //$NON-NLS-1$ //$NON-NLS-2$
+ };
+
+ /**
+ * Field CHARACTER_WIDTHS
+ * The widths of each column in Standard Characters.
+ */
+ private static final int[] CHARACTER_WIDTHS =
+ {
+ 16, 32
+ };
+
+ /**
+ * Field FIXED_WIDTHS
+ * The columns that cannot be resized are true.
+ * The columns that can be resized are false.
+ */
+ private static final boolean[] FIXED_WIDTHS =
+ {
+ false, false
+ };
+
+ /**
+ * Field CLASSES
+ * Gives object type of contained in each of the column.
+ */
+ private static final Class[] CLASSES =
+ {
+ String.class, String.class
+ };
+
+ /**
+ * Field SORT_KEYS
+ * The numerical index (0 based) of the columns that
+ * participate in default sorting and column
+ * sorting.
+ */
+ private static final int[] SORT_KEYS =
+ {
+ 0
+ };
+
+ /**
+ * Field TABLE_NAME
+ * The Title of the table displayed in a titled border.
+ */
+ private static final String TABLE_NAME = "FlashCards: "; //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * @see FlashCardColumns#getHeaders()
+ */
+ public String[] getHeaders()
+ {
+ return FlashCardColumns.HEADERS;
+ }
+
+ /* (non-Javadoc)
+ * @see FlashCardColumns#getHeaderToolTips()
+ */
+ public String[] getHeaderToolTips()
+ {
+ return FlashCardColumns.HEADER_TOOLTIPS;
+ }
+
+ /* (non-Javadoc)
+ * @see FlashCardColumns#getCharacterWidths()
+ */
+ public int[] getCharacterWidths()
+ {
+ return FlashCardColumns.CHARACTER_WIDTHS;
+ }
+
+ /* (non-Javadoc)
+ * @see FlashCardColumns#getFixedWidths()
+ */
+ public boolean[] getFixedWidths()
+ {
+ return FlashCardColumns.FIXED_WIDTHS;
+ }
+
+ /* (non-Javadoc)
+ * @see FlashCardColumns#getClasses()
+ */
+ public Class[] getClasses()
+ {
+ return FlashCardColumns.CLASSES;
+ }
+
+ /* (non-Javadoc)
+ * @see FlashCardColumns#getSortKeys()
+ */
+ public int[] getSortKeys()
+ {
+ return FlashCardColumns.SORT_KEYS;
+ }
+
+ /* (non-Javadoc)
+ * @see RowColumns#getValueAt(java.lang.Object, int)
+ */
+ public Object getValueAt(Object row, int columnIndex)
+ {
+ FlashCard flashCard = (FlashCard) row;
+ if (flashCard != null)
+ {
+ return flashCard.getSide(columnIndex == 0);
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see FlashCardColumns#getTableName()
+ */
+ public String getTableName()
+ {
+ return FlashCardColumns.TABLE_NAME;
+ }
+}
\ No newline at end of file
Added: trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,184 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.awt.BorderLayout;
+import java.awt.ComponentOrientation;
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+import javax.swing.WindowConstants;
+
+import org.crosswire.modedit.UniTextEdit;
+
+/**
+ * Editor for lessons used by Quiz (part of FlashCards).
+ *
+ * @author Troy A. Griffitts [scribe at crosswire dot org]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class FlashCardEditor extends JPanel
+{
+
+ //
+ // Attributes
+ //
+
+ private JPanel answerPanel = new JPanel();
+ private JTextField answers = new JTextField();
+ private UniTextEdit wordText = new UniTextEdit();
+ protected JDialog dlgMain;
+
+ //
+ // Methods
+ //
+
+ // ---------------
+ public FlashCardEditor()
+ {
+ try
+ {
+ jbInit();
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace();
+ Debug.error(this.toString(), exception.getMessage());
+ }
+ }
+
+ //Component initialization
+ private void jbInit() throws Exception
+ {
+ setLayout(new BorderLayout());
+
+ wordText.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Front"));
+ wordText.setText("");
+ wordText.showIMSelect(true);
+ wordText.setComponentOrientation(ComponentOrientation.UNKNOWN);
+ wordText.setFontSize(30);
+ add(wordText, BorderLayout.CENTER);
+
+ answers.setSelectionStart(0);
+ answers.setText("");
+ answerPanel.setLayout(new BorderLayout());
+ answerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Back"));
+ answerPanel.add(answers);
+ add(answerPanel, BorderLayout.SOUTH);
+ }
+
+ protected boolean createFlashCard(FlashCardPane flashCardPane)
+ {
+
+ String front = wordText.getText();
+ String back = answers.getText();
+
+ if (front == null || front.length() == 0)
+ {
+ JOptionPane.showMessageDialog(null, "Front is empty", "Unable to Create Flash Card", JOptionPane.PLAIN_MESSAGE);
+ return false;
+ }
+ if (back == null || back.length() == 0)
+ {
+ JOptionPane.showMessageDialog(null, "Back is empty", "Unable to Create Flash Card", JOptionPane.PLAIN_MESSAGE);
+ return false;
+ }
+ // Create a new flash card
+ FlashCard flashCard = new FlashCard();
+ flashCard.setFront(front);
+ flashCard.setBack(back);
+ if (flashCardPane.contains(flashCard))
+ {
+ JOptionPane.showMessageDialog(null, "FlashCard already exists", "Unable to Create Flash Card", JOptionPane.PLAIN_MESSAGE);
+ return false;
+ }
+ flashCardPane.add(flashCard);
+ return true;
+ }
+
+ /**
+ * Open this Panel in it's own dialog box.
+ */
+ public void showInDialog(final FlashCardPane flashCardPane)
+ {
+ dlgMain = new JDialog(JOptionPane.getFrameForComponent(flashCardPane), "Create a Flash Card", true);
+ dlgMain.setSize(new Dimension(320, 240));
+ dlgMain.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
+
+ JComponent contentPane = (JComponent) dlgMain.getContentPane();
+ contentPane.setLayout(new BorderLayout());
+ contentPane.add(this, BorderLayout.CENTER);
+
+ JButton btnAdd = new JButton("Create");
+
+ btnAdd.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ if (createFlashCard(flashCardPane))
+ {
+ wordText.setText("");
+ answers.setText("");
+ }
+ }
+ });
+
+ JButton btnOK = new JButton("OK");
+ btnOK.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ if (createFlashCard(flashCardPane))
+ {
+ dlgMain.dispose();
+ }
+ }
+ });
+
+
+ JButton btnClose = new JButton("Close");
+
+ btnClose.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ dlgMain.dispose();
+ }
+ });
+
+ JPanel pnlButtons = new JPanel();
+ pnlButtons.add(btnAdd);
+ pnlButtons.add(btnOK);
+ pnlButtons.add(btnClose);
+
+ contentPane.add(pnlButtons, BorderLayout.SOUTH);
+ dlgMain.setLocationRelativeTo(flashCardPane);
+ dlgMain.show();
+ }
+}
Added: trunk/app/src/org/crosswire/flashcards/FlashCardPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardPane.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardPane.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,237 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.swing.BorderFactory;
+import javax.swing.JList;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+import org.crosswire.common.swing.RowTable;
+import org.crosswire.common.swing.RowTableModel;
+
+/**
+ * A panel listing the Flash Cards in a Lesson.
+ *
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class FlashCardPane extends JPanel implements ListSelectionListener
+{
+ private RowTable wordList = new RowTable(new ArrayList(), new FlashCardColumns());
+ private boolean editable;
+ private JMenuItem newItem;
+ private JMenuItem deleteItem;
+ private Lesson lesson;
+
+ /**
+ * The listeners for handling ViewEvent Listeners
+ */
+ private EventListenerList listenerList = new EventListenerList();
+
+
+ public FlashCardPane()
+ {
+ this(false);
+ }
+
+ /**
+ * @param b
+ */
+ public FlashCardPane(boolean allowsEdits)
+ {
+ editable = allowsEdits;
+ try
+ {
+ jbInit();
+ }
+ catch (Exception exception)
+ {
+ exception.printStackTrace();
+ Debug.error(this.toString(), exception.getMessage());
+ }
+ }
+
+ //Component initialization
+ private void jbInit() throws Exception
+ {
+ setLayout(new BorderLayout());
+ setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Flash Cards: "));
+
+ wordList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ add(new JScrollPane(wordList), BorderLayout.CENTER);
+
+ JMenuBar menuBar = new JMenuBar();
+ JMenu editMenu = new JMenu("Edit");
+ newItem = new JMenuItem("New Flash Card");
+ deleteItem = new JMenuItem("Delete Flash Card");
+ menuBar.add(editMenu);
+ editMenu.add(newItem);
+ editMenu.add(deleteItem);
+ if (editable)
+ {
+ add(menuBar, BorderLayout.NORTH);
+ }
+ enableControls();
+ newItem.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ FlashCardEditor flashCardEditor = new FlashCardEditor();
+ flashCardEditor.showInDialog(FlashCardPane.this);
+ }
+ });
+ deleteItem.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ deleteSelected();
+ }
+ });
+ wordList.addListSelectionListener(new ListSelectionListener()
+ {
+
+ public void valueChanged(ListSelectionEvent e)
+ {
+ if (e.getValueIsAdjusting())
+ {
+ return;
+ }
+ enableControls();
+ }
+
+ });
+ }
+
+ public boolean contains(FlashCard flashCard)
+ {
+ return lesson.contains(flashCard);
+ }
+
+ public void add(FlashCard flashCard)
+ {
+ lesson.add(flashCard);
+ RowTableModel model = (RowTableModel) wordList.getModel();
+ model.addRow(flashCard);
+ wordList.selectRow(model.getRow(flashCard));
+
+ fireLessonChanged(new LessonChangeEvent(this));
+ }
+
+ public void deleteSelected()
+ {
+ int row = wordList.getSelectedRow();
+ RowTableModel model = (RowTableModel) wordList.getModel();
+ FlashCard flashCard = (FlashCard) model.getRow(row);
+ lesson.remove(flashCard);
+ model.removeRow(flashCard);
+ fireLessonChanged(new LessonChangeEvent(this));
+ }
+
+ protected void enableControls()
+ {
+ newItem.setEnabled(lesson != null);
+ int selectedRow = wordList.getSelectedRow();
+ deleteItem.setEnabled(-1 != selectedRow);
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
+ */
+ public void valueChanged(ListSelectionEvent e)
+ {
+ if (e.getValueIsAdjusting())
+ {
+ return;
+ }
+
+ JList list = (JList) e.getSource();
+ RowTableModel model = (RowTableModel) wordList.getModel();
+ model.clear();
+ lesson = null;
+ // If only one is selected then we show its flash cards
+ Object[] lessons = list.getSelectedValues();
+ if (lessons != null && lessons.length == 1)
+ {
+ lesson = (Lesson) lessons[0];
+ Iterator flashCardIterator = lesson.iterator();
+ while (flashCardIterator.hasNext())
+ {
+ FlashCard flashCard = (FlashCard) flashCardIterator.next();
+ model.addRow(flashCard);
+ }
+ }
+ enableControls();
+ }
+
+ /**
+ * Adds a view event listener for notification of any changes to the view.
+ *
+ * @param listener the listener
+ */
+ public synchronized void addLessonChangeEvent(LessonChangeEventListener listener)
+ {
+ listenerList.add(LessonChangeEventListener.class, listener);
+ }
+
+ /**
+ * Removes a view event listener.
+ *
+ * @param listener the listener
+ */
+ public synchronized void removeLessonChangeEvent(LessonChangeEventListener listener)
+ {
+ listenerList.remove(LessonChangeEventListener.class, listener);
+ }
+
+ /**
+ * Notify the listeners that the view has been removed.
+ *
+ * @param e the event
+ * @see EventListenerList
+ */
+ public void fireLessonChanged(LessonChangeEvent e)
+ {
+ // Guaranteed to return a non-null array
+ Object[] listeners = listenerList.getListenerList();
+ // Process the listeners last to first, notifying
+ // those that are interested in this event
+ for (int i = listeners.length - 2; i >= 0; i -= 2)
+ {
+ if (listeners[i] == LessonChangeEventListener.class)
+ {
+ ((LessonChangeEventListener) listeners[i + 1]).lessonChanged(e);
+ }
+ }
+ }
+}
Added: trunk/app/src/org/crosswire/flashcards/FlashCardRep.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardRep.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardRep.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,166 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+/**
+ * A FlashCard has a front and a back. The front has the test
+ * and the back has the answer.
+ *
+ * @author Troy A. Griffitts [scribe at crosswire dot org]
+ * @author DM Smith [ dmsmith555 at yahoo dot com]
+ */
+public class FlashCardRep implements Cloneable, Comparable
+{
+ /**
+ * Create a partial FlashCard.
+ * @param front
+ */
+ public FlashCardRep(String front)
+ {
+ this(front, "");
+ }
+
+ /**
+ * Create a complete FlashCard
+ * @param front
+ * @param back
+ */
+ public FlashCardRep(String front, String back)
+ {
+ this.front = front;
+ this.back = back;
+ }
+
+ /**
+ * Get a particular side of this FlashCard.
+ * This is useful to flip the cards.
+ * @param front
+ * @return the requested side
+ */
+ public String getSide(boolean frontside)
+ {
+ if (frontside)
+ {
+ return getFront();
+ }
+ return getBack();
+ }
+
+ /**
+ * @return Returns the back.
+ */
+ public String getBack()
+ {
+ return back;
+ }
+
+ /**
+ * @param newBack The back to set.
+ */
+ public void setBack(String newBack)
+ {
+ back = newBack;
+ }
+
+ /**
+ * @return Returns the front.
+ */
+ public String getFront()
+ {
+ return front;
+ }
+
+ /**
+ * @param newFront The front to set.
+ */
+ public void setFront(String newFront)
+ {
+ front = newFront;
+ }
+
+ public void assign(FlashCardRep rep)
+ {
+ front = rep.front;
+ back = rep.back;
+ }
+
+ public boolean isIncomplete()
+ {
+ return (back.length() == 0 || front.length() == 0);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#clone()
+ */
+ public Object clone() throws CloneNotSupportedException
+ {
+ return super.clone();
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (!(obj instanceof FlashCardRep))
+ return false;
+ FlashCardRep otherCard = (FlashCardRep) obj;
+ return front.equals(otherCard.front)
+ && back.equals(otherCard.back);
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode()
+ {
+ int hashCode = 31 + front.hashCode();
+ hashCode = 31 * hashCode + back.hashCode();
+ return hashCode;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#toString()
+ */
+ public String toString()
+ {
+ return front + " " + back;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Comparable#compareTo(java.lang.Object)
+ */
+ public int compareTo(Object obj)
+ {
+ FlashCardRep otherCard = (FlashCardRep) obj;
+ int result = front.compareTo(otherCard.front);
+ if (result == 0)
+ {
+ result = back.compareTo(otherCard.back);
+ }
+ return result;
+ }
+
+ private String front;
+ private String back;
+}
Modified: trunk/app/src/org/crosswire/flashcards/Lesson.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/Lesson.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/Lesson.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -18,6 +18,26 @@
* The copyright to this program is held by it's authors
* Copyright: 2004
*/
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
package org.crosswire.flashcards;
import java.io.File;
@@ -29,9 +49,10 @@
import java.util.Set;
import java.util.TreeSet;
-import org.crosswire.common.CWClassLoader;
-import org.crosswire.common.ResourceUtil;
+import org.crosswire.common.util.CWClassLoader;
+import org.crosswire.common.util.ResourceUtil;
+
/**
* A Lesson is an ordered list of FlashCards.
* The lesson also has a description which is useful for showing to a user.
@@ -42,29 +63,70 @@
public class Lesson implements Comparable
{
/**
+ * Construct a new, empty lesson.
+ * @param aFilename
+ */
+ public Lesson()
+ {
+ this("NewLesson.flash", "New Lesson");
+ loaded = true;
+ modified = true;
+ }
+
+ /**
+ * Construct a lesson from file.
+ * @param aFilename
+ */
+ public Lesson(String aFilename)
+ {
+ this(aFilename, null);
+ }
+
+ /**
* Construct a fully described, empty lesson.
- * @param filename
- * @param description
+ * @param aFilename
+ * @param aDescription
*/
- public Lesson(String filename, String description)
+ public Lesson(String aFilename, String aDescription)
{
- this.filename = filename;
- this.description = description;
+ this.filename = aFilename;
+ this.description = aDescription;
flashCards = new TreeSet();
- load();
}
/**
- * Appends the specified <code>FlashCard</code> to the end of this list.
+ * Adds the specified <code>FlashCard</code> to this Lesson.
*
- * @param flashCard to be appended to this list.
+ * @param flashCard to be added.
*/
public void add(FlashCard flashCard)
{
+ load();
flashCards.add(flashCard);
}
/**
+ * Removes the specified <code>FlashCard</code> from the lesson.
+ *
+ * @param flashCard to be removed.
+ */
+ public void remove(FlashCard flashCard)
+ {
+ load();
+ flashCards.remove(flashCard);
+ }
+
+ /**
+ * @param flashCard
+ * @return
+ */
+ public boolean contains(FlashCard flashCard)
+ {
+ load();
+ return flashCards.contains(flashCard);
+ }
+
+ /**
* @return Returns the filename.
*/
public String getFilename()
@@ -73,6 +135,14 @@
}
/**
+ * @param filename The filename to set.
+ */
+ public void setFilename(String filename)
+ {
+ this.filename = filename;
+ }
+
+ /**
* @return Returns the description.
*/
public String getDescription()
@@ -93,10 +163,31 @@
}
/**
+ * @return Returns the font.
+ */
+ public String getFont()
+ {
+ return font;
+ }
+
+ /**
+ * @param font The font to set.
+ */
+ public void setFont(String newFont)
+ {
+ if (newFont != null && !newFont.equals(font))
+ {
+ modified = true;
+ font = newFont;
+ }
+ }
+
+ /**
* @return Returns the flashCards.
*/
public Iterator iterator()
{
+ load();
return flashCards.iterator();
}
@@ -109,7 +200,7 @@
{
return true;
}
- Iterator iter = flashCards.iterator();
+ Iterator iter = iterator();
while (iter.hasNext())
{
FlashCard flashCard = (FlashCard) iter.next();
@@ -143,22 +234,29 @@
*/
public void load()
{
- Properties lesson = new Properties();
+ if (loaded)
+ {
+ return;
+ }
+
+ loaded = true;
+
try
{
URL lessonURL = ResourceUtil.getResource(filename);
+ Properties lesson = new Properties();
lesson.load(lessonURL.openConnection().getInputStream());
+ int wordCount = Integer.parseInt(lesson.getProperty("wordCount"));
+ for (int i = 0; i < wordCount; i++)
+ {
+ add(new FlashCard(lesson.getProperty("word" + i), lesson.getProperty("answers" + i)));
+ }
}
catch (Exception e1)
{
- e1.printStackTrace();
+ /* ignore it */;
}
- int wordCount = Integer.parseInt(lesson.getProperty("wordCount"));
- for (int i = 0; i < wordCount; i++)
- {
- add(new FlashCard(lesson.getProperty("word" + i), lesson.getProperty("answers" + i)));
- }
}
/**
@@ -166,6 +264,7 @@
*/
public void store()
{
+ load();
Properties lesson = new Properties();
try
{
@@ -210,6 +309,11 @@
private String description;
/**
+ * A path to the <code>font</code> to be used by the lesson.
+ */
+ private String font;
+
+ /**
* An ordered list of <code>flashCards</code>
*/
private Set flashCards;
@@ -218,4 +322,10 @@
* Flag indicating whether this lesson has been <code>modified</code>
*/
private boolean modified;
+
+ /**
+ * Flag indicating whether this lesson has been <code>loaded</code>
+ */
+ private boolean loaded;
+
}
\ No newline at end of file
Added: trunk/app/src/org/crosswire/flashcards/LessonChangeEvent.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonChangeEvent.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/LessonChangeEvent.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,43 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.util.EventObject;
+
+/**
+ * A LessonChangeEvent indicates that a lesson has changed and
+ * needs to be saved.
+ *
+ * @author DM Smith [ dmsmith555 at yahoo dot com]
+ */
+public class LessonChangeEvent extends EventObject
+{
+
+ /**
+ * @param source
+ */
+ public LessonChangeEvent(Object source)
+ {
+ super(source);
+ }
+
+
+}
Added: trunk/app/src/org/crosswire/flashcards/LessonChangeEventListener.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonChangeEventListener.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/LessonChangeEventListener.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,33 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.util.EventListener;
+
+/**
+ * An interface that defines a listener of LessonChangeEvents.
+ *
+ * @author DM Smith [ dmsmith555 at yahoo dot com]
+ */
+public interface LessonChangeEventListener extends EventListener
+{
+ void lessonChanged(LessonChangeEvent event);
+}
Modified: trunk/app/src/org/crosswire/flashcards/LessonManager.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonManager.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/LessonManager.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -34,7 +34,7 @@
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import org.crosswire.common.CWClassLoader;
+import org.crosswire.common.util.CWClassLoader;
/**
* The <code>LessonManager</code> provides the management of <code>LessonSet</code>s.
@@ -42,10 +42,15 @@
* @author Troy A. Griffitts [scribe at crosswire dot org]
* @author DM Smith [dmsmith555 at yahoo dot com]
*/
-public class LessonManager implements Comparable
+public class LessonManager
{
- public LessonManager()
+ public static LessonManager instance()
{
+ return INSTANCE;
+ }
+
+ private LessonManager()
+ {
lessonSets = new TreeSet();
try
{
@@ -61,6 +66,14 @@
}
/**
+ * @return the home directory url
+ */
+ public URL getHome()
+ {
+ return CWClassLoader.getHome();
+ }
+
+ /**
* Appends the specified <code>Lesson</code> to the end of this list.
*
* @param flashCard to be appended to this list.
@@ -71,31 +84,6 @@
}
/**
- * @return Returns the description.
- */
- public String getDescription()
- {
- return description;
- }
-
- /**
- * @param description The description to set.
- */
- public void setDescription(String newDescription)
- {
- description = newDescription;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- public int compareTo(Object obj)
- {
- LessonManager lesson = (LessonManager) obj;
- return description.compareTo(lesson.description);
- }
-
- /**
* Load this lesson from persistent store named by the lesson's <code>LESSON_ROOT</code>.
*/
public void load()
@@ -149,7 +137,7 @@
if (entryName.startsWith(LESSON_ROOT) && ! entryName.equals(LESSON_ROOT))
{
// let the description be just the directory name and not the path
- add(new LessonSet(entryName, entryName.substring(entryName.indexOf('/') + 1)));
+ add(new LessonSet(entryName));
}
}
}
@@ -183,7 +171,7 @@
int offset = lessonPath.indexOf(LESSON_ROOT);
lessonPath = lessonPath.substring(offset, lessonPath.length());
// let the description be just the directory name and not the path
- add(new LessonSet(lessonPath, file.getName()));
+ add(new LessonSet(lessonPath));
}
}
}
@@ -194,6 +182,23 @@
}
/**
+ * See if any LessonSet has changes that need to be saved
+ */
+ public boolean isModified()
+ {
+ Iterator iter = lessonSets.iterator();
+ while (iter.hasNext())
+ {
+ LessonSet lessonSet = (LessonSet) iter.next();
+ if (lessonSet.isModified())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Save all the modified lesson sets to persistent store named by the lesson's <code>LESSON_ROOT</code>.
*/
public void store()
@@ -218,13 +223,10 @@
private static final String DIR_PROJECT = ".flashcards";
private static final String FILE_PROTOCOL = "file";
- /**
- * A <code>description</code> of the lesson to be displayed to the user.
- */
- private String description;
+ private static final LessonManager INSTANCE = new LessonManager();
/**
* An ordered list of <code>lessonSets</code>
*/
private Set lessonSets;
-}
\ No newline at end of file
+}
Added: trunk/app/src/org/crosswire/flashcards/LessonPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonPane.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/LessonPane.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,264 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Iterator;
+
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JList;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+/**
+ * A panel listing the lessons in a lesson set.
+ *
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class LessonPane extends JPanel implements ListSelectionListener
+{
+ private JList lessonList = new JList(new DefaultListModel());
+ private LessonSet lessonSet;
+
+ private JMenuItem newItem;
+ private boolean editable;
+
+ /**
+ * The listeners for handling ViewEvent Listeners
+ */
+ private EventListenerList listenerList = new EventListenerList();
+
+ //Construct the frame
+ public LessonPane()
+ {
+ this(false);
+ }
+
+ /**
+ * @param b
+ */
+ public LessonPane(boolean allowEdits)
+ {
+ editable = allowEdits;
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void setSelectionMode(int mode)
+ {
+ lessonList.setSelectionMode(mode);
+ }
+
+ public Iterator iterator()
+ {
+ return new SelectedLessonIterator(lessonList);
+ }
+
+ /**
+ * @param flashCardPanel
+ */
+ public void addListSelectionListener(ListSelectionListener listener)
+ {
+ lessonList.addListSelectionListener(listener);
+ }
+
+ private void jbInit() throws Exception
+ {
+ setLayout(new BorderLayout());
+
+ setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Lessons: "));
+ add(new JScrollPane(lessonList), BorderLayout.CENTER);
+
+ JMenuBar menuBar = new JMenuBar();
+ JMenu editMenu = new JMenu("Edit");
+ newItem = new JMenuItem("New Lesson");
+ menuBar.add(editMenu);
+ editMenu.add(newItem);
+ if (editable)
+ {
+ add(menuBar, BorderLayout.NORTH);
+ }
+ enableControls();
+ newItem.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ String answer = JOptionPane.showInputDialog(null, "Lesson Description: ", "Create a New Lesson", JOptionPane.PLAIN_MESSAGE);
+ if (answer == null)
+ {
+ return;
+ }
+ createLesson(answer);
+ }
+ });
+
+// JMenuItem editLesson = new JMenuItem("Edit Lesson");
+// JMenuItem renameLesson = new JMenuItem("Rename Lesson");
+// lessonEditMenu.add(editLesson);
+// lessonEditMenu.add(renameLesson);
+
+ enableControls();
+ }
+
+ public void createLesson(String description)
+ {
+ Lesson lesson = new Lesson(lessonSet.getNextLessonFilename(), description);
+ DefaultListModel model = (DefaultListModel) lessonList.getModel();
+ if (!model.contains(lesson))
+ {
+ model.addElement(lesson);
+ lessonSet.add(lesson);
+ fireLessonChanged(new LessonChangeEvent(this));
+ }
+ lessonList.setSelectedValue(lesson, true);
+
+ }
+
+ /* (non-Javadoc)
+ * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
+ */
+ public void valueChanged(ListSelectionEvent e)
+ {
+ if (e.getValueIsAdjusting())
+ {
+ return;
+ }
+ JList list = (JList) e.getSource();
+ lessonSet = (LessonSet) list.getSelectedValue();
+ DefaultListModel model = (DefaultListModel) lessonList.getModel();
+ model.clear();
+ if (lessonSet != null)
+ {
+ Iterator lessonIterator = lessonSet.iterator();
+ while (lessonIterator.hasNext())
+ {
+ Lesson lesson = (Lesson) lessonIterator.next();
+ model.addElement(lesson);
+ }
+ }
+ enableControls();
+ }
+
+ private void enableControls()
+ {
+ newItem.setEnabled(lessonSet != null);
+ }
+
+
+ /**
+ * Adds a view event listener for notification of any changes to the view.
+ *
+ * @param listener the listener
+ */
+ public synchronized void addLessonChangeEvent(LessonChangeEventListener listener)
+ {
+ listenerList.add(LessonChangeEventListener.class, listener);
+ }
+
+ /**
+ * Removes a view event listener.
+ *
+ * @param listener the listener
+ */
+ public synchronized void removeLessonChangeEvent(LessonChangeEventListener listener)
+ {
+ listenerList.remove(LessonChangeEventListener.class, listener);
+ }
+
+ /**
+ * Notify the listeners that the view has been removed.
+ *
+ * @param e the event
+ * @see EventListenerList
+ */
+ public void fireLessonChanged(LessonChangeEvent e)
+ {
+ // Guaranteed to return a non-null array
+ Object[] listeners = listenerList.getListenerList();
+ // Process the listeners last to first, notifying
+ // those that are interested in this event
+ for (int i = listeners.length - 2; i >= 0; i -= 2)
+ {
+ if (listeners[i] == LessonChangeEventListener.class)
+ {
+ ((LessonChangeEventListener) listeners[i + 1]).lessonChanged(e);
+ }
+ }
+ }
+
+ /**
+ * Iterator over the selections in a JList
+ */
+ private static class SelectedLessonIterator implements Iterator
+ {
+
+ public SelectedLessonIterator(JList list)
+ {
+ model = (DefaultListModel) list.getModel();
+ selectedIndexes = list.getSelectedIndices();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#remove()
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext()
+ {
+ return currentIndex < selectedIndexes.length;
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.Iterator#next()
+ */
+ public Object next()
+ {
+ return model.get(selectedIndexes[currentIndex++]);
+ }
+
+ private int[] selectedIndexes;
+ private DefaultListModel model;
+ private int currentIndex;
+ }
+
+}
Modified: trunk/app/src/org/crosswire/flashcards/LessonSet.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonSet.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/LessonSet.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -25,21 +25,18 @@
import java.net.JarURLConnection;
import java.net.URL;
import java.net.URLConnection;
-import java.util.ArrayList;
+import java.text.MessageFormat;
import java.util.Arrays;
-import java.util.Collections;
import java.util.Enumeration;
-import java.util.HashSet;
import java.util.Iterator;
-import java.util.List;
import java.util.Properties;
import java.util.Set;
import java.util.TreeSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-import org.crosswire.common.CWClassLoader;
-import org.crosswire.common.ResourceUtil;
+import org.crosswire.common.util.CWClassLoader;
+import org.crosswire.common.util.ResourceUtil;
/**
* A <code>LessonSet</code> is an ordered list of <code>Lesson</code>s.
@@ -53,10 +50,10 @@
*/
public class LessonSet implements Comparable
{
- public LessonSet(String dirname, String description)
+ public LessonSet(String aDirname)
{
- this.dirname = dirname;
- this.description = description;
+ dirname = aDirname.toLowerCase();
+ description = dirname.substring(dirname.indexOf('/') + 1);
lessons = new TreeSet();
load();
}
@@ -100,6 +97,17 @@
return dirname;
}
+ public String getNextLessonFilename()
+ {
+ // This needs work: It should check for collisions
+ String result = null;
+ int next = lessons.size();
+ Object [] params = { dirname, new Integer(next) };
+ MessageFormat format = new MessageFormat("{0}/lesson{1,number,00}.flash");
+ result = format.format(params);
+ return result;
+ }
+
/* (non-Javadoc)
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
@@ -116,6 +124,7 @@
{
return description;
}
+
/**
* Load this lesson set from persistent store named by the lesson set's <code>dirname</code>.
* This is the union of lessons in the Jar and in the user's flashcard home directory.
@@ -170,10 +179,10 @@
{
JarEntry jarEntry = (JarEntry) entries.nextElement();
String lessonPath = jarEntry.getName();
- if (lessonPath.startsWith(dirname) && ! jarEntry.isDirectory())
+ if (lessonPath.startsWith(dirname) && !jarEntry.isDirectory())
{
String lessonDescription = getLessonDescription(lessonPath);
- add(new Lesson(lessonPath, lessonDescription));
+ lessons.add(new Lesson(lessonPath, lessonDescription));
}
}
}
@@ -206,7 +215,7 @@
int offset = lessonPath.indexOf(dirname);
lessonPath = lessonPath.substring(offset, lessonPath.length());
String lessonDescription = getLessonDescription(lessonPath);
- add(new Lesson(lessonPath, lessonDescription));
+ lessons.add(new Lesson(lessonPath, lessonDescription));
}
}
catch (Exception e)
@@ -214,7 +223,7 @@
// that's fine. We just failed to load local files.
}
}
-
+
/**
* Get the description of the lesson
* @param lessonpath the relative path to the lesson
@@ -272,7 +281,7 @@
}
return false;
}
-
+
public Iterator iterator()
{
return lessons.iterator();
Added: trunk/app/src/org/crosswire/flashcards/LessonSetPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonSetPane.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/LessonSetPane.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,189 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Iterator;
+
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JList;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.ListSelectionModel;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.ListSelectionListener;
+
+
+/**
+ * A panel consisting of all the lesson sets known to FlashCards.
+ *
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class LessonSetPane extends JPanel
+{
+ private JList lessonSetList = new JList(new DefaultListModel());
+ private boolean editable;
+
+ /**
+ * The listeners for handling ViewEvent Listeners
+ */
+ private EventListenerList listenerList = new EventListenerList();
+
+ //Construct the frame
+ public LessonSetPane()
+ {
+ this(false);
+ }
+
+ /**
+ * @param b
+ */
+ public LessonSetPane(boolean allowEdits)
+ {
+ editable = allowEdits;
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @param lessonPanel
+ */
+ public void addListSelectionListener(ListSelectionListener listener)
+ {
+ lessonSetList.addListSelectionListener(listener);
+ }
+
+ private void jbInit() throws Exception
+ {
+ lessonSetList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+
+ setLayout(new BorderLayout());
+
+ setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Lesson Sets: "));
+ add(new JScrollPane(lessonSetList), BorderLayout.CENTER);
+
+ JMenuBar lessonMenuBar = new JMenuBar();
+ JMenu lessonSetEditMenu = new JMenu("Edit");
+ JMenuItem newLessonSet = new JMenuItem("New Lesson Set");
+ newLessonSet.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ String answer = JOptionPane.showInputDialog(null, "<html>Lesson Set name:<br>(Single word, only letters)", "Create a New Lesson Set",
+ JOptionPane.PLAIN_MESSAGE);
+ if (answer == null)
+ {
+ return;
+ }
+ createLessonSet(answer);
+ }
+ });
+ JMenuItem renameLessonSet = new JMenuItem("Rename Lesson Set");
+ lessonMenuBar.add(lessonSetEditMenu);
+ lessonSetEditMenu.add(newLessonSet);
+ lessonSetEditMenu.add(renameLessonSet);
+
+ if (editable)
+ {
+ add(lessonMenuBar, BorderLayout.NORTH);
+ }
+
+ loadLessonSets();
+ }
+
+ public void createLessonSet(String name)
+ {
+ LessonSet lessonSet = new LessonSet(LessonManager.LESSON_ROOT + '/' + name);
+ DefaultListModel model = (DefaultListModel) lessonSetList.getModel();
+ if (!model.contains(lessonSet))
+ {
+ model.addElement(lessonSet);
+ LessonManager.instance().add(lessonSet);
+ fireLessonChanged(new LessonChangeEvent(this));
+ }
+ lessonSetList.setSelectedValue(lessonSet, true);
+ }
+
+ private void loadLessonSets()
+ {
+ Iterator lessonSetIterator = LessonManager.instance().iterator();
+ while (lessonSetIterator.hasNext())
+ {
+ LessonSet lessonSet = (LessonSet) lessonSetIterator.next();
+ DefaultListModel model = (DefaultListModel) lessonSetList.getModel();
+ model.addElement(lessonSet);
+ }
+ }
+
+ /**
+ * Adds a view event listener for notification of any changes to the view.
+ *
+ * @param listener the listener
+ */
+ public synchronized void addLessonChangeEvent(LessonChangeEventListener listener)
+ {
+ listenerList.add(LessonChangeEventListener.class, listener);
+ }
+
+ /**
+ * Removes a view event listener.
+ *
+ * @param listener the listener
+ */
+ public synchronized void removeLessonChangeEvent(LessonChangeEventListener listener)
+ {
+ listenerList.remove(LessonChangeEventListener.class, listener);
+ }
+
+ /**
+ * Notify the listeners that the view has been removed.
+ *
+ * @param e the event
+ * @see EventListenerList
+ */
+ public void fireLessonChanged(LessonChangeEvent e)
+ {
+ // Guaranteed to return a non-null array
+ Object[] listeners = listenerList.getListenerList();
+ // Process the listeners last to first, notifying
+ // those that are interested in this event
+ for (int i = listeners.length - 2; i >= 0; i -= 2)
+ {
+ if (listeners[i] == LessonChangeEventListener.class)
+ {
+ ((LessonChangeEventListener) listeners[i + 1]).lessonChanged(e);
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: trunk/app/src/org/crosswire/flashcards/MainFrame.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/MainFrame.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/MainFrame.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -22,109 +22,37 @@
import java.awt.AWTEvent;
import java.awt.BorderLayout;
-import java.awt.Component;
import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.GridLayout;
-import java.awt.SystemColor;
-import java.awt.event.ActionEvent;
-import java.awt.event.ItemEvent;
import java.awt.event.WindowEvent;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Vector;
-import javax.swing.BorderFactory;
-import javax.swing.DefaultListModel;
-import javax.swing.JButton;
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
import javax.swing.JFrame;
-import javax.swing.JLabel;
-import javax.swing.JList;
+import javax.swing.JOptionPane;
import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
-import javax.swing.ListCellRenderer;
-import javax.swing.ListSelectionModel;
-import javax.swing.SwingConstants;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-public class MainFrame extends JFrame {
- LessonManager lessonManager;
- JPanel contentPane;
- JLabel statusBar = new JLabel();
- BorderLayout borderLayout1 = new BorderLayout();
- JPanel jPanel1 = new JPanel();
- JPanel jPanel2 = new JPanel();
- BorderLayout borderLayout2 = new BorderLayout();
- JPanel choicesPanel = new JPanel();
- JTabbedPane jTabbedPane1 = new JTabbedPane();
- JPanel testPanel = new JPanel();
- BorderLayout borderLayout3 = new BorderLayout();
- JButton startLessonButton = new JButton();
- Vector words = new Vector();
- Vector notLearned = new Vector();
- WordEntry currentWord = null;
- int wrong = 0;
- int totalAsked = 0;
- int totalWrong = 0;
- JButton showAnswerButton = new JButton();
- BorderLayout borderLayout6 = new BorderLayout();
- boolean shownAnswer = false;
- JLabel wordText = new JLabel();
- GridLayout gridLayout1 = new GridLayout();
- JPanel jPanel3 = new JPanel();
- BorderLayout borderLayout7 = new BorderLayout();
- JLabel wCount = new JLabel();
- private MainMenu mainMenu;
- private SetupPane setupPane;
- private JCheckBox flipSideCheckBox = new JCheckBox("Flip Flash Cards");
+/**
+ * The main flash card program.
+ *
+ * @author Troy A. Griffitts [scribe at crosswire dot org]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class MainFrame extends JFrame
+{
+ private SetupPane setupPane;
+ private QuizPane testPane;
+ private EditPane editPane;
- static class WordEntry
- {
- public WordEntry(FlashCard flashCard)
- {
- this.flashCard = flashCard;
- }
- public void incrementFailures(int failures)
- {
- attempts += failures;
- }
-
- public int getFailures()
- {
- return attempts;
- }
-
- public String getSide(boolean front)
- {
- return flashCard.getSide(front);
- }
-
- public String toString()
- {
- return flashCard.getFront();
- }
- private FlashCard flashCard;
- private int attempts;
- }
-
-
//Construct the frame
- public MainFrame(LessonManager lessonManager)
+ public MainFrame()
{
- this.lessonManager = lessonManager;
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
- mainMenu = new MainMenu(lessonManager, this );
- setJMenuBar( mainMenu );
- setupPane = new SetupPane(lessonManager);
+ setJMenuBar(new MainMenu(this));
+ setupPane = new SetupPane();
+ testPane = new QuizPane(setupPane);
+ editPane = new EditPane();
+ JOptionPane.setRootFrame(this);
try
{
jbInit();
@@ -135,259 +63,30 @@
}
}
- //Component initialization
- private void jbInit() throws Exception {
- contentPane = (JPanel) this.getContentPane();
- contentPane.setLayout(borderLayout1);
- this.setSize(new Dimension(400, 300));
- this.setTitle("FlashCards - (c) 2004 CrossWire Bible Society http://crosswire.org");
- statusBar.setBorder(BorderFactory.createEtchedBorder());
- statusBar.setText(" ");
- jPanel2.setLayout(borderLayout2);
- testPanel.setLayout(borderLayout3);
- choicesPanel.setLayout(gridLayout1);
- startLessonButton.setText("Start");
- startLessonButton.addActionListener(new MainFrame_jButton1_actionAdapter(this));
- showAnswerButton.setFocusPainted(true);
- showAnswerButton.setMnemonic('A');
- showAnswerButton.setText("Show Answer");
- showAnswerButton.addActionListener(new MainFrame_jButton3_actionAdapter(this));
- jPanel1.setLayout(borderLayout6);
- wordText.setBackground(SystemColor.text);
- wordText.setFont(new java.awt.Font("Dialog", 0, 30));
- wordText.setMaximumSize(new Dimension(106, 100));
- wordText.setMinimumSize(new Dimension(106, 100));
- wordText.setPreferredSize(new Dimension(106, 100));
- wordText.setHorizontalAlignment(SwingConstants.CENTER);
- wordText.setHorizontalTextPosition(SwingConstants.CENTER);
- gridLayout1.setColumns(3);
- gridLayout1.setRows(0);
- jPanel3.setLayout(borderLayout7);
- wCount.setBorder(BorderFactory.createEtchedBorder());
- contentPane.add(jTabbedPane1, BorderLayout.CENTER);
- jTabbedPane1.addTab("Test", testPanel);
- testPanel.add(jPanel2, BorderLayout.CENTER);
- testPanel.add(jPanel1, BorderLayout.NORTH);
- testPanel.add(jPanel3, BorderLayout.SOUTH);
- jPanel3.add(statusBar, BorderLayout.CENTER);
- jPanel3.add(wCount, BorderLayout.EAST);
- jTabbedPane1.addTab("Setup", setupPane);
-
- jPanel2.add(choicesPanel, BorderLayout.CENTER);
- jPanel2.add(wordText, BorderLayout.NORTH);
- jPanel1.add(startLessonButton, BorderLayout.WEST);
- jPanel1.add(flipSideCheckBox, BorderLayout.CENTER);
- jPanel1.add(showAnswerButton, BorderLayout.EAST);
-
- jTabbedPane1.setSelectedIndex(1);
- }
-
- //Overridden so we can exit when window is closed
- protected void processWindowEvent(WindowEvent e) {
- super.processWindowEvent(e);
- if (e.getID() == WindowEvent.WINDOW_CLOSING) {
- System.exit(0);
- }
- }
-
- public void deleteChildren(JComponent c) {
- while (c.getComponentCount() > 0)
- c.remove(c.getComponent(0));
- }
-
- public void loadTest() {
-// boolean loadedFont = false;
- words = new Vector();
- Iterator lessonIter = setupPane.iterator();
- while (lessonIter.hasNext())
+ //Component initialization
+ private void jbInit() throws Exception
{
- Lesson lesson = (Lesson) lessonIter.next();
- Iterator cardIter = lesson.iterator();
- while (cardIter.hasNext())
- {
- words.add(new WordEntry((FlashCard)cardIter.next()));
- }
-// if (!loadedFont) {
-// String font = lesson.getFont();
-// if (font.length() > 1) {
-// try {
-// loadFont(new FileInputStream(font));
-// loadedFont = true;
-// }
-// catch (FileNotFoundException ex) {
-// }
-// }
-// }
+ JPanel contentPane = (JPanel) this.getContentPane();
+ contentPane.setLayout(new BorderLayout());
+ this.setSize(new Dimension(640, 480));
+ this.setTitle("FlashCards - (c) 2004 CrossWire Bible Society http://crosswire.org");
+ JTabbedPane tabs = new JTabbedPane();
+ tabs.addTab("Setup", setupPane);
+ tabs.addTab("Quiz", testPane);
+ tabs.addTab("Edit", editPane);
+ tabs.setSelectedComponent(setupPane);
+ contentPane.add(tabs, BorderLayout.CENTER);
}
- }
-// public void loadFont(InputStream is) {
-// try {
-// statusBar.setText("Loading font...");
-// statusBar.paintImmediately(statusBar.getVisibleRect());
-// Font font = Font.createFont(Font.TRUETYPE_FONT, is);
-// Font newFont = font.deriveFont((float)18.0);
-// wordText.setFont(newFont);
-// is.close();
-// statusBar.setText("New Font Loaded.");
-// }
-// catch (Exception ex) { ex.printStackTrace(); }
-// }
-
- void jButton1_actionPerformed(ActionEvent e) {
- loadTest();
- notLearned = (Vector)words.clone();
- totalAsked = 0;
- totalWrong = 0;
- showRandomWord(currentWord);
- }
-
- public void showRandomWord(WordEntry last) {
- deleteChildren(choicesPanel);
- int numToLearn = notLearned.size();
- if (numToLearn == 0)
+ //Overridden so we can exit when window is closed
+ protected void processWindowEvent(WindowEvent e)
{
- return;
- }
- while (currentWord == last) {
- int wordNum = (int) (Math.random() * notLearned.size());
- currentWord = (WordEntry) notLearned.get(wordNum);
- }
- showWord(currentWord);
- }
-
-
- public void showWord(WordEntry w) {
- currentWord = w;
- wordText.setText(w.getSide(!flipSideCheckBox.isSelected()));
- Vector choices = (Vector)words.clone();
- choices.remove(w);
-// deleteChildren(choicesPanel);
- int size = choices.size();
- for (int i = 0; ((i < 9) && (size > 0)); i++) {
- int c = (int)(Math.random() * size);
- WordEntry wc = (WordEntry)choices.get(c);
- JCheckBox ck = new JCheckBox(wc.getSide(flipSideCheckBox.isSelected()), false);
- choicesPanel.add(ck, null);
- ck.addItemListener(new MainFrame_answer_itemAdapter(this));
- choices.remove(wc);
- size = choices.size();
- }
- int correct = (int)(Math.random() * choicesPanel.getComponentCount());
- JCheckBox ck = (JCheckBox)choicesPanel.getComponent(correct);
- ck.setText(w.getSide(flipSideCheckBox.isSelected()));
- wrong = 0;
- shownAnswer = false;
- updateStats();
-// this.pack();
- choicesPanel.repaint();
- }
-
-
- void updateStats() {
- int percent = 100;
- if (totalAsked > 0) {
- percent = (int)((((float)(totalAsked - totalWrong)) / (float)totalAsked) * (float)100);
- }
- wCount.setText(Integer.toString(notLearned.size())+" | "+Integer.toString(totalAsked-totalWrong)+"/"+Integer.toString(totalAsked)+" ("+Integer.toString(percent)+"%)");
- }
-
-
- void answer_itemStateChanged(ItemEvent e) {
- JCheckBox ck = (JCheckBox)e.getItem();
- if (ck.isSelected()) {
- totalAsked++;
- if (ck.getText().compareTo(currentWord.getSide(flipSideCheckBox.isSelected())) != 0) {
- statusBar.setText(ck.getText() + " is not correct. Please try again.");
- wrong++;
- totalWrong++;
- ck.setSelected(false);
- }
- else {
- if (notLearned.size() > 1) {
- statusBar.setText("Correct. Try this next word");
- if (wrong > 0) {
- currentWord.incrementFailures(wrong);
- }
- else currentWord.incrementFailures(-1);
- if (currentWord.getFailures() < 0) {
- notLearned.remove(currentWord);
- }
- showRandomWord(currentWord);
+ super.processWindowEvent(e);
+ if (e.getID() == WindowEvent.WINDOW_CLOSING)
+ {
+ System.exit(0);
}
- else {
- notLearned.remove(currentWord);
- deleteChildren(choicesPanel);
- wordText.setText("-=+* Great! *+=-");
- statusBar.setText("Nice Job! You've mastered all " + words.size() +
- " words!");
- }
- }
- updateStats();
}
- }
-
- public void showAnswer() {
- for (int i = 0; i < choicesPanel.getComponentCount(); i++) {
- JCheckBox ck = (JCheckBox)choicesPanel.getComponent(i);
- if (ck.getText() == currentWord.getSide(flipSideCheckBox.isSelected())) {
- ck.setFont(new Font(ck.getFont().getName(), Font.BOLD|Font.ITALIC, ck.getFont().getSize()));
- break;
- }
- }
- shownAnswer = true;
- }
-
- void jButton3_actionPerformed(ActionEvent e) {
- if (!shownAnswer) {
- showAnswer();
- return;
- }
- int next = notLearned.indexOf(currentWord) + 1;
- if (next == 0)
- {
- return;
- }
- if (next >= notLearned.size())
- next = 0;
- deleteChildren(choicesPanel);
- showWord((WordEntry)notLearned.get(next));
- showAnswer();
- }
-
}
-
-class MainFrame_jButton1_actionAdapter implements java.awt.event.ActionListener {
- MainFrame adaptee;
-
- MainFrame_jButton1_actionAdapter(MainFrame adaptee) {
- this.adaptee = adaptee;
- }
- public void actionPerformed(ActionEvent e) {
- adaptee.jButton1_actionPerformed(e);
- }
-}
-
-class MainFrame_answer_itemAdapter implements java.awt.event.ItemListener {
- MainFrame adaptee;
-
- MainFrame_answer_itemAdapter(MainFrame adaptee) {
- this.adaptee = adaptee;
- }
- public void itemStateChanged(ItemEvent e) {
- adaptee.answer_itemStateChanged(e);
- }
-}
-
-class MainFrame_jButton3_actionAdapter implements java.awt.event.ActionListener {
- MainFrame adaptee;
-
- MainFrame_jButton3_actionAdapter(MainFrame adaptee) {
- this.adaptee = adaptee;
- }
- public void actionPerformed(ActionEvent e) {
- adaptee.jButton3_actionPerformed(e);
- }
-}
Modified: trunk/app/src/org/crosswire/flashcards/MainMenu.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/MainMenu.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/MainMenu.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -33,7 +33,6 @@
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
-import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
@@ -43,7 +42,6 @@
class MainMenu extends JMenuBar {
- private LessonManager lessonManager;
//
// Attributes
//
@@ -56,8 +54,7 @@
//
// ---------------
- MainMenu(LessonManager lessonManager, JFrame frame ) {
- this.lessonManager = lessonManager;
+ MainMenu( JFrame frame ) {
this.frame = frame;
JMenu menu1, menu2;
@@ -132,7 +129,9 @@
public void actionPerformed( ActionEvent event ) {
Debug.trace( this.toString( ), "Beginning\n" );
- new Editor( lessonManager, false );
+ JFrame lessonEditor = new EditorFrame( false );
+ lessonEditor.validate( );
+ lessonEditor.setVisible( true );
Debug.trace( this.toString( ), "Ending\n" );
}
Modified: trunk/app/src/org/crosswire/flashcards/Quiz.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/Quiz.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/Quiz.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -18,16 +18,6 @@
* The copyright to this program is held by it's authors.
* Copyright: 2004
*/
-///////////////////////////////////////////////////////////////////////////
-//
-// Quiz.java
-//
-// The start of it all
-//
-// Copyright : 2004 CrossWire Bible Society http://crosswire.org
-//
-///////////////////////////////////////////////////////////////////////////
-
package org.crosswire.flashcards;
import java.awt.Dimension;
@@ -35,6 +25,11 @@
import javax.swing.UIManager;
+/**
+ * The start of it all.
+ *
+ * @author Troy A. Griffitts [scribe at crosswire dot org]
+ */
public class Quiz {
//
@@ -50,10 +45,8 @@
// ---------------
public Quiz( ) {
- LessonManager lm = new LessonManager();
+ MainFrame frame = new MainFrame();
- MainFrame frame = new MainFrame(lm);
-
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info,
// e.g. from their layout
Added: trunk/app/src/org/crosswire/flashcards/QuizPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/QuizPane.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/QuizPane.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -0,0 +1,445 @@
+/*
+ * Distribution Licence:
+ * FlashCard is free software; you can redistribute it
+ * and/or modify it under the terms of the GNU General Public License,
+ * version 2 as published by the Free Software Foundation.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * See the GNU General Public License for more details.
+ * The License is available on the internet at:
+ * http://www.gnu.org/copyleft/gpl.html,
+ * or by writing to:
+ * Free Software Foundation, Inc.
+ * 59 Temple Place - Suite 330
+ * Boston, MA 02111-1307, USA
+ *
+ * The copyright to this program is held by it's authors
+ * Copyright: 2004
+ */
+package org.crosswire.flashcards;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.GridLayout;
+import java.awt.Insets;
+import java.awt.SystemColor;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+
+
+/**
+ * A panel that quizzes over a selection of lessons.
+ *
+ * @author Troy A. Griffitts [scribe at crosswire dot org]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class QuizPane extends JPanel
+{
+ SetupPane setupPane;
+ Vector words = new Vector();
+ Vector notLearned = new Vector();
+ WordEntry currentWord = null;
+ int wrong = 0;
+ int totalAsked = 0;
+ int totalWrong = 0;
+ boolean shownAnswer = false;
+ JButton startLessonButton = new JButton();
+ JButton showAnswerButton = new JButton();
+ JLabel wordText = new JLabel();
+ JLabel statusBar = new JLabel();
+ JLabel wCount = new JLabel();
+
+ JPanel choicesPanel = new JPanel();
+ GridLayout choicesPanelGridLayout = new GridLayout();
+ JPanel statusPanel = new JPanel();
+ BorderLayout statusPanelBorderLayout = new BorderLayout();
+
+ static class WordEntry
+ {
+ public WordEntry(FlashCard flashCard)
+ {
+ this.flashCard = flashCard;
+ }
+
+ public void incrementFailures(int failures)
+ {
+ attempts += failures;
+ }
+
+ public int getFailures()
+ {
+ return attempts;
+ }
+
+ public String getSide(boolean front)
+ {
+ return flashCard.getSide(front);
+ }
+
+ public String toString()
+ {
+ return flashCard.getFront();
+ }
+ private FlashCard flashCard;
+ private int attempts;
+ }
+
+
+ //Construct the frame
+ public QuizPane(SetupPane setupPane)
+ {
+ this.setupPane = setupPane;
+ try
+ {
+ jbInit();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ //Component initialization
+ private void jbInit() throws Exception
+ {
+ startLessonButton.setText("Start");
+ startLessonButton.addActionListener(new QuizPane_startLessonButton_actionAdapter(this));
+
+ showAnswerButton.setFocusPainted(true);
+ showAnswerButton.setMnemonic('A');
+ showAnswerButton.setText("Show Answer");
+ showAnswerButton.addActionListener(new QuizPane_showAnswerButton_actionAdapter(this));
+
+ wordText.setBackground(SystemColor.text);
+ wordText.setFont(new Font("Dialog", 0, 30));
+ wordText.setHorizontalAlignment(SwingConstants.CENTER);
+ wordText.setHorizontalTextPosition(SwingConstants.CENTER);
+
+ statusBar.setBorder(BorderFactory.createEtchedBorder());
+ statusBar.setText(" ");
+ wCount.setBorder(BorderFactory.createEtchedBorder());
+
+ choicesPanel.setLayout(choicesPanelGridLayout);
+ choicesPanelGridLayout.setColumns(2);
+ choicesPanelGridLayout.setRows(0);
+
+ statusPanel.setLayout(statusPanelBorderLayout);
+ statusPanel.add(statusBar, BorderLayout.CENTER);
+ statusPanel.add(wCount, BorderLayout.EAST);
+
+ setLayout(new GridBagLayout());
+ GridBagConstraints gbc = new GridBagConstraints();
+
+ gbc.gridx = 0;
+ gbc.weightx = 1.0;
+ gbc.anchor = GridBagConstraints.WEST;
+ add(startLessonButton, gbc);
+
+ gbc.gridx = 2;
+ gbc.anchor = GridBagConstraints.EAST;
+ add(showAnswerButton, gbc);
+
+ gbc.gridwidth = 3;
+ gbc.gridx = 0;
+ gbc.anchor = GridBagConstraints.NORTH;
+ Insets standardInsets = gbc.insets;
+ gbc.insets = new Insets(10,0,20,0);
+ add(wordText, gbc);
+
+ gbc.weighty = 1.0;
+ gbc.insets = standardInsets;
+ add(choicesPanel, gbc);
+
+ gbc.weighty = 0.0;
+ gbc.fill = GridBagConstraints.HORIZONTAL;
+ add(statusPanel, gbc);
+ }
+
+ public void deleteChildren(JComponent c)
+ {
+ while (c.getComponentCount() > 0)
+ c.remove(c.getComponent(0));
+ }
+
+ public void loadTest()
+ {
+// boolean loadedFont = false;
+ words = new Vector();
+ Iterator lessonIter = setupPane.iterator();
+ while (lessonIter.hasNext())
+ {
+ Lesson lesson = (Lesson) lessonIter.next();
+ Iterator cardIter = lesson.iterator();
+ while (cardIter.hasNext())
+ {
+ words.add(new WordEntry((FlashCard) cardIter.next()));
+ }
+// if (!loadedFont)
+// {
+// String font = lesson.getFont();
+// if (font.length() > 1)
+// {
+// try
+// {
+// loadFont(new FileInputStream(font));
+// loadedFont = true;
+// }
+// catch (FileNotFoundException ex)
+// {
+// }
+// }
+// }
+ }
+ }
+
+// public void loadFont(InputStream is)
+// {
+// try
+// {
+// statusBar.setText("Loading font...");
+// statusBar.paintImmediately(statusBar.getVisibleRect());
+// Font font = Font.createFont(Font.TRUETYPE_FONT, is);
+// Font newFont = font.deriveFont((float) 18.0);
+// wordText.setFont(newFont);
+// is.close();
+// statusBar.setText("New Font Loaded.");
+// }
+// catch (Exception ex)
+// {
+// ex.printStackTrace();
+// }
+// }
+
+ void startLessonButton_actionPerformed(ActionEvent e)
+ {
+ loadTest();
+ notLearned = (Vector) words.clone();
+ totalAsked = 0;
+ totalWrong = 0;
+ showRandomWord(currentWord);
+ }
+
+ public void showRandomWord(WordEntry last)
+ {
+ deleteChildren(choicesPanel);
+ int numToLearn = notLearned.size();
+ if (numToLearn == 0)
+ {
+ return;
+ }
+ while (currentWord == last)
+ {
+ int wordNum = (int) (Math.random() * notLearned.size());
+ currentWord = (WordEntry) notLearned.get(wordNum);
+ }
+ showWord(currentWord);
+ }
+
+
+ public void showWord(WordEntry w)
+ {
+ currentWord = w;
+ wordText.setText(w.getSide(!setupPane.isFlipped()));
+ Vector choices = (Vector) words.clone();
+ choices.remove(w);
+
+ // randomly pick answers
+ boolean flipped = setupPane.isFlipped();
+ List picks = new ArrayList();
+ picks.add(createAnswerEntry(w.getSide(flipped)));
+ int size = words.size();
+ while (picks.size() < Math.min(10, size))
+ {
+ int c = (int) (Math.random() * choices.size());
+ WordEntry wc = (WordEntry) choices.get(c);
+ String answer = wc.getSide(flipped);
+
+ // some times two different word have the same answer
+ if (!picks.contains(answer))
+ {
+ picks.add(createAnswerEntry(answer));
+ choices.remove(wc);
+ }
+ }
+ // Now randomize these answers. To do this we swap the first one
+ // with another.
+ int c = (int) (Math.random() * picks.size());
+ // If we have selected something other than ourselves.
+ if (c > 0)
+ {
+ picks.add(0, picks.remove(c));
+ picks.add(c, picks.remove(1));
+ }
+ Iterator iter = picks.iterator();
+ while (iter.hasNext())
+ {
+ choicesPanel.add((Component) iter.next());
+ }
+ wrong = 0;
+ shownAnswer = false;
+ updateStats();
+ choicesPanel.repaint();
+ }
+
+
+ Component createAnswerEntry(String answer)
+ {
+ JCheckBox ck = new JCheckBox(answer, false);
+ ck.setFont(new Font("Dialog", 0, 16));
+ ck.addItemListener(new QuizPane_answer_itemAdapter(this));
+ return ck;
+ }
+
+ void updateStats()
+ {
+ int percent = 100;
+ if (totalAsked > 0)
+ {
+ percent = (int) ((((float) (totalAsked - totalWrong)) / (float) totalAsked) * (float) 100);
+ }
+ wCount.setText(Integer.toString(notLearned.size()) + " | " + Integer.toString(totalAsked - totalWrong) + "/" + Integer.toString(totalAsked) + " ("
+ + Integer.toString(percent) + "%)");
+ }
+
+
+ void answer_itemStateChanged(ItemEvent e)
+ {
+ JCheckBox ck = (JCheckBox) e.getItem();
+ if (ck.isSelected())
+ {
+ totalAsked++;
+ if (ck.getText().compareTo(currentWord.getSide(setupPane.isFlipped())) != 0)
+ {
+ statusBar.setText(ck.getText() + " is not correct. Please try again.");
+ wrong++;
+ totalWrong++;
+ ck.setSelected(false);
+ }
+ else
+ {
+ if (notLearned.size() > 1)
+ {
+ statusBar.setText("Correct. Try this next word");
+ if (wrong > 0)
+ {
+ currentWord.incrementFailures(wrong);
+ }
+ else
+ currentWord.incrementFailures(-1);
+ if (currentWord.getFailures() < 0)
+ {
+ notLearned.remove(currentWord);
+ }
+ showRandomWord(currentWord);
+ }
+ else
+ {
+ notLearned.remove(currentWord);
+ deleteChildren(choicesPanel);
+ wordText.setText("-=+* Great! *+=-");
+ statusBar.setText("Nice Job! You've mastered all " + words.size() + " words!");
+ }
+ }
+ updateStats();
+ }
+ }
+
+
+ public void showAnswer()
+ {
+ for (int i = 0; i < choicesPanel.getComponentCount(); i++)
+ {
+ JCheckBox ck = (JCheckBox) choicesPanel.getComponent(i);
+ if (ck.getText() == currentWord.getSide(setupPane.isFlipped()))
+ {
+ ck.setFont(new Font(ck.getFont().getName(), Font.BOLD | Font.ITALIC, ck.getFont().getSize()));
+ break;
+ }
+ }
+ shownAnswer = true;
+ }
+
+ void showAnswerButton_actionPerformed(ActionEvent e)
+ {
+ if (!shownAnswer)
+ {
+ showAnswer();
+ return;
+ }
+ int next = notLearned.indexOf(currentWord) + 1;
+ if (next == 0)
+ {
+ return;
+ }
+ if (next >= notLearned.size())
+ next = 0;
+ deleteChildren(choicesPanel);
+ showWord((WordEntry) notLearned.get(next));
+ showAnswer();
+ }
+
+}
+
+class QuizPane_startLessonButton_actionAdapter implements ActionListener
+{
+ QuizPane adaptee;
+
+ QuizPane_startLessonButton_actionAdapter(QuizPane adaptee)
+ {
+ this.adaptee = adaptee;
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ adaptee.startLessonButton_actionPerformed(e);
+ }
+}
+
+class QuizPane_answer_itemAdapter implements ItemListener
+{
+ QuizPane adaptee;
+
+ QuizPane_answer_itemAdapter(QuizPane adaptee)
+ {
+ this.adaptee = adaptee;
+ }
+
+ public void itemStateChanged(ItemEvent e)
+ {
+ adaptee.answer_itemStateChanged(e);
+ }
+}
+
+class QuizPane_showAnswerButton_actionAdapter implements ActionListener
+{
+ QuizPane adaptee;
+
+ QuizPane_showAnswerButton_actionAdapter(QuizPane adaptee)
+ {
+ this.adaptee = adaptee;
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ adaptee.showAnswerButton_actionPerformed(e);
+ }
+}
\ No newline at end of file
Modified: trunk/app/src/org/crosswire/flashcards/SetupPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/SetupPane.java 2004-09-19 12:32:10 UTC (rev 46)
+++ trunk/app/src/org/crosswire/flashcards/SetupPane.java 2004-09-19 17:42:28 UTC (rev 47)
@@ -20,37 +20,31 @@
*/
package org.crosswire.flashcards;
-import java.awt.AWTEvent;
import java.awt.BorderLayout;
-import java.awt.Component;
import java.util.Iterator;
import javax.swing.BorderFactory;
-import javax.swing.DefaultListModel;
import javax.swing.JCheckBox;
-import javax.swing.JList;
import javax.swing.JPanel;
-import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
-import javax.swing.ListCellRenderer;
-import javax.swing.ListSelectionModel;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
import org.crosswire.common.swing.FixedSplitPane;
+/**
+ * A panel used for setting up a quiz.
+ *
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
public class SetupPane extends JPanel
{
- private LessonManager lessonManager;
- private JList lessonSetList = new JList(new DefaultListModel());
- private JList lessonList = new JList(new DefaultListModel());
+ private LessonPane lessonPanel = new LessonPane();
+ private LessonSetPane lessonSetPanel = new LessonSetPane();
+ private JCheckBox flipped = new JCheckBox("Flip the Flash Cards");
//Construct the frame
- public SetupPane(LessonManager lessonManager)
+ public SetupPane()
{
- this.lessonManager = lessonManager;
- enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
@@ -61,151 +55,47 @@
}
}
+ public boolean isFlipped()
+ {
+ return flipped.isSelected();
+ }
+
public Iterator iterator()
{
- return new SelectedLessonIterator(lessonList);
+ return lessonPanel.iterator();
}
private void jbInit() throws Exception
{
setLayout(new BorderLayout());
- JPanel lessonPanel = new JPanel(new BorderLayout());
- lessonPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Lessons: "));
- lessonPanel.add(new JScrollPane(lessonList));
-// lessonList.setCellRenderer(new CheckBoxListCellRenderer());
- lessonSetList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
- lessonSetList.addListSelectionListener(new LessonSetSelectionListener(lessonList));
+ setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
+ "Select a Lesson Set, then one or more Lessons: "));
- JPanel lessonSetPanel = new JPanel(new BorderLayout());
- lessonSetPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Lesson Sets: "));
- lessonSetPanel.add(new JScrollPane(lessonSetList), BorderLayout.CENTER);
+ FlashCardPane flashCardPanel = new FlashCardPane();
- JSplitPane splitPane = new FixedSplitPane();
- splitPane.setResizeWeight(0.3D);
- splitPane.setDividerLocation(0.3D);
- splitPane.setRightComponent(lessonPanel);
- splitPane.setLeftComponent(lessonSetPanel);
+ lessonSetPanel.addListSelectionListener(lessonPanel);
+ lessonPanel.addListSelectionListener(flashCardPanel);
- add(splitPane);
+ JSplitPane horizontalSplitPane = new FixedSplitPane();
+ horizontalSplitPane.setResizeWeight(0.3D);
+ horizontalSplitPane.setDividerLocation(0.3D);
+ horizontalSplitPane.setRightComponent(lessonPanel);
+ horizontalSplitPane.setLeftComponent(lessonSetPanel);
- loadLessonSets();
- }
+// JSplitPane verticalSplitPane = new FixedSplitPane(JSplitPane.VERTICAL_SPLIT);
+// verticalSplitPane.setOneTouchExpandable(true);
+// verticalSplitPane.setDividerSize(6);
+// verticalSplitPane.setDividerLocation(0.5D);
+// verticalSplitPane.setResizeWeight(0.5D);
+// verticalSplitPane.setTopComponent(horizontalSplitPane);
+// verticalSplitPane.setBottomComponent(flashCardPanel);
+ add(horizontalSplitPane, BorderLayout.CENTER);
- private void loadLessonSets()
- {
- Iterator lessonSetIterator = lessonManager.iterator();
- while (lessonSetIterator.hasNext())
- {
- LessonSet lessonSet = (LessonSet) lessonSetIterator.next();
- DefaultListModel model = (DefaultListModel) lessonSetList.getModel();
- model.addElement(lessonSet);
- }
+ JPanel panel = new JPanel();
+ panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
+ "Show the backs of the Flash Cards for the test: "));
+ panel.add(flipped);
+ add(panel, BorderLayout.SOUTH);
}
- /**
- * Iterator over the selections in a JList
- */
- private static class SelectedLessonIterator implements Iterator
- {
-
- public SelectedLessonIterator(JList list)
- {
- model = (DefaultListModel) list.getModel();
- selectedIndexes = list.getSelectedIndices();
- }
-
- /* (non-Javadoc)
- * @see java.util.Iterator#remove()
- */
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
- /* (non-Javadoc)
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext()
- {
- return currentIndex < selectedIndexes.length;
- }
-
- /* (non-Javadoc)
- * @see java.util.Iterator#next()
- */
- public Object next()
- {
- return model.get(selectedIndexes[currentIndex++]);
- }
-
- private int[] selectedIndexes;
- private DefaultListModel model;
- private int currentIndex;
- }
- /**
- * When a <code>LessonSet</code> is loaded this listener will populate the lessonList
- * with the <code>Lesson</code>s.
- */
- private static class LessonSetSelectionListener implements ListSelectionListener
- {
-
- /**
- * Create a listener that populates the lessonList with lessons.
- * @param lessonList the list to populate
- */
- public LessonSetSelectionListener(JList lessonList)
- {
- this.lessonList = lessonList;
- }
-
- /* (non-Javadoc)
- * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
- */
- public void valueChanged(ListSelectionEvent e)
- {
- if (e.getValueIsAdjusting())
- {
- return;
- }
- JList list = (JList) e.getSource();
- LessonSet lessonSet = (LessonSet) list.getSelectedValue();
- DefaultListModel model = (DefaultListModel) lessonList.getModel();
- model.clear();
- if (lessonSet != null)
- {
- Iterator lessonIterator = lessonSet.iterator();
- while (lessonIterator.hasNext())
- {
- Lesson lesson = (Lesson) lessonIterator.next();
- model.addElement(lesson);
- }
- }
- }
- private JList lessonList;
- }
-
- /**
- * This renderer shows selection with a check box instead of shading the row.
- */
- private static class CheckBoxListCellRenderer extends JCheckBox implements ListCellRenderer
- {
- public CheckBoxListCellRenderer()
- {
- // So it looks like it is a row in a list, we need to show the background of the list
- // and not the checkbox.
- setOpaque(false);
- }
-
- /* (non-Javadoc)
- * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
- */
- public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
- {
- setSelected(isSelected);
- setText(value.toString());
- setFocusPainted(cellHasFocus);
- return this;
- }
-
- }
-}
\ No newline at end of file
+}
More information about the sword-cvs
mailing list