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

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Sat Jul 21 16:28:34 MST 2007


Author: dmsmith
Date: 2007-07-21 16:28:34 -0700 (Sat, 21 Jul 2007)
New Revision: 1508

Added:
   trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java
Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleNameCellRenderer.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookListCellRenderer.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeModel.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/Verse.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java
Log:
More Farsi work.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java	2007-07-21 23:06:56 UTC (rev 1507)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleComboBoxModelSet.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -29,6 +29,7 @@
 import javax.swing.JComboBox;
 import javax.swing.event.EventListenerList;
 
+import org.crosswire.common.swing.NumberCellRenderer;
 import org.crosswire.jsword.passage.NoSuchVerseException;
 import org.crosswire.jsword.passage.Verse;
 import org.crosswire.jsword.versification.BibleInfo;
@@ -94,6 +95,7 @@
         // There are over 100 chapters in some books
         cboChapter.setPrototypeDisplayValue(new Integer(999));
         cboChapter.addItemListener(cil);
+        cboChapter.setRenderer(new NumberCellRenderer());
     }
 
     /**
@@ -107,6 +109,7 @@
         // There are over 100 verses in some chapters
         cboVerse.setPrototypeDisplayValue(new Integer(999));
         cboVerse.addItemListener(cil);
+        cboVerse.setRenderer(new NumberCellRenderer());
     }
 
     /**

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleNameCellRenderer.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleNameCellRenderer.java	2007-07-21 23:06:56 UTC (rev 1507)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BibleNameCellRenderer.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -45,7 +45,6 @@
     public BibleNameCellRenderer()
     {
         this(false);
-        GuiUtil.applyDefaultOrientation(this);
     }
 
     /**
@@ -58,6 +57,7 @@
     {
         super();
         this.abbreviated = abbreviated;
+        GuiUtil.applyDefaultOrientation(this);
     }
 
     /**

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookListCellRenderer.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookListCellRenderer.java	2007-07-21 23:06:56 UTC (rev 1507)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/BookListCellRenderer.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -27,6 +27,7 @@
 import javax.swing.JList;
 
 import org.crosswire.bibledesktop.book.install.BookIcon;
+import org.crosswire.common.swing.GuiUtil;
 import org.crosswire.jsword.book.Book;
 
 /**
@@ -59,6 +60,7 @@
     {
         super();
         this.abbreviated = abbreviated;
+        GuiUtil.applyDefaultOrientation(this);
     }
 
     /**

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeModel.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeModel.java	2007-07-21 23:06:56 UTC (rev 1507)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeModel.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -36,8 +36,6 @@
 {
     /**
      * Basic constructor.
-     * At some stage when editing this and PassageTreeNode we should be able to
-     * remove the JTree param.
      */
     public WholeBibleTreeModel()
     {

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java	2007-07-21 23:06:56 UTC (rev 1507)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/WholeBibleTreeNode.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -25,6 +25,7 @@
 
 import javax.swing.tree.TreeNode;
 
+import org.crosswire.common.icu.NumberShaper;
 import org.crosswire.jsword.passage.NoSuchVerseException;
 import org.crosswire.jsword.passage.Verse;
 import org.crosswire.jsword.passage.VerseRange;
@@ -40,7 +41,7 @@
 public final class WholeBibleTreeNode implements TreeNode
 {
     /**
-     * The starrt point for all WholeBibleTreeNodes.
+     * The start point for all WholeBibleTreeNodes.
      */
     public static WholeBibleTreeNode getRootNode()
     {
@@ -110,6 +111,7 @@
 
         this.range = range;
         this.level = level;
+        shaper = new NumberShaper();
     }
 
     /**
@@ -161,10 +163,10 @@
                 return BibleInfo.getPreferredBookName(range.getStart().getBook());
 
             case LEVEL_CHAPTER:
-                return Integer.toString(range.getStart().getChapter());
+                return shaper.shape(Integer.toString(range.getStart().getChapter()));
 
             case LEVEL_VERSE:
-                return Integer.toString(range.getStart().getVerse());
+                return shaper.shape(Integer.toString(range.getStart().getVerse()));
 
             default:
                 return Msg.ERROR.toString();
@@ -289,6 +291,9 @@
     private static final int LEVEL_CHAPTER = 2;
     private static final int LEVEL_VERSE = 3;
 
+    /** Change the number representation as needed */
+    private NumberShaper shaper;
+
     /** The range that this node refers to */
     private VerseRange range;
 

Added: trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java	                        (rev 0)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -0,0 +1,81 @@
+/**
+ * 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: BibleNameCellRenderer.java 1471 2007-07-03 21:01:02Z dmsmith $
+ */
+package org.crosswire.common.swing;
+
+import java.awt.Component;
+
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JList;
+
+import org.crosswire.common.icu.NumberShaper;
+
+/**
+ * Render a list of Bible Book names with their full name as a tooltip
+ *
+ * @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 NumberCellRenderer extends DefaultListCellRenderer
+{
+    /**
+     * Constructs a default renderer for a list of numbers.
+     */
+    public NumberCellRenderer()
+    {
+        this.shaper = new NumberShaper();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
+     */
+    public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focus)
+    {
+        // Do the default rendering
+        Component comp = super.getListCellRendererComponent(list, value, index, selected, focus);
+
+        // Do our rendering
+        setToolTipText(null);
+
+        if (value == null)
+        {
+            setText(""); //$NON-NLS-1$
+            setEnabled(false);
+        }
+        else
+        {
+            setText(shaper.shape(value.toString()));
+        }
+
+        return comp;
+    }
+
+    /**
+     * Used to display numbers in the user's expected representations.
+     */
+    private NumberShaper shaper;
+
+    /**
+     * Serialization ID
+     */
+    private static final long serialVersionUID = 3978138859576308017L;
+}

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/Verse.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/Verse.java	2007-07-21 23:06:56 UTC (rev 1507)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/Verse.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -28,6 +28,7 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
+import org.crosswire.common.icu.NumberShaper;
 import org.crosswire.common.util.Logger;
 import org.crosswire.jsword.versification.BibleInfo;
 
@@ -68,8 +69,9 @@
      */
     public Verse()
     {
+        shaper = new NumberShaper();
         originalName = null;
-
+        
         book = DEFAULT.book;
         chapter = DEFAULT.chapter;
         verse = DEFAULT.verse;
@@ -87,6 +89,7 @@
      */
     /*package*/ Verse(String original, int book, int chapter, int verse) throws NoSuchVerseException
     {
+        shaper = new NumberShaper();
         originalName = original;
         set(book, chapter, verse);
     }
@@ -119,6 +122,7 @@
      */
     public Verse(int book, int chapter, int verse, boolean patch_up)
     {
+        shaper = new NumberShaper();
         if (!patch_up)
         {
             throw new IllegalArgumentException(Msg.ERROR_PATCH.toString());
@@ -139,6 +143,7 @@
      */
     public Verse(int ordinal) throws NoSuchVerseException
     {
+        shaper = new NumberShaper();
         originalName = null;
         set(ordinal);
     }
@@ -157,31 +162,7 @@
      */
     public String getName()
     {
-        try
-        {
-            if (PassageUtil.isPersistentNaming() && originalName != null)
-            {
-                return originalName;
-            }
-
-            // To cope with thing like Jude 2...
-            if (BibleInfo.chaptersInBook(book) == 1)
-            {
-                return BibleInfo.getPreferredBookName(book)
-                    + Verse.VERSE_PREF_DELIM1
-                    + verse;
-            }
-            return BibleInfo.getPreferredBookName(book)
-                + Verse.VERSE_PREF_DELIM1
-                + chapter
-                + Verse.VERSE_PREF_DELIM2
-                + verse;
-        }
-        catch (NoSuchKeyException ex)
-        {
-            assert false : ex;
-            return "!Error!"; //$NON-NLS-1$
-        }
+        return getName(null);
     }
 
     /* (non-Javadoc)
@@ -189,7 +170,7 @@
      */
     public String getName(Key base)
     {
-        if (!(base instanceof Verse))
+        if (base != null && !(base instanceof Verse))
         {
             return getName();
         }
@@ -201,37 +182,14 @@
                 return originalName;
             }
 
-            Verse verseBase = (Verse) base;
-            // To cope with thing like Jude 2...
-            if (BibleInfo.chaptersInBook(book) == 1)
+            String verseName = doGetName((Verse) base);
+            // Only shape it if it can be unshaped.
+            if (shaper.canUnshape())
             {
-                if (verseBase.book != book)
-                {
-                    return BibleInfo.getPreferredBookName(book)
-                        + Verse.VERSE_PREF_DELIM1
-                        + verse;
-                }
-
-                return String.valueOf(verse);
+                return shaper.shape(verseName);
             }
 
-            if (verseBase.book != book)
-            {
-                return BibleInfo.getPreferredBookName(book)
-                    + Verse.VERSE_PREF_DELIM1
-                    + chapter
-                    + Verse.VERSE_PREF_DELIM2
-                    + verse;
-            }
-
-            if (verseBase.chapter != chapter)
-            {
-                return chapter
-                    + Verse.VERSE_PREF_DELIM2
-                    + verse;
-            }
-
-            return String.valueOf(verse);
+            return verseName;
         }
         catch (NoSuchKeyException ex)
         {
@@ -299,6 +257,7 @@
             copy.verse = verse;
             //copy.ord = ord;
             copy.originalName = originalName;
+            shaper = new NumberShaper();
         }
         catch (CloneNotSupportedException e)
         {
@@ -713,6 +672,46 @@
     }
 
     /**
+     * Compute the verse representation given the context.
+     * @param verseBase the context or null if there is none
+     * @return the verse representation
+     * @throws NoSuchVerseException
+     */
+    private String doGetName(Verse verseBase) throws NoSuchVerseException
+    {
+        // To cope with thing like Jude 2...
+        if (BibleInfo.chaptersInBook(book) == 1)
+        {
+            if (verseBase == null || verseBase.book != book)
+            {
+                return BibleInfo.getPreferredBookName(book)
+                    + Verse.VERSE_PREF_DELIM1
+                    + verse;
+            }
+
+            return String.valueOf(verse);
+        }
+
+        if (verseBase == null || verseBase.book != book)
+        {
+            return BibleInfo.getPreferredBookName(book)
+                + Verse.VERSE_PREF_DELIM1
+                + chapter
+                + Verse.VERSE_PREF_DELIM2
+                + verse;
+        }
+
+        if (verseBase.chapter != chapter)
+        {
+            return chapter
+                + Verse.VERSE_PREF_DELIM2
+                + verse;
+        }
+
+        return String.valueOf(verse);
+    }
+
+    /**
      * This is simply a convenience function to wrap Integer.parseInt()
      * and give us a reasonable exception on failure. It is called by
      * VerseRange hence protected, however I would prefer private
@@ -734,7 +733,7 @@
 
     /**
      * Mutate into this reference and fix the reference if needed.
-     * This nust only be called from a ctor to maintain immutability
+     * This must only be called from a ctor to maintain immutability
      * @param book The book to set (Genesis = 1)
      * @param chapter The chapter to set
      * @param verse The verse to set
@@ -973,17 +972,17 @@
     static final long serialVersionUID = -4033921076023185171L;
 
     /**
-     * To make the code more readible, the book is the first part of a int[]
+     * To make the code more readable, the book is the first part of a int[]
      */
     private static final int BOOK = 0;
 
     /**
-     * To make the code more readible, the chapter is the second part of a int[]
+     * To make the code more readable, the chapter is the second part of a int[]
      */
     private static final int CHAPTER = 1;
 
     /**
-     * To make the code more readible, the verse is the third part of a int[]
+     * To make the code more readable, the verse is the third part of a int[]
      */
     private static final int VERSE = 2;
 
@@ -1008,6 +1007,11 @@
     public static final Verse DEFAULT = new Verse(1, 1, 1, true);
 
     /**
+     * Allow the conversion to and from other number representations.
+     */
+    private transient NumberShaper shaper;
+
+    /**
      * The parent key. See the key interface for more information.
      * NOTE(joe): These keys are not serialized, should we?
      * @see Key

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java	2007-07-21 23:06:56 UTC (rev 1507)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/VerseRange.java	2007-07-21 23:28:34 UTC (rev 1508)
@@ -28,6 +28,7 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 
+import org.crosswire.common.icu.NumberShaper;
 import org.crosswire.common.util.Logger;
 import org.crosswire.jsword.versification.BibleInfo;
 
@@ -37,7 +38,7 @@
  * and an end. A VerseRange is designed to be immutable. This is a
  * necessary from a collections point of view. A VerseRange should always
  * be valid, although some versions may not return any text for verses
- * that they consider to be mis-translated in some way.
+ * that they consider to be miss-translated in some way.
  *
  * @see gnu.lgpl.License for license details.
  *      The copyright to this program is held by it's authors.
@@ -86,6 +87,7 @@
         assert end != null;
 
         this.originalName = original;
+        shaper = new NumberShaper();
 
         switch (start.compareTo(end))
         {
@@ -116,12 +118,13 @@
 
     /**
      * Merge 2 VerseRanges together. The resulting range will encompass
-     * Everying in-between the extremities of the 2 ranges.
+     * Everything in-between the extremities of the 2 ranges.
      * @param a The first verse range to be merged
      * @param b The second verse range to be merged
      */
     public VerseRange(VerseRange a, VerseRange b)
     {
+        shaper = new NumberShaper();
         start = Verse.min(a.getStart(), b.getStart());
         end = Verse.max(a.getEnd(), b.getEnd());
         verseCount = calcVerseCount(start, end);
@@ -145,86 +148,16 @@
             return originalName;
         }
 
-        // Cache these we're going to be using them a lot.
-        int startBook = start.getBook();
-        int startChapter = start.getChapter();
-        int startVerse = start.getVerse();
-        int endBook = end.getBook();
-        int endChapter = end.getChapter();
-        int endVerse = end.getVerse();
-
         try
         {
-            // If this is in 2 separate books
-            if (startBook != endBook)
+            String rangeName = doGetName(base);
+            // Only shape it if it can be unshaped.
+            if (shaper.canUnshape())
             {
-                // This range is exactly a whole book
-                if (isWholeBooks())
-                {
-                    // Just report the name of the book, we don't need to worry about the
-                    // base since we start at the start of a book, and should have been
-                    // recently normalized()
-                    return BibleInfo.getPreferredBookName(startBook)
-                         + VerseRange.RANGE_PREF_DELIM
-                         + BibleInfo.getPreferredBookName(endBook);
-                }
-
-                // If this range is exactly a whole chapter
-                if (isWholeChapters())
-                {
-                    // Just report book and chapter names
-                    return BibleInfo.getPreferredBookName(startBook)
-                         + Verse.VERSE_PREF_DELIM1 + startChapter
-                         + VerseRange.RANGE_PREF_DELIM + BibleInfo.getPreferredBookName(endBook)
-                         + Verse.VERSE_PREF_DELIM1 + endChapter;
-                }
-
-                return start.getName(base) + VerseRange.RANGE_PREF_DELIM + end.getName(base);
+                return shaper.shape(rangeName);
             }
-
-            // This range is exactly a whole book
-            if (isWholeBook())
-            {
-                // Just report the name of the book, we don't need to worry about the
-                // base since we start at the start of a book, and should have been
-                // recently normalized()
-                return BibleInfo.getPreferredBookName(startBook);
-            }
-
-            // If this is 2 separate chapters
-            if (startChapter != endChapter)
-            {
-                // If this range is a whole number of chapters
-                if (isWholeChapters())
-                {
-                    // Just report the name of the book and the chapters
-                    return BibleInfo.getPreferredBookName(startBook)
-                         + Verse.VERSE_PREF_DELIM1 + startChapter
-                         + VerseRange.RANGE_PREF_DELIM + endChapter;
-                }
-
-                return start.getName(base)
-                     + VerseRange.RANGE_PREF_DELIM + endChapter
-                     + Verse.VERSE_PREF_DELIM2 + endVerse;
-            }
-
-            // If this range is exactly a whole chapter
-            if (isWholeChapter())
-            {
-                // Just report the name of the book and the chapter
-                return BibleInfo.getPreferredBookName(startBook)
-                     + Verse.VERSE_PREF_DELIM1 + startChapter;
-            }
-
-            // If this is 2 separate verses
-            if (startVerse != endVerse)
-            {
-                return start.getName(base)
-                     + VerseRange.RANGE_PREF_DELIM + endVerse;
-            }
-
-            // The range is a single verse
-            return start.getName(base);
+    
+            return rangeName;
         }
         catch (NoSuchVerseException ex)
         {
@@ -511,6 +444,7 @@
             copy.end = (Verse) end.clone();
             copy.verseCount = verseCount;
             copy.originalName = originalName;
+            copy.shaper = new NumberShaper();
         }
         catch (CloneNotSupportedException e)
         {
@@ -609,8 +543,8 @@
     }
 
     /**
-     * Are the 2 VerseRanges in question contigious.
-     * ie - could they be represented by a single VerseRange. Note that one
+     * Are the 2 VerseRanges in question contiguous.
+     * that is - could they be represented by a single VerseRange. Note that one
      * range could be entirely contained within the other and they would be
      * considered adjacentTo()
      * For example Gen 1:1-2 is adjacent to Gen 1:1-5 and Gen 1:3-4 but
@@ -871,7 +805,7 @@
      * Create a DistinctPassage that is the stuff left of VerseRange a
      * when you remove the stuff in VerseRange b.
      * @param a The verses that you might want
-     * @param b The verses that you definately don't
+     * @param b The verses that you definitely don't
      * @return A list of the Verses outstanding
      */
     public static VerseRange[] remainder(VerseRange a, VerseRange b)
@@ -911,7 +845,7 @@
      * Create a DistinctPassage that is the stuff in VerseRange a
      * that is also in VerseRange b.
      * @param a The verses that you might want
-     * @param b The verses that you definately don't
+     * @param b The verses that you definitely don't
      * @return A list of the Verses outstanding
      */
     public static VerseRange intersection(VerseRange a, VerseRange b)
@@ -949,6 +883,88 @@
         return whole;
     }
 
+    private String doGetName(Key base) throws NoSuchVerseException
+    {
+        // Cache these we're going to be using them a lot.
+        int startBook = start.getBook();
+        int startChapter = start.getChapter();
+        int startVerse = start.getVerse();
+        int endBook = end.getBook();
+        int endChapter = end.getChapter();
+        int endVerse = end.getVerse();
+
+        // If this is in 2 separate books
+        if (startBook != endBook)
+        {
+            // This range is exactly a whole book
+            if (isWholeBooks())
+            {
+                // Just report the name of the book, we don't need to worry about the
+                // base since we start at the start of a book, and should have been
+                // recently normalized()
+                return BibleInfo.getPreferredBookName(startBook)
+                + VerseRange.RANGE_PREF_DELIM
+                + BibleInfo.getPreferredBookName(endBook);
+            }
+
+            // If this range is exactly a whole chapter
+            if (isWholeChapters())
+            {
+                // Just report book and chapter names
+                return BibleInfo.getPreferredBookName(startBook)
+                + Verse.VERSE_PREF_DELIM1 + startChapter
+                + VerseRange.RANGE_PREF_DELIM + BibleInfo.getPreferredBookName(endBook)
+                + Verse.VERSE_PREF_DELIM1 + endChapter;
+            }
+
+            return start.getName(base) + VerseRange.RANGE_PREF_DELIM + end.getName(base);
+        }
+
+        // This range is exactly a whole book
+        if (isWholeBook())
+        {
+            // Just report the name of the book, we don't need to worry about the
+            // base since we start at the start of a book, and should have been
+            // recently normalized()
+            return BibleInfo.getPreferredBookName(startBook);
+        }
+
+        // If this is 2 separate chapters
+        if (startChapter != endChapter)
+        {
+            // If this range is a whole number of chapters
+            if (isWholeChapters())
+            {
+                // Just report the name of the book and the chapters
+                return BibleInfo.getPreferredBookName(startBook)
+                + Verse.VERSE_PREF_DELIM1 + startChapter
+                + VerseRange.RANGE_PREF_DELIM + endChapter;
+            }
+
+            return start.getName(base)
+            + VerseRange.RANGE_PREF_DELIM + endChapter
+            + Verse.VERSE_PREF_DELIM2 + endVerse;
+        }
+
+        // If this range is exactly a whole chapter
+        if (isWholeChapter())
+        {
+            // Just report the name of the book and the chapter
+            return BibleInfo.getPreferredBookName(startBook)
+            + Verse.VERSE_PREF_DELIM1 + startChapter;
+        }
+
+        // If this is 2 separate verses
+        if (startVerse != endVerse)
+        {
+            return start.getName(base)
+            + VerseRange.RANGE_PREF_DELIM + endVerse;
+        }
+
+        // The range is a single verse
+        return start.getName(base);
+    }
+
     /**
      * Calculate the last verse in this range.
      * @param start The first verse in the range
@@ -961,7 +977,7 @@
     }
 
     /**
-     * Calcualte how many verses in this range
+     * Calculate how many verses in this range
      * @param start The first verse in the range
      * @param end The last verse in the range
      * @return The number of verses. Always >= 1.
@@ -1015,6 +1031,7 @@
             start = new Verse(in.readInt());
             verseCount = in.readInt();
             end = calcEnd(start, verseCount);
+            shaper = new NumberShaper();
 
             verifyData();
         }
@@ -1226,6 +1243,11 @@
     private transient Verse end;
 
     /**
+     * Allow the conversion to and from other number representations.
+     */
+    private transient NumberShaper shaper;
+
+    /**
      * The parent key. See the key interface for more information.
      * NOTE(joe): These keys are not serialized, should we?
      * @see Key




More information about the jsword-svn mailing list