[jsword-svn] r1253 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop bibledesktop/src/main/java/org/crosswire/bibledesktop/passage jsword/src/main/java/org/crosswire/jsword/book jsword/src/main/java/org/crosswire/jsword/book/sword jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Fri Mar 16 14:16:27 MST 2007


Author: dmsmith
Date: 2007-03-16 14:16:26 -0700 (Fri, 16 Mar 2007)
New Revision: 1253

Added:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordGenBook.java
Removed:
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java
   trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java
Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DictionaryPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/BookFilters.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
Log:
Some GUI work for GenBook

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DictionaryPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DictionaryPane.java	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DictionaryPane.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -33,14 +33,18 @@
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JSplitPane;
+import javax.swing.JTree;
 import javax.swing.ListSelectionModel;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
+import javax.swing.event.TreeSelectionEvent;
+import javax.swing.event.TreeSelectionListener;
 
 import org.crosswire.bibledesktop.display.BookDataDisplay;
 import org.crosswire.bibledesktop.display.BookDataDisplayFactory;
 import org.crosswire.bibledesktop.display.URLEventListener;
 import org.crosswire.bibledesktop.passage.KeyListListModel;
+import org.crosswire.bibledesktop.passage.KeyTreeModel;
 import org.crosswire.common.swing.FixedSplitPane;
 import org.crosswire.common.util.Logger;
 import org.crosswire.jsword.book.Book;
@@ -55,7 +59,7 @@
 import org.crosswire.jsword.passage.Verse;
 
 /**
- * Builds a panel on which all the Dictionaries and their entries are visible.
+ * Builds a panel on which all the non-Bible books and their entries are visible.
  * 
  * @see gnu.gpl.License for license details.
  *      The copyright to this program is held by it's authors.
@@ -72,7 +76,7 @@
         init();
 
         // This must come after the setViewportView() calls so scrolling works
-        lstDicts.setSelectedValue(Defaults.getDailyDevotional(), true);
+        bookList.setSelectedValue(Defaults.getDailyDevotional(), true);
     }
 
     /**
@@ -82,73 +86,16 @@
     {
         display = BookDataDisplayFactory.createBookDataDisplay();
 
-        BookFilter filter =
-            BookFilters.either(
-                               BookFilters.either(BookFilters.getDictionaries(),
-                                                  BookFilters.getCommentaries()),
-                               BookFilters.getDailyDevotionals()
-                               );
-        BooksComboBoxModel mdlDicts = new BooksComboBoxModel(filter);
+        Component bookPicker = createBookPicker();
 
-        lstDicts = new JList();
-        lstDicts.setVisibleRowCount(6);
-        lstDicts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
-        lstDicts.setModel(mdlDicts);
-        lstDicts.setCellRenderer(new BookListCellRenderer());
-        lstDicts.setPrototypeCellValue(BookListCellRenderer.PROTOTYPE_BOOK_NAME);
-        lstDicts.addListSelectionListener(new ListSelectionListener()
-        {
-            public void valueChanged(ListSelectionEvent ev)
-            {
-                if (ev.getValueIsAdjusting())
-                {
-                    return;
-                }
+        commentaryPicker = createCommentaryPicker();
 
-                newDictionary();
-            }
-        });
+        dictionaryKeyScroller = createDictionaryPicker();
 
-        JScrollPane scrDicts = new JScrollPane();
-        scrDicts.setViewportView(lstDicts);
+        genBookKeyScroller = createGenBookPicker();
 
-        JComboBox cboBooks = new JComboBox();
-        JComboBox cboChaps = new JComboBox();
-        JComboBox cboVerse = new JComboBox();
-        set = new BibleComboBoxModelSet(cboBooks, cboChaps, cboVerse);
+        JScrollPane scrDisplay = new JScrollPane(display.getComponent());
 
-        set.addActionListener(new ActionListener()
-        {
-            public void actionPerformed(ActionEvent ev)
-            {
-                updateDisplay();
-            }
-        });
-
-        cboBooks.setToolTipText(Msg.SELECT_BOOK.toString());
-        cboChaps.setToolTipText(Msg.SELECT_CHAPTER.toString());
-        cboVerse.setToolTipText(Msg.SELECT_VERSE.toString());
-
-        pnlSelect = new JPanel();
-        pnlSelect.setLayout(new FlowLayout());
-        pnlSelect.add(cboBooks, null);
-        pnlSelect.add(cboChaps, null);
-        pnlSelect.add(cboVerse, null);
-
-        lstEntries = new JList();
-        lstEntries.addListSelectionListener(new ListSelectionListener()
-        {
-            public void valueChanged(ListSelectionEvent ev)
-            {
-                newEntry();
-            }
-        });
-        scrEntries = new JScrollPane();
-        scrEntries.setViewportView(lstEntries);
-
-        JScrollPane scrDisplay = new JScrollPane();
-        scrDisplay.setViewportView(display.getComponent());
-
         sptMain = new FixedSplitPane(false);
         sptMain.setOrientation(JSplitPane.VERTICAL_SPLIT);
         // Make the top 20% of the total
@@ -159,7 +106,7 @@
 //        this.setResizeWeight(0.1D);
 //        this.setMinimumSize(new Dimension(0, 0));
         this.setOrientation(JSplitPane.VERTICAL_SPLIT);
-        this.setTopComponent(scrDicts);
+        this.setTopComponent(bookPicker);
         this.setBottomComponent(sptMain);
         this.setBorder(null);
 
@@ -207,7 +154,7 @@
      */
     public Key getKey()
     {
-        return (Key) lstEntries.getSelectedValue();
+        return (Key) dictionaryKeyList.getSelectedValue();
     }
 
     /* (non-Javadoc)
@@ -231,7 +178,7 @@
      */
     public Book getBook()
     {
-        return dict;
+        return book;
     }
 
     /**
@@ -240,15 +187,15 @@
      */
     public void setWord(String data)
     {
-        if (dict == null)
+        if (book == null)
         {
             return;
         }
 
         try
         {
-            Key key = dict.getKey(data);
-            lstEntries.setSelectedValue(key, true);
+            Key key = book.getKey(data);
+            dictionaryKeyList.setSelectedValue(key, true);
         }
         catch (NoSuchKeyException ex)
         {
@@ -283,7 +230,7 @@
             try
             {
                 Key key = tempdict.getKey(data);
-                lstdicts.setSelectedValue(tempdict, true);
+                bookList.setSelectedValue(tempdict, true);
                 lstentries.setSelectedValue(key, true);
                 return;
             }
@@ -294,53 +241,183 @@
         }     
     */
 
-    public void selectDictionary(Book book)
+    public void selectBook(Book selectedBook)
     {
-        lstDicts.setSelectedValue(book, true);
+        bookList.setSelectedValue(selectedBook, true);
     }
 
     /**
+     * Create a book picker of all non-bibles
+     * @return The scrollable picker
+     */
+    private Component createBookPicker()
+    {
+        BookFilter filter = BookFilters.getNonBibles();
+        BooksComboBoxModel mdlBooks = new BooksComboBoxModel(filter);
+
+        bookList = new JList();
+        bookList.setVisibleRowCount(6);
+        bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+        bookList.setModel(mdlBooks);
+        bookList.setCellRenderer(new BookListCellRenderer());
+        bookList.setPrototypeCellValue(BookListCellRenderer.PROTOTYPE_BOOK_NAME);
+        bookList.addListSelectionListener(new ListSelectionListener()
+        {
+            public void valueChanged(ListSelectionEvent ev)
+            {
+                if (ev.getValueIsAdjusting())
+                {
+                    return;
+                }
+
+                newBook();
+            }
+        });
+
+        return new JScrollPane(bookList);
+    }
+
+    /**
+     * Build a tree for a GenBook
+     */
+    private Component createCommentaryPicker()
+    {
+        JComboBox cboBooks = new JComboBox();
+        JComboBox cboChaps = new JComboBox();
+        JComboBox cboVerse = new JComboBox();
+        set = new BibleComboBoxModelSet(cboBooks, cboChaps, cboVerse);
+
+        set.addActionListener(new ActionListener()
+        {
+            public void actionPerformed(ActionEvent ev)
+            {
+                updateDisplay();
+            }
+        });
+
+        cboBooks.setToolTipText(Msg.SELECT_BOOK.toString());
+        cboChaps.setToolTipText(Msg.SELECT_CHAPTER.toString());
+        cboVerse.setToolTipText(Msg.SELECT_VERSE.toString());
+
+        JPanel panel = new JPanel();
+        panel.setLayout(new FlowLayout());
+        panel.add(cboBooks, null);
+        panel.add(cboChaps, null);
+        panel.add(cboVerse, null);
+        return panel;
+    }
+   
+    /**
+     * Build a tree for a GenBook
+     */
+    private Component createDictionaryPicker()
+    {
+        dictionaryKeyList = new JList();
+        dictionaryKeyList.addListSelectionListener(new ListSelectionListener()
+        {
+            public void valueChanged(ListSelectionEvent ev)
+            {
+                newEntry();
+            }
+        });
+        return new JScrollPane(dictionaryKeyList);
+    }
+   
+    /**
+     * Build a tree for a GenBook
+     */
+    private Component createGenBookPicker()
+    {
+        genBookKeyTree = new JTree();
+        genBookKeyTree.setModel(new KeyTreeModel(null));
+        genBookKeyTree.setShowsRootHandles(true);
+        genBookKeyTree.setRootVisible(false);
+        genBookKeyTree.putClientProperty("JTree.lineStyle", "Angled"); //$NON-NLS-1$//$NON-NLS-2$
+        genBookKeyTree.addTreeSelectionListener(new TreeSelectionListener()
+        {
+            public void valueChanged(TreeSelectionEvent ev)
+            {
+                // treeSelected();
+            }
+        });
+
+        return new JScrollPane(genBookKeyTree);
+    }
+
+    /**
      * Called when someone selects a new Dictionary
      */
-    /*private*/ final void newDictionary()
+    /*private*/ final void newBook()
     {
-        Object selected = lstDicts.getSelectedValue();
-        // Don't leave the scroller in the middle of the list!
-        lstEntries.ensureIndexIsVisible(0);
-        // Make sure that the list of keys is empty.
-        lstEntries.setModel(new KeyListListModel(null));
+        // First ensure that all the pickers make sense if the user
+        // unselects the book
+        if (book != null)
+        {
+            BookCategory currentCategory = book.getBookCategory();
+            if (currentCategory.equals(BookCategory.DICTIONARY) || currentCategory.equals(BookCategory.GLOSSARY)
+                || currentCategory.equals(BookCategory.DAILY_DEVOTIONS))
+            {
+                // Don't leave the scroller in the middle of the list!
+                dictionaryKeyList.ensureIndexIsVisible(0);
+                // Make sure that the list of keys is empty.
+                dictionaryKeyList.setModel(new KeyListListModel(null));
+            }
+            else if (currentCategory.equals(BookCategory.GENERAL_BOOK))
+            {
+                // Don't leave the scroller in the middle of the list!
+                genBookKeyTree.scrollRowToVisible(0);
+
+                // Make sure that the list of keys is empty.
+                KeyTreeModel model = new KeyTreeModel(null);
+                genBookKeyTree.setModel(model);
+            }
+        }
         // Make sure that the display is emtpy.
         display.setBookData(null, null);
+
+        Object selected = bookList.getSelectedValue();
         if (selected != null)
         {
-            Book book = (Book) selected;
-            BookCategory category = book.getBookCategory();
+            Book selectedBook = (Book) selected;
+            BookCategory category = selectedBook.getBookCategory();
             //divider snaps back to its starting point when a new component is set
             int dividerLocation = sptMain.getDividerLocation();
-            if (category.equals(BookCategory.DICTIONARY)
-                || category.equals(BookCategory.GLOSSARY)
-                || category.equals(BookCategory.DAILY_DEVOTIONS))
+            if (category.equals(BookCategory.COMMENTARY))
             {
-                dict = book;
-                Key key = dict.getGlobalKeyList();
+                updateDisplay();
+                sptMain.setTopComponent(commentaryPicker);
+            }
+            else if (category.equals(BookCategory.DICTIONARY)
+                     || category.equals(BookCategory.GLOSSARY)
+                     || category.equals(BookCategory.DAILY_DEVOTIONS))
+            {
+                book = selectedBook;
+                Key key = book.getGlobalKeyList();
 
                 KeyListListModel model = new KeyListListModel(key);
-                lstEntries.setModel(model);
+                dictionaryKeyList.setModel(model);
 
-                if (dict instanceof PreferredKey)
+                if (book instanceof PreferredKey)
                 {
-                    PreferredKey pref = (PreferredKey) dict;
+                    PreferredKey pref = (PreferredKey) book;
                     Key prefkey = pref.getPreferred();
 
-                    lstEntries.setSelectedValue(prefkey, true);
+                    dictionaryKeyList.setSelectedValue(prefkey, true);
                 }
-                sptMain.setTopComponent(scrEntries);
+
+                sptMain.setTopComponent(dictionaryKeyScroller);
             }
-            else
+            else // currentCategory.equals(BookCategory.GENERAL_BOOK)
             {
-                updateDisplay();
-                sptMain.setTopComponent(pnlSelect);
+                book = selectedBook;
+                Key key = book.getGlobalKeyList();
+
+                KeyTreeModel model = new KeyTreeModel(key);
+                genBookKeyTree.setModel(model);
+
+                sptMain.setTopComponent(genBookKeyScroller);
             }
+
             sptMain.setDividerLocation(dividerLocation);
         }
     }
@@ -350,15 +427,15 @@
      */
     /*protected*/ final void updateDisplay()
     {
-        Book book = (Book) lstDicts.getSelectedValue();
-        if (book == null)
+        Book selectedBook = (Book) bookList.getSelectedValue();
+        if (selectedBook == null)
         {
-            log.warn("no selected dictionary"); //$NON-NLS-1$
+            log.warn("no selected book"); //$NON-NLS-1$
             return;
         }
 
         Verse verse = set.getVerse();
-        display.setBookData(book, verse);
+        display.setBookData(selectedBook, verse);
     }
 
     /**
@@ -366,10 +443,10 @@
      */
     /*private*/ final void newEntry()
     {
-        Key key = (Key) lstEntries.getSelectedValue();
+        Key key = (Key) dictionaryKeyList.getSelectedValue();
         if (key != null)
         {
-            display.setBookData(dict, key);
+            display.setBookData(book, key);
         }
     }
 
@@ -384,7 +461,7 @@
     {
         // We don't serialize views
         display = BookDataDisplayFactory.createBookDataDisplay();
-        dict = null;
+        book = null;
         set = null;
         is.defaultReadObject();
     }
@@ -393,13 +470,15 @@
      * The display of OSIS data
      */
     private transient BookDataDisplay display;
-    private transient Book dict;
+    private transient Book book;
     protected transient BibleComboBoxModelSet set;
-    private JPanel pnlSelect;
-    private JList lstDicts;
+    private Component commentaryPicker;
+    private Component genBookKeyScroller;
+    private JTree genBookKeyTree;
+    private JList bookList;
     private JSplitPane sptMain;
-    private JScrollPane scrEntries;
-    private JList lstEntries;
+    private Component dictionaryKeyScroller;
+    private JList dictionaryKeyList;
 
     /**
      * The log stream

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/desktop/Desktop.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -677,7 +677,7 @@
                 Book book = Defaults.getCommentary();
                 if (book != null && Books.installed().getBook(book.getName()) != null)
                 {
-                    reference.selectDictionary(book);
+                    reference.selectBook(book);
                     Key key = reference.getBook().getKey(data);
                     reference.setKey(key);
                 }
@@ -723,7 +723,7 @@
         // TODO(DM): If it is not installed, offer to install it.
         if (book != null && Books.installed().getBook(book.getName()) != null)
         {
-            reference.selectDictionary(book);
+            reference.selectBook(book);
             reference.setWord(data);
         }
     }

Copied: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java (from rev 1251, trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java)
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java	                        (rev 0)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -0,0 +1,73 @@
+/**
+ * Distribution License:
+ * BibleDesktop is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, version 2 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/gpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id$
+ */
+package org.crosswire.bibledesktop.passage;
+
+import java.awt.Component;
+
+import javax.swing.JTree;
+import javax.swing.tree.DefaultTreeCellRenderer;
+
+import org.crosswire.common.util.Logger;
+import org.crosswire.jsword.passage.Key;
+
+/**
+ * A specialization of DefaultTreeCellRenderer that knows how to get names from
+ * Keys.
+ * 
+ * @see gnu.gpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author Joe Walker [joe at eireneh dot com]
+ */
+public class KeyTreeCellRenderer extends DefaultTreeCellRenderer
+{
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
+     */
+    /* @Override */
+    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isselected, boolean expanded, boolean leaf, int row, boolean focus)
+    {
+        super.getTreeCellRendererComponent(tree, value, isselected, expanded, leaf, row, focus);
+
+        if (value instanceof KeyTreeNode)
+        {
+            KeyTreeNode keytn = (KeyTreeNode) value;
+            Key key = keytn.getKey();
+            setText(key.getName());
+        }
+        else // if (value != null)
+        {
+            log.warn("value is not a key: " + value.getClass().getName()); //$NON-NLS-1$
+        }
+
+        return this;
+    }
+
+    /**
+     * The log stream
+     */
+    private static final Logger log = Logger.getLogger(KeyTreeCellRenderer.class);
+
+    /**
+     * Serialization ID
+     */
+    private static final long serialVersionUID = 3545232531516765241L;
+}

Copied: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java (from rev 1251, trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java)
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java	                        (rev 0)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -0,0 +1,74 @@
+/**
+ * Distribution License:
+ * BibleDesktop is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, version 2 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/gpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id$
+ */
+package org.crosswire.bibledesktop.passage;
+
+import javax.swing.tree.DefaultTreeModel;
+
+import org.crosswire.jsword.passage.Key;
+
+/**
+ * A TreeModel that helps with working with Keys.
+ * 
+ * @see gnu.gpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author Joe Walker [joe at eireneh dot com]
+ */
+public class KeyTreeModel extends DefaultTreeModel
+{
+    /**
+     * Simple ctor
+     * @param key The root TreeNode
+     */
+    public KeyTreeModel(Key key)
+    {
+        super(new KeyTreeNode(key, null));
+        this.key = key;
+    }
+
+    /**
+     * What key is this tree editing
+     * @return Returns the key.
+     */
+    public Key getKey()
+    {
+        return key;
+    }
+
+    /**
+     * Sets the key is this tree editing
+     */
+    public void setKey(Key key)
+    {
+        this.key = key;
+        setRoot(new KeyTreeNode(key, null));
+    }
+
+    /**
+     * The key that this tree is displaying.
+     */
+    private Key key;
+
+    /**
+     * Serialization ID
+     */
+    private static final long serialVersionUID = 3977303235050353714L;
+}

Copied: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java (from rev 1251, trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java)
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java	                        (rev 0)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -0,0 +1,128 @@
+/**
+ * Distribution License:
+ * BibleDesktop is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, version 2 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/gpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id$
+ */
+package org.crosswire.bibledesktop.passage;
+
+import java.util.Enumeration;
+
+import javax.swing.tree.TreeNode;
+
+import org.crosswire.common.util.EmptyIterator;
+import org.crosswire.common.util.IteratorEnumeration;
+import org.crosswire.jsword.passage.Key;
+
+/**
+ * An implementation of TreeNode that reads from Keys and KeyLists.
+ * 
+ * @see gnu.gpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author Joe Walker [joe at eireneh dot com]
+ */
+public class KeyTreeNode implements TreeNode
+{
+    /**
+     * Simple ctor
+     */
+    public KeyTreeNode(Key key, TreeNode parent)
+    {
+        this.key = key;
+        this.parent = parent;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getChildCount()
+     */
+    public int getChildCount()
+    {
+        return key == null ? 0 : key.getCardinality();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getAllowsChildren()
+     */
+    public boolean getAllowsChildren()
+    {
+        return key != null && key.canHaveChildren();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#isLeaf()
+     */
+    public boolean isLeaf()
+    {
+        return key == null || key.isEmpty();
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#children()
+     */
+    public Enumeration children()
+    {
+        if (key != null)
+        {
+            return new IteratorEnumeration(key.iterator());
+        }
+        return new IteratorEnumeration(new EmptyIterator());
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getParent()
+     */
+    public TreeNode getParent()
+    {
+        return parent;
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getChildAt(int)
+     */
+    public TreeNode getChildAt(int index)
+    {
+        Key child = key.get(index);
+        return new KeyTreeNode(child, this);
+    }
+
+    /* (non-Javadoc)
+     * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
+     */
+    public int getIndex(TreeNode node)
+    {
+        if (key != null && node instanceof KeyTreeNode)
+        {
+            KeyTreeNode keynode = (KeyTreeNode) node;
+            Key that = keynode.getKey();
+
+            return key.indexOf(that);
+        }
+        return -1;
+    }
+
+    /**
+     * Accessor for the key
+     */
+    public Key getKey()
+    {
+        return key;
+    }
+
+    private Key key;
+    private TreeNode parent;
+}

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/BookFilters.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/BookFilters.java	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/BookFilters.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -53,22 +53,6 @@
     }
 
     /**
-     * Filter for all books
-     */
-    private static BookFilter allBookFilter = new AllBookFilter();
-
-    /**
-     * Filter for all books
-     */
-    static class AllBookFilter implements BookFilter
-    {
-        public boolean test(Book book)
-        {
-            return true;
-        }
-    }
-
-    /**
      * A filter that accepts everything that implements Bible
      */
     public static BookFilter getBibles()
@@ -77,19 +61,11 @@
     }
 
     /**
-     * Filter for all Bibles
+     * A filter that accepts everything that's not a Bible
      */
-    private static BookFilter biblesBookFilter = new BiblesBookFilter();
-
-    /**
-     * Filter for all Bibles
-     */
-    static class BiblesBookFilter implements BookFilter
+    public static BookFilter getNonBibles()
     {
-        public boolean test(Book book)
-        {
-            return book.getBookCategory().equals(BookCategory.BIBLE) && !book.isLocked();
-        }
+        return noneBibleBookFilter;
     }
 
     /**
@@ -101,21 +77,11 @@
     }
 
     /**
-     * Filter for all dictionaries
+     * A filter that accepts everything that implements Dictionary
      */
-    private static BookFilter dictionariesBookFilter = new DictionariesBookFilter();
-
-    /**
-     * Filter for all dictionaries
-     */
-    static class DictionariesBookFilter implements BookFilter
+    public static BookFilter getGlossaries()
     {
-        public boolean test(Book book)
-        {
-            BookCategory category = book.getBookCategory();
-            return (category.equals(BookCategory.DICTIONARY) || category.equals(BookCategory.GLOSSARY))
-                  && !book.isLocked();
-        }
+        return glossariesBookFilter;
     }
 
     /**
@@ -127,23 +93,6 @@
     }
 
     /**
-     * Filter for all dictionaries
-     */
-    private static BookFilter dailyDevotionalsBookFilter = new DailyDevotionalsBookFilter();
-
-    /**
-     * Filter for all dictionaries
-     */
-    static class DailyDevotionalsBookFilter implements BookFilter
-    {
-        public boolean test(Book book)
-        {
-            BookCategory category = book.getBookCategory();
-            return category.equals(BookCategory.DAILY_DEVOTIONS) && !book.isLocked();
-        }
-    }
-
-    /**
      * A filter that accepts everything that implements Commentary
      */
     public static BookFilter getCommentaries()
@@ -152,19 +101,11 @@
     }
 
     /**
-     * Filter for all commentaries
+     * A filter that accepts everything that implements GeneralBook
      */
-    private static BookFilter commentariesBookFilter = new CommentariesBookFilter();
-
-    /**
-     * Filter for all commentaries
-     */
-    static class CommentariesBookFilter implements BookFilter
+    public static BookFilter getGeneralBooks()
     {
-        public boolean test(Book book)
-        {
-            return book.getBookCategory().equals(BookCategory.COMMENTARY) && !book.isLocked();
-        }
+        return generalBookFilter;
     }
 
     /**
@@ -177,94 +118,167 @@
     }
 
     /**
-     * Filter for all Greek Definition Dictionaries
+     * A filter that accepts everything that is a
+     * Greek Parse/Morphology Dictionary
      */
-    private static BookFilter greekDefinitionsBookFilter = new GreekDefinitionsBookFilter();
+    public static BookFilter getGreekParse()
+    {
+        return greekParseBookFilter;
+    }
 
     /**
-     * Filter for all Greek Definition Dictionaries
+     * A filter that accepts everything that is a
+     * Hebrew Definition Dictionary
      */
-    static class GreekDefinitionsBookFilter implements BookFilter
+    public static BookFilter getHebrewDefinitions()
     {
-        public boolean test(Book book)
-        {
-            return book.hasFeature(FeatureType.GREEK_DEFINITIONS) && !book.isLocked();
-        }
+        return hebrewDefinitionsBookFilter;
     }
 
     /**
      * A filter that accepts everything that is a
-     * Greek Parse/Morphology Dictionary
+     * Hebrew Parse/Morphology Dictionary
      */
-    public static BookFilter getGreekParse()
+    public static BookFilter getHebrewParse()
     {
-        return greekParseBookFilter;
+        return hebrewParseBookFilter;
     }
 
     /**
-     * Filter for all Greek Parse/Morphology Dictionaries
+     * Filter for all books
      */
-    private static BookFilter greekParseBookFilter = new GreekParseBookFilter();
+    private static BookFilter allBookFilter = new AllBookFilter();
 
     /**
-     * Filter for all Greek Parse/Morphology Dictionaries
+     * Filter for all Bibles
      */
-    static class GreekParseBookFilter implements BookFilter
-    {
-        public boolean test(Book book)
-        {
-            return book.hasFeature(FeatureType.GREEK_PARSE) && !book.isLocked();
-        }
-    }
+    private static BookFilter biblesBookFilter = new BookCategoryFilter(BookCategory.BIBLE);
 
     /**
-     * A filter that accepts everything that is a
-     * Hebrew Definition Dictionary
+     * Filter for all non-Bibles
      */
-    public static BookFilter getHebrewDefinitions()
-    {
-        return hebrewDefinitionsBookFilter;
-    }
+    private static BookFilter noneBibleBookFilter = new NotBookCategoryFilter(BookCategory.BIBLE);
 
     /**
-     * Filter for all Hebrew Definition Dictionaries
+     * Filter for all dictionaries
      */
-    private static BookFilter hebrewDefinitionsBookFilter = new HebrewDefinitionsBookFilter();
+    private static BookFilter dictionariesBookFilter = new BookCategoryFilter(BookCategory.DICTIONARY);
 
     /**
+     * Filter for all glossaries
+     */
+    private static BookFilter glossariesBookFilter = new BookCategoryFilter(BookCategory.GLOSSARY);
+
+    /**
+     * Filter for all dictionaries
+     */
+    private static BookFilter dailyDevotionalsBookFilter = new BookCategoryFilter(BookCategory.DAILY_DEVOTIONS);
+
+    /**
+     * Filter for all commentaries
+     */
+    private static BookFilter commentariesBookFilter = new BookCategoryFilter(BookCategory.COMMENTARY);
+
+    /**
+     * Filter for all commentaries
+     */
+    private static BookFilter generalBookFilter = new BookCategoryFilter(BookCategory.GENERAL_BOOK);
+
+    /**
+     * Filter for all Greek Definition Dictionaries
+     */
+    private static BookFilter greekDefinitionsBookFilter = new BookFeatureFilter(FeatureType.GREEK_DEFINITIONS);
+
+    /**
+     * Filter for all Greek Parse/Morphology Dictionaries
+     */
+    private static BookFilter greekParseBookFilter = new BookFeatureFilter(FeatureType.GREEK_PARSE);
+
+    /**
      * Filter for all Hebrew Definition Dictionaries
      */
-    static class HebrewDefinitionsBookFilter implements BookFilter
+    private static BookFilter hebrewDefinitionsBookFilter = new BookFeatureFilter(FeatureType.HEBREW_DEFINITIONS);
+
+    /**
+     * Filter for all Hebrew Parse/Morphology Dictionaries
+     */
+    private static BookFilter hebrewParseBookFilter = new BookFeatureFilter(FeatureType.HEBREW_PARSE);
+
+    /**
+     * Filter for all books
+     */
+    static class AllBookFilter implements BookFilter
     {
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.BookFilter#test(org.crosswire.jsword.book.Book)
+         */
         public boolean test(Book book)
         {
-            return book.hasFeature(FeatureType.HEBREW_DEFINITIONS) && !book.isLocked();
+            return true;
         }
     }
 
     /**
-     * A filter that accepts everything that is a
-     * Hebrew Parse/Morphology Dictionary
+     * Filter for books by category
      */
-    public static BookFilter getHebrewParse()
+    static class BookCategoryFilter implements BookFilter
     {
-        return hebrewParseBookFilter;
+        BookCategoryFilter(BookCategory category)
+        {
+            this.category = category;
+        }
+
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.BookFilter#test(org.crosswire.jsword.book.Book)
+         */
+        public boolean test(Book book)
+        {
+            return book.getBookCategory().equals(category) && !book.isLocked();
+        }
+
+        private BookCategory category;
     }
 
     /**
-     * Filter for all Hebrew Parse/Morphology Dictionaries
+     * Filter for books by category
      */
-    private static BookFilter hebrewParseBookFilter = new HebrewParseBookFilter();
+    static class NotBookCategoryFilter implements BookFilter
+    {
+        NotBookCategoryFilter(BookCategory category)
+        {
+            this.category = category;
+        }
 
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.BookFilter#test(org.crosswire.jsword.book.Book)
+         */
+        public boolean test(Book book)
+        {
+            return !book.getBookCategory().equals(category) && !book.isLocked();
+        }
+
+        private BookCategory category;
+    }
+
     /**
-     * Filter for all Hebrew Parse/Morphology Dictionaries
+     * Filter for books by feature
      */
-    static class HebrewParseBookFilter implements BookFilter
+    static class BookFeatureFilter implements BookFilter
     {
+        BookFeatureFilter(FeatureType feature)
+        {
+            this.feature = feature;
+        }
+
+        /* (non-Javadoc)
+         * @see org.crosswire.jsword.book.BookFilter#test(org.crosswire.jsword.book.Book)
+         */
         public boolean test(Book book)
         {
-            return book.hasFeature(FeatureType.HEBREW_PARSE) && !book.isLocked();
+            return book.hasFeature(feature) && !book.isLocked();
         }
+
+        private FeatureType feature;
     }
 
     /**
@@ -296,7 +310,7 @@
     }
 
     /**
-     * A filter that accepts Books that match either of two criteria.
+     * A filter that accepts Books that match by book driver.
      */
     public static BookFilter getBooksByDriver(final BookDriver driver)
     {

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/BookType.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -255,7 +255,7 @@
     {
         protected Book getBook(SwordBookMetaData sbmd, AbstractBackend backend)
         {
-            return new SwordBook(sbmd, backend);
+            return new SwordGenBook(sbmd, backend);
         }
 
         protected AbstractBackend getBackend(SwordBookMetaData sbmd) throws BookException

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	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -30,6 +30,7 @@
 import org.crosswire.common.util.FileUtil;
 import org.crosswire.common.util.Logger;
 import org.crosswire.jsword.book.BookException;
+import org.crosswire.jsword.passage.DefaultKeyList;
 import org.crosswire.jsword.passage.Key;
 
 /**
@@ -113,7 +114,10 @@
     /* @Override */
     public Key readIndex()
     {
-        return null;
+        SwordBookMetaData bmd = getBookMetaData();
+        Key reply = new DefaultKeyList(null, bmd.getName());
+
+        return reply;
     }
 
     /* (non-Javadoc)

Added: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordGenBook.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordGenBook.java	                        (rev 0)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/SwordGenBook.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -0,0 +1,279 @@
+/**
+ * Distribution License:
+ * JSword is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License, version 2.1 as published by
+ * the Free Software Foundation. This program is distributed in the hope
+ * that it will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Lesser General Public License for more details.
+ *
+ * The License is available on the internet at:
+ *       http://www.gnu.org/copyleft/lgpl.html
+ * or by writing to:
+ *      Free Software Foundation, Inc.
+ *      59 Temple Place - Suite 330
+ *      Boston, MA 02111-1307, USA
+ *
+ * Copyright: 2005
+ *     The copyright to this program is held by it's authors.
+ *
+ * ID: $Id: SwordDictionary.java 1185 2006-11-13 13:32:18Z dmsmith $
+ */
+package org.crosswire.jsword.book.sword;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.crosswire.common.activate.Activator;
+import org.crosswire.common.activate.Lock;
+import org.crosswire.jsword.book.BookData;
+import org.crosswire.jsword.book.BookException;
+import org.crosswire.jsword.book.OSISUtil;
+import org.crosswire.jsword.book.basic.AbstractBook;
+import org.crosswire.jsword.book.filter.FilterException;
+import org.crosswire.jsword.passage.DefaultKeyList;
+import org.crosswire.jsword.passage.Key;
+import org.crosswire.jsword.passage.NoSuchKeyException;
+import org.crosswire.jsword.passage.ReadOnlyKeyList;
+import org.jdom.Element;
+
+/**
+ * A Sword version of Dictionary.
+ * 
+ * @see gnu.lgpl.License for license details.
+ *      The copyright to this program is held by it's authors.
+ * @author Joe Walker [joe at eireneh dot com]
+ */
+public class SwordGenBook extends AbstractBook
+{
+    /**
+     * Start and to as much checking as we can without using memory.
+     * (i.e. actually reading the indexes)
+     */
+    protected SwordGenBook(SwordBookMetaData sbmd, AbstractBackend backend)
+    {
+        super(sbmd);
+
+        this.sbmd = sbmd;
+        this.backend = backend;
+        map = null;
+        set = null;
+        global = null;
+        active = false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.common.activate.Activatable#activate(org.crosswire.common.activate.Lock)
+     */
+    /* @Override */
+    public final void activate(Lock lock)
+    {
+        super.activate(lock);
+
+        set = backend.readIndex();
+
+        map = new HashMap();
+        Iterator iter = set.iterator();
+        while (iter.hasNext())
+        {
+            Key key = (Key) iter.next();
+            map.put(key.getName(), key);
+        }
+
+        global = new ReadOnlyKeyList(set, false);
+
+        active = true;
+
+        // We don't need to activate the backend because it should be capable
+        // of doing it for itself.
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.common.activate.Activatable#deactivate(org.crosswire.common.activate.Lock)
+     */
+    /* @Override */
+    public final void deactivate(Lock lock)
+    {
+        super.deactivate(lock);
+
+        map = null;
+        set = null;
+        global = null;
+
+        Activator.deactivate(backend);
+
+        active = false;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.Book#getData(org.crosswire.jsword.passage.Key)
+     */
+    public BookData getData(Key key) throws BookException
+    {
+        checkActive();
+
+        assert key != null;
+        assert backend != null;
+
+        try
+        {
+            Element osis = OSISUtil.createOsisFramework(getBookMetaData());
+            Element text = osis.getChild(OSISUtil.OSIS_ELEMENT_OSISTEXT);
+
+            Element div = OSISUtil.factory().createDiv();
+            Element title = OSISUtil.factory().createTitle();
+            title.addContent(key.getName());
+            div.addContent(title);
+            text.addContent(div);
+
+            String txt = backend.getRawText(key);
+
+            List osisContent = sbmd.getFilter().toOSIS(this, key, txt);
+            div.addContent(osisContent);
+
+            return new BookData(osis, this, key);
+        }
+        catch (FilterException ex)
+        {
+            throw new BookException(Msg.FILTER_FAIL, ex);
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.book.Book#getRawData(org.crosswire.jsword.passage.Key)
+     */
+    public String getRawData(Key key) throws BookException
+    {
+        checkActive();
+
+        assert key != null;
+        assert backend != null;
+
+        return backend.getRawText(key);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.KeyFactory#getGlobalKeyList()
+     */
+    public Key getGlobalKeyList()
+    {
+        checkActive();
+
+        return global;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.KeyFactory#isValidKey(java.lang.String)
+     */
+    public Key getValidKey(String name)
+    {
+        try
+        {
+            return getKey(name);
+        }
+        catch (NoSuchKeyException e)
+        {
+            return createEmptyKeyList();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.KeyFactory#getKey(java.lang.String)
+     */
+    public Key getKey(String text) throws NoSuchKeyException
+    {
+        checkActive();
+
+        Key key = (Key) map.get(text);
+        if (key != null)
+        {
+            return key;
+        }
+
+        // First check for keys that match ignoring case
+        Iterator iter = map.keySet().iterator();
+        while (iter.hasNext())
+        {
+            String keyName = (String) iter.next();
+            if (keyName.equalsIgnoreCase(text))
+            {
+                return (Key) map.get(keyName);
+            }
+        }
+
+        // Next keys that start with the given text
+        iter = map.keySet().iterator();
+        while (iter.hasNext())
+        {
+            String keyName = (String) iter.next();
+            if (keyName.startsWith(text))
+            {
+                return (Key) map.get(keyName);
+            }
+        }
+
+        // Next try keys that contain the given text
+        iter = map.keySet().iterator();
+        while (iter.hasNext())
+        {
+            String keyName = (String) iter.next();
+            if (keyName.indexOf(text) != -1)
+            {
+                return (Key) map.get(keyName);
+            }
+        }
+
+        throw new NoSuchKeyException(Msg.NO_KEY, new Object[] { text, getInitials() });
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.KeyFactory#getEmptyKeyList()
+     */
+    public Key createEmptyKeyList()
+    {
+        return new DefaultKeyList();
+    }
+
+    /**
+     * Helper method so we can quickly activate ourselves on access
+     */
+    private void checkActive()
+    {
+        if (!active)
+        {
+            Activator.activate(this);
+        }
+    }
+
+    /**
+     * The global key list
+     */
+    private Key global;
+
+    /**
+     * Are we active
+     */
+    private boolean active;
+
+    /**
+     * So we can quickly find a Key given the text for the key
+     */
+    private Map map;
+
+    /**
+     * So we can implement getIndex() easily
+     */
+    private Key set;
+
+    /**
+     * To read the data from the disk
+     */
+    private AbstractBackend backend;
+
+    /**
+     * The Sword configuration file
+     */
+    private SwordBookMetaData sbmd;
+}

Deleted: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -1,73 +0,0 @@
-/**
- * Distribution License:
- * BibleDesktop is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, version 2 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * The License is available on the internet at:
- *       http://www.gnu.org/copyleft/gpl.html
- * or by writing to:
- *      Free Software Foundation, Inc.
- *      59 Temple Place - Suite 330
- *      Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- *     The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.bibledesktop.passage;
-
-import java.awt.Component;
-
-import javax.swing.JTree;
-import javax.swing.tree.DefaultTreeCellRenderer;
-
-import org.crosswire.common.util.Logger;
-import org.crosswire.jsword.passage.Key;
-
-/**
- * A specialization of DefaultTreeCellRenderer that knows how to get names from
- * Keys.
- * 
- * @see gnu.gpl.License for license details.
- *      The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
- */
-public class KeyTreeCellRenderer extends DefaultTreeCellRenderer
-{
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
-     */
-    /* @Override */
-    public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isselected, boolean expanded, boolean leaf, int row, boolean focus)
-    {
-        super.getTreeCellRendererComponent(tree, value, isselected, expanded, leaf, row, focus);
-
-        if (value instanceof KeyTreeNode)
-        {
-            KeyTreeNode keytn = (KeyTreeNode) value;
-            Key key = keytn.getKey();
-            setText(key.getName());
-        }
-        else
-        {
-            log.warn("value is not a key: " + value.getClass().getName()); //$NON-NLS-1$
-        }
-
-        return this;
-    }
-
-    /**
-     * The log stream
-     */
-    private static final Logger log = Logger.getLogger(KeyTreeCellRenderer.class);
-
-    /**
-     * Serialization ID
-     */
-    private static final long serialVersionUID = 3545232531516765241L;
-}

Deleted: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeModel.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -1,74 +0,0 @@
-/**
- * Distribution License:
- * BibleDesktop is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, version 2 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * The License is available on the internet at:
- *       http://www.gnu.org/copyleft/gpl.html
- * or by writing to:
- *      Free Software Foundation, Inc.
- *      59 Temple Place - Suite 330
- *      Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- *     The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.bibledesktop.passage;
-
-import javax.swing.tree.DefaultTreeModel;
-
-import org.crosswire.jsword.passage.Key;
-
-/**
- * A TreeModel that helps with working with Keys.
- * 
- * @see gnu.gpl.License for license details.
- *      The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
- */
-public class KeyTreeModel extends DefaultTreeModel
-{
-    /**
-     * Simple ctor
-     * @param key The root TreeNode
-     */
-    public KeyTreeModel(Key key)
-    {
-        super(new KeyTreeNode(key, null));
-        this.key = key;
-    }
-
-    /**
-     * What key is this tree editing
-     * @return Returns the key.
-     */
-    public Key getKey()
-    {
-        return key;
-    }
-
-    /**
-     * Sets the key is this tree editing
-     */
-    public void setKey(Key key)
-    {
-        this.key = key;
-        setRoot(new KeyTreeNode(key, null));
-    }
-
-    /**
-     * The key that this tree is displaying.
-     */
-    private Key key;
-
-    /**
-     * Serialization ID
-     */
-    private static final long serialVersionUID = 3977303235050353714L;
-}

Deleted: trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java
===================================================================
--- trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java	2007-03-16 17:43:28 UTC (rev 1252)
+++ trunk/jsword-limbo/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java	2007-03-16 21:16:26 UTC (rev 1253)
@@ -1,123 +0,0 @@
-/**
- * Distribution License:
- * BibleDesktop is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, version 2 as published by
- * the Free Software Foundation. This program is distributed in the hope
- * that it will be useful, but WITHOUT ANY WARRANTY; without even the
- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * The License is available on the internet at:
- *       http://www.gnu.org/copyleft/gpl.html
- * or by writing to:
- *      Free Software Foundation, Inc.
- *      59 Temple Place - Suite 330
- *      Boston, MA 02111-1307, USA
- *
- * Copyright: 2005
- *     The copyright to this program is held by it's authors.
- *
- * ID: $Id$
- */
-package org.crosswire.bibledesktop.passage;
-
-import java.util.Enumeration;
-
-import javax.swing.tree.TreeNode;
-
-import org.crosswire.common.util.IteratorEnumeration;
-import org.crosswire.jsword.passage.Key;
-
-/**
- * An implementation of TreeNode that reads from Keys and KeyLists.
- * 
- * @see gnu.gpl.License for license details.
- *      The copyright to this program is held by it's authors.
- * @author Joe Walker [joe at eireneh dot com]
- */
-public class KeyTreeNode implements TreeNode
-{
-    /**
-     * Simple ctor
-     */
-    public KeyTreeNode(Key key, TreeNode parent)
-    {
-        this.key = key;
-        this.parent = parent;
-    }
-
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getChildCount()
-     */
-    public int getChildCount()
-    {
-        return key.getCardinality();
-    }
-
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getAllowsChildren()
-     */
-    public boolean getAllowsChildren()
-    {
-        return key.canHaveChildren();
-    }
-
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#isLeaf()
-     */
-    public boolean isLeaf()
-    {
-        return key.isEmpty();
-    }
-
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#children()
-     */
-    public Enumeration children()
-    {
-        return new IteratorEnumeration(key.iterator());
-    }
-
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getParent()
-     */
-    public TreeNode getParent()
-    {
-        return parent;
-    }
-
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getChildAt(int)
-     */
-    public TreeNode getChildAt(int index)
-    {
-        Key child = key.get(index);
-        return new KeyTreeNode(child, this);
-    }
-
-    /* (non-Javadoc)
-     * @see javax.swing.tree.TreeNode#getIndex(javax.swing.tree.TreeNode)
-     */
-    public int getIndex(TreeNode node)
-    {
-        if (node instanceof KeyTreeNode)
-        {
-            KeyTreeNode keynode = (KeyTreeNode) node;
-            Key that = keynode.getKey();
-
-            return key.indexOf(that);
-        }
-        return -1;
-    }
-
-    /**
-     * Accessor for the key
-     */
-    public Key getKey()
-    {
-        return key;
-    }
-
-    private Key key;
-    private TreeNode parent;
-}




More information about the jsword-svn mailing list