[sword-svn] r147 - trunk/app/src/org/crosswire/flashcards
Apache
apache at www.crosswire.org
Tue Jan 1 18:24:04 MST 2008
Author:
Date: 2008-01-01 18:24:03 -0700 (Tue, 01 Jan 2008)
New Revision: 147
Modified:
trunk/app/src/org/crosswire/flashcards/ComplexLesson.java
trunk/app/src/org/crosswire/flashcards/LessonManager.java
trunk/app/src/org/crosswire/flashcards/QuizPane.java
Log:
Fixed java 1.5 webstart bug with ' ' spaces in path
Added a font URL cache
Removed most debug
Adjusted choices size slightly to allow for padding
-TAG
Modified: trunk/app/src/org/crosswire/flashcards/ComplexLesson.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/ComplexLesson.java 2008-01-01 23:54:38 UTC (rev 146)
+++ trunk/app/src/org/crosswire/flashcards/ComplexLesson.java 2008-01-02 01:24:03 UTC (rev 147)
@@ -35,6 +35,8 @@
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;
+import java.util.Hashtable;
+import java.security.AccessControlException;
import javax.imageio.ImageIO;
import java.awt.geom.Rectangle2D;
@@ -47,6 +49,7 @@
public class ComplexLesson extends Lesson {
private static final String DIR_PROJECT = ".flashcards";
static String homeProjectPath = "";
+ static Hashtable fontURLCache = new Hashtable();
static {
try {
homeProjectPath = System.getProperty("user.home") + File.separator + DIR_PROJECT;
@@ -81,6 +84,13 @@
// while loop is not really to loop, but instead for break when we find the font
while (font != null && font.length() > 0) {
+ // try to find font in cache
+ String cachedURL = (String)fontURLCache.get(font);
+ if (cachedURL != null) {
+ setFont(cachedURL);
+ break;
+ }
+
// try to find font in ./<FONT>.ttf
try {
String fontPath = "./" + File.separator + font + ".ttf";
@@ -88,10 +98,12 @@
if (fontFile.exists()) {
String url = fontFile.toURL().toString();
setFont(url);
+ fontURLCache.put(font, url);
System.out.println("found font in ./; URL: " + url);
break;
}
}
+ catch (AccessControlException ea) {}
catch (Exception e) { e.printStackTrace(); }
// try to find font in ~/.flashcards/<FONT>.ttf
@@ -101,23 +113,27 @@
if (fontFile.exists()) {
String url = fontFile.toURL().toString();
setFont(url);
+ fontURLCache.put(font, url);
System.out.println("found font in ~/.flashcards; URL: " + url);
break;
}
}
+ catch (AccessControlException ea) {}
catch (Exception e) { e.printStackTrace(); }
// try to find font on our classpath
try {
URL fontURL = ComplexLesson.class.getResource("/" + font + ".ttf");
if (fontURL != null) {
- URLConnection connection = null;
- connection = fontURL.openConnection();
- setFont(fontURL.toString());
+ URLConnection connection = null;
+ connection = fontURL.openConnection();
+ setFont(fontURL.toString());
+ fontURLCache.put(font, fontURL.toString());
System.out.println("found font on classpath");
- break;
+ break;
}
}
+ catch (AccessControlException ea) {}
catch (Exception e) { e.printStackTrace(); }
System.out.println("didn't find font");
Modified: trunk/app/src/org/crosswire/flashcards/LessonManager.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonManager.java 2008-01-01 23:54:38 UTC (rev 146)
+++ trunk/app/src/org/crosswire/flashcards/LessonManager.java 2008-01-02 01:24:03 UTC (rev 147)
@@ -152,8 +152,7 @@
if ((uri.startsWith("file:")) && (!uri.startsWith("file:/"))) {
uri = "file:/" + uri.substring(5);
}
-// int value = JOptionPane.showConfirmDialog(null, uri,
-// "Text Edit", JOptionPane.OK_OPTION) ;
+ uri = uri.replace(" ", "%20");
System.out.println("uri = " + uri);
loadJarLessonSets(new File(new java.net.URI(uri)));
Modified: trunk/app/src/org/crosswire/flashcards/QuizPane.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/QuizPane.java 2008-01-01 23:54:38 UTC (rev 146)
+++ trunk/app/src/org/crosswire/flashcards/QuizPane.java 2008-01-02 01:24:03 UTC (rev 147)
@@ -562,8 +562,6 @@
public float getOptimalFontSize(Rectangle bounds) {
float fontSize = 30;
Rectangle referenceBounds = getMaxBounds(fontSize);
-System.out.println("30 pt Max Bound: " + referenceBounds.toString());
-
float xmult = (float)bounds.width / (float)referenceBounds.width;
float ymult = (float)bounds.height / (float)referenceBounds.height;
fontSize *= (xmult < ymult) ? xmult : ymult;
@@ -579,18 +577,16 @@
Rectangle bounds = jPanel2.getBounds();
bounds.height /= 2;
optimalFontSize = getOptimalFontSize(bounds);
-System.out.println("optimal Font Size: " + optimalFontSize);
- Font newFont = loadFont(currentWord.getFontURL()).deriveFont(optimalFontSize);
- Font choiceFont = newFont.deriveFont(optimalFontSize/(NUM_ANSWERS/NUM_COLUMNS));
+ Font newFont = loadFont(currentWord.getFontURL());
+ Font choiceFont = newFont.deriveFont((float)(optimalFontSize * 0.90) / (NUM_ANSWERS/NUM_COLUMNS));
Iterator iter = picks.iterator();
while (iter.hasNext()) {
((Component) iter.next()).setFont(choiceFont);
}
// Now that bottom layout is adjusted for new font size, computer real
// font size for top
- optimalFontSize = getOptimalFontSize(wordText.getBounds());
+ optimalFontSize = getOptimalFontSize(bounds);
newFont = loadFont(currentWord.getFontURL()).deriveFont(optimalFontSize);
-System.out.println("optimal Font Size: " + optimalFontSize);
wordText.setFont(newFont);
}
More information about the sword-cvs
mailing list