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

dmsmith at www.crosswire.org dmsmith at www.crosswire.org
Wed Mar 21 12:24:04 MST 2007


Author: dmsmith
Date: 2007-03-21 12:24:03 -0700 (Wed, 21 Mar 2007)
New Revision: 1256

Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DictionaryPane.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractKeyList.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/DefaultKeyList.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/Key.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/SetKeyList.java
Log:
More GenBook changes. Now index is viewable.

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-20 21:36:44 UTC (rev 1255)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/DictionaryPane.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -44,6 +44,7 @@
 import org.crosswire.bibledesktop.display.BookDataDisplayFactory;
 import org.crosswire.bibledesktop.display.URLEventListener;
 import org.crosswire.bibledesktop.passage.KeyListListModel;
+import org.crosswire.bibledesktop.passage.KeyTreeCellRenderer;
 import org.crosswire.bibledesktop.passage.KeyTreeModel;
 import org.crosswire.common.swing.FixedSplitPane;
 import org.crosswire.common.util.Logger;
@@ -333,6 +334,7 @@
         genBookKeyTree.setShowsRootHandles(true);
         genBookKeyTree.setRootVisible(false);
         genBookKeyTree.putClientProperty("JTree.lineStyle", "Angled"); //$NON-NLS-1$//$NON-NLS-2$
+        genBookKeyTree.setCellRenderer(new KeyTreeCellRenderer());
         genBookKeyTree.addTreeSelectionListener(new TreeSelectionListener()
         {
             public void valueChanged(TreeSelectionEvent ev)

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeCellRenderer.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -51,7 +51,10 @@
         {
             KeyTreeNode keytn = (KeyTreeNode) value;
             Key key = keytn.getKey();
-            setText(key.getName());
+            if (key != null)
+            {
+                setText(key.getName());
+            }
         }
         else // if (value != null)
         {

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/passage/KeyTreeNode.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -52,7 +52,7 @@
      */
     public int getChildCount()
     {
-        return key == null ? 0 : key.getCardinality();
+        return key == null ? 0 : key.getChildCount();
     }
 
     /* (non-Javadoc)

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-20 21:36:44 UTC (rev 1255)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -126,17 +126,48 @@
         try
         {
             TreeNode node = index.getRoot();
-            TreeKey key = new TreeKey(node, null);
-            reply.addAll(key);
+            reply = new TreeKey(node.getName(), null);
+            doReadIndex(node, reply);
         }
         catch (IOException e)
         {
-            log.error("Could not get root of GenBook", e); //$NON-NLS-1$
+            log.error("Could not get read GenBook index", e); //$NON-NLS-1$
         }
         
         return reply;
     }
 
+    /**
+     * A helper function to recursively read the entire tree.
+     * 
+     * @param parentNode the current node whose children are being sought
+     * @param parentKey
+     * @throws IOException 
+     */
+    private void doReadIndex(TreeNode parentNode, Key parentKey) throws IOException
+    {
+        TreeNode currentNode = parentNode;
+        if (currentNode.hasChildren())
+        {
+            TreeNode childNode = index.getFirstChild(currentNode);
+            do
+            {
+                TreeKey childKey = new TreeKey(childNode.getName(), parentKey);
+                parentKey.addAll(childKey);
+
+                // Build the tree as deep as possible
+                doReadIndex(childNode, childKey);
+
+                if (!childNode.hasNextSibling())
+                {
+                    break;
+                }
+
+                childNode = index.getNextSibling(childNode);
+            }
+            while (true);
+        }
+    }
     /* (non-Javadoc)
      * @see org.crosswire.jsword.book.sword.AbstractBackend#isSupported()
      */

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeKey.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -20,8 +20,14 @@
  *
  * ID: $Id: LZSSBackend.java 1143 2006-10-04 22:07:23 -0400 (Wed, 04 Oct 2006) dmsmith $
  */
-import org.crosswire.jsword.passage.DefaultLeafKeyList;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.crosswire.common.util.Logger;
+import org.crosswire.jsword.passage.AbstractKeyList;
 import org.crosswire.jsword.passage.Key;
+import org.crosswire.jsword.passage.RestrictionType;
 
 /**
  * A Key that knows where the data is in the real file.
@@ -30,16 +36,16 @@
  *      The copyright to this program is held by it's authors.
  * @author Joe Walker [joe at eireneh dot com]
  */
-class TreeKey extends DefaultLeafKeyList
+class TreeKey extends AbstractKeyList
 {
     /**
      * Setup with the key name and positions of data in the file
      */
-    TreeKey(TreeNode node, Key parent)
+    TreeKey(String name, Key parent)
     {
-        super(node.getName(), node.getName(), parent);
-
-        this.node = node;
+        super(name);
+        this.parent = parent;
+        this.children = new ArrayList();
     }
 
     /**
@@ -47,44 +53,139 @@
      */
     TreeKey(String text)
     {
-        super(text, text, null);
+        this(text, null);
+    }
 
-        this.node = null;
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#canHaveChildren()
+     */
+    public boolean canHaveChildren()
+    {
+        return true;
     }
 
-    /**
-     * @return the name
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#getChildCount()
      */
-    public String getName()
+    public int getChildCount()
     {
-        return node.getName();
+        return children.size();
     }
 
-    /**
-     * @param newName the offset to set
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#getCardinality()
      */
-    public void setName(String newName)
+    public int getCardinality()
     {
-        node.setName(newName);
+        int cardinality = 1; // count this node
+        Iterator iter = children.iterator();
+        while (iter.hasNext())
+        {
+            Key child = (Key) iter.next();
+            cardinality += child.getCardinality();
+        }
+
+        return cardinality;
     }
 
-    /**
-     * @return the offset
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#isEmpty()
      */
-    public int getOffset()
+    /* @Override */
+    public boolean isEmpty()
     {
-        return node.getOffset();
+        return children.isEmpty();
     }
 
-    /**
-     * @param newOffset the offset to set
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#contains(org.crosswire.jsword.passage.Key)
      */
-    public void setOffset(int newOffset)
+    /* @Override */
+    public boolean contains(Key key)
     {
-        node.setOffset(newOffset);
+        if (children.contains(key))
+        {
+            return true;
+        }
+
+        Iterator iter = children.iterator();
+        while (iter.hasNext())
+        {
+            Key child = (Key) iter.next();
+            if (child.contains(key))
+            {
+                return true;
+            }
+        }
+
+        return false;
     }
 
     /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#iterator()
+     */
+    public Iterator iterator()
+    {
+        return children.iterator();
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#add(org.crosswire.jsword.passage.Key)
+     */
+    public void addAll(Key key)
+    {
+        children.add(key);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#remove(org.crosswire.jsword.passage.Key)
+     */
+    public void removeAll(Key key)
+    {
+        children.remove(key);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#clear()
+     */
+    public void clear()
+    {
+        children.clear();
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#get(int)
+     */
+    public Key get(int index)
+    {
+        return (Key) children.get(index);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#indexOf(org.crosswire.jsword.passage.Key)
+     */
+    public int indexOf(Key that)
+    {
+        return children.indexOf(that);
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#getParent()
+     */
+    public Key getParent()
+    {
+        return parent;
+    }
+
+    /* (non-Javadoc)
+     * @see org.crosswire.jsword.passage.Key#blur(int)
+     */
+    public void blur(int by, RestrictionType restrict)
+    {
+        log.warn("attempt to blur a non-blur-able list"); //$NON-NLS-1$
+    }
+
+    /* (non-Javadoc)
      * @see java.lang.Object#clone()
      */
     public Object clone()
@@ -92,11 +193,17 @@
         return super.clone();
     }
 
-    private TreeNode node;
+    private Key parent;
 
+    private List children;
+
     /**
      * Serialization ID
      */
     private static final long serialVersionUID = -6560408145705717977L;
 
+    /**
+     * The log stream
+     */
+    private static final Logger log = Logger.getLogger(TreeKey.class);
 }

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/TreeNode.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -113,6 +113,14 @@
     }
 
     /**
+     * @return whether there are children
+     */
+    public boolean hasChildren()
+    {
+        return firstChild != -1;
+    }
+
+    /**
      * @param firstChild the firstChild to set
      */
     public void setFirstChild(int firstChild)
@@ -129,6 +137,14 @@
     }
 
     /**
+     * @return if there are more siblings
+     */
+    public boolean hasNextSibling()
+    {
+        return nextSibling != -1;
+    }
+
+    /**
      * @param nextSibling the nextSibling to set
      */
     public void setNextSibling(int nextSibling)

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractKeyList.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractKeyList.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/AbstractKeyList.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -32,6 +32,15 @@
  */
 public abstract class AbstractKeyList implements Key
 {
+    /**
+     * Build an AbstractKeyList with the given name.
+     * @param name
+     */
+    protected AbstractKeyList(String name)
+    {
+        this.name = name;
+    }
+
     /* (non-Javadoc)
      * @see org.crosswire.jsword.passage.Key#isEmpty()
      */
@@ -201,9 +210,29 @@
     {
         Key that = (Key) obj;
 
-        Key thisfirst = (Key) this.iterator().next();
-        Key thatfirst = (Key) that.iterator().next();
+        int ret = this.getName().compareTo(that.getName());
 
+        if (ret != 0)
+        {
+            return ret;
+        }
+
+        Iterator thisIter = this.iterator();
+        Iterator thatIter = that.iterator();
+
+        Key thisfirst = null;
+        Key thatfirst = null;
+
+        if (thisIter.hasNext())
+        {
+            thisfirst = (Key) thisIter.next();
+        }
+
+        if (thatIter.hasNext())
+        {
+            thatfirst = (Key) thatIter.next();
+        }
+
         if (thisfirst == null)
         {
             if (thatfirst == null)

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/DefaultKeyList.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/DefaultKeyList.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/DefaultKeyList.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -43,6 +43,7 @@
      */
     public DefaultKeyList()
     {
+        super(null);
     }
 
     /**
@@ -50,8 +51,8 @@
      */
     public DefaultKeyList(Key parent, String name)
     {
+        super(name);
         this.parent = parent;
-        setName(name);
     }
 
     /* (non-Javadoc)

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/Key.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/Key.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/Key.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -112,7 +112,7 @@
     int getCardinality();
 
     /**
-     * Does this Passage have 0 members
+     * Does this Key have 0 members
      * @return <tt>true</tt> if this set contains no elements.
      */
     boolean isEmpty();
@@ -153,14 +153,14 @@
     void clear();
 
     /**
-     * Gets a key from a specific point in this list.
+     * Gets a key from a specific point in this list of children.
      * @param index The index of the Key to retrieve
      * @return The specified key
      */
     Key get(int index);
 
     /**
-     * Reverse a Key into the position the key holds in the list
+     * Reverse a Key into the position the key holds in the list of children
      * @param that The Key to find
      * @return The index of the key or -1 if the key is not in the list
      */
@@ -181,6 +181,7 @@
      * @return A complete copy of ourselves
      */
     Object clone();
+
     /**
      * This needs to be declared here so that it is visible as a method
      * on a derived Key.

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/SetKeyList.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/SetKeyList.java	2007-03-20 21:36:44 UTC (rev 1255)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/SetKeyList.java	2007-03-21 19:24:03 UTC (rev 1256)
@@ -42,7 +42,7 @@
      */
     public SetKeyList(Set set)
     {
-        list.addAll(set);
+        this(set, null, null);
     }
 
     /**
@@ -50,8 +50,7 @@
      */
     public SetKeyList(Set set, String name)
     {
-        list.addAll(set);
-        setName(name);
+        this(set, null, name);
     }
 
     /**
@@ -59,8 +58,7 @@
      */
     public SetKeyList(Set set, Key parent)
     {
-        list.addAll(set);
-        this.parent = parent;
+        this(set, parent, null);
     }
 
     /**
@@ -68,9 +66,9 @@
      */
     public SetKeyList(Set set, Key parent, String name)
     {
-        list.addAll(set);
+        super(name);
         this.parent = parent;
-        setName(name);
+        list.addAll(set);
     }
 
     /* (non-Javadoc)




More information about the jsword-svn mailing list