[sword-cvs] r49 - trunk/app/src/org/crosswire/flashcards

Apache apache at crosswire.org
Mon Sep 20 13:27:12 MST 2004


Author: 
Date: 2004-09-20 13:27:12 -0700 (Mon, 20 Sep 2004)
New Revision: 49

Added:
   trunk/app/src/org/crosswire/flashcards/FlashCardEvent.java
   trunk/app/src/org/crosswire/flashcards/FlashCardEventListener.java
Modified:
   trunk/app/src/org/crosswire/flashcards/EditPane.java
   trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java
   trunk/app/src/org/crosswire/flashcards/FlashCardPane.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
   trunk/app/src/org/crosswire/flashcards/SetupPane.java
Log:
added editor to edit tab

Modified: trunk/app/src/org/crosswire/flashcards/EditPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/EditPane.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/EditPane.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -25,15 +25,19 @@
 import java.awt.event.ActionListener;
 
 import javax.swing.BorderFactory;
+import javax.swing.DefaultListSelectionModel;
 import javax.swing.JButton;
+import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
 
 import org.crosswire.common.swing.FixedSplitPane;
 
 
 /**
- * An EditPane consists of Lesson Sets, Lessons and Flash Cards.
+ * An EditPane consists of Lesson Sets, Lessons, Flash Cards and a Flash Card editor.
  * 
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
@@ -58,17 +62,17 @@
         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 LessonSetPane lessonSetPanel = new LessonSetPane(true);
+        final LessonPane lessonPanel = new LessonPane(true);
+        final FlashCardPane flashCardPanel = new FlashCardPane(true);
+        final FlashCardEditor flashCardEditor = new FlashCardEditor();
         final JButton saveButton = new JButton("Save");
         
         saveButton.addActionListener(new ActionListener()
         {
             public void actionPerformed(ActionEvent e)
             {
-                System.err.println("do save");
-                
+                LessonManager.instance().store();
             }
         });
         
@@ -85,24 +89,101 @@
         boolean modified = LessonManager.instance().isModified();
         saveButton.setEnabled(modified);
 
-        lessonSetPanel.addLessonChangeEvent(changeListener);
-        lessonPanel.addLessonChangeEvent(changeListener);
-        flashCardPanel.addLessonChangeEvent(changeListener);
+        // Hook up everything so that they see each other
+        // When changes happen the save button is activated
+        lessonSetPanel.addLessonChangeEventListener(changeListener);
+        lessonPanel.addLessonChangeEventListener(changeListener);
+        flashCardPanel.addLessonChangeEventListener(changeListener);
+        
+        // When flash cards are edited the FlashCard panel is updated
+        flashCardEditor.addFlashCardEventListener(flashCardPanel);
 
-        lessonSetPanel.addListSelectionListener(lessonPanel);
-        lessonPanel.addListSelectionListener(flashCardPanel);
+        // When a lesson set is selected list the lessons in it.
+        lessonSetPanel.addListSelectionListener(new ListSelectionListener()
+        {
+            /* (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();
+                lessonPanel.loadLessons((LessonSet) list.getSelectedValue());
+            }
+        });
 
-        JSplitPane horizontalSplitPane = new FixedSplitPane();
-        horizontalSplitPane.setResizeWeight(0.3D);
-        horizontalSplitPane.setDividerLocation(0.3D);
-        horizontalSplitPane.setRightComponent(lessonPanel);
-        horizontalSplitPane.setLeftComponent(lessonSetPanel);
+        // When a lesson is selected list the flash cards in it
+        lessonPanel.addListSelectionListener(new ListSelectionListener()
+        {
+            /* (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();
+                flashCardPanel.loadFlashCards((Lesson) list.getSelectedValue());
+            }
+        });
+        
+        // When a lesson is selected then FlashCards can be edited
+        lessonPanel.addListSelectionListener(new ListSelectionListener()
+        {
+            public void valueChanged(ListSelectionEvent e)
+            {
+                if (e.getValueIsAdjusting())
+                {
+                    return;
+                }
+                JList list = (JList) e.getSource();
+                flashCardEditor.setActive(list.getSelectedValue() != null);
+            }
+        });
 
+        // When a flash card is selected then it can be edited
+        flashCardPanel.addListSelectionListener(new ListSelectionListener()
+        {
+            public void valueChanged(ListSelectionEvent e)
+            {
+                if (e.getValueIsAdjusting())
+                {
+                    return;
+                }
+                DefaultListSelectionModel listSelectionModel = (DefaultListSelectionModel) e.getSource();
+                int row = listSelectionModel.getMinSelectionIndex();
+                FlashCard flashCard = null;
+                if (row != -1)
+                {
+                    flashCard = flashCardPanel.getFlashCard(row);
+                }
+                flashCardEditor.setFlashCard(flashCard);
+            }
+        });
+
+        JSplitPane lessonSplitPane = new FixedSplitPane();
+        lessonSplitPane.setResizeWeight(0.5D);
+        lessonSplitPane.setDividerLocation(0.5D);
+        lessonSplitPane.setLeftComponent(lessonSetPanel);
+        lessonSplitPane.setRightComponent(lessonPanel);
+
+        JSplitPane flashCardSplitPane = new FixedSplitPane();
+        flashCardSplitPane.setResizeWeight(0.5D);
+        flashCardSplitPane.setDividerLocation(0.5D);
+        flashCardSplitPane.setLeftComponent(flashCardPanel);
+        flashCardSplitPane.setRightComponent(flashCardEditor);
+        flashCardSplitPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(), "Flash Cards: "));
+
         JSplitPane verticalSplitPane = new FixedSplitPane(JSplitPane.VERTICAL_SPLIT);
-        verticalSplitPane.setDividerLocation(0.5D);
-        verticalSplitPane.setResizeWeight(0.5D);
-        verticalSplitPane.setTopComponent(horizontalSplitPane);
-        verticalSplitPane.setBottomComponent(flashCardPanel);
+        verticalSplitPane.setDividerLocation(0.4D);
+        verticalSplitPane.setResizeWeight(0.4D);
+        verticalSplitPane.setTopComponent(lessonSplitPane);
+        verticalSplitPane.setBottomComponent(flashCardSplitPane);
         add(verticalSplitPane, BorderLayout.CENTER);
         
         JPanel buttonPane = new JPanel();

Modified: trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardEditor.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -22,18 +22,18 @@
 
 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.JList;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
-import javax.swing.WindowConstants;
+import javax.swing.event.EventListenerList;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
 
 import org.crosswire.modedit.UniTextEdit;
 
@@ -54,6 +54,10 @@
     private JTextField answers = new JTextField();
     private UniTextEdit wordText = new UniTextEdit();
     protected JDialog dlgMain;
+    private FlashCard flashCard;
+    private JButton btnAdd = new JButton("Add");
+    private JButton btnModify = new JButton("Modify");
+    private JButton btnDelete = new JButton("Delete");
 
     //
     // Methods
@@ -77,108 +81,150 @@
     private void jbInit() throws Exception
     {
         setLayout(new BorderLayout());
+        setBorder(BorderFactory.createEtchedBorder());
 
         wordText.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Front"));
         wordText.setText("");
         wordText.showIMSelect(true);
         wordText.setComponentOrientation(ComponentOrientation.UNKNOWN);
         wordText.setFontSize(30);
-        add(wordText, BorderLayout.CENTER);
+        add(wordText, BorderLayout.NORTH);
 
         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");
-        
+        add(answerPanel, BorderLayout.CENTER);
         btnAdd.addActionListener(new ActionListener()
         {
             public void actionPerformed(ActionEvent e)
             {
-                if (createFlashCard(flashCardPane))
-                {
-                    wordText.setText("");
-                    answers.setText("");
-                }
+                createFlashCard();
             }
+            
         });
 
-        JButton btnOK = new JButton("OK");
-        btnOK.addActionListener(new ActionListener()
+        btnModify.addActionListener(new ActionListener()
         {
             public void actionPerformed(ActionEvent e)
             {
-                if (createFlashCard(flashCardPane))
-                {
-                    dlgMain.dispose();
-                }
+                modifyFlashCard();
             }
+
         });
 
-
-        JButton btnClose = new JButton("Close");
-        
-        btnClose.addActionListener(new ActionListener()
+        btnDelete.addActionListener(new ActionListener()
         {
             public void actionPerformed(ActionEvent e)
             {
-                dlgMain.dispose();
+                deleteFlashCard();
             }
         });
 
         JPanel pnlButtons = new JPanel();
         pnlButtons.add(btnAdd);
-        pnlButtons.add(btnOK);
-        pnlButtons.add(btnClose);
+        pnlButtons.add(btnModify);
+        pnlButtons.add(btnDelete);
+        add(pnlButtons, BorderLayout.SOUTH);
 
-        contentPane.add(pnlButtons, BorderLayout.SOUTH);
-        dlgMain.setLocationRelativeTo(flashCardPane);
-        dlgMain.show();
+        setActive(false);
     }
+    
+    public void setFlashCard(FlashCard newFlashCard)
+    {
+        boolean selected = newFlashCard != null;
+        if (selected)
+        {
+            try
+            {
+                flashCard = (FlashCard) newFlashCard.clone();
+            }
+            catch (CloneNotSupportedException e)
+            {
+                assert false;
+            }
+            wordText.setText(flashCard.getFront());
+            answers.setText(flashCard.getBack());
+        }
+        else
+        {
+            wordText.setText("");
+            answers.setText("");
+        }
+        btnDelete.setEnabled(selected);
+        btnModify.setEnabled(selected);
+    }
+    
+    public void setActive(boolean state)
+    {
+        btnAdd.setEnabled(state);
+        btnModify.setEnabled(flashCard != null);
+        btnDelete.setEnabled(state);
+    }
+
+    protected void createFlashCard()
+    {
+        flashCard = new FlashCard();
+        flashCard.setFront(wordText.getText());
+        flashCard.setBack(answers.getText());
+
+        fireFlashCardChanged(new FlashCardEvent(this, flashCard, FlashCardEvent.ADDED));
+    }
+
+    protected void modifyFlashCard()
+    {
+        assert flashCard != null;
+
+        flashCard.setFront(wordText.getText());
+        flashCard.setBack(answers.getText());
+
+        fireFlashCardChanged(new FlashCardEvent(this, flashCard, FlashCardEvent.MODIFIED));
+    }
+
+    protected void deleteFlashCard()
+    {
+        fireFlashCardChanged(new FlashCardEvent(this, flashCard, FlashCardEvent.DELETED));
+    }
+
+    /**
+     * Adds a view event listener for notification of any changes to the view.
+     *
+     * @param listener the listener
+     */
+    public synchronized void addFlashCardEventListener(FlashCardEventListener listener)
+    {
+        listenerList.add(FlashCardEventListener.class, listener);
+    }
+
+    /**
+     * Removes a view event listener.
+     *
+     * @param listener the listener
+     */
+    public synchronized void removeFlashCardEventListener(FlashCardEventListener listener)
+    {
+        listenerList.remove(FlashCardEventListener.class, listener);
+    }
+
+    /**
+     * Notify the listeners that the view has been removed.
+     *
+     * @param e the event
+     * @see EventListenerList
+     */
+    public void fireFlashCardChanged(FlashCardEvent 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] == FlashCardEventListener.class)
+            {
+                ((FlashCardEventListener) listeners[i + 1]).flashCardChanged(e);
+            }
+        }
+    }
 }

Added: trunk/app/src/org/crosswire/flashcards/FlashCardEvent.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardEvent.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardEvent.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -0,0 +1,66 @@
+/*
+ * 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 FlashCardEvent indicates that a FlashCard has been added, modified or deleted
+ * 
+ * @author DM Smith [ dmsmith555 at yahoo dot com]
+ */
+public class FlashCardEvent extends EventObject
+{
+
+    public static final int ADDED = 0;
+    public static final int MODIFIED = 1;
+    public static final int DELETED = 2;
+    /**
+     * @param source
+     */
+    public FlashCardEvent(Object source, FlashCard aFlashCard, int anAction)
+    {
+        super(source);
+        this.flashCard = aFlashCard;
+        this.action = anAction;
+    }
+
+    /**
+     * @return Returns the flashCard.
+     */
+    public FlashCard getFlashCard()
+    {
+        return flashCard;
+    }
+
+    /**
+     * @return Returns the action.
+     */
+    public int getAction()
+    {
+        return action;
+    }
+
+    private FlashCard flashCard;
+    private int action;
+    
+
+}

Added: trunk/app/src/org/crosswire/flashcards/FlashCardEventListener.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardEventListener.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardEventListener.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -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 FlashCardEvents.
+ *
+ * @author DM Smith [ dmsmith555 at yahoo dot com]
+ */
+public interface FlashCardEventListener extends EventListener
+{
+    void flashCardChanged(FlashCardEvent event);
+}

Modified: trunk/app/src/org/crosswire/flashcards/FlashCardPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardPane.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardPane.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -46,12 +46,9 @@
  * 
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
-public class FlashCardPane extends JPanel implements ListSelectionListener
+public class FlashCardPane extends JPanel implements FlashCardEventListener
 {
     private RowTable wordList = new RowTable(new ArrayList(), new FlashCardColumns());
-    private boolean editable;
-    private JMenuItem newItem;
-    private JMenuItem deleteItem;
     private Lesson lesson;
 
     /**
@@ -70,7 +67,6 @@
      */
     public FlashCardPane(boolean allowsEdits)
     {
-        editable = allowsEdits;
         try
         {
             jbInit();
@@ -85,52 +81,11 @@
     //Component initialization
     private void jbInit() throws Exception
     {
+        wordList.setShowGrid(false);
         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)
@@ -138,13 +93,22 @@
         return lesson.contains(flashCard);
     }
 
+    public FlashCard getFlashCard(int i)
+    {
+        FlashCard flashCard = null;
+        RowTableModel model = (RowTableModel) wordList.getModel();
+        flashCard = (FlashCard) model.getRow(i);
+        return flashCard;
+    }
+
     public void add(FlashCard flashCard)
     {
         lesson.add(flashCard);
         RowTableModel model = (RowTableModel) wordList.getModel();
         model.addRow(flashCard);
         wordList.selectRow(model.getRow(flashCard));
-        
+        wordList.validate();
+        wordList.repaint();
         fireLessonChanged(new LessonChangeEvent(this));
     }
 
@@ -155,35 +119,41 @@
         FlashCard flashCard = (FlashCard) model.getRow(row);
         lesson.remove(flashCard);
         model.removeRow(flashCard);
+        wordList.validate();
+        wordList.repaint();
         fireLessonChanged(new LessonChangeEvent(this));
     }
 
-    protected void enableControls()
+    public void replaceSelected(FlashCard newFlashCard)
     {
-        newItem.setEnabled(lesson != null);
-        int selectedRow = wordList.getSelectedRow();
-        deleteItem.setEnabled(-1 != selectedRow);
+        int row = wordList.getSelectedRow();
+        RowTableModel model = (RowTableModel) wordList.getModel();
+        FlashCard flashCard = (FlashCard) model.getRow(row);
+        lesson.remove(flashCard);
+        model.removeRow(flashCard);
+        lesson.add(newFlashCard);
+        model.addRow(newFlashCard);
+        wordList.selectRow(model.getRow(newFlashCard));
+        wordList.validate();
+        wordList.repaint();
+        fireLessonChanged(new LessonChangeEvent(this));
     }
 
-    /* (non-Javadoc)
-     * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
+    /**
+     * @param lessonPanel
      */
-    public void valueChanged(ListSelectionEvent e)
+    public void addListSelectionListener(ListSelectionListener listener)
     {
-        if (e.getValueIsAdjusting())
-        {
-            return;
-        }
+        wordList.addListSelectionListener(listener);
+    }
 
-        JList list = (JList) e.getSource();
+    public void loadFlashCards(Lesson aLesson)
+    {
         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 = aLesson;
+        if (lesson != null)
         {
-            lesson = (Lesson) lessons[0];
             Iterator flashCardIterator = lesson.iterator();
             while (flashCardIterator.hasNext())
             {
@@ -191,15 +161,36 @@
                 model.addRow(flashCard);
             }
         }
-        enableControls();
     }
 
+    /* (non-Javadoc)
+     * @see org.crosswire.flashcards.FlashCardEventListener#flashCardChanged(org.crosswire.flashcards.FlashCardEvent)
+     */
+    public void flashCardChanged(FlashCardEvent event)
+    {
+        switch (event.getAction())
+        {
+        case FlashCardEvent.ADDED:
+            add(event.getFlashCard());
+            break;
+        case FlashCardEvent.DELETED:
+            deleteSelected();
+            break;
+        case FlashCardEvent.MODIFIED:
+            replaceSelected(event.getFlashCard());
+            break;
+        default :
+            break;
+        }
+
+    }
+
     /**
      * Adds a view event listener for notification of any changes to the view.
      *
      * @param listener the listener
      */
-    public synchronized void addLessonChangeEvent(LessonChangeEventListener listener)
+    public synchronized void addLessonChangeEventListener(LessonChangeEventListener listener)
     {
         listenerList.add(LessonChangeEventListener.class, listener);
     }
@@ -209,7 +200,7 @@
      *
      * @param listener the listener
      */
-    public synchronized void removeLessonChangeEvent(LessonChangeEventListener listener)
+    public synchronized void removeLessonChangeEventListener(LessonChangeEventListener listener)
     {
         listenerList.remove(LessonChangeEventListener.class, listener);
     }
@@ -234,4 +225,4 @@
             }
         }
     }
-}
+}
\ No newline at end of file

Modified: trunk/app/src/org/crosswire/flashcards/LessonPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonPane.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/LessonPane.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -43,7 +43,7 @@
  * 
  * @author DM Smith [dmsmith555 at yahoo dot com]
  */
-public class LessonPane extends JPanel implements ListSelectionListener
+public class LessonPane extends JPanel
 {
     private JList lessonList = new JList(new DefaultListModel());
     private LessonSet lessonSet;
@@ -148,17 +148,9 @@
         
     }
 
-    /* (non-Javadoc)
-     * @see javax.swing.event.ListSelectionListener#valueChanged(javax.swing.event.ListSelectionEvent)
-     */
-    public void valueChanged(ListSelectionEvent e)
+    public void loadLessons(LessonSet aLessonSet)
     {
-        if (e.getValueIsAdjusting())
-        {
-            return;
-        }
-        JList list = (JList) e.getSource();
-        lessonSet = (LessonSet) list.getSelectedValue();
+        lessonSet = aLessonSet;
         DefaultListModel model = (DefaultListModel) lessonList.getModel();
         model.clear();
         if (lessonSet != null)
@@ -170,7 +162,7 @@
                 model.addElement(lesson);
             }
         }
-        enableControls();
+        enableControls();        
     }
 
     private void enableControls()
@@ -184,7 +176,7 @@
      *
      * @param listener the listener
      */
-    public synchronized void addLessonChangeEvent(LessonChangeEventListener listener)
+    public synchronized void addLessonChangeEventListener(LessonChangeEventListener listener)
     {
         listenerList.add(LessonChangeEventListener.class, listener);
     }

Modified: trunk/app/src/org/crosswire/flashcards/LessonSetPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonSetPane.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/LessonSetPane.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -151,7 +151,7 @@
      *
      * @param listener the listener
      */
-    public synchronized void addLessonChangeEvent(LessonChangeEventListener listener)
+    public synchronized void addLessonChangeEventListener(LessonChangeEventListener listener)
     {
         listenerList.add(LessonChangeEventListener.class, listener);
     }

Modified: trunk/app/src/org/crosswire/flashcards/QuizPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/QuizPane.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/QuizPane.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -22,6 +22,7 @@
 
 import java.awt.BorderLayout;
 import java.awt.Component;
+import java.awt.ComponentOrientation;
 import java.awt.Font;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
@@ -143,6 +144,7 @@
         choicesPanelGridLayout.setRows(0);
 
         statusPanel.setLayout(statusPanelBorderLayout);
+        statusBar.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
         statusPanel.add(statusBar, BorderLayout.CENTER);
         statusPanel.add(wCount, BorderLayout.EAST);
 
@@ -171,6 +173,8 @@
 
         gbc.weighty = 0.0;
         gbc.fill = GridBagConstraints.HORIZONTAL;
+        gbc.ipadx = 10;
+        gbc.ipady = 10;
         add(statusPanel, gbc);
     }
 
@@ -329,7 +333,7 @@
             totalAsked++;
             if (ck.getText().compareTo(currentWord.getSide(setupPane.isFlipped())) != 0)
             {
-                statusBar.setText(ck.getText() + " is not correct.  Please try again.");
+                statusBar.setText("Please try again. " + ck.getText() + " is not correct.");
                 wrong++;
                 totalWrong++;
                 ck.setSelected(false);

Modified: trunk/app/src/org/crosswire/flashcards/SetupPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/SetupPane.java	2004-09-19 22:57:31 UTC (rev 48)
+++ trunk/app/src/org/crosswire/flashcards/SetupPane.java	2004-09-20 20:27:12 UTC (rev 49)
@@ -25,8 +25,11 @@
 
 import javax.swing.BorderFactory;
 import javax.swing.JCheckBox;
+import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JSplitPane;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
 
 import org.crosswire.common.swing.FixedSplitPane;
 
@@ -71,11 +74,44 @@
         setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
                         "Select a Lesson Set, then one or more Lessons: "));
 
-        FlashCardPane flashCardPanel = new FlashCardPane();
+        final FlashCardPane flashCardPanel = new FlashCardPane();
 
-        lessonSetPanel.addListSelectionListener(lessonPanel);
-        lessonPanel.addListSelectionListener(flashCardPanel);
+        lessonSetPanel.addListSelectionListener(new ListSelectionListener()
+                        {
+            /* (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();
+                lessonPanel.loadLessons((LessonSet) list.getSelectedValue());
+            }
+        });
 
+        lessonPanel.addListSelectionListener(new ListSelectionListener()
+                        {
+            /* (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();
+                Object[] selections = list.getSelectedValues();
+                if (selections != null && selections.length == 1)
+                {
+                    flashCardPanel.loadFlashCards((Lesson) selections[0]);
+                }
+            }
+        });
+
         JSplitPane horizontalSplitPane = new FixedSplitPane();
         horizontalSplitPane.setResizeWeight(0.3D);
         horizontalSplitPane.setDividerLocation(0.3D);



More information about the sword-cvs mailing list