[jsword-svn] r1957 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install common-swing/src/main/java/org/crosswire/common/swing

dmsmith at crosswire.org dmsmith at crosswire.org
Sun Oct 25 05:41:16 MST 2009


Author: dmsmith
Date: 2009-10-25 05:41:16 -0700 (Sun, 25 Oct 2009)
New Revision: 1957

Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.properties
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane_control.properties
   trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/FontStore.java
Log:
BD-144,BD-145 - Reset Font and bug fix to show styles of set font.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java	2009-10-25 00:33:35 UTC (rev 1956)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/BookFont.java	2009-10-25 12:41:16 UTC (rev 1957)
@@ -94,5 +94,40 @@
         return fonts.getFont(null, language, null);
     }
 
+    /**
+     * Is a font for this book / language set in the properties file?
+     * 
+     * @param book the book to test
+     * @param lang the language to test
+     * @return <code>true</code> a font property was set, <code>false</code> otherwise
+     */
+    public boolean isSet(Book book, Language lang)
+    {
+        if (book != null)
+        {
+            return getFontMap().getProperty(book.getInitials()) != null;
+        }
+        if (lang != null)
+        {
+            return getFontMap().getProperty(new StringBuffer(LANG_KEY_PREFIX).append(lang.getCode()).toString()) != null;
+        }
+        return false;
+    }
+
+    /**
+     * Remove the entry for this book / language in the properties file and use the default font
+     */
+    public void resetFont(Book book, Language lang)
+    {
+        if (book != null)
+        {
+            resetFont(book.getInitials());
+        }
+        if (lang != null)
+        {
+            resetFont(new StringBuffer(LANG_KEY_PREFIX).append(lang.getCode()).toString());
+        }
+    }
+
     private 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	2009-10-25 00:33:35 UTC (rev 1956)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.java	2009-10-25 12:41:16 UTC (rev 1957)
@@ -296,11 +296,12 @@
         }
         else
         {
-            panel.setLayout(new GridLayout(2, 2, 3, 3));
+            panel.setLayout(new GridLayout(3, 2, 3, 3));
             panel.add(new JButton(actions.getAction(DELETE)));
             panel.add(new JButton(actions.getAction(UNINDEX)));
             panel.add(new JButton(actions.getAction(CHOOSE_FONT)));
             panel.add(new JButton(actions.getAction(UNLOCK)));
+            panel.add(new JButton(actions.getAction(RESET_FONT)));
         }
         return panel;
     }
@@ -533,9 +534,28 @@
             Font picked = FontChooser.showDialog(this, Msg.FONT_CHOOSER.toString(), BookFont.instance().getFont(language));
             BookFont.instance().setFont(language, picked);
         }
+        actions.getAction(RESET_FONT).setEnabled(BookFont.instance().isSet(book, language));
     }
 
     /**
+     * Resets any font specifically set for this Book / Language
+     */
+    public void doResetFont()
+    {
+        TreePath path = treAvailable.getSelectionPath();
+        if (path == null)
+        {
+            return;
+        }
+
+        Object last = path.getLastPathComponent();
+        Book book = getBook(last);
+        Language language = getLanguage(last);
+        BookFont.instance().resetFont(book, language);
+        actions.getAction(RESET_FONT).setEnabled(false);
+    }
+
+    /**
      * Something has been (un)selected in the tree
      */
     protected void selected()
@@ -559,6 +579,7 @@
         actions.getAction(INSTALL).setEnabled(book != null && book.isSupported());
         actions.getAction(INSTALL_SEARCH).setEnabled(book != null && book.isSupported() && book.getBookCategory() == BookCategory.BIBLE);
         actions.getAction(CHOOSE_FONT).setEnabled(book != null || lang != null);
+        actions.getAction(RESET_FONT).setEnabled(BookFont.instance().isSet(book, lang));
     }
 
     public void setTreeModel(BookList books)
@@ -614,6 +635,7 @@
     private static final String UNLOCK = "Unlock"; //$NON-NLS-1$
     private static final String CHOOSE_FONT = "ChooseFont"; //$NON-NLS-1$
     private static final String UNINDEX = "Unindex"; //$NON-NLS-1$
+    private static final String RESET_FONT = "ResetFont"; //$NON-NLS-1$
 
     /**
      * From which we get our list of installable books

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.properties
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.properties	2009-10-25 00:33:35 UTC (rev 1956)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane.properties	2009-10-25 12:41:16 UTC (rev 1957)
@@ -5,6 +5,9 @@
 ChooseFont.MnemonicKey=F
 ChooseFont.Name=Font...
 ChooseFont.ToolTip=Choose a Font for the Language or Book
+ResetFont.MnemonicKey=E
+ResetFont.Name=Reset Font
+ResetFont.ToolTip=Reset the custom font set for this Language or Book
 Delete.MnemonicKey=D
 Delete.Name=Delete Book
 Delete.ToolTip=Delete the selected book

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane_control.properties
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane_control.properties	2009-10-25 00:33:35 UTC (rev 1956)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitePane_control.properties	2009-10-25 12:41:16 UTC (rev 1957)
@@ -2,5 +2,6 @@
 Unindex.Enabled=false
 Unlock.Enabled=false
 ChooseFont.Enabled=false
+ResetFont.Enabled=false
 Install.Enabled=false
 InstallSearch.Enabled=false

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java	2009-10-25 00:33:35 UTC (rev 1956)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java	2009-10-25 12:41:16 UTC (rev 1957)
@@ -112,7 +112,11 @@
                       ? new JDialog((JFrame) root, title, true)
                       : new JDialog((JDialog) root, title, true);
 
-        fontc.name.setSelectedItem(initial != null ? initial : DEFAULT_FONT.getFont());
+        Font font = (initial != null) ? initial : DEFAULT_FONT.getFont();
+        fontc.name.setSelectedItem(font);
+        fontc.bold.setSelected(font.isBold());
+        fontc.italic.setSelected(font.isItalic());
+        fontc.size.setSelectedItem(new Integer(font.getSize()));
 
         final ActionFactory actions = new ActionFactory(FontChooser.class, fontc);
 
@@ -333,6 +337,35 @@
         private static final long serialVersionUID = 3256726195025358905L;
     }
 
+    /**
+     * An extension of JComboBox that selects a font in the combo based on it's
+     * name, not object equivalence.
+     */
+    static class FontNameComboBox extends JComboBox
+    {
+        public void setSelectedItem(Object anObject)
+        {
+            if ((selectedItemReminder == null || !selectedItemReminder.equals(anObject)) && (anObject instanceof Font))
+            {
+                String fontName = ((Font) anObject).getName();
+                for (int i = 0; i < dataModel.getSize(); i++)
+                {
+                    Object element = dataModel.getElementAt(i);
+                    if (element instanceof Font && (((Font) element).getName().equals(fontName)))
+                    {
+                        super.setSelectedItem(element);
+                        return;
+                    }
+                }
+            }
+        }
+
+        /**
+         * Serialization ID
+         */
+        private static final long serialVersionUID = -7394816349446551753L;
+    }
+
     public static final String PROPERTY_STYLE = "style"; // //$NON-NLS-1$
 
     /**
@@ -368,7 +401,7 @@
     /**
      * The choice of font name
      */
-    protected JComboBox name = new JComboBox();
+    protected JComboBox name = new FontNameComboBox();
 
     /**
      * Bold font?

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	2009-10-25 00:33:35 UTC (rev 1956)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/FontStore.java	2009-10-25 12:41:16 UTC (rev 1957)
@@ -141,6 +141,18 @@
     }
 
     /**
+     * Remove the font settings for a given key
+     * 
+     * @param key the book initials or language code 
+     */
+    public void resetFont(String key)
+    {
+        load();
+        fontMap.remove(key);
+        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




More information about the jsword-svn mailing list