[jsword-svn] jsword/java/jsword/org/crosswire/jsword/book s

jswordcvs at crosswire.org jswordcvs at crosswire.org
Sun Mar 20 19:37:30 MST 2005


Update of /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book
In directory www.crosswire.org:/tmp/cvs-serv13749/java/jsword/org/crosswire/jsword/book

Modified Files:
	BookFilters.java BookMetaData.java Defaults.java 
Added Files:
	FeatureType.java DefaultBook.java 
Log Message:
Fixed BD-34. Clicking a Strong's link now switches books and selects the key.

--- NEW FILE: FeatureType.java ---
package org.crosswire.jsword.book;

import java.io.Serializable;

/**
 * An Enumeration of the possible Features a Book may have.
 * 
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 *
 * Distribution Licence:<br />
 * JSword 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.<br />
 * 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.<br />
 * The License is available on the internet
 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA<br />
 * The copyright to this program is held by it's authors.
 * </font></td></tr></table>
 * @see gnu.gpl.Licence
 * @author Joe Walker [joe at eireneh dot com]
 * @version $Id: FeatureType.java,v 1.1 2005/03/21 02:37:28 dmsmith Exp $
 */
public class FeatureType implements Serializable
{
    /**
     * The book is one of Greek Definitions. AKA, Strongs.
     */
    public static final FeatureType GREEK_DEFINITIONS = new FeatureType("GreekDef"); //$NON-NLS-1$

    /**
     * The book is one of Greek word parsings. AKA, Robinson.
     */
    public static final FeatureType GREEK_PARSE = new FeatureType("GreekParse"); //$NON-NLS-1$

    /**
     * The book is one of Hebrew Definitions. AKA, Strongs.
     */
    public static final FeatureType HEBREW_DEFINITIONS = new FeatureType("HebrewDef"); //$NON-NLS-1$

    /**
     * The book is one of Hebrew word parsings. AKA, ???.
     */
    public static final FeatureType HEBREW_PARSE = new FeatureType("HebrewParse"); //$NON-NLS-1$


    /**
     * The book is one of Daily Devotions. 
     */
    public static final FeatureType DAILY_DEVOTIONS = new FeatureType("DailyDevotions"); //$NON-NLS-1$

    /**
     * The book is glossary of translations from one language to another. 
     */
    public static final FeatureType GLOSSARY = new FeatureType("Glossary"); //$NON-NLS-1$

    /**
     * @param name The name of the BookType
     */
    private FeatureType(String name)
    {
        this.name = name;
    }

    /**
     * Lookup method to convert from a String
     */
    public static FeatureType fromString(String name)
    {
        for (int i = 0; i < VALUES.length; i++)
        {
            FeatureType 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 FeatureType 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 BookType
     */
    private String name;

    // Support for serialization
    private static int nextObj;
    private final int obj = nextObj++;

    Object readResolve()
    {
        return VALUES[obj];
    }

    private static final FeatureType[] VALUES =
    {
        GREEK_DEFINITIONS,
        GREEK_PARSE,
        HEBREW_DEFINITIONS,
        HEBREW_PARSE,
        DAILY_DEVOTIONS,
        GLOSSARY
    };

    /**
     * Serialization ID
     */
    private static final long serialVersionUID = 3256727260177708345L;
}

Index: Defaults.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/Defaults.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** Defaults.java	19 Mar 2005 01:56:47 -0000	1.27
--- Defaults.java	21 Mar 2005 02:37:28 -0000	1.28
***************
*** 1,8 ****
  package org.crosswire.jsword.book;
  
  import java.util.Iterator;
  import java.util.List;
  
! import org.crosswire.common.util.Logger;
  
  /**
--- 1,10 ----
  package org.crosswire.jsword.book;
  
+ import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
! import org.crosswire.common.config.ChoiceFactory;
! import org.crosswire.jsword.book.readings.ReadingsBookDriver;
  
  /**
***************
*** 42,296 ****
      }
  
!     /**
!      * Set the default Bible. The new name must be equal() to a string
!      * returned from getBibleNames. (if does not need to be == however)
!      * A BookException results if you get it wrong.
!      * @param book The version to use as default.
       */
      public static void setBible(Book book)
      {
!         bdeft = book;
      }
  
!     /**
!      * UnSet the current default Bible and attempt to appoint another.
       */
      protected static void unsetBible()
      {
!         bdeft = null;
! 
!         checkAllPreferable();
      }
  
!     /**
!      * Get the current default Bible or null if there are no Bibles.
!      * @return the current default version
       */
      public static Book getBible()
      {
!         return bdeft;
      }
  
!     /**
!      * This method is identical to <code>getBibleMetaData().getFullName()</code>
!      * and is only used by Config which works best with strings under reflection.
       */
      public static String getBibleByName()
      {
!         if (bdeft == null)
!         {
!             return null;
!         }
! 
!         return bdeft.getBookMetaData().getFullName();
      }
  
!     /**
!      * Trawl through all the known Bibles looking for the one closest to
!      * the given name.
!      * <p>This method is for use with config scripts and other things that
!      * <b>need</b> to work with Strings. The preferred method is to use
!      * Book objects.
!      * <p>This method is picky in that it only matches when the driver and the
!      * version are the same. The user (probably) only cares about the version
!      * though, and so might be dissapointed when we fail to match AV (FooDriver)
!      * against AV (BarDriver).
!      * @param name The version to use as default.
       */
      public static void setBibleByName(String name)
      {
!         if (name == null || name.length() == 0)
!         {
!             log.warn("Attempt to set empty Bible as default. Ignoring"); //$NON-NLS-1$
!             return;
!         }
! 
!         List lbmds = Books.installed().getBooks(BookFilters.getBibles());
!         for (Iterator it = lbmds.iterator(); it.hasNext(); )
!         {
!             Book book = (Book) it.next();
!             String tname = book.getBookMetaData().getFullName();
!             if (tname.equals(name))
!             {
!                 setBible(book);
!                 return;
!             }
!         }
! 
!         // This is thrown while the splash screen is up.
!         // It only occurs if the book has been deleted, but the reference
!         // has not changed.
!         // This happens if the user manually deletes the entry.
!         //throw new BookException(Msg.BIBLE_NOTFOUND, new Object[] { name });
      }
  
!     /**
!      * Set the default Commentary. The new name must be equal() to a string
!      * returned from getCommentaryNames. (if does not need to be == however)
!      * A BookException results if you get it wrong.
!      * @param cmd The version to use as default.
       */
!     public static void setCommentary(Book cmd)
      {
!         cdeft = cmd;
      }
  
!     /**
!      * UnSet the current default Commentary and attempt to appoint another.
       */
      protected static void unsetCommentary()
      {
!         cdeft = null;
! 
!         checkAllPreferable();
      }
  
!     /**
!      * Get the current default Commentary or null if none exist.
!      * @return the current default version
       */
      public static Book getCommentary()
      {
!         return cdeft;
      }
  
!     /**
!      * This method is identical to <code>getCommentaryMetaData().getFullName()</code>
!      * and is only used by Config which works best with strings under reflection.
!      * <p>Generally <code>getCommentaryByName().getFullName()</code> is a better
!      * way of getting what you want.
       */
      public static String getCommentaryByName()
      {
!         if (cdeft == null)
!         {
!             return null;
!         }
! 
!         return cdeft.getBookMetaData().getFullName();
      }
  
!     /**
!      * Trawl through all the known Commentary looking for the one closest to
!      * the given name.
!      * <p>This method is for use with config scripts and other things that
!      * <b>need</b> to work with Strings. The preferred method is to use
!      * Book objects.
!      * <p>This method is picky in that it only matches when the driver and the
!      * version are the same. The user (probably) only cares about the version
!      * though, and so might be dissapointed when we fail to match AV (FooDriver)
!      * against AV (BarDriver).
!      * @param name The version to use as default.
       */
      public static void setCommentaryByName(String name)
      {
!         if (name == null || name.length() == 0)
!         {
!             log.warn("Attempt to set empty Commentary as default. Ignoring"); //$NON-NLS-1$
!             return;
!         }
! 
!         List lbmds = Books.installed().getBooks(BookFilters.getCommentaries());
!         for (Iterator it = lbmds.iterator(); it.hasNext(); )
!         {
!             Book book = (Book) it.next();
!             String tname = book.getBookMetaData().getFullName();
!             if (tname.equals(name))
!             {
!                 setCommentary(book);
!                 return;
!             }
!         }
! 
!         // This is thrown while the splash screen is up.
!         // It only occurs if the book has been deleted, but the reference
!         // has not changed.
!         // This happens if the user manually deletes the entry.
!         //throw new BookException(Msg.COMMENTARY_NOTFOUND, new Object[] { name });
      }
  
!     /**
!      * Set the default Dictionary. The new name must be equal() to a string
!      * returned from getDictionaryNames. (if does not need to be == however)
!      * A BookException results if you get it wrong.
!      * @param dmd The version to use as default.
       */
!     public static void setDictionary(Book dmd)
      {
!         ddeft = dmd;
      }
  
!     /**
!      * UnSet the current default Dictionary and attempt to appoint another.
       */
      protected static void unsetDictionary()
      {
!         ddeft = null;
! 
!         checkAllPreferable();
      }
  
!     /**
!      * Get the current default Dictionary or null if none exist.
!      * @return the current default version
       */
      public static Book getDictionary()
      {
!         return ddeft;
      }
  
!     /**
!      * This method is identical to <code>getDictionaryMetaData().getFullName()</code>
!      * and is only used by Config which works best with strings under reflection.
!      * <p>Generally <code>getDictionaryByName().getFullName()</code> is a better
!      * way of getting what you want.
       */
      public static String getDictionaryByName()
      {
!         if (ddeft == null)
!         {
!             return null;
!         }
! 
!         return ddeft.getBookMetaData().getFullName();
      }
  
!     /**
!      * Trawl through all the known Dictionaries looking for the one closest to
!      * the given name.
!      * <p>This method is for use with config scripts and other things that
!      * <b>need</b> to work with Strings. The preferred method is to use
!      * Book objects.
!      * <p>This method is picky in that it only matches when the driver and the
!      * version are the same. The user (probably) only cares about the version
!      * though, and so might be dissapointed when we fail to match AV (FooDriver)
!      * against AV (BarDriver).
!      * @param name The version to use as default.
       */
      public static void setDictionaryByName(String name)
      {
!         if (name == null || name.length() == 0)
!         {
!             log.warn("Attempt to set empty Dictionary as default. Ignoring"); //$NON-NLS-1$
!             return;
!         }
  
!         List lbmds = Books.installed().getBooks(BookFilters.getDictionaries());
!         for (Iterator it = lbmds.iterator(); it.hasNext(); )
!         {
!             Book book = (Book) it.next();
!             String tname = book.getBookMetaData().getFullName();
!             if (tname.equals(name))
!             {
!                 setDictionary(book);
!                 return;
!             }
!         }
  
!         // This is thrown while the splash screen is up.
!         // It only occurs if the book has been deleted, but the reference
!         // has not changed.
!         // This happens if the user manually deletes the entry.
!         //throw new BookException(Msg.DICTIONARY_NOTFOUND, new Object[] { name });
      }
  
--- 44,394 ----
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefault(org.crosswire.jsword.book.Book)
       */
      public static void setBible(Book book)
      {
!         bibleDeft.setDefault(book);
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#unsetDefault()
       */
      protected static void unsetBible()
      {
!         bibleDeft.unsetDefault();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefault()
       */
      public static Book getBible()
      {
!         return bibleDeft.getDefault();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefaultName()
       */
      public static String getBibleByName()
      {
!         return bibleDeft.getDefaultName();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefaultByName(java.lang.String)
       */
      public static void setBibleByName(String name)
      {
!         bibleDeft.setDefaultByName(name);
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefault(org.crosswire.jsword.book.Book)
       */
!     public static void setCommentary(Book book)
      {
!         commentaryDeft.setDefault(book);
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#unsetDefault()
       */
      protected static void unsetCommentary()
      {
!         commentaryDeft.unsetDefault();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefault()
       */
      public static Book getCommentary()
      {
!         return commentaryDeft.getDefault();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefaultName()
       */
      public static String getCommentaryByName()
      {
!         return commentaryDeft.getDefaultName();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefaultByName(java.lang.String)
       */
      public static void setCommentaryByName(String name)
      {
!         commentaryDeft.setDefaultByName(name);
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefault(org.crosswire.jsword.book.Book)
       */
!     public static void setDictionary(Book book)
      {
!         dictionaryDeft.setDefault(book);
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#unsetDefault()
       */
      protected static void unsetDictionary()
      {
!         dictionaryDeft.unsetDefault();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefault()
       */
      public static Book getDictionary()
      {
!         return dictionaryDeft.getDefault();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefaultName()
       */
      public static String getDictionaryByName()
      {
!         return dictionaryDeft.getDefaultName();
      }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefaultByName(java.lang.String)
       */
      public static void setDictionaryByName(String name)
      {
!         dictionaryDeft.setDefaultByName(name);
!     }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefault(org.crosswire.jsword.book.Book)
!      */
!     public static void setGreekDefinitions(Book book)
!     {
!         greekDefinitionsDeft.setDefault(book);
!     }
  
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#unsetDefault()
!      */
!     protected static void unsetGreekDefinitions()
!     {
!         greekDefinitionsDeft.unsetDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefault()
!      */
!     public static Book getGreekDefinitions()
!     {
!         return greekDefinitionsDeft.getDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefaultName()
!      */
!     public static String getGreekDefinitionsByName()
!     {
!         return greekDefinitionsDeft.getDefaultName();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefaultByName(java.lang.String)
!      */
!     public static void setGreekDefinitionsByName(String name)
!     {
!         greekDefinitionsDeft.setDefaultByName(name);
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefault(org.crosswire.jsword.book.Book)
!      */
!     public static void setHebrewDefinitions(Book book)
!     {
!         hebrewDefinitionsDeft.setDefault(book);
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#unsetDefault()
!      */
!     protected static void unsetHebrewDefinitions()
!     {
!         hebrewDefinitionsDeft.unsetDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefault()
!      */
!     public static Book getHebrewDefinitions()
!     {
!         return hebrewDefinitionsDeft.getDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefaultName()
!      */
!     public static String getHebrewDefinitionsByName()
!     {
!         return hebrewDefinitionsDeft.getDefaultName();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefaultByName(java.lang.String)
!      */
!     public static void setHebrewDefinitionsByName(String name)
!     {
!         hebrewDefinitionsDeft.setDefaultByName(name);
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefault(org.crosswire.jsword.book.Book)
!      */
!     public static void setGreekParse(Book book)
!     {
!         greekParseDeft.setDefault(book);
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#unsetDefault()
!      */
!     protected static void unsetGreekParse()
!     {
!         greekParseDeft.unsetDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefault()
!      */
!     public static Book getGreekParse()
!     {
!         return greekParseDeft.getDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefaultName()
!      */
!     public static String getGreekParseByName()
!     {
!         return greekParseDeft.getDefaultName();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefaultByName(java.lang.String)
!      */
!     public static void setGreekParseByName(String name)
!     {
!         greekParseDeft.setDefaultByName(name);
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefault(org.crosswire.jsword.book.Book)
!      */
!     public static void setHebrewParse(Book book)
!     {
!         hebrewParseDeft.setDefault(book);
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#unsetDefault()
!      */
!     protected static void unsetHebrewParse()
!     {
!         hebrewParseDeft.unsetDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefault()
!      */
!     public static Book getHebrewParse()
!     {
!         return hebrewParseDeft.getDefault();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#getDefaultName()
!      */
!     public static String getHebrewParseByName()
!     {
!         return hebrewParseDeft.getDefaultName();
!     }
! 
!     /* (non-Javadoc)
!      * @see org.crosswire.jsword.book.BookDefault#setDefaultByName(java.lang.String)
!      */
!     public static void setHebrewParseByName(String name)
!     {
!         hebrewParseDeft.setDefaultByName(name);
!     }
! 
!     protected static DefaultBook getDefaultBible()
!     {
!         return bibleDeft;
!     }
! 
!     protected static DefaultBook getDefaultCommentary()
!     {
!         return commentaryDeft;
!     }
! 
!     protected static DefaultBook getDefaultDictionary()
!     {
!         return dictionaryDeft;
!     }
! 
!     protected static DefaultBook getDefaultGreekDefinitions()
!     {
!         return greekDefinitionsDeft;
!     }
! 
!     protected static DefaultBook getDefaultHebrewDefinitions()
!     {
!         return hebrewDefinitionsDeft;
!     }
! 
!     protected static DefaultBook getDefaultGreekParse()
!     {
!         return greekParseDeft;
!     }
! 
!     protected static DefaultBook getDefaultHebrewParse()
!     {
!         return hebrewParseDeft;
!     }
! 
!     public static void refreshBooks()
!     {
!         // Create the array of Bibles
!         String[] bnames = getFullNameArray(BookFilters.getBibles());
!         ChoiceFactory.getDataMap().put(BIBLE_KEY, bnames);
! 
!         // Create the array of Commentaries
!         String[] cnames = getFullNameArray(BookFilters.getCommentaries());
!         ChoiceFactory.getDataMap().put(COMMENTARY_KEY, cnames);
! 
!         // Create the array of Dictionaries
!         String[] dnames = getFullNameArray(BookFilters.getDictionaries());
!         ChoiceFactory.getDataMap().put(DICTIONARY_KEY, dnames);
! 
!         // Create the array of Dictionaries
!         String[] greekDef = getFullNameArray(BookFilters.getGreekDefinitions());
!         ChoiceFactory.getDataMap().put(GREEKDEF_KEY, greekDef);
! 
!         // Create the array of Dictionaries
!         String[] hebrewDef = getFullNameArray(BookFilters.getHebrewDefinitions());
!         ChoiceFactory.getDataMap().put(HEBREWDEF_KEY, hebrewDef);
! 
!         // Create the array of Dictionaries
!         String[] greekParse = getFullNameArray(BookFilters.getGreekParse());
!         ChoiceFactory.getDataMap().put(GREEKPARSE_KEY, greekParse);
! 
!         // Create the array of Dictionaries
!         String[] hebrewParse = getFullNameArray(BookFilters.getHebrewParse());
!         ChoiceFactory.getDataMap().put(HEBREWPARSE_KEY, hebrewParse);
! 
!         // Create the array of readings sets
!         ChoiceFactory.getDataMap().put(READINGS_KEY, ReadingsBookDriver.getInstalledReadingsSets());
      }
  
***************
*** 317,341 ****
          assert book != null;
  
!         if (book.getType().equals(BookType.BIBLE) && bdeft == null)
!         {
!             bdeft = book;
!         }
!         else if (book.getType().equals(BookType.COMMENTARY) && cdeft == null)
!         {
!             cdeft = book;
!         }
!         else if (book.getType().equals(BookType.DICTIONARY) && ddeft == null)
!         {
!             ddeft = book;
!         }
      }
  
      /**
!      * Register with Books so we know how to provide valid defaults
       */
!     static
      {
!         Books.installed().addBooksListener(new DefaultsBookListener());
!         checkAllPreferable();
      }
  
--- 415,442 ----
          assert book != null;
  
!         bibleDeft.setDefaultConditionally(book);
!         commentaryDeft.setDefaultConditionally(book);
!         dictionaryDeft.setDefaultConditionally(book);
!         greekDefinitionsDeft.setDefaultConditionally(book);
!         greekParseDeft.setDefaultConditionally(book);
!         hebrewDefinitionsDeft.setDefaultConditionally(book);
!         hebrewParseDeft.setDefaultConditionally(book);
      }
  
      /**
!      * Convert a filter into an array of names of Books that pass the filter.
       */
!     private static String[] getFullNameArray(BookFilter filter)
      {
!         List books = Books.installed().getBooks(filter);
!         List names = new ArrayList();
! 
!         for (Iterator it = books.iterator(); it.hasNext(); )
!         {
!             Book book = (Book) it.next();
!             names.add(book.getBookMetaData().getFullName());
!         }
! 
!         return (String[]) names.toArray(new String[names.size()]);
      }
  
***************
*** 352,355 ****
--- 453,457 ----
              Book book = ev.getBook();
              checkPreferable(book);
+             refreshBooks();
          }
  
***************
*** 361,400 ****
              Book book = ev.getBook();
  
!             // Was this a default?
!             if (getBible().equals(book))
!             {
!                 unsetBible();
!             }
! 
!             if (getCommentary().equals(book))
!             {
!                 unsetCommentary();
!             }
! 
!             if (getDictionary().equals(book))
!             {
!                 unsetDictionary();
!             }
          }
      }
!     /**
!      * The log stream
!      */
!     private static final Logger log = Logger.getLogger(Defaults.class);
  
      /**
       * The default Bible
       */
!     private static Book bdeft;
  
      /**
       * The default Commentary
       */
!     private static Book cdeft;
  
      /**
       * The default Dictionary
       */
!     private static Book ddeft;
  
  }
--- 463,528 ----
              Book book = ev.getBook();
  
!             getDefaultBible().unsetDefaultConditionally(book);
!             getDefaultCommentary().unsetDefaultConditionally(book);
!             getDefaultDictionary().unsetDefaultConditionally(book);
!             getDefaultGreekDefinitions().unsetDefaultConditionally(book);
!             getDefaultGreekParse().unsetDefaultConditionally(book);
!             getDefaultHebrewDefinitions().unsetDefaultConditionally(book);
!             getDefaultHebrewParse().unsetDefaultConditionally(book);
          }
      }
! 
!     private static final String BIBLE_KEY = "bible-names"; //$NON-NLS-1$
!     private static final String COMMENTARY_KEY = "commentary-names"; //$NON-NLS-1$
!     private static final String DICTIONARY_KEY = "dictionary-names"; //$NON-NLS-1$
!     private static final String READINGS_KEY = "readings"; //$NON-NLS-1$
!     private static final String GREEKDEF_KEY = "greekdef-names"; //$NON-NLS-1$
!     private static final String HEBREWDEF_KEY = "hebrewdef-names"; //$NON-NLS-1$
!     private static final String GREEKPARSE_KEY = "greekparse-names"; //$NON-NLS-1$
!     private static final String HEBREWPARSE_KEY = "hebrewparse-names"; //$NON-NLS-1$
  
      /**
       * The default Bible
       */
!     private static DefaultBook bibleDeft = new DefaultBook(Books.installed(), BookFilters.getBibles());
  
      /**
       * The default Commentary
       */
!     private static DefaultBook commentaryDeft = new DefaultBook(Books.installed(), BookFilters.getCommentaries());
  
      /**
       * The default Dictionary
       */
!     private static DefaultBook dictionaryDeft = new DefaultBook(Books.installed(), BookFilters.getDictionaries());
! 
!     /**
!      * The default Greek Parse Dictinary.
!      */
!     private static DefaultBook greekParseDeft = new DefaultBook(Books.installed(), BookFilters.getGreekParse());
! 
!     /**
!      * The default Hebrew Parse Dictinary.
!      */
!     private static DefaultBook hebrewParseDeft = new DefaultBook(Books.installed(), BookFilters.getHebrewParse());
! 
!     /**
!      * The default Greek Definitions Dictinary.
!      */
!     private static DefaultBook greekDefinitionsDeft = new DefaultBook(Books.installed(), BookFilters.getGreekDefinitions());
! 
!     /**
!      * The default Hebrew Definitions Dictionary.
!      */
!     private static DefaultBook hebrewDefinitionsDeft = new DefaultBook(Books.installed(), BookFilters.getHebrewDefinitions());
! 
!     /**
!      * Register with Books so we know how to provide valid defaults
!      */
!     static
!     {
!         Books.installed().addBooksListener(new DefaultsBookListener());
!         checkAllPreferable();
!     }
  
  }

Index: BookFilters.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/BookFilters.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** BookFilters.java	19 Mar 2005 01:56:47 -0000	1.8
--- BookFilters.java	21 Mar 2005 02:37:28 -0000	1.9
***************
*** 132,135 ****
--- 132,235 ----
  
      /**
+      * A filter that accepts everything that is a
+      * Greek Definition Dictionary
+      */
+     public static BookFilter getGreekDefinitions()
+     {
+         return greekDefinitionsBookFilter;
+     }
+ 
+     /**
+      * Filter for all Greek Definition Dictionaries
+      */
+     private static BookFilter greekDefinitionsBookFilter = new GreekDefinitionsBookFilter();
+ 
+     /**
+      * Filter for all Greek Definition Dictionaries
+      */
+     private static class GreekDefinitionsBookFilter implements BookFilter
+     {
+         public boolean test(Book book)
+         {
+             return book.hasFeature(FeatureType.GREEK_DEFINITIONS);
+         }
+     }
+ 
+     /**
+      * A filter that accepts everything that is a
+      * Greek Parse/Morphology Dictionary
+      */
+     public static BookFilter getGreekParse()
+     {
+         return greekParseBookFilter;
+     }
+ 
+     /**
+      * Filter for all Greek Parse/Morphology Dictionaries
+      */
+     private static BookFilter greekParseBookFilter = new GreekParseBookFilter();
+ 
+     /**
+      * Filter for all Greek Parse/Morphology Dictionaries
+      */
+     private static class GreekParseBookFilter implements BookFilter
+     {
+         public boolean test(Book book)
+         {
+             return book.hasFeature(FeatureType.GREEK_PARSE);
+         }
+     }
+ 
+     /**
+      * A filter that accepts everything that is a
+      * Hebrew Definition Dictionary
+      */
+     public static BookFilter getHebrewDefinitions()
+     {
+         return hebrewDefinitionsBookFilter;
+     }
+ 
+     /**
+      * Filter for all Hebrew Definition Dictionaries
+      */
+     private static BookFilter hebrewDefinitionsBookFilter = new HebrewDefinitionsBookFilter();
+ 
+     /**
+      * Filter for all Hebrew Definition Dictionaries
+      */
+     private static class HebrewDefinitionsBookFilter implements BookFilter
+     {
+         public boolean test(Book book)
+         {
+             return book.hasFeature(FeatureType.HEBREW_DEFINITIONS);
+         }
+     }
+ 
+     /**
+      * A filter that accepts everything that is a
+      * Hebrew Parse/Morphology Dictionary
+      */
+     public static BookFilter getHebrewParse()
+     {
+         return hebrewParseBookFilter;
+     }
+ 
+     /**
+      * Filter for all Hebrew Parse/Morphology Dictionaries
+      */
+     private static BookFilter hebrewParseBookFilter = new HebrewParseBookFilter();
+ 
+     /**
+      * Filter for all Hebrew Parse/Morphology Dictionaries
+      */
+     private static class HebrewParseBookFilter implements BookFilter
+     {
+         public boolean test(Book book)
+         {
+             return book.hasFeature(FeatureType.HEBREW_PARSE);
+         }
+     }
+ 
+     /**
       * A filter that accepts Books that match two criteria.
       */

--- NEW FILE: DefaultBook.java ---
package org.crosswire.jsword.book;

import java.util.Iterator;
import java.util.List;

import org.crosswire.common.util.Logger;

/**
 * Defines a single default book.
 * *
 * <p><table border='1' cellPadding='3' cellSpacing='0'>
 * <tr><td bgColor='white' class='TableRowColor'><font size='-7'>
 *
 * Distribution Licence:<br />
 * JSword 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.<br />
 * 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.<br />
 * The License is available on the internet
 * <a href='http://www.gnu.org/copyleft/gpl.html'>here</a>, or by writing to:
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 * MA 02111-1307, USA<br />
 * The copyright to this program is held by it's authors.
 * </font></td></tr></table>
 * @see gnu.gpl.Licence
 * @author Joe Walker [joe at eireneh dot com]
 * @version $Id: DefaultBook.java,v 1.1 2005/03/21 02:37:28 dmsmith Exp $
 */
public class DefaultBook
{
    public DefaultBook(BookList bookList, BookFilter bookFilter)
    {
        books  = bookList;
        filter = bookFilter;
    }

    /**
     * Set the default Book. It must satisfy the filter.
     * @param newBook The version to use as default.
     */
    public void setDefault(Book newBook)
    {
        if (filter.test(newBook))
        {
            book = newBook;
        }
    }

    /**
     * Set the default Book conditionally. It has to satisfy the filter
     * and the book must not currently be set.
     * @param newBook The version to use as default.
     */
    public void setDefaultConditionally(Book newBook)
    {
        if (book == null)
        {
            setDefault(newBook);
        }
    }

    /**
     * Unset the current default book and attempt to appoint another.
     */
    protected void unsetDefault()
    {
        book = null;

        checkReplacement();
    }

    /**
     * Unset the current default book, if it matches the argument
     * and attempt to appoint another.
     */
    protected void unsetDefaultConditionally(Book oldBook)
    {
        if (book == oldBook)
        {
            unsetDefault();
        }
    }

    /**
     * Get the current default book or null if there is none.
     * @return the current default version
     */
    public Book getDefault()
    {
        return book;
    }

    /**
     * This method is identical to <code>getDefault().getFullName()</code>
     * and is only used by Config which works best with strings under reflection.
     */
    public String getDefaultName()
    {
        if (book == null)
        {
            return null;
        }

        return book.getFullName();
    }

    /**
     * Trawl through all the known Books satisfying the filter
     * looking for the one matching the given name.
     * <p>This method is for use with config scripts and other things that
     * <b>need</b> to work with Strings. The preferred method is to use
     * Book objects.
     * <p>This method is picky in that it only matches when the driver and the
     * version are the same. The user (probably) only cares about the version
     * though, and so might be dissapointed when we fail to match AV (FooDriver)
     * against AV (BarDriver).
     * @param name The version to use as default.
     */
    public void setDefaultByName(String name)
    {
        if (name == null || name.length() == 0)
        {
            log.warn("Attempt to set empty book as default. Ignoring"); //$NON-NLS-1$
            return;
        }

        List bookList = books.getBooks(filter);
        Iterator it = bookList.iterator();
        while (it.hasNext())
        {
            Book aBook = (Book) it.next();
            if (name.equals(aBook.getFullName()))
            {
                setDefault(aBook);
                return;
            }
        }

        log.warn("Book not found. Ignoring: " + name); //$NON-NLS-1$
    }

    /**
     * Go through all of the current books checking to see if we need to replace
     * the current defaults with one of these.
     */
    protected void checkReplacement()
    {
        List bookList = books.getBooks(filter);

        Iterator it = bookList.iterator();
        if (it.hasNext())
        {
            book = (Book) it.next();
        }
    }

    /**
     * The default book
     */
    private Book book;

    /**
     * The list of candidate books.
     */
    private final BookList books;

    /**
     * The filter against books that returns candidates.
     */
    private final BookFilter filter;

    /**
     * The log stream
     */
    private static final Logger log = Logger.getLogger(DefaultBook.class);
}

Index: BookMetaData.java
===================================================================
RCS file: /cvs/jsword/jsword/java/jsword/org/crosswire/jsword/book/BookMetaData.java,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** BookMetaData.java	19 Mar 2005 01:56:47 -0000	1.25
--- BookMetaData.java	21 Mar 2005 02:37:28 -0000	1.26
***************
*** 110,113 ****
--- 110,118 ----
  
      /**
+      * Return whether the feature is supported by the book.
+      */
+     public boolean hasFeature(FeatureType feature);
+ 
+     /**
       * Get a list of all the properties available to do with this Book.
       * The returned Properties will be read-only so any attempts to alter it



More information about the jsword-svn mailing list