[jsword-svn] r1258 - in trunk: bibledesktop/src/main/java/org/crosswire/bibledesktop/book 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 15:18:40 MST 2007


Author: dmsmith
Date: 2007-03-21 15:18:40 -0700 (Wed, 21 Mar 2007)
New Revision: 1258

Modified:
   trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java
   trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java
   trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java
Log:
GenBook key can be selected to get raw text. Still need to get the text.

Modified: trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java
===================================================================
--- trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java	2007-03-21 20:43:23 UTC (rev 1257)
+++ trunk/bibledesktop/src/main/java/org/crosswire/bibledesktop/book/MultiBookPane.java	2007-03-21 22:18:40 UTC (rev 1258)
@@ -39,6 +39,7 @@
 import javax.swing.event.ListSelectionListener;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
+import javax.swing.tree.TreePath;
 
 import org.crosswire.bibledesktop.display.BookDataDisplay;
 import org.crosswire.bibledesktop.display.BookDataDisplayFactory;
@@ -46,6 +47,7 @@
 import org.crosswire.bibledesktop.passage.KeyListListModel;
 import org.crosswire.bibledesktop.passage.KeyTreeCellRenderer;
 import org.crosswire.bibledesktop.passage.KeyTreeModel;
+import org.crosswire.bibledesktop.passage.KeyTreeNode;
 import org.crosswire.common.swing.FixedSplitPane;
 import org.crosswire.common.util.Logger;
 import org.crosswire.jsword.book.Book;
@@ -339,7 +341,7 @@
         {
             public void valueChanged(TreeSelectionEvent ev)
             {
-                // treeSelected();
+                selected();
             }
         });
 
@@ -453,6 +455,24 @@
     }
 
     /**
+     * Something has been (un)selected in the tree
+     */
+    /*private*/ void selected()
+    {
+        TreePath path = genBookKeyTree.getSelectionPath();
+
+        if (path != null)
+        {
+            KeyTreeNode node = (KeyTreeNode) path.getLastPathComponent();
+            if (node != null)
+            {
+                display.setBookData(book, node.getKey());
+            }
+        }
+
+    }
+
+    /**
      * Serialization support.
      * 
      * @param is

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-21 20:43:23 UTC (rev 1257)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/book/sword/GenBookBackend.java	2007-03-21 22:18:40 UTC (rev 1258)
@@ -24,6 +24,8 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.crosswire.common.activate.Activator;
 import org.crosswire.common.activate.Lock;
@@ -32,6 +34,7 @@
 import org.crosswire.jsword.book.BookException;
 import org.crosswire.jsword.passage.DefaultKeyList;
 import org.crosswire.jsword.passage.Key;
+import org.crosswire.jsword.passage.TreeKey;
 
 /**
  * Backend for General Books. These are currently not supported.
@@ -111,6 +114,60 @@
     public String getRawText(Key key) throws BookException
     {
         checkActive();
+        List path = new ArrayList();
+        Key parentKey = key;
+        do
+        {
+            path.add(parentKey.getName());
+            parentKey = parentKey.getParent();
+        }
+        while (parentKey != null && parentKey.getName().length() > 0);
+
+        try
+        {
+            TreeNode node = index.getRoot();
+
+            node = index.getFirstChild(node);
+
+            for (int i = path.size() - 1; i >= 0; i--)
+            {
+                String name = (String) path.get(i);
+                
+//                System.err.println("--" + name + "--"); //$NON-NLS-1$ //$NON-NLS-2$
+                while (!name.equals(node.getName()))
+                {
+//                    System.err.println("compare to " + node.getName()); //$NON-NLS-1$
+                    if (node.hasNextSibling())
+                    {
+                        node = index.getNextSibling(node);
+                    }
+                    else
+                    {
+                        log.error("Could not find " + name); //$NON-NLS-1$
+                        break;
+                    }
+                }
+//                System.err.println("compare to " + node.getName()); //$NON-NLS-1$
+
+                if (name.equals(node.getName()))
+                {
+                    if (i > 0)
+                    {
+                        node = index.getFirstChild(node);
+                    }
+                }
+            }
+
+            if (node.getName().equals(key.getName()))
+            {
+                return "Content of " + key.getName(); //$NON-NLS-1$
+            }
+        }
+        catch (IOException e)
+        {
+            log.error("Could not get GenBook text", e); //$NON-NLS-1$
+        }
+        
         return ""; //$NON-NLS-1$
     }
 

Modified: trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java
===================================================================
--- trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java	2007-03-21 20:43:23 UTC (rev 1257)
+++ trunk/jsword/src/main/java/org/crosswire/jsword/passage/TreeKey.java	2007-03-21 22:18:40 UTC (rev 1258)
@@ -31,14 +31,14 @@
  * 
  * @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]
+ * @author DM Smith [dmsmith555 at yahoo dot com]
  */
-class TreeKey extends AbstractKeyList
+public class TreeKey extends AbstractKeyList
 {
     /**
      * Setup with the key name and positions of data in the file
      */
-    TreeKey(String name, Key parent)
+    public TreeKey(String name, Key parent)
     {
         super(name);
         this.parent = parent;
@@ -48,7 +48,7 @@
     /**
      * Setup with the key name. Use solely for searching.
      */
-    TreeKey(String text)
+    public TreeKey(String text)
     {
         this(text, null);
     }
@@ -190,8 +190,14 @@
         return super.clone();
     }
 
+    /**
+     * The parent of this key.
+     */
     private Key parent;
 
+    /**
+     * The immediate children of this tree node.
+     */
     private List children;
 
     /**




More information about the jsword-svn mailing list