[jsword-svn] r2285 - in trunk/bibledesktop/src/main/java/org/crosswire: bibledesktop/book/install common/progress/swing common/swing
dmsmith at crosswire.org
dmsmith at crosswire.org
Wed Mar 6 07:27:14 MST 2013
Author: dmsmith
Date: 2013-03-06 07:27:14 -0700 (Wed, 06 Mar 2013)
New Revision: 2285
Modified:
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java
trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java
trunk/bibledesktop/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java
trunk/bibledesktop/src/main/java/org/crosswire/common/swing/ActionFactory.java
Log:
Keeping up with changes in JSword.
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java 2013-03-01 11:56:00 UTC (rev 2284)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/IndexResolver.java 2013-03-06 14:27:14 UTC (rev 2285)
@@ -62,7 +62,7 @@
* @param parent
*
*/
- public static void scheduleIndex(Book book, Component parent) {
+ public static void scheduleIndex(final Book book, Component parent) {
int choice = 1;
switch (choice) {
@@ -97,14 +97,24 @@
int yn = CWOptionPane.showConfirmDialog(parent, gmsg.toString(), gtitle, JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (yn == JOptionPane.YES_OPTION) {
- IndexManagerFactory.getIndexManager().scheduleIndexCreation(book);
+ Thread work = new Thread(new Runnable() {
+ public void run() {
+ IndexManagerFactory.getIndexManager().scheduleIndexCreation(book);
+ }
+ });
+ work.start();
}
}
}
break;
case 1: // generate
- IndexManagerFactory.getIndexManager().scheduleIndexCreation(book);
+ Thread work = new Thread(new Runnable() {
+ public void run() {
+ IndexManagerFactory.getIndexManager().scheduleIndexCreation(book);
+ }
+ });
+ work.start();
break;
default: // cancel
Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java 2013-03-01 11:56:00 UTC (rev 2284)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java 2013-03-06 14:27:14 UTC (rev 2285)
@@ -466,46 +466,62 @@
}
Object last = path.getLastPathComponent();
- Book name = getBook(last);
+ final Book name = getBook(last);
- try {
- // Is the book already installed? Then nothing to do.
- Book book = Books.installed().getBook(name.getName());
- if (book != null && !installer.isNewer(name)) {
- // TRANSLATOR: Popup message indicating that the book is already installed.
- // {0} is a placeholder for the name of the book.
- Reporter.informUser(this, BDMsg.gettext("Book already installed: {0}", name.getName()));
- return;
- }
+ // Is the book already installed? Then nothing to do.
+ Book book = Books.installed().getBook(name.getName());
+ if (book != null && !installer.isNewer(name)) {
+ // TRANSLATOR: Popup message indicating that the book is already installed.
+ // {0} is a placeholder for the name of the book.
+ Reporter.informUser(this, BDMsg.gettext("Book already installed: {0}", name.getName()));
+ return;
+ }
- float size = installer.getSize(name) / 1024.0F;
+ float size = installer.getSize(name) / 1024.0F;
- String formattedMsg = "";
- if (size > 1024.0F) {
- size /= 1024.0F;
- // TRANSLATOR: The size of the book is provided so that the user can decide whether to continue a download.
- // {0} is a placeholder for the name of the book.
- // {1,number,###,###,###.#} is a placeholder for the size of the download in megabytes.
- // The pattern ###,###,###.# says to separate the number at every third digit and
- // to show one digit of fractional part.
- // The , and . will automatically be converted into the user's proper separators.
- formattedMsg = BDMsg.gettext("{0} is {1,number,###,###,###.#}MB. Continue?", name.getName(), Float.valueOf(size));
- } else {
- // TRANSLATOR: The size of the book is provided so that the user can decide whether to continue a download.
- // {0} is a placeholder for the name of the book.
- // {1,number,###,###,###.#} is a placeholder for the size of the download in kilobytes.
- // The pattern ###,###,###.# says to separate the number at every third digit and
- // to show one digit of fractional part.
- // The , and . will automatically be converted into the user's proper separators.
- formattedMsg = BDMsg.gettext("{0} is {1,number,###,###,###.#}KB. Continue?", name.getName(), Float.valueOf(size));
- }
+ String formattedMsg = "";
+ if (size > 1024.0F) {
+ size /= 1024.0F;
+ // TRANSLATOR: The size of the book is provided so that the user can decide whether to continue a download.
+ // {0} is a placeholder for the name of the book.
+ // {1,number,###,###,###.#} is a placeholder for the size of the download in megabytes.
+ // The pattern ###,###,###.# says to separate the number at every third digit and
+ // to show one digit of fractional part.
+ // The , and . will automatically be converted into the user's proper separators.
+ formattedMsg = BDMsg.gettext("{0} is {1,number,###,###,###.#}MB. Continue?", name.getName(), Float.valueOf(size));
+ } else {
+ // TRANSLATOR: The size of the book is provided so that the user can decide whether to continue a download.
+ // {0} is a placeholder for the name of the book.
+ // {1,number,###,###,###.#} is a placeholder for the size of the download in kilobytes.
+ // The pattern ###,###,###.# says to separate the number at every third digit and
+ // to show one digit of fractional part.
+ // The , and . will automatically be converted into the user's proper separators.
+ formattedMsg = BDMsg.gettext("{0} is {1,number,###,###,###.#}KB. Continue?", name.getName(), Float.valueOf(size));
+ }
- // TRANSLATOR: Title to a dialog asking whether the user should download the book based on it's size.
- if (CWOptionPane.showConfirmDialog(this, formattedMsg, BDMsg.gettext("Download Book"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
- installer.install(name);
- }
- } catch (InstallException ex) {
- Reporter.informUser(this, ex);
+ // TRANSLATOR: Title to a dialog asking whether the user should download the book based on it's size.
+ if (CWOptionPane.showConfirmDialog(this, formattedMsg, BDMsg.gettext("Download Book"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
+ // So now we know what we want to install
+ // All we need to do is installer.install(name)
+ // however we are doing it in the background.
+ final SitePane pane = this;
+ final Thread worker = new Thread("BookDownloader") {
+ /* (non-Javadoc)
+ * @see java.lang.Thread#run()
+ */
+ @Override
+ public void run() {
+ try {
+ installer.install(name);
+ } catch (InstallException ex) {
+ Reporter.informUser(pane, ex);
+ }
+ }
+ };
+
+ // this actually starts the thread off
+ worker.setPriority(Thread.MIN_PRIORITY);
+ worker.start();
}
}
Modified: trunk/bibledesktop/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java 2013-03-01 11:56:00 UTC (rev 2284)
+++ trunk/bibledesktop/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java 2013-03-06 14:27:14 UTC (rev 2285)
@@ -30,9 +30,9 @@
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import javax.swing.JButton;
import javax.swing.JPanel;
@@ -77,9 +77,9 @@
JobManager.addWorkListener(this);
- Set<Progress> current = JobManager.getJobs();
- for (Progress job : current) {
- addJob(job);
+ Iterator<Progress> iter = JobManager.iterator();
+ while (iter.hasNext()) {
+ addJob(iter.next());
}
this.setLayout(new GridLayout(1, 0, 2, 0));
Modified: trunk/bibledesktop/src/main/java/org/crosswire/common/swing/ActionFactory.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/common/swing/ActionFactory.java 2013-03-01 11:56:00 UTC (rev 2284)
+++ trunk/bibledesktop/src/main/java/org/crosswire/common/swing/ActionFactory.java 2013-03-06 14:27:14 UTC (rev 2285)
@@ -33,6 +33,7 @@
import javax.swing.JLabel;
import org.crosswire.common.util.OSType;
+import org.crosswire.common.util.Reporter;
import org.crosswire.common.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -173,7 +174,7 @@
// Instead of cascading if/then/else
// use reflection to do a direct lookup and call
String methodName = METHOD_PREFIX + action;
- Exception ex = null;
+ Throwable ex = null;
try {
try {
Method doMethod = bean.getClass().getDeclaredMethod(methodName, ActionEvent.class);
@@ -189,11 +190,13 @@
} catch (IllegalAccessException e) {
ex = e;
} catch (InvocationTargetException e) {
- ex = e;
+ // When the method throws an exception, this wraps the real reason.
+ ex = e.getCause();
}
if (ex != null) {
log.error("Could not execute method {}.{}()", bean.getClass().getName(), methodName, ex);
+ Reporter.informUser(bean.getClass(), ex);
}
}
More information about the jsword-svn
mailing list