[jsword-svn] r1606 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic common-swing/src/main/java/org/crosswire/common/swing jsword/src/main/java/org/crosswire/jsword/book/basic

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Fri Aug 3 20:36:23 MST 2007


Author: dmsmith
Date: 2007-08-03 20:36:22 -0700 (Fri, 03 Aug 2007)
New Revision: 1606

Added:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java
Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/FontStore.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookMetaData.java
Log:
Added persistent font to Books and Languages

Added: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java	                        (rev 0)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java	2007-08-04 03:36:22 UTC (rev 1606)
@@ -0,0 +1,98 @@
+/**
+ * Distribution License:
+ * BibleDesktop 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
+ *
+ * Copyright: 2007
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: org.eclipse.jdt.ui.prefs 1178 2006-11-06 12:48:02Z dmsmith $
+ */
+
+package org.crosswire.bibledesktop.book.install;
+
+import java.awt.Font;
+
+import org.crosswire.bibledesktop.desktop.XSLTProperty;
+import org.crosswire.common.swing.FontStore;
+import org.crosswire.common.swing.GuiConvert;
+import org.crosswire.common.util.Language;
+import org.crosswire.jsword.book.Book;
+import org.crosswire.jsword.book.BookMetaData;
+import org.crosswire.jsword.util.Project;
+
+/**
+ *
+ *
+ * @see gnu.gpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author DM Smith [dmsmith555 at yahoo dot com]
+ */
+public class BookFont extends FontStore
+{
+
+    /**
+     * Create a persistent Book Font Store.
+     */
+    private BookFont()
+    {
+        super("BookFonts", Project.instance().getWritablePropertiesURI("BookFonts")); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    public static BookFont instance()
+    {
+        return fonts;
+    }
+
+    /**
+     * Set the font for the book.
+     * 
+     * @param book the book
+     * @param font the font
+     */
+    public void setFont(Book book, Font font)
+    {
+        super.setFont(book.getInitials(), font);
+    }
+
+    /**
+     * Get the most appropriate font for the book.
+     * 
+     * @param book the book
+     * @return the font
+     */
+    public Font getFont(Book book)
+    {
+        String fontName = (String) book.getBookMetaData().getProperty(BookMetaData.KEY_FONT);
+        String fontSpec = XSLTProperty.FONT.getStringState();
+        if (fontName != null)
+        {
+            Font bookFont = GuiConvert.deriveFont(fontSpec, fontName);
+            // Make sure it is installed. Java does substitution. Make sure we got what we wanted.
+            if (bookFont.getFamily().equalsIgnoreCase(fontName))
+            {
+                fontSpec = GuiConvert.font2String(bookFont);
+            }
+        }
+
+        return fonts.getFont(book.getInitials(), book.getLanguage(), fontSpec);
+    }
+
+    public Font getFont(Language language)
+    {
+        return fonts.getFont(null, language, null);
+    }
+
+    static BookFont fonts = new BookFont();
+}

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	2007-08-03 21:34:46 UTC (rev 1605)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java	2007-08-04 03:36:22 UTC (rev 1606)
@@ -498,10 +498,19 @@
         }
 
         Object last = path.getLastPathComponent();
-        //Book book = getBook(last);
+        Book book = getBook(last);
+        if (book != null)
+        {
+            Font picked = FontChooser.showDialog(this, Msg.FONT_CHOOSER.toString(), BookFont.instance().getFont(book));
+            BookFont.instance().setFont(book, picked);
+        }
 
-        Font picked = FontChooser.showDialog(this, Msg.FONT_CHOOSER.toString(), null);
-        
+        Language language = getLanguage(last);
+        if (language != null)
+        {
+            Font picked = FontChooser.showDialog(this, Msg.FONT_CHOOSER.toString(), BookFont.instance().getFont(language));
+            BookFont.instance().setFont(language, picked);
+        }
     }
 
     /**

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2007-08-03 21:34:46 UTC (rev 1605)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2007-08-04 03:36:22 UTC (rev 1606)
@@ -42,6 +42,7 @@
 import javax.swing.text.JTextComponent;
 import javax.xml.transform.TransformerException;
 
+import org.crosswire.bibledesktop.book.install.BookFont;
 import org.crosswire.bibledesktop.util.ConfigurableSwingConverter;
 import org.crosswire.common.swing.ActionFactory;
 import org.crosswire.common.swing.CWScrollPane;
@@ -95,17 +96,7 @@
 
             BookMetaData bmd = book.getBookMetaData();
 
-            String fontName = (String) bmd.getProperty(BookMetaData.KEY_FONT);
-            String fontSpec = XSLTProperty.FONT.getStringState();
-            if (fontName != null)
-            {
-                Font bookFont = GuiConvert.deriveFont(fontSpec, fontName);
-                // Make sure it is installed. Java does substitution. Make sure we got what we wanted.
-                if (bookFont.getFamily().equalsIgnoreCase(fontName))
-                {
-                    fontSpec = GuiConvert.font2String(bookFont);
-                }
-            }
+            String fontSpec = GuiConvert.font2String(BookFont.instance().getFont(book));
 
             SAXEventProvider osissep = bdata.getSAXEventProvider();
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java	2007-08-03 21:34:46 UTC (rev 1605)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java	2007-08-04 03:36:22 UTC (rev 1606)
@@ -23,7 +23,6 @@
 
 import java.awt.Component;
 import java.awt.ComponentOrientation;
-import java.awt.Font;
 import java.awt.event.MouseListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
@@ -43,6 +42,7 @@
 import javax.swing.text.html.HTMLEditorKit;
 import javax.xml.transform.TransformerException;
 
+import org.crosswire.bibledesktop.book.install.BookFont;
 import org.crosswire.bibledesktop.desktop.XSLTProperty;
 import org.crosswire.bibledesktop.display.BookDataDisplay;
 import org.crosswire.bibledesktop.display.URIEvent;
@@ -152,19 +152,7 @@
         boolean direction = bmd.isLeftToRight();
         txtView.applyComponentOrientation(direction ? ComponentOrientation.LEFT_TO_RIGHT : ComponentOrientation.RIGHT_TO_LEFT);
 
-        String fontName = (String) bmd.getProperty(BookMetaData.KEY_FONT);
-        // normalize to a consistent way
-        String fontSpec = XSLTProperty.FONT.getStringState();
-        if (fontName != null)
-        {
-            Font bookFont = GuiConvert.deriveFont(fontSpec, fontName);
-            // Make sure it is installed. Java does substitution. Make sure we got what we wanted.
-            if (bookFont.getFamily().equalsIgnoreCase(fontName))
-            {
-                fontSpec = GuiConvert.font2String(bookFont);
-            }
-        }
-
+        String fontSpec = GuiConvert.font2String(BookFont.instance().getFont(getFirstBook()));
         try
         {
             SAXEventProvider osissep = bdata.getSAXEventProvider();

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/FontStore.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/FontStore.java	2007-08-03 21:34:46 UTC (rev 1605)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/FontStore.java	2007-08-04 03:36:22 UTC (rev 1606)
@@ -26,6 +26,7 @@
 import java.net.URI;
 import java.util.Properties;
 
+import org.crosswire.common.util.Language;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.NetUtil;
 
@@ -103,17 +104,37 @@
      * Store a font specification for the resource.
      * 
      * @param resource the resource
-     * @param fontSpec the font specification, understandable by
-     *            <code>Font.decode()</code>
+     * @param font the font
      */
-    public void setFont(String resource, String fontSpec)
+    public void setFont(String resource, Font font)
     {
+        if (resource == null || font == null)
+        {
+            return;
+        }
         load();
-        fontMap.setProperty(resource, fontSpec);
+        fontMap.setProperty(resource, GuiConvert.font2String(font));
         store();
     }
 
     /**
+     * Store a font specification for the resource.
+     * 
+     * @param resource the resource
+     * @param font the font
+     */
+    public void setFont(Language lang, Font font)
+    {
+        if (lang == null || font == null)
+        {
+            return;
+        }
+        load();
+        fontMap.setProperty(new StringBuffer(LANG_KEY_PREFIX).append(lang.getCode()).toString(), GuiConvert.font2String(font));
+        store();
+    }
+
+    /**
      * Get a font for the specified resource. If it does not work try the
      * following in order: the specified language's font, the fallback font, and
      * the default font. Of course, if that does not work, use any font that
@@ -122,9 +143,10 @@
      * 
      * @param resource the name of the resource for whom the font is stored.
      * @param lang the language of the resource
+     * @param fallback the fontspec for the fallback font
      * @return the requested font if possible. A fallback font otherwise.
      */
-    public Font getFont(String resource, String fallback, String lang)
+    public Font getFont(String resource, Language lang, String fallback)
     {
         load();
 
@@ -146,7 +168,7 @@
 
         if (lang != null)
         {
-            fontSpec = fontMap.getProperty(new StringBuffer(LANG_KEY_PREFIX).append(lang).toString());
+            fontSpec = fontMap.getProperty(new StringBuffer(LANG_KEY_PREFIX).append(lang.getCode()).toString());
         }
 
         if (fontSpec != null)

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookMetaData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookMetaData.java	2007-08-03 21:34:46 UTC (rev 1605)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookMetaData.java	2007-08-04 03:36:22 UTC (rev 1606)
@@ -133,7 +133,7 @@
      */
     public Language getLanguage()
     {
-        return lang;
+        return (Language) getProperty(KEY_XML_LANG);
     }
 
     /**
@@ -141,7 +141,7 @@
      */
     public void setLanguage(Language language)
     {
-        lang = language;
+        putProperty(KEY_XML_LANG, language);
     }
 
     /* (non-Javadoc)
@@ -327,7 +327,6 @@
      * The single key version of the properties
      */
     private Map prop = new LinkedHashMap();
-    private Language lang;
 
     private BookDriver driver;
     private IndexStatus indexStatus = IndexStatus.UNDONE;




More information about the jsword-svn mailing list