[jsword-svn] r1852 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book 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/src/main/java/org/crosswire/common/util common-swing/src/main/java/org/crosswire/common/config/swing common-swing/src/main/java/org/crosswire/common/progress/swing common-swing/src/main/java/org/crosswire/common/swing jsword/src/main/java/org/crosswire/jsword/book/basic jsword/src/main/java/org/crosswire/jsword/book/sword jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb jsword-limbo/src/main/java/org/crosswire/common/config/swing

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Sun May 11 12:46:47 MST 2008


Author: dmsmith
Date: 2008-05-11 12:46:46 -0700 (Sun, 11 May 2008)
New Revision: 1852

Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitesPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/AboutPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java
   trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java
   trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FontField.java
   trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MappedOptionsField.java
   trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java
   trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java
   trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java
   trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/MapEntryRenderer.java
   trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java
   trunk/common/src/main/java/org/crosswire/common/util/Language.java
   trunk/common/src/main/java/org/crosswire/common/util/Languages.java
   trunk/common/src/main/java/org/crosswire/common/util/Translations.java
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java
   trunk/jsword-limbo/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/DefaultBookMetaData.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDictionary.java
Log:
RtoL changes:
Fixed AdvancedSearchPane
Moved isLeftToRight into Language and stopped using ComponentOrientation to determine it.
Eliminated some redundant calls to set component orientation and added some, unifying on GuiUtil.applyOrientation.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/AdvancedSearchPane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -297,7 +297,6 @@
 
         Frame root = JOptionPane.getFrameForComponent(parent);
         dlgMain = new JDialog(root);
-        dlgMain.setComponentOrientation(root.getComponentOrientation());
 
         KeyStroke esc = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
         bailout = true;
@@ -321,13 +320,13 @@
 
         GuiUtil.restrainedPack(dlgMain, 0.5f, 0.75f);
         GuiUtil.centerWindow(dlgMain);
+        GuiUtil.applyDefaultOrientation(dlgMain);
         dlgMain.setVisible(true);
 
         if (bailout)
         {
             return null;
         }
-        GuiUtil.applyDefaultOrientation(dlgMain);
 
         return txtSummary.getText();
     }

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/PassageSelectionPane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -292,7 +292,6 @@
 
         Frame root = JOptionPane.getFrameForComponent(parent);
         dlgMain = new JDialog(root);
-        dlgMain.setComponentOrientation(root.getComponentOrientation());
 
         JPanel pnlAction = new JPanel();
         KeyStroke esc = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/EditSitePane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -217,7 +217,6 @@
     {
         Frame root = JOptionPane.getFrameForComponent(parent);
         dlgMain = new JDialog(root);
-        dlgMain.setComponentOrientation(root.getComponentOrientation());
 
         ActionListener closer = new ActionListener()
         {
@@ -244,6 +243,7 @@
 
         GuiUtil.setSize(dlgMain, new Dimension(750, 400));
         GuiUtil.centerWindow(dlgMain);
+        GuiUtil.applyDefaultOrientation(dlgMain);
         dlgMain.setVisible(true);
         dlgMain.toFront();
     }

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/InternetWarning.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -97,8 +97,6 @@
                       ? new JDialog((JFrame) root, title, true)
                       : new JDialog((JDialog) root, title, true);
 
-        dialog.setComponentOrientation(root.getComponentOrientation());
-
         webWarning.dialog = dialog;
         webWarning.choice = InternetWarning.DENIED;
 

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitesPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitesPane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/install/SitesPane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -147,7 +147,6 @@
     {
         Frame root = JOptionPane.getFrameForComponent(parent);
         dlgMain = new JDialog(root);
-        dlgMain.setComponentOrientation(root.getComponentOrientation());
         dlgMain.setSize(new Dimension(750, 500));
         dlgMain.getContentPane().setLayout(new BorderLayout());
         dlgMain.getContentPane().add(this, BorderLayout.CENTER);

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/AboutPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/AboutPane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/AboutPane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -182,7 +182,6 @@
     {
         Frame root = JOptionPane.getFrameForComponent(parent);
         dlgMain = new JDialog(root);
-        dlgMain.setComponentOrientation(root.getComponentOrientation());
 
         dlgMain.getContentPane().add(pnlMain);
         dlgMain.setTitle(Msg.getAboutInfo());

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/ViewSourcePane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -28,7 +28,6 @@
 import java.awt.Frame;
 import java.awt.Toolkit;
 import java.awt.datatransfer.StringSelection;
-import java.io.IOException;
 import java.net.URI;
 import java.util.Iterator;
 
@@ -48,7 +47,6 @@
 import org.crosswire.common.swing.CWScrollPane;
 import org.crosswire.common.swing.GuiConvert;
 import org.crosswire.common.swing.GuiUtil;
-import org.crosswire.common.util.NetUtil;
 import org.crosswire.common.util.Reporter;
 import org.crosswire.common.xml.Converter;
 import org.crosswire.common.xml.FormatType;
@@ -122,7 +120,7 @@
             XSLTProperty.DIRECTION.setState(bmd.isLeftToRight() ? "ltr" : "rtl"); //$NON-NLS-1$ //$NON-NLS-2$
 
             URI loc = bmd.getLocation();
-            XSLTProperty.BASE_URL.setState(loc == null ? "" : NetUtil.getAsFile(loc).getCanonicalPath()); //$NON-NLS-1$
+            XSLTProperty.BASE_URL.setState(loc == null ? "" : loc.getPath()); //$NON-NLS-1$
 
             if (bmd.getBookCategory() == BookCategory.BIBLE)
             {
@@ -156,10 +154,6 @@
         {
             Reporter.informUser(null, e);
         }
-        catch (IOException e)
-        {
-            Reporter.informUser(null, e);
-        }
     }
 
     /**

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/SplitBookDataDisplay.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -80,7 +80,7 @@
     }
 
     /**
-     * @return Returns the sidebar.
+     * @return Returns the display area.
      */
     public BookDataDisplay getBookDataDisplay()
     {

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	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/display/basic/TextPaneBookDataDisplay.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -22,11 +22,9 @@
 package org.crosswire.bibledesktop.display.basic;
 
 import java.awt.Component;
-import java.awt.ComponentOrientation;
 import java.awt.event.MouseListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
-import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.text.MessageFormat;
@@ -50,8 +48,8 @@
 import org.crosswire.bibledesktop.passage.KeyChangeListener;
 import org.crosswire.common.swing.AntiAliasedTextPane;
 import org.crosswire.common.swing.GuiConvert;
+import org.crosswire.common.swing.GuiUtil;
 import org.crosswire.common.util.Logger;
-import org.crosswire.common.util.NetUtil;
 import org.crosswire.common.util.Reporter;
 import org.crosswire.common.xml.Converter;
 import org.crosswire.common.xml.SAXEventProvider;
@@ -150,7 +148,7 @@
         }
 
         boolean direction = bmd.isLeftToRight();
-        txtView.applyComponentOrientation(direction ? ComponentOrientation.LEFT_TO_RIGHT : ComponentOrientation.RIGHT_TO_LEFT);
+        GuiUtil.applyOrientation(txtView, direction);
 
         String fontSpec = GuiConvert.font2String(BookFont.instance().getFont(getFirstBook()));
         try
@@ -158,10 +156,10 @@
             SAXEventProvider osissep = bdata.getSAXEventProvider();
             TransformingSAXEventProvider htmlsep = (TransformingSAXEventProvider) converter.convert(osissep);
 
-            XSLTProperty.DIRECTION.setState(bmd.isLeftToRight() ? "ltr" : "rtl"); //$NON-NLS-1$ //$NON-NLS-2$
+            XSLTProperty.DIRECTION.setState(direction ? "ltr" : "rtl"); //$NON-NLS-1$ //$NON-NLS-2$
 
             URI loc = bmd.getLocation();
-            XSLTProperty.BASE_URL.setState(loc == null ? "" : NetUtil.getAsFile(loc).toURL().toString()); //$NON-NLS-1$
+            XSLTProperty.BASE_URL.setState(loc == null ? "" : loc.getPath()); //$NON-NLS-1$
 
             if (bmd.getBookCategory() == BookCategory.BIBLE)
             {
@@ -205,10 +203,6 @@
         {
             Reporter.informUser(this, e);
         }
-        catch (IOException e)
-        {
-            Reporter.informUser(this, e);
-        }
     }
 
     /* (non-Javadoc)

Modified: trunk/common/src/main/java/org/crosswire/common/util/Language.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Language.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common/src/main/java/org/crosswire/common/util/Language.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -30,6 +30,8 @@
  */
 public class Language implements Comparable
 {
+    public static final Language DEFAULT_LANG = new Language(null);
+
     /**
      * A single language defined by an ISO-639 code.
      * If the code is null or empty then it is considered to be DEFAULT_LANG_CODE (that is, English).
@@ -38,12 +40,9 @@
      */
     public Language(String iso639Code)
     {
-        this.code = iso639Code;
-        if (iso639Code == null || iso639Code.length() == 0)
-        {
-            this.code = Languages.DEFAULT_LANG_CODE;
-        }
+        this.code = Languages.getLanguageCode(iso639Code);
     }
+
     /**
      * Determine whether this language is valid.
      * The code is valid if it is in iso639.properties.
@@ -74,11 +73,33 @@
     {
         if (name == null)
         {
-            name = Languages.getLanguage(code);
+            name = Languages.getLanguageName(code);
         }
         return name;
     }
 
+    /**
+     * Determine whether this language is a Left-to-Right or a Right-to-Left language.
+     * @return true if the language is Left-to-Right.
+     */
+    public boolean isLeftToRight()
+    {
+        if (!knowsDirection)
+        {
+            ltor = ! ("he".equals(code)  || //$NON-NLS-1$ Hebrew
+                      "ar".equals(code)  || //$NON-NLS-1$ Arabic
+                      "fa".equals(code)  || //$NON-NLS-1$ Farsi/Persian
+                      "ur".equals(code)  || //$NON-NLS-1$ Uighur
+                      "uig".equals(code) || //$NON-NLS-1$ Uighur, too
+                      "syr".equals(code) || //$NON-NLS-1$ Syriac
+                      "iw".equals(code));   //$NON-NLS-1$ Java's notion of Hebrew
+
+            knowsDirection = true;
+        }
+
+        return ltor;
+    }
+
     /* (non-Javadoc)
      * @see java.lang.Object#hashCode()
      */
@@ -125,4 +146,6 @@
 
     private String code;
     private String name;
+    private boolean knowsDirection;
+    private boolean ltor;
 }

Modified: trunk/common/src/main/java/org/crosswire/common/util/Languages.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Languages.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common/src/main/java/org/crosswire/common/util/Languages.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -54,75 +54,81 @@
      */
     public static boolean isValidLanguage(String iso639Code)
     {
-        String lookup = iso639Code;
-        if (lookup == null || lookup.length() == 0)
+        try
         {
+            String code = getLanguageCode(iso639Code);
+            if (code == DEFAULT_LANG_CODE || code == UNKNOWN_LANG_CODE)
+            {
+                return true;
+            }
+            languages.getString(code);
             return true;
         }
-
-        if (lookup.indexOf('_') != -1)
+        catch (MissingResourceException e)
         {
-            String[] locale = StringUtil.split(lookup, '_');
-            return isValidLanguage(locale[0]);
-        }
-
-        // These are not uncommon. Looking for them prevents exceptions
-        // and provides the same result.
-        if (lookup.startsWith("x-") || lookup.startsWith("X-") || lookup.length() > 3) //$NON-NLS-1$ //$NON-NLS-2$
-        {
             return false;
         }
+    }
 
+    /**
+     * Get the language name from the language code.
+     * If the code is null or empty then it is considered to be DEFAULT_LANG_CODE (that is, English).
+     * If it starts with x- or is too long then it will return unknown.
+     * If the code's name cannot be found, it will return the code.
+     * If a locale is used for the iso639Code, it will use the part before the '_'.
+     * Thus, this code does not support dialects, except as found in the iso639.
+     *
+     * @param iso639Code
+     * @return the name of the language
+     */
+    public static String getLanguageName(String iso639Code)
+    {
+        String code = getLanguageCode(iso639Code);
         try
         {
-            languages.getString(lookup);
-            return true;
+            return languages.getString(code);
         }
         catch (MissingResourceException e)
         {
-            return false;
+            return code;
         }
     }
 
     /**
-     * Get the language name from the language code.
+     * Get the language code from the input.
      * If the code is null or empty then it is considered to be DEFAULT_LANG_CODE (that is, English).
-     * Otherwise, it will generate a log message and return unknown.
      * If a locale is used for the iso639Code, it will use the part before the '_'.
      * Thus, this code does not support dialects, except as found in the iso639.
+     * If it is known to be unknown then return unknown.
+     * Otherwise, return the 2 or 3 letter code.
+     * Note: it might not be valid.
      *
-     * @param iso639Code
-     * @return the name of the language
+     * @param input
+     * @return the code for the language
      */
-    public static String getLanguage(String iso639Code)
+    public static String getLanguageCode(String input)
     {
-        String lookup = iso639Code;
+        String lookup = input;
         if (lookup == null || lookup.length() == 0)
         {
-            return getLanguage(DEFAULT_LANG_CODE);
+            return DEFAULT_LANG_CODE;
         }
 
         if (lookup.indexOf('_') != -1)
         {
             String[] locale = StringUtil.split(lookup, '_');
-            return getLanguage(locale[0]);
+            // We need to check what stands before the _, it might be empty or unknown.
+            return getLanguageCode(locale[0]);
         }
 
         // These are not uncommon. Looking for them prevents exceptions
         // and provides the same result.
         if (lookup.startsWith("x-") || lookup.startsWith("X-") || lookup.length() > 3) //$NON-NLS-1$ //$NON-NLS-2$
         {
-            return getLanguage(UNKNOWN_LANG_CODE);
+            return UNKNOWN_LANG_CODE;
         }
 
-        try
-        {
-            return languages.getString(lookup);
-        }
-        catch (MissingResourceException e)
-        {
-            return getLanguage(UNKNOWN_LANG_CODE);
-        }
+        return lookup;
     }
 
     public static final String DEFAULT_LANG_CODE = "en"; //$NON-NLS-1$

Modified: trunk/common/src/main/java/org/crosswire/common/util/Translations.java
===================================================================
--- trunk/common/src/main/java/org/crosswire/common/util/Translations.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common/src/main/java/org/crosswire/common/util/Translations.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -215,7 +215,7 @@
 
     public String toString(String translationCode)
     {
-        StringBuffer currentTranslation = new StringBuffer(Languages.getLanguage(translationCode));
+        StringBuffer currentTranslation = new StringBuffer(Languages.getLanguageName(translationCode));
 
         if (translationCode.indexOf('_') != -1)
         {

Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/AbstractConfigEditor.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -101,8 +101,6 @@
         {
             Component root =  SwingUtilities.getRoot(parent);
             dialog = new JDialog((JFrame) root);
-            dialog.setComponentOrientation(root.getComponentOrientation());
-
             dialog.getContentPane().add(this);
 
             // Why is this only available in Frames?

Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FontField.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FontField.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/FontField.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -27,6 +27,7 @@
 import org.crosswire.common.config.Choice;
 import org.crosswire.common.swing.FontChooser;
 import org.crosswire.common.swing.GuiConvert;
+import org.crosswire.common.swing.GuiUtil;
 
 /**
  * A swing view of a FontChoice.
@@ -44,6 +45,7 @@
     {
         setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(),
                                                      BorderFactory.createEmptyBorder(5, 5, 5, 5)));
+        GuiUtil.applyDefaultOrientation(this);
 
     }
 

Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MappedOptionsField.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MappedOptionsField.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/MappedOptionsField.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -30,6 +30,7 @@
 
 import org.crosswire.common.config.Choice;
 import org.crosswire.common.config.MappedChoice;
+import org.crosswire.common.swing.GuiUtil;
 import org.crosswire.common.swing.MapComboBoxModel;
 import org.crosswire.common.swing.MapEntryRenderer;
 import org.crosswire.common.util.Logger;
@@ -51,6 +52,7 @@
         combo = new JComboBox(new String[] { Msg.NO_OPTIONS.toString() });
         // Set the preferred width. Note, the actual combo box will resize to the width of it's container
         combo.setPreferredSize(new Dimension(100, combo.getPreferredSize().height));
+        GuiUtil.applyDefaultOrientation(combo);
     }
 
     /**

Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/OptionsField.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -31,6 +31,7 @@
 import org.crosswire.common.config.Choice;
 import org.crosswire.common.config.MultipleChoice;
 import org.crosswire.common.diff.Distance;
+import org.crosswire.common.swing.GuiUtil;
 import org.crosswire.common.util.Logger;
 
 /**
@@ -51,6 +52,7 @@
         combo = new JComboBox(new String[] { Msg.NO_OPTIONS.toString() });
         // Set the preferred width. Note, the actual combo box will resize to the width of it's container
         combo.setPreferredSize(new Dimension(100, combo.getPreferredSize().height));
+        GuiUtil.applyDefaultOrientation(combo);
     }
 
     /**

Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/StringArrayField.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -47,6 +47,7 @@
 import org.crosswire.common.swing.ActionFactory;
 import org.crosswire.common.swing.CWOptionPane;
 import org.crosswire.common.swing.CWScrollPane;
+import org.crosswire.common.swing.GuiUtil;
 import org.crosswire.common.util.Convert;
 
 /**
@@ -88,6 +89,7 @@
         setLayout(new BorderLayout());
         add(scroll, BorderLayout.CENTER);
         add(buttons, BorderLayout.PAGE_END);
+        GuiUtil.applyDefaultOrientation(this);
     }
 
     /* (non-Javadoc)

Modified: trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/config/swing/TreeConfigEditor.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -218,6 +218,7 @@
         }
 
         String key = path.toString();
+        GuiUtil.applyDefaultOrientation(deck);
         if (decks.containsKey(key))
         {
             layout.show(deck, key);

Modified: trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/progress/swing/JobsProgressBar.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -22,7 +22,6 @@
 package org.crosswire.common.progress.swing;
 
 import java.awt.Component;
-import java.awt.ComponentOrientation;
 import java.awt.Font;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
@@ -31,7 +30,6 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 
@@ -148,7 +146,6 @@
         log.debug("adding job to panel at " + i + ": " + job.getJobName()); //$NON-NLS-1$ //$NON-NLS-2$
 
         JProgressBar progress = new JProgressBar();
-        GuiUtil.applyOrientation(progress, ComponentOrientation.getOrientation(Locale.getDefault()));
         progress.setStringPainted(true);
         progress.setToolTipText(job.getJobName());
         progress.setBorder(null);
@@ -158,6 +155,8 @@
         {
             progress.setFont(font);
         }
+        GuiUtil.applyDefaultOrientation(progress);
+
         // Dimension preferred = progress.getPreferredSize();
         // preferred.width = 50;
         // progress.setPreferredSize(preferred);
@@ -175,6 +174,7 @@
 
         this.add(jobdata.getComponent(), i);
         GuiUtil.refresh(this);
+        GuiUtil.applyDefaultOrientation(this);
     }
 
     /**

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/CWOptionPane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -728,6 +728,7 @@
             }
         });
 
+        GuiUtil.applyDefaultOrientation(dialog);
         return dialog;
     }
 

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/ExceptionPane.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -230,7 +230,6 @@
         dialog.getRootPane().setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, pane.upper.getBackground()));
         dialog.getRootPane().add(pane, BorderLayout.CENTER);
 
-        dialog.setComponentOrientation(root.getComponentOrientation());
 
         if (actions == null)
         {
@@ -249,6 +248,7 @@
         dialog.getRootPane().setDefaultButton(ok);
 
         GuiUtil.centerWindow(dialog);
+        GuiUtil.applyDefaultOrientation(dialog);
         dialog.pack();
         dialog.setVisible(true);
     }

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	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/FontChooser.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -112,8 +112,6 @@
                       ? new JDialog((JFrame) root, title, true)
                       : new JDialog((JDialog) root, title, true);
 
-        fontc.dialog.setComponentOrientation(root.getComponentOrientation());
-
         fontc.name.setSelectedItem(initial != null ? initial : DEFAULT_FONT.getFont());
 
         if (actions == null)
@@ -305,6 +303,11 @@
      */
     static class CustomListCellRenderer extends DefaultListCellRenderer
     {
+        public CustomListCellRenderer()
+        {
+            GuiUtil.applyDefaultOrientation(this);
+        }
+
         /* (non-Javadoc)
          * @see javax.swing.ListCellRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
          */

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/GuiUtil.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -47,6 +47,7 @@
 import javax.swing.JToolTip;
 import javax.swing.text.JTextComponent;
 
+import org.crosswire.common.util.Language;
 import org.crosswire.common.util.Logger;
 import org.crosswire.common.util.ResourceUtil;
 
@@ -547,17 +548,27 @@
      * Recursively apply default component orientation to the component and all it contains.
      * 
      * @param comp the root of the tree to which orientation needs to be applied
-     * @param o the orientation to be applied
      */
     public static void applyDefaultOrientation(Component comp)
     {
-        applyOrientation(comp, ComponentOrientation.getOrientation(Locale.getDefault()));
+        applyOrientation(comp, new Language(Locale.getDefault().getLanguage()).isLeftToRight());
     }
 
     /**
      * Recursively apply component orientation to the component and all it contains.
      * 
      * @param comp the root of the tree to which orientation needs to be applied
+     * @param ltr whether the orientation is left to right or not.
+     */
+    public static void applyOrientation(Component comp, boolean ltr)
+    {
+        applyOrientation(comp, ltr ? ComponentOrientation.LEFT_TO_RIGHT : ComponentOrientation.RIGHT_TO_LEFT);
+    }
+
+    /**
+     * Recursively apply component orientation to the component and all it contains.
+     * 
+     * @param comp the root of the tree to which orientation needs to be applied
      * @param orientation the orientation to be applied
      */
     public static void applyOrientation(Component comp, ComponentOrientation orientation)

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/MapEntryRenderer.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/MapEntryRenderer.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/MapEntryRenderer.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -48,7 +48,9 @@
             displayObject = mapEntry.getValue();
         }
 
-        return super.getListCellRendererComponent(list, displayObject, index, selected, focus);
+        Component comp = super.getListCellRendererComponent(list, displayObject, index, selected, focus);
+        GuiUtil.applyDefaultOrientation(comp);
+        return comp;
     }
 
     /**

Modified: trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java
===================================================================
--- trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/common-swing/src/main/java/org/crosswire/common/swing/NumberCellRenderer.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -43,6 +43,7 @@
     public NumberCellRenderer()
     {
         this.shaper = new NumberShaper();
+        GuiUtil.applyDefaultOrientation(this);
     }
 
     /* (non-Javadoc)
@@ -66,6 +67,7 @@
             setText(shaper.shape(value.toString()));
         }
 
+        GuiUtil.applyDefaultOrientation(comp);
         return comp;
     }
 

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/DefaultBookMetaData.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/DefaultBookMetaData.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/basic/DefaultBookMetaData.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -21,8 +21,6 @@
  */
 package org.crosswire.jsword.book.basic;
 
-import java.awt.ComponentOrientation;
-import java.util.Locale;
 import java.util.Map;
 
 import org.crosswire.common.util.Language;
@@ -118,15 +116,7 @@
      */
     public boolean isLeftToRight()
     {
-        String lang = getLanguage().getName();
-
-        // Java does not know that the following languages are right to left
-        if ("fa".equals(lang) || "syr".equals(lang))  //$NON-NLS-1$ //$NON-NLS-2$
-        {
-            return false;
-        }
-
-        return ComponentOrientation.getOrientation(new Locale(lang)).isLeftToRight();
+        return getLanguage().isLeftToRight();
     }
 
     /**

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/ConfigEntryTable.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -21,7 +21,6 @@
  */
 package org.crosswire.jsword.book.sword;
 
-import java.awt.ComponentOrientation;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.File;
@@ -32,7 +31,6 @@
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.util.HashMap;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.regex.Matcher;
@@ -585,18 +583,6 @@
         add(ConfigEntryType.DATA_PATH, datapath);
     }
 
-    private boolean isLeftToRight(Language language)
-    {
-        String lang = language.getCode();
-        // Java does not know that the following languages are right to left
-        if ("fa".equals(lang) || "syr".equals(lang) || "ug".equals(lang) || "uig".equals(lang))  //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-        {
-            return false;
-        }
-
-        return ComponentOrientation.getOrientation(new Locale(lang)).isLeftToRight();
-    }
-
     private void adjustLanguage()
     {
         // Java thinks it is LtoR but it is stated to be something else
@@ -604,44 +590,34 @@
         String newDir = dir == null ? (String) ConfigEntryType.DIRECTION.getDefault() : dir;
 
         Language lang = (Language) getValue(ConfigEntryType.LANG);
-        Language langFrom = (Language) getValue(ConfigEntryType.GLOSSARY_FROM);
-        Language langTo = (Language) getValue(ConfigEntryType.GLOSSARY_TO);
-        testLanguage(internal, lang);
-        testLanguage(internal, langFrom);
-        testLanguage(internal, langTo);
-
-        // The LANG field should match the GLOSSARY_FROM field
-        if (langFrom != null && !langFrom.equals(lang))
+        if (lang == null)
         {
-            lang = langFrom;
+            lang = Language.DEFAULT_LANG;
+            add(ConfigEntryType.LANG, lang.toString());
         }
+        testLanguage(internal, lang);
 
-        // This returns Left to Right if
-        // it does not know what it is.
-        boolean leftToRight = isLeftToRight(lang);
+        Language langFrom = (Language) getValue(ConfigEntryType.GLOSSARY_FROM);
+        Language langTo = (Language) getValue(ConfigEntryType.GLOSSARY_TO);
 
+        // If we have either langFrom or langTo, we are dealing with a glossary
         if (langFrom != null || langTo != null)
         {
-            boolean fromLeftToRight = true;
-            boolean toLeftToRight = true;
-
             if (langFrom == null)
             {
                 log.warn("Missing data for " + internal + ". Assuming " + ConfigEntryType.GLOSSARY_FROM.getName() + '=' + Languages.DEFAULT_LANG_CODE);  //$NON-NLS-1$ //$NON-NLS-2$
+                langFrom = Language.DEFAULT_LANG;
+                add(ConfigEntryType.GLOSSARY_FROM, lang.toString());
             }
-            else
-            {
-                fromLeftToRight = isLeftToRight(langFrom);
-            }
+            testLanguage(internal, langFrom);
 
             if (langTo == null)
             {
                 log.warn("Missing data for " + internal + ". Assuming " + ConfigEntryType.GLOSSARY_TO.getName() + '=' + Languages.DEFAULT_LANG_CODE);  //$NON-NLS-1$ //$NON-NLS-2$
+                langTo = Language.DEFAULT_LANG;
+                add(ConfigEntryType.GLOSSARY_TO, lang.toString());
             }
-            else
-            {
-                toLeftToRight = isLeftToRight(langTo);
-            }
+            testLanguage(internal, langTo);
 
             // At least one of the two languages should match the lang entry
             if (!langFrom.equals(lang) && !langTo.equals(lang))
@@ -652,11 +628,23 @@
                           " match " + ConfigEntryType.LANG.getName()); //$NON-NLS-1$
             }
 
-            if (fromLeftToRight != toLeftToRight)
+            // The LANG field should match the GLOSSARY_FROM field
+            else if (!langFrom.equals(lang))
             {
+            /*
+                log.error("Data error in " + internal + //$NON-NLS-1$
+                          ". " + ConfigEntryType.GLOSSARY_FROM.getName() + //$NON-NLS-1$
+                          " (" + langFrom.getCode() + ") does not match " + ConfigEntryType.LANG.getName() + " (" + lang.getCode() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+			*/
+                lang = langFrom;
+                add(ConfigEntryType.LANG, lang.toString());
+            }
+
+            if (langFrom.isLeftToRight() != langTo.isLeftToRight())
+            {
                 newDir = ConfigEntryType.DIRECTION_BIDI;
             }
-            else if (fromLeftToRight)
+            else if (langFrom.isLeftToRight())
             {
                 newDir = ConfigEntryType.DIRECTION_LTOR;
             }
@@ -667,7 +655,7 @@
         }
         else
         {
-            if (leftToRight)
+            if (lang.isLeftToRight())
             {
                 newDir = ConfigEntryType.DIRECTION_LTOR;
             }
@@ -769,7 +757,7 @@
 
     private void testLanguage(String initials, Language lang)
     {
-        if (lang != null && !lang.isValidLanguage())
+        if (!lang.isValidLanguage())
         {
             log.warn("Unknown language " + lang.getCode() + " in book " + initials); //$NON-NLS-1$ //$NON-NLS-2$
         }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -169,7 +169,7 @@
         }
         catch (IOException e)
         {
-            throw new BookException(UserMsg.READ_FAIL);
+            throw new BookException(UserMsg.READ_FAIL, e, new Object[] { key.getName() });
         }
     }
 

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/RawLDBackend.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -25,12 +25,15 @@
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.net.URI;
-import java.util.Date;
+import java.text.DecimalFormat;
 import java.text.MessageFormat;
 import java.text.ParseException;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.crosswire.common.activate.Activator;
 import org.crosswire.common.activate.Lock;
@@ -41,6 +44,7 @@
 import org.crosswire.common.util.StringUtil;
 import org.crosswire.jsword.book.BookCategory;
 import org.crosswire.jsword.book.BookException;
+import org.crosswire.jsword.book.FeatureType;
 import org.crosswire.jsword.passage.DefaultLeafKeyList;
 import org.crosswire.jsword.passage.Key;
 
@@ -95,11 +99,11 @@
                 }
                 return getRawText(entry);
             }
-            throw new BookException(UserMsg.READ_FAIL);
+            throw new BookException(UserMsg.READ_FAIL, new Object[] { key });
         }
         catch (IOException ex)
         {
-            throw new BookException(UserMsg.READ_FAIL, ex);
+            throw new BookException(UserMsg.READ_FAIL, ex, new Object[] { key });
         }
     }
 
@@ -145,22 +149,7 @@
                 if (index < getCardinality())
                 {
                     DataEntry entry = getEntry(getBookMetaData().getInitials(), index);
-                    SwordBookMetaData bmd = getBookMetaData();
-
-                    boolean isDailyDevotional = bmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS);
-
-                    Calendar greg = new GregorianCalendar();
-                    DateFormatter nameDF = DateFormatter.getDateInstance();
-                    String keytitle = entry.getKey();
-
-                    if (isDailyDevotional && keytitle.length() >= 3)
-                    {
-                        String[] spec = StringUtil.splitAll(keytitle, '.');
-                        greg.set(Calendar.MONTH, Integer.parseInt(spec[0]) - 1);
-                        greg.set(Calendar.DATE, Integer.parseInt(spec[1]));
-                        keytitle = nameDF.format(greg.getTime());
-                    }
-
+                    String keytitle = internal2external(entry.getKey());
                     return new DefaultLeafKeyList(keytitle);
                 }
             }
@@ -348,82 +337,153 @@
             return -1;
         }
 
-        SwordBookMetaData bmd = getBookMetaData();
+        String target = external2internal(key);
 
-        boolean isDailyDevotional = bmd.getBookCategory().equals(BookCategory.DAILY_DEVOTIONS);
+        // Initialize to one beyond both ends.
+        int total = getCardinality();
+        int low = -1;
+        int high = total;
 
-        String target = key.toUpperCase(Locale.US);
-        if (isDailyDevotional)
+        while (high - low > 1)
         {
+            // use >>> to keep mid always in range
+            int mid = (low + high) >>> 1;
+
+            // Get the key for the item at "mid"
+            if (normalizeForSearch(getEntry(key, mid).getKey()).compareTo(target) < 0)
+            {
+                low = mid;
+            }
+            else
+            {
+                high = mid;
+            }
+        }
+
+        // At this point high is what we are what is the candidate.        
+        if (high < total &&  normalizeForSearch(getEntry(key, high).getKey()).compareTo(target) == 0)
+        {
+            return high;
+        }
+
+        // Strong's Greek And Hebrew dictionaries have an introductory entry, so check it for a match.
+        // Get the key for the item at "mid"
+        if (normalizeForSearch(getEntry(key, 0).getKey()).compareTo(target) == 0)
+        {
+            return 0;
+        }
+
+        return -(high - 1);
+    }
+
+    /**
+     * Convert the Gregorian Calendar to a string.
+     * @param externalKey
+     * @return
+     */
+    private String external2internal(String externalKey)
+    {
+        SwordBookMetaData bmd = getBookMetaData();
+        String keytitle = externalKey;
+        if (BookCategory.DAILY_DEVOTIONS.equals(bmd.getBookCategory()))
+        {
             Calendar greg = new GregorianCalendar();
             DateFormatter nameDF = DateFormatter.getDateInstance();
             nameDF.setLenient(true);
             try
             {
-                Date date = nameDF.parse(key);
+                Date date = nameDF.parse(keytitle);
                 greg.setTime(date);
-                target = external2internal(greg);
+                Object[] objs = {new Integer(1 + greg.get(Calendar.MONTH)),
+                                 new Integer(greg.get(Calendar.DATE))};
+                return DATE_KEY_FORMAT.format(objs);
             }
             catch (ParseException e)
             {
                 assert false : e;
             }
         }
-
-        int low = 1;
-        int high = getCardinality() - 1;
-
-        while (low <= high)
+        else if (bmd.hasFeature(FeatureType.GREEK_DEFINITIONS) || bmd.hasFeature(FeatureType.HEBREW_DEFINITIONS))
         {
-            int mid = (low + high) >> 1;
-
-            // Get the key for the item at "mid"
-            DataEntry entry = getEntry(key, mid);
-            String midVal = entry.getKey();
-
-            int cmp = midVal.toUpperCase(Locale.US).compareTo(target);
-
-            if (cmp < 0)
+            // Is the string valid?
+            Matcher m = STRONGS_PATTERN.matcher(keytitle);
+            if (!m.matches())
             {
-                low = mid + 1;
+                return keytitle.toUpperCase(Locale.US);
             }
-            else if (cmp > 0)
+
+            // NASB has trailing letters!
+            int pos = keytitle.length() - 1;
+            char lastLetter = keytitle.charAt(pos);
+            boolean hasTrailingLetter = Character.isLetter(lastLetter);
+            if (hasTrailingLetter)
             {
-                high = mid - 1;
+                keytitle = keytitle.substring(0, pos);
+                // And it might be preceded by a !
+                pos--;
+                if (pos > 0 && keytitle.charAt(pos) == '!')
+                {
+                    keytitle = keytitle.substring(0, pos);
+                }
             }
-            else
+
+            // Get the G or the H.
+            char type = keytitle.charAt(0);
+
+            // Get the number after the G or H
+            int strongsNumber = Integer.parseInt(keytitle.substring(1));
+            if (bmd.hasFeature(FeatureType.GREEK_DEFINITIONS) && bmd.hasFeature(FeatureType.HEBREW_DEFINITIONS))
             {
-                return mid; // key found
+                // The convention is that a Strong's dictionary with both Greek and Hebrew have G or H prefix
+                StringBuffer buf = new StringBuffer();
+                buf.append(Character.toUpperCase(type));
+                buf.append(ZERO_4PAD.format(strongsNumber));
+
+                // The NAS lexicon has some entries that end in A-Z, but it is not preceded by a !
+                if (hasTrailingLetter && "naslex".equalsIgnoreCase(bmd.getInitials())) //$NON-NLS-1$
+                {
+                    buf.append(Character.toUpperCase(lastLetter));
+                }
+                return buf.toString();
             }
+            
+            return ZERO_5PAD.format(strongsNumber);
         }
+        else
+        {
+            return keytitle.toUpperCase(Locale.US);
+        }
 
-        // Strong's Greek And Hebrew dictionaries have an introductory entry, so check it for a match.
-        // Get the key for the item at "mid"
-        DataEntry entry = getEntry(key, 0);
-        String midVal = entry.getKey();
+        return keytitle;
+    }
 
-        int cmp = midVal.toUpperCase(Locale.US).compareTo(target);
-        if (cmp == 0)
+    private String internal2external(String internalKey)
+    {
+        SwordBookMetaData bmd = getBookMetaData();
+        String keytitle = internalKey;
+        if (BookCategory.DAILY_DEVOTIONS.equals(bmd.getBookCategory()) && keytitle.length() >= 3)
         {
-            return 0;
+            Calendar greg = new GregorianCalendar();
+            DateFormatter nameDF = DateFormatter.getDateInstance();
+            String[] spec = StringUtil.splitAll(keytitle, '.');
+            greg.set(Calendar.MONTH, Integer.parseInt(spec[0]) - 1);
+            greg.set(Calendar.DATE, Integer.parseInt(spec[1]));
+            keytitle = nameDF.format(greg.getTime());
         }
-
-        return -(low + 1); // key not found
+        return keytitle;
     }
 
-    /**
-     * Convert the Gregorian Calendar to a string.
-     * @param externalKey
-     * @return
-     */
-    public static String external2internal(Calendar externalKey)
+    private String normalizeForSearch(String internalKey)
     {
-        Object[] objs = {new Integer(1 + externalKey.get(Calendar.MONTH)),
-                         new Integer(externalKey.get(Calendar.DATE))};
-        return KEY_FORMAT.format(objs);
+        SwordBookMetaData bmd = getBookMetaData();
+        String keytitle = internalKey;
+        if (!BookCategory.DAILY_DEVOTIONS.equals(bmd.getBookCategory()))
+        {
+            return keytitle.toUpperCase(Locale.US);
+        }
 
+        return keytitle;
     }
-
     /**
      * How many bytes in the offset pointers in the index
      */
@@ -472,9 +532,22 @@
     /**
      * Date formatter
      */
-    private static final MessageFormat KEY_FORMAT = new MessageFormat("{0,number,00}.{1,number,00}"); //$NON-NLS-1$
+    private static final MessageFormat DATE_KEY_FORMAT = new MessageFormat("{0,number,00}.{1,number,00}"); //$NON-NLS-1$
 
     /**
+     * This is the pattern of a Strong's Number. It begins with a G or H. Is followed by a number.
+     * It can be followed by a ! and a letter or just a letter.
+     */
+    private static final Pattern STRONGS_PATTERN = Pattern.compile("^([GH])(\\d+)((!)?([a-z])?)$"); //$NON-NLS-1$
+
+    /**
+     * A means to normalize Strong's Numbers.
+     */
+    private static final DecimalFormat ZERO_5PAD = new DecimalFormat("00000"); //$NON-NLS-1$
+
+    private static final DecimalFormat ZERO_4PAD = new DecimalFormat("0000"); //$NON-NLS-1$
+
+    /**
      * Serialization ID
      */
     private static final long serialVersionUID = 818089833394450383L;

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	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordBookMetaData.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -30,6 +30,7 @@
 import java.util.Locale;
 import java.util.Map;
 
+import org.crosswire.common.util.Language;
 import org.crosswire.common.util.NetUtil;
 import org.crosswire.jsword.book.BookCategory;
 import org.crosswire.jsword.book.FeatureType;
@@ -264,8 +265,10 @@
      */
     public boolean isLeftToRight()
     {
-        String dir = (String) getProperty(ConfigEntryType.DIRECTION);
-        return dir == null || dir.equals(ConfigEntryType.DIRECTION.getDefault());
+        // Return the dominate direction based upon the Book's Language not Direction
+        // because Direction can be BiDi.
+        Language lang = (Language) getProperty(ConfigEntryType.LANG);
+        return lang.isLeftToRight();
     }
 
     /* (non-Javadoc)

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDictionary.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDictionary.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordDictionary.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -21,12 +21,9 @@
  */
 package org.crosswire.jsword.book.sword;
 
-import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
 import org.crosswire.common.activate.Activator;
 import org.crosswire.common.activate.Lock;
@@ -169,15 +166,6 @@
     {
         checkActive();
 
-        // So we need to find a matching key.
-        // TODO(DM): This is a hack.
-        Key key = getStrongsKey(text);
-
-        if (key != null)
-        {
-            return key;
-        }
-
         int pos = backend.indexOf(new DefaultLeafKeyList(text));
         if (pos < 0)
         {
@@ -190,42 +178,6 @@
         return backend.get(pos);
     }
 
-    // TODO(DM): Hack alert!!! This is not in the right place!!!
-    private Key getStrongsKey(String txt)
-    {
-        String text = txt;
-        // Is the string all digits?
-        Matcher m = STRONGS_PATTERN.matcher(text);
-        if (!m.matches())
-        {
-            return null;
-        }
-
-        // Hack alert!!! NASB has trailing letters!!!!
-        int pos = text.length() - 1;
-        if (Character.isLetter(text.charAt(pos)))
-        {
-            text = text.substring(0, pos);
-        }
-
-
-        Key key = null;
-        String internalName = sbmd.getInitials();
-        if ("StrongsGreek".equals(internalName)) //$NON-NLS-1$
-        {
-            // Get the number after the G or H
-            int strongsNumber = Integer.parseInt(text.substring(1));
-            key = backend.get(backend.indexOf(new DefaultLeafKeyList(ZERO_PAD.format(strongsNumber))));
-        }
-        else if ("StrongsHebrew".equals(internalName)) //$NON-NLS-1$
-        {
-            // Get the number after the G or H
-            int strongsNumber = Integer.parseInt(text.substring(1));
-            key = backend.get(backend.indexOf(new DefaultLeafKeyList(ZERO_PAD.format(strongsNumber))));
-        }
-        return key;
-    }
-
     /* (non-Javadoc)
      * @see org.crosswire.jsword.passage.KeyFactory#getEmptyKeyList()
      */
@@ -269,10 +221,6 @@
         }
     }
 
-    // This should move along with getStrongsKey
-    private static final Pattern STRONGS_PATTERN = Pattern.compile("^[GH]\\d+[a-z]?$"); //$NON-NLS-1$
-    private static final DecimalFormat ZERO_PAD = new DecimalFormat("00000"); //$NON-NLS-1$
-
     /**
      * Are we active
      */

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/display/jdtb/JDTBBookDataDisplay.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -105,7 +105,7 @@
             // Make sure Hebrew displays from Right to Left
 //            BookMetaData bmd = book.getBookMetaData();
 //            boolean direction = bmd.isLeftToRight();
-//            txtView.applyComponentOrientation(direction ? ComponentOrientation.LEFT_TO_RIGHT : ComponentOrientation.RIGHT_TO_LEFT);
+//            GuiUtil.applyOrientation(txtView, direction);
 
 //            BookData bdata = new BookData(book, key);
 

Modified: trunk/jsword-limbo/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java	2008-05-10 18:36:47 UTC (rev 1851)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/common/config/swing/WizardConfigEditor.java	2008-05-11 19:46:46 UTC (rev 1852)
@@ -261,13 +261,13 @@
     {
         Component root = SwingUtilities.getRoot(parent);
         dialog = new JDialog((JFrame) root);
-        dialog.setComponentOrientation(root.getComponentOrientation());
         dialog.getRootPane().setDefaultButton(next);
         dialog.getContentPane().add(this);
         dialog.setTitle(config.getTitle());
         dialog.setSize(800, 500);
         dialog.pack();
         dialog.setModal(true);
+        GuiUtil.applyDefaultOrientation(dialog);
         dialog.setVisible(true);
 
         // Why is this only available in Frames?




More information about the jsword-svn mailing list