[sword-svn] r99 - in trunk/app: . src/org/crosswire/flashcards
Apache
apache at www.crosswire.org
Sun Dec 3 17:14:32 MST 2006
Author:
Date: 2006-12-03 17:14:30 -0700 (Sun, 03 Dec 2006)
New Revision: 99
Modified:
trunk/app/Flash.jpx.local
trunk/app/src/org/crosswire/flashcards/FlashCard.java
trunk/app/src/org/crosswire/flashcards/FlashCardRep.java
trunk/app/src/org/crosswire/flashcards/Lesson.java
trunk/app/src/org/crosswire/flashcards/LessonManager.java
trunk/app/src/org/crosswire/flashcards/QuizPane.java
Log:
First cut at working audio (play, not yet record)
Modified: trunk/app/Flash.jpx.local
===================================================================
--- trunk/app/Flash.jpx.local 2006-12-03 11:07:44 UTC (rev 98)
+++ trunk/app/Flash.jpx.local 2006-12-04 00:14:30 UTC (rev 99)
@@ -5,9 +5,11 @@
classFilter.unittest.3[0]=com.borland.jbuilder.unittest.JBTestRunner
classFilter.unittest.4[0]=sun.reflect.NativeMethodAccessorImpl
classFilter.unittest.5[0]=sun.reflect.DelegatingMethodAccessorImpl
-content.layout.xml.[0]=<project-layout><tab_container selected_index="0"><tab node_name="src/org/crosswire/flashcards/QuizPane.java"/></tab_container></project-layout>
+content.layout.xml.[0]=<project-layout><tab_container selected_index="3"><tab node_name="src/org/crosswire/flashcards/FlashCard.java"/><tab node_name="src/org/crosswire/flashcards/FlashCardRep.java"/><tab node_name="src/org/crosswire/flashcards/Lesson.java"/><tab node_name="src/org/crosswire/flashcards/LessonManager.java"/><tab node_name="src/org/crosswire/flashcards/LessonPane.java"/><tab node_name="src/org/crosswire/flashcards/LessonSet.java"/><tab node_name="src/org/crosswire/flashcards/QuizPane.java"/></tab_container></project-layout>
debug.Breakpoints.1[0]=1 038 org.crosswire.flashcards.LessonSetPane47 src/org/crosswire/flashcards/LessonSetPane.java3 1271 10 1 10 1 10 1 0 -1
debug.Breakpoints.2[0]=1 038 org.crosswire.flashcards.LessonManager47 src/org/crosswire/flashcards/LessonManager.java3 1341 10 1 10 1 10 1 0 -1
+debug.Breakpoints.3[0]=1 038 org.crosswire.flashcards.LessonManager47 src/org/crosswire/flashcards/LessonManager.java3 1931 10 1 10 1 10 1 0 -1
+debug.Breakpoints.4[0]=1 038 org.crosswire.flashcards.LessonManager47 src/org/crosswire/flashcards/LessonManager.java3 2191 10 1 10 1 10 1 0 -1
debug.EvaluateExpressions.1[0]=uri
debug.NoTracingClasses.1[0]=16 java.lang.Object1 1 -1
debug.NoTracingClasses.2[0]=21 java.lang.ClassLoader1 1 -1
@@ -18,8 +20,14 @@
debug.Watches.3[0]=1 19 entryName10 expression1 02 501 01 01 01 1 -1
editor.search.file_filter_history.1[0]=*.*
editor.search.path_history.1[0]=/space/home/scribe/src/flashcards/app/src
-history.files.active[0]=src/org/crosswire/flashcards/QuizPane.java,F;160,5833,d240``0``open
-history.files.open.1[0]=src/org/crosswire/flashcards/QuizPane.java,F;160,5833,d240``0``open
+history.files.active[0]=src/org/crosswire/flashcards/LessonManager.java,F;177,7533,d240``0``open
+history.files.open.1[0]=src/org/crosswire/flashcards/FlashCard.java,F;45,1394,d240``0``open
+history.files.open.2[0]=src/org/crosswire/flashcards/FlashCardRep.java,F;131,4051,d240``0``open
+history.files.open.3[0]=src/org/crosswire/flashcards/Lesson.java,F;94,2508,d216``1``save
+history.files.open.4[0]=src/org/crosswire/flashcards/LessonManager.java,F;177,7533,d240``0``open
+history.files.open.5[0]=src/org/crosswire/flashcards/LessonPane.java,F;112,3623,d240``0``open
+history.files.open.6[0]=src/org/crosswire/flashcards/LessonSet.java,F;37,1828,d240``0``open
+history.files.open.7[0]=src/org/crosswire/flashcards/QuizPane.java,F;334,12025,d216``1``save
import.optimize.legacyPropertiesRead[0]=1
java.classdefaults.1[0]=java.util.Enumeration
java.classdefaults.2[0]=javax.swing.filechooser.FileFilter
@@ -33,52 +41,52 @@
svn.showconsole[0]=1
sys.Author[0]=
sys.DefaultPackage[0]=flash
-sys.ReopenHistory.1[0]=src/org/crosswire/flashcards/EditorFrame.java
-sys.ReopenHistory.10[0]=[C%|/Borland/JBuilder2005/jdk1.4/jre/lib/rt.jar]/sun/misc/Launcher.class
-sys.ReopenHistory.11[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/net/JarURLConnection.java
-sys.ReopenHistory.12[0]=src/org/crosswire/flashcards/FlashCardPane.java
-sys.ReopenHistory.13[0]=src/org/crosswire/flashcards/LessonSetPane.java
-sys.ReopenHistory.14[0]=src/org/crosswire/flashcards/EditPane.java
-sys.ReopenHistory.15[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/io/File.java
-sys.ReopenHistory.16[0]=src/org/crosswire/flashcards/Lesson.java
-sys.ReopenHistory.17[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/util/Iterator.java
-sys.ReopenHistory.18[0]=src/org/crosswire/flashcards/FlashCardColumns.java
-sys.ReopenHistory.19[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/util/Set.java
-sys.ReopenHistory.2[0]=src/org/crosswire/flashcards/MainFrame.java
-sys.ReopenHistory.20[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/io/File.java
-sys.ReopenHistory.21[0]=[/space/opt/JBuilder2005/jdk1.4/jre/lib/rt.jar]/sun/misc/Launcher.class
-sys.ReopenHistory.22[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/net/URL.java
-sys.ReopenHistory.23[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/util/TreeSet.java
-sys.ReopenHistory.24[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/lang/StringBuffer.java
-sys.ReopenHistory.25[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/lang/System.java
-sys.ReopenHistory.26[0]=src/org/crosswire/common/util/CWClassLoader.java
-sys.ReopenHistory.27[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/lang/Class.java
-sys.ReopenHistory.28[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/net/JarURLConnection.java
-sys.ReopenHistory.29[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/net/URLConnection.java
-sys.ReopenHistory.3[0]=src/org/crosswire/flashcards/LessonManager.java
-sys.ReopenHistory.30[0]=src/org/crosswire/flashcards/migrate/ImportLesson.java
-sys.ReopenHistory.31[0]=src/org/crosswire/modedit/SWInputMethod.java
-sys.ReopenHistory.32[0]=src/org/crosswire/modedit/NullIM.java
-sys.ReopenHistory.33[0]=src/org/crosswire/modedit/Ibycus4IM.java
-sys.ReopenHistory.34[0]=src/org/crosswire/modedit/HebrewMCIM.java
-sys.ReopenHistory.35[0]=src/org/crosswire/modedit/HebrewDurusauIM.java
-sys.ReopenHistory.36[0]=src/org/crosswire/modedit/Gtk2ClassicalGreekIM.java
-sys.ReopenHistory.37[0]=src/org/crosswire/modedit/GreekKeymanIM.java
-sys.ReopenHistory.38[0]=src/org/crosswire/modedit/CGreekIM.java
-sys.ReopenHistory.39[0]=E%|/Eclipse/JSword/flashcards/target/jar/flashcards.jar
-sys.ReopenHistory.4[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/net/URL.java
-sys.ReopenHistory.40[0]=E%|/Eclipse/JSword/flashcards/lessons/black/eimi_pi.flash
-sys.ReopenHistory.41[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter21vocab.flash
-sys.ReopenHistory.42[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter19vocab.flash
-sys.ReopenHistory.43[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter18vocab.flash
-sys.ReopenHistory.44[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter17vocab.flash
-sys.ReopenHistory.45[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter15vocab.flash
-sys.ReopenHistory.46[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter14vocab.flash
-sys.ReopenHistory.47[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter13vocab.flash
-sys.ReopenHistory.48[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter12vocab.flash
-sys.ReopenHistory.49[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter11vocab.flash
-sys.ReopenHistory.5[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/net/URI.java
-sys.ReopenHistory.50[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter04vocab.flash
+sys.ReopenHistory.1[0]=[D%|/Borland/JBuilder2006/jdk1.5/src.zip]/java/awt/Component.java
+sys.ReopenHistory.10[0]=src/org/crosswire/flashcards/LessonSet.java
+sys.ReopenHistory.11[0]=[C%|/Borland/JBuilder2005/jdk1.4/jre/lib/rt.jar]/sun/misc/Launcher.class
+sys.ReopenHistory.12[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/net/JarURLConnection.java
+sys.ReopenHistory.13[0]=src/org/crosswire/flashcards/FlashCardPane.java
+sys.ReopenHistory.14[0]=src/org/crosswire/flashcards/LessonSetPane.java
+sys.ReopenHistory.15[0]=src/org/crosswire/flashcards/EditPane.java
+sys.ReopenHistory.16[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/io/File.java
+sys.ReopenHistory.17[0]=src/org/crosswire/flashcards/Lesson.java
+sys.ReopenHistory.18[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/util/Iterator.java
+sys.ReopenHistory.19[0]=src/org/crosswire/flashcards/FlashCardColumns.java
+sys.ReopenHistory.2[0]=src/org/crosswire/flashcards/EditorFrame.java
+sys.ReopenHistory.20[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/util/Set.java
+sys.ReopenHistory.21[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/io/File.java
+sys.ReopenHistory.22[0]=[/space/opt/JBuilder2005/jdk1.4/jre/lib/rt.jar]/sun/misc/Launcher.class
+sys.ReopenHistory.23[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/net/URL.java
+sys.ReopenHistory.24[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/util/TreeSet.java
+sys.ReopenHistory.25[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/lang/StringBuffer.java
+sys.ReopenHistory.26[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/lang/System.java
+sys.ReopenHistory.27[0]=src/org/crosswire/common/util/CWClassLoader.java
+sys.ReopenHistory.28[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/lang/Class.java
+sys.ReopenHistory.29[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/net/JarURLConnection.java
+sys.ReopenHistory.3[0]=src/org/crosswire/flashcards/MainFrame.java
+sys.ReopenHistory.30[0]=[/space/opt/JBuilder2005/jdk1.4/src.zip]/java/net/URLConnection.java
+sys.ReopenHistory.31[0]=src/org/crosswire/flashcards/migrate/ImportLesson.java
+sys.ReopenHistory.32[0]=src/org/crosswire/modedit/SWInputMethod.java
+sys.ReopenHistory.33[0]=src/org/crosswire/modedit/NullIM.java
+sys.ReopenHistory.34[0]=src/org/crosswire/modedit/Ibycus4IM.java
+sys.ReopenHistory.35[0]=src/org/crosswire/modedit/HebrewMCIM.java
+sys.ReopenHistory.36[0]=src/org/crosswire/modedit/HebrewDurusauIM.java
+sys.ReopenHistory.37[0]=src/org/crosswire/modedit/Gtk2ClassicalGreekIM.java
+sys.ReopenHistory.38[0]=src/org/crosswire/modedit/GreekKeymanIM.java
+sys.ReopenHistory.39[0]=src/org/crosswire/modedit/CGreekIM.java
+sys.ReopenHistory.4[0]=src/org/crosswire/flashcards/LessonManager.java
+sys.ReopenHistory.40[0]=E%|/Eclipse/JSword/flashcards/target/jar/flashcards.jar
+sys.ReopenHistory.41[0]=E%|/Eclipse/JSword/flashcards/lessons/black/eimi_pi.flash
+sys.ReopenHistory.42[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter21vocab.flash
+sys.ReopenHistory.43[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter19vocab.flash
+sys.ReopenHistory.44[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter18vocab.flash
+sys.ReopenHistory.45[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter17vocab.flash
+sys.ReopenHistory.46[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter15vocab.flash
+sys.ReopenHistory.47[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter14vocab.flash
+sys.ReopenHistory.48[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter13vocab.flash
+sys.ReopenHistory.49[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter12vocab.flash
+sys.ReopenHistory.5[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/net/URL.java
+sys.ReopenHistory.50[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter11vocab.flash
sys.ReopenHistory.51[0]=E%|/Eclipse/JSword/flashcards/lessons/black/chapter03vocab.flash
sys.ReopenHistory.52[0]=Flash.jar
sys.ReopenHistory.53[0]=src/org/crosswire/flashcards/MainFrame_AboutBox.java
@@ -88,7 +96,7 @@
sys.ReopenHistory.57[0]=src/flash/OpenFile.java
sys.ReopenHistory.58[0]=src/flash/MainFrame_AboutBox.java
sys.ReopenHistory.59[0]=src/flash/MainFrame.java
-sys.ReopenHistory.6[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/lang/System.java
+sys.ReopenHistory.6[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/net/URI.java
sys.ReopenHistory.60[0]=src/flash/help.png
sys.ReopenHistory.61[0]=Flash.html
sys.ReopenHistory.62[0]=src/flash/EditorFrame_AboutBox.java
@@ -99,12 +107,12 @@
sys.ReopenHistory.67[0]=[/space/opt/JBuilderX/jdk1.4/src.zip]/java/awt/Font.java
sys.ReopenHistory.68[0]=[/space/opt/JBuilderX/jdk1.4/src.zip]/javax/swing/JFileChooser.java
sys.ReopenHistory.69[0]=[/space/opt/JBuilderX/jdk1.4/src.zip]/javax/swing/text/JTextComponent.java
-sys.ReopenHistory.7[0]=src/org/crosswire/flashcards/SetupPane.java
+sys.ReopenHistory.7[0]=[C%|/Borland/JBuilder2005/jdk1.4/src.zip]/java/lang/System.java
sys.ReopenHistory.70[0]=[/space/opt/JBuilderX/jdk1.4/src.zip]/java/util/Properties.java
-sys.ReopenHistory.8[0]=src/org/crosswire/common/swing/RowTable.java
-sys.ReopenHistory.9[0]=src/org/crosswire/flashcards/LessonSet.java
+sys.ReopenHistory.8[0]=src/org/crosswire/flashcards/SetupPane.java
+sys.ReopenHistory.9[0]=src/org/crosswire/common/swing/RowTable.java
team.ActiveVCS[0]=Subversion
-team.lastScanned[0]=1165143667125
+team.lastScanned[0]=1165191489359
wizard.package.package_history.1[0]=flash
wizards.classes.class_type_history.1[0]=boolean
wizards.classes.class_type_history.10[0]=java.lang.String
Modified: trunk/app/src/org/crosswire/flashcards/FlashCard.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCard.java 2006-12-03 11:07:44 UTC (rev 98)
+++ trunk/app/src/org/crosswire/flashcards/FlashCard.java 2006-12-04 00:14:30 UTC (rev 99)
@@ -6,7 +6,7 @@
* 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,
@@ -14,7 +14,7 @@
* 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
*/
@@ -26,7 +26,7 @@
/**
* 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]
*/
@@ -60,6 +60,15 @@
}
}
+ public void setAudioURL(String url) {
+ copy.setAudioURL(url);
+ }
+
+ public String getAudioURL() {
+ return copy.getAudioURL();
+ }
+
+
/**
* Get a particular side of this FlashCard.
* This is useful to flip the cards.
Modified: trunk/app/src/org/crosswire/flashcards/FlashCardRep.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/FlashCardRep.java 2006-12-03 11:07:44 UTC (rev 98)
+++ trunk/app/src/org/crosswire/flashcards/FlashCardRep.java 2006-12-04 00:14:30 UTC (rev 99)
@@ -6,7 +6,7 @@
* 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,
@@ -14,7 +14,7 @@
* 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
*/
@@ -25,7 +25,7 @@
/**
* 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]
*/
@@ -51,6 +51,14 @@
this.back = back;
}
+ public void setAudioURL(String url) {
+ audioURL = url;
+ }
+
+ public String getAudioURL() {
+ return audioURL;
+ }
+
/**
* Get a particular side of this FlashCard.
* This is useful to flip the cards.
@@ -169,6 +177,7 @@
private String front;
private String back;
+ private String audioURL = null;
/**
* Serialization ID
Modified: trunk/app/src/org/crosswire/flashcards/Lesson.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/Lesson.java 2006-12-03 11:07:44 UTC (rev 98)
+++ trunk/app/src/org/crosswire/flashcards/Lesson.java 2006-12-04 00:14:30 UTC (rev 99)
@@ -114,8 +114,25 @@
lesson.load(lessonURL.openConnection().getInputStream());
int wordCount = Integer.parseInt(lesson.getProperty("wordCount"));
description = lesson.getProperty("lessonTitle", url.substring(url.lastIndexOf('/') + 1));
+
+ int baseOffset = url.lastIndexOf("/");
+ if (baseOffset < 0) {
+ baseOffset = url.lastIndexOf( ("\\"));
+ }
+ String lname = url.substring(baseOffset+1);
+ lname = lname.substring(0, lname.indexOf(".flash"));
+ String audioPath = url.substring(0, baseOffset) + "/audio";
+
for (int i = 0; i < wordCount; i++) {
- add(new FlashCard(lesson.getProperty("word" + i), lesson.getProperty("answers" + i)));
+ FlashCard f = new FlashCard(lesson.getProperty("word" + i), lesson.getProperty("answers" + i));
+ String audioURLString = audioPath + "/" + lname + "_" + Integer.toString(i) + ".wav";
+ URL audioURL = new URL(audioURLString);
+ try {
+ audioURL.openConnection().getInputStream();
+ f.setAudioURL(audioURLString);
+ }
+ catch (Exception e) {}
+ add(f);
}
modified = false;
}
Modified: trunk/app/src/org/crosswire/flashcards/LessonManager.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonManager.java 2006-12-03 11:07:44 UTC (rev 98)
+++ trunk/app/src/org/crosswire/flashcards/LessonManager.java 2006-12-04 00:14:30 UTC (rev 99)
@@ -152,7 +152,7 @@
loadJarLessonSets(new File(new java.net.URI(uri)));
}
- catch (Exception e) {
+ catch (Exception e) {
Debug.error(this.getClass().getName(), e.getMessage());
}
}
@@ -190,7 +190,7 @@
String entryName = jarEntry.getName();
// remove trailing '/'
entryName = entryName.substring(0, entryName.length() - 1);
- if (entryName.startsWith(LESSON_ROOT) && !entryName.equals(LESSON_ROOT)) {
+ if (entryName.startsWith(LESSON_ROOT) && !entryName.equals(LESSON_ROOT) && !entryName.endsWith("/audio")) {
// let the description be just the directory name and not the path
add(new LessonSet("jar:" + jarFile.getCanonicalFile().toURL().toString() + "!/" +
entryName));
@@ -216,7 +216,7 @@
Arrays.sort(files);
for (int i = 0; i < files.length; i++) {
File file = files[i];
- if (file.isDirectory()) {
+ if (file.isDirectory() && !file.getName().equals("audio")) {
add(new LessonSet(files[i].toURL().toString()));
}
}
Modified: trunk/app/src/org/crosswire/flashcards/QuizPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/QuizPane.java 2006-12-03 11:07:44 UTC (rev 98)
+++ trunk/app/src/org/crosswire/flashcards/QuizPane.java 2006-12-04 00:14:30 UTC (rev 99)
@@ -48,8 +48,21 @@
import javax.swing.SwingConstants;
import java.awt.*;
import java.awt.Dimension;
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import javax.sound.sampled.AudioFormat;
+import javax.sound.sampled.AudioInputStream;
+import javax.sound.sampled.AudioSystem;
+import javax.sound.sampled.DataLine;
+import javax.sound.sampled.LineUnavailableException;
+import javax.sound.sampled.SourceDataLine;
+
+
+
+
/**
* A panel that quizzes over a selection of lessons.
*
@@ -126,6 +139,9 @@
return (front) ? flashCard.getFront() : back;
}
+ public String getAudioURL() {
+ return flashCard.getAudioURL();
+ }
public String toString() {
return flashCard.getFront();
@@ -147,6 +163,7 @@
playSoundButton.setText("Listen");
playSoundButton.addActionListener(new QuizPane_playSoundButton_actionAdapter(this));
+ playSoundButton.setVisible(false);
showAnswerButton.setFocusPainted(true);
showAnswerButton.setMnemonic('A');
@@ -266,15 +283,64 @@
}
- void playSoundButton_actionPerformed(ActionEvent e) {
- loadTest();
- notLearned = (List) ((ArrayList) words).clone();
- totalAsked = 0;
- totalWrong = 0;
- showRandomWord(currentWord);
- }
+ void playSoundButton_actionPerformed(ActionEvent e1) {
+ // assert we have an audioURL
+ if (currentWord.getAudioURL() == null) {
+ return;
+ }
+ final int EXTERNAL_BUFFER_SIZE = 128000;
+
+ AudioInputStream audioInputStream = null;
+ try {
+ URL audioURL = new URL(currentWord.getAudioURL());
+ audioInputStream = AudioSystem.getAudioInputStream(audioURL);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ AudioFormat audioFormat = audioInputStream.getFormat();
+
+ SourceDataLine line = null;
+ DataLine.Info info = new DataLine.Info(SourceDataLine.class,
+ audioFormat);
+ try {
+ line = (SourceDataLine) AudioSystem.getLine(info);
+ line.open(audioFormat);
+ }
+ catch (LineUnavailableException e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+
+ line.start();
+
+ int nBytesRead = 0;
+ byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
+ while (nBytesRead != -1) {
+ try {
+ nBytesRead = audioInputStream.read(abData, 0, abData.length);
+ }
+ catch (IOException e) {
+ e.printStackTrace();
+ }
+ if (nBytesRead >= 0) {
+ int nBytesWritten = line.write(abData, 0, nBytesRead);
+ }
+ }
+
+ line.drain();
+ line.close();
+ }
+
+
public void showRandomWord(WordEntry last) {
deleteChildren(choicesPanel);
int numToLearn = notLearned.size();
@@ -291,6 +357,9 @@
public void showWord(WordEntry w) {
currentWord = w;
+
+ playSoundButton.setVisible(currentWord.getAudioURL() != null);
+
wordText.setText(w.getSide(!setupPane.isFlipped()));
if (setupPane.isNoMultipleChoice()) {
choicesPanel.invalidate();
More information about the sword-cvs
mailing list