[jsword-svn] r1935 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book jsword/src/main/java/org/crosswire/jsword/book jsword/src/main/java/org/crosswire/jsword/book/basic jsword/src/main/java/org/crosswire/jsword/book/sword

dmsmith at crosswire.org dmsmith at crosswire.org
Tue Feb 24 05:57:51 MST 2009


Author: dmsmith
Date: 2009-02-24 05:57:51 -0700 (Tue, 24 Feb 2009)
New Revision: 1935

Added:
   trunk/jsword/src/main/java/org/crosswire/jsword/book/KeyType.java
Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookMetaData.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java
Log:
Fixed a problem where a CategoryType of MAPS was assuming that it was a Gen Book when it was a Dictionary.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java	2009-02-24 11:39:08 UTC (rev 1934)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java	2009-02-24 12:57:51 UTC (rev 1935)
@@ -55,10 +55,10 @@
 import org.crosswire.common.swing.GuiUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.jsword.book.Book;
-import org.crosswire.jsword.book.BookCategory;
 import org.crosswire.jsword.book.BookFilter;
 import org.crosswire.jsword.book.BookFilters;
 import org.crosswire.jsword.book.Defaults;
+import org.crosswire.jsword.book.KeyType;
 import org.crosswire.jsword.passage.Key;
 import org.crosswire.jsword.passage.NoSuchKeyException;
 import org.crosswire.jsword.passage.Passage;
@@ -414,16 +414,15 @@
         // unselects the book
         if (book != null)
         {
-            BookCategory currentCategory = book.getBookCategory();
-            if (currentCategory.equals(BookCategory.DICTIONARY) || currentCategory.equals(BookCategory.GLOSSARY)
-                || currentCategory.equals(BookCategory.DAILY_DEVOTIONS))
+            KeyType currentCategory = book.getBookMetaData().getKeyType();
+            if (KeyType.LIST.equals(currentCategory))
             {
                 // Don't leave the scroller in the middle of the list!
                 dictionaryKeyList.ensureIndexIsVisible(0);
                 // Make sure that the list of keys is empty.
                 dictionaryKeyList.setModel(new KeyListListModel(null));
             }
-            else if (currentCategory.equals(BookCategory.GENERAL_BOOK))
+            else if (KeyType.TREE.equals(currentCategory))
             {
                 // Don't leave the scroller in the middle of the list!
                 genBookKeyTree.scrollRowToVisible(0);
@@ -440,17 +439,15 @@
         if (selected != null)
         {
             Book selectedBook = (Book) selected;
-            BookCategory category = selectedBook.getBookCategory();
+            KeyType category = selectedBook.getBookMetaData().getKeyType();
             //divider snaps back to its starting point when a new component is set
             int dividerLocation = sptMain.getDividerLocation();
-            if (category.equals(BookCategory.COMMENTARY))
+            if (KeyType.VERSE.equals(category))
             {
                 updateDisplay();
                 sptMain.setTopComponent(commentaryPicker);
             }
-            else if (category.equals(BookCategory.DICTIONARY)
-                     || category.equals(BookCategory.GLOSSARY)
-                     || category.equals(BookCategory.DAILY_DEVOTIONS))
+            else if (KeyType.LIST.equals(category))
             {
                 book = selectedBook;
                 Key key = book.getGlobalKeyList();
@@ -468,7 +465,7 @@
 
                 sptMain.setTopComponent(dictionaryKeyScroller);
             }
-            else // currentCategory.equals(BookCategory.GENERAL_BOOK)
+            else // KeyType.TREE.equals(category)
             {
                 book = selectedBook;
                 Key key = book.getGlobalKeyList();

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java	2009-02-24 11:39:08 UTC (rev 1934)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/BookMetaData.java	2009-02-24 12:57:51 UTC (rev 1935)
@@ -58,6 +58,13 @@
     String getName();
 
     /**
+     * How this Book organizes it's keys.
+     * 
+     * @return the organization of keys of this Book
+     */
+    KeyType getKeyType();
+
+    /**
      * What category of content is this, a Bible or a reference work like a
      * Dictionary or Commentary.
      * @return The category of book

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/KeyType.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/KeyType.java	                        (rev 0)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/KeyType.java	2009-02-24 12:57:51 UTC (rev 1935)
@@ -0,0 +1,153 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 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 Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: CaseType.java 1890 2008-07-09 12:15:15Z dmsmith $
+ */
+package org.crosswire.jsword.book;
+
+import java.io.Serializable;
+
+/**
+ * Types of Key that a Book uses, either verse, list, or tree.
+ *
+ * @see gnu.lgpl.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 KeyType implements Serializable
+{
+    /**
+     * Book contains verses and can be understood as book, chapter and verse.
+     */
+    public static final KeyType VERSE = new KeyType("verse"); //$NON-NLS-1$
+
+    /**
+     * Book organizes its entries in a list, as in a dictionary.
+     */
+    public static final KeyType LIST = new KeyType("list"); //$NON-NLS-1$
+
+    /**
+     * Book organizes its entries in a tree, as in a general book.
+     */
+    public static final KeyType TREE = new KeyType("tree"); //$NON-NLS-1$
+
+    /**
+     * Simple ctor
+     */
+    public KeyType(String name)
+    {
+        this.name = name;
+    }
+
+    /**
+     * Get an integer representation for this CaseType
+     */
+    public int toInteger()
+    {
+        for (int i = 0; i < VALUES.length; i++)
+        {
+            if (equals(VALUES[i]))
+            {
+                return i;
+            }
+        }
+        // cannot get here
+        assert false;
+        return -1;
+    }
+
+    /**
+     * Lookup method to convert from a String
+     */
+    public static KeyType fromString(String name)
+    {
+        for (int i = 0; i < VALUES.length; i++)
+        {
+            KeyType o = VALUES[i];
+            if (o.name.equalsIgnoreCase(name))
+            {
+                return o;
+            }
+        }
+        // cannot get here
+        assert false;
+        return null;
+    }
+
+    /**
+     * Lookup method to convert from an integer
+     */
+    public static KeyType fromInteger(int i)
+    {
+        return VALUES[i];
+    }
+
+    /**
+     * Prevent subclasses from overriding canonical identity based Object methods
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public final boolean equals(Object o)
+    {
+        return super.equals(o);
+    }
+
+    /**
+     * Prevent subclasses from overriding canonical identity based Object methods
+     * @see java.lang.Object#hashCode()
+     */
+    public final int hashCode()
+    {
+        return super.hashCode();
+    }
+
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        return name;
+    }
+
+    /**
+     * The name of the type
+     */
+    private transient String name;
+
+    // Support for serialization
+    private static int nextObj;
+    private final int obj = nextObj++;
+
+    Object readResolve()
+    {
+        return VALUES[obj];
+    }
+
+    private static final KeyType[] VALUES =
+    {
+        VERSE,
+        LIST,
+        TREE,
+    };
+
+    /**
+     * Serialization ID
+     */
+    private static final long serialVersionUID = 8856576924393105712L;
+
+}

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	2009-02-24 11:39:08 UTC (rev 1934)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/AbstractBookMetaData.java	2009-02-24 12:57:51 UTC (rev 1935)
@@ -31,6 +31,7 @@
 import org.crosswire.jsword.book.BookDriver;
 import org.crosswire.jsword.book.BookMetaData;
 import org.crosswire.jsword.book.FeatureType;
+import org.crosswire.jsword.book.KeyType;
 import org.crosswire.jsword.index.IndexStatus;
 import org.jdom.Document;
 
@@ -43,7 +44,16 @@
  */
 public abstract class AbstractBookMetaData implements BookMetaData
 {
+
     /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.BookMetaData#getKeyType()
+     */
+    public KeyType getKeyType()
+    {
+        return KeyType.LIST;
+    }
+
+    /* (non-Javadoc)
      * @see org.crosswire.jsword.book.BookMetaData#getDriver()
      */
     public BookDriver getDriver()

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java	2009-02-24 11:39:08 UTC (rev 1934)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java	2009-02-24 12:57:51 UTC (rev 1935)
@@ -26,6 +26,7 @@
 import org.crosswire.jsword.book.Book;
 import org.crosswire.jsword.book.BookCategory;
 import org.crosswire.jsword.book.BookException;
+import org.crosswire.jsword.book.KeyType;
 
 /**
  * Data about book types.
@@ -52,6 +53,14 @@
             return new RawBackend(sbmd, 2);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.VERSE;
+        }
+
         /**
          * Serialization ID
          */
@@ -74,6 +83,14 @@
             return new ZVerseBackend(sbmd, blockType);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.VERSE;
+        }
+
         /**
          * Serialization ID
          */
@@ -95,6 +112,14 @@
             return new RawBackend(sbmd, 2);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.VERSE;
+        }
+
         /**
          * Serialization ID
          */
@@ -113,6 +138,14 @@
             return new RawBackend(sbmd, 4);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.VERSE;
+        }
+
         /**
          * Serialization ID
          */
@@ -134,6 +167,14 @@
             return new ZVerseBackend(sbmd, blockType);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.VERSE;
+        }
+
         /**
          * Serialization ID
          */
@@ -155,6 +196,14 @@
             return new RawBackend(sbmd, 2);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.VERSE;
+        }
+
         /**
          * Serialization ID
          */
@@ -176,6 +225,14 @@
             return new RawBackend(sbmd, 2);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.VERSE;
+        }
+
         /**
          * Serialization ID
          */
@@ -201,6 +258,14 @@
             return new RawLDBackend(sbmd, 2);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.LIST;
+        }
+
         /**
          * Serialization ID
          */
@@ -226,6 +291,14 @@
             return new RawLDBackend(sbmd, 4);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.LIST;
+        }
+
         /**
          * Serialization ID
          */
@@ -251,6 +324,14 @@
             return new ZLDBackend(sbmd);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.LIST;
+        }
+
         /**
          * Serialization ID
          */
@@ -272,6 +353,14 @@
             return new GenBookBackend(sbmd);
         }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.sword.BookType#getKeyType()
+         */
+        public KeyType getKeyType()
+        {
+            return KeyType.TREE;
+        }
+
         /**
          * Serialization ID
          */
@@ -318,7 +407,7 @@
      * Given a SwordBookMetaData determine whether this BookType
      * will work for it.
      * @param sbmd the BookMetaData that this BookType works upon
-     * @return true if this is a useable BookType
+     * @return true if this is a usable BookType
      */
     public boolean isSupported(SwordBookMetaData sbmd)
     {
@@ -345,6 +434,12 @@
     protected abstract AbstractBackend getBackend(SwordBookMetaData sbmd) throws BookException;
 
     /**
+     * Get the way this type of Book organizes it's keys.
+     * @return the organization of keys for this book
+     */
+    public abstract KeyType getKeyType();
+
+    /**
      * The name of the BookType
      */
     private String name;
@@ -421,4 +516,9 @@
         Z_LD,
         RAW_GEN_BOOK,
     };
+
+    /**
+     * Serialization ID
+     */
+    private static final long serialVersionUID = 5597156322295331692L;
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java	2009-02-24 11:39:08 UTC (rev 1934)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java	2009-02-24 12:57:51 UTC (rev 1935)
@@ -34,6 +34,7 @@
 import org.crosswire.common.util.NetUtil;
 import org.crosswire.jsword.book.BookCategory;
 import org.crosswire.jsword.book.FeatureType;
+import org.crosswire.jsword.book.KeyType;
 import org.crosswire.jsword.book.basic.AbstractBookMetaData;
 import org.crosswire.jsword.book.filter.Filter;
 import org.crosswire.jsword.book.filter.FilterFactory;
@@ -158,6 +159,19 @@
         return (String) ENCODING_JAVA.get(getProperty(ConfigEntryType.ENCODING));
     }
 
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.basic.AbstractBookMetaData#getKeyType()
+     */
+    public KeyType getKeyType()
+    {
+        BookType bookType = getBookType();
+        if (bookType == null)
+        {
+            return null;
+        }
+        return bookType.getKeyType();
+    }
+
     /**
      * Returns the Book Type.
      */




More information about the jsword-svn mailing list