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

jswordcvs at crosswire.org jswordcvs at crosswire.org
Mon Jan 24 17:02:28 MST 2005


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

Modified Files:
	SitePane.java 
Added Files:
	BookNode.java 
Log Message:
Added language to the book installer tree.

--- NEW FILE: BookNode.java ---
package org.crosswire.bibledesktop.book;

import java.util.Iterator;
import java.util.Set;

import javax.swing.tree.DefaultMutableTreeNode;

import org.crosswire.jsword.book.BookMetaDataSet;

/**
 * A Node for a book in a tree. It may be a property of a BookMetaData
 * or the BookMetaData itself.
 * 
 * <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 DM Smith [dmsmith555 at yahoo dot com]
 * @version $Id: BookNode.java,v 1.1 2005/01/25 00:02:26 dmsmith Exp $
 */
public class BookNode extends DefaultMutableTreeNode
{

    public BookNode(Object node, BookMetaDataSet books, Object [] grouping, int level)
    {
        setUserObject(node);
        if (level < grouping.length)
        {
            String key = (String) grouping[level];
            Set group = books.getGroup(key);
            Iterator iter = group.iterator();
            while (iter.hasNext())
            {
                String value = iter.next().toString();
                BookMetaDataSet subBooks = books.filter(key, value);
                add(new BookNode(value, subBooks, grouping, level + 1));
            }
        }
        else if (books != null)
        {
            Iterator iter = books.iterator();
            while (iter.hasNext())
            {
                add(new BookNode(iter.next(), null, grouping, level + 1));
            }
        }
    }

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

Index: SitePane.java
===================================================================
RCS file: /cvs/jsword/bibledesktop/java/main/org/crosswire/bibledesktop/book/SitePane.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** SitePane.java	28 Nov 2004 21:36:04 -0000	1.14
--- SitePane.java	25 Jan 2005 00:02:26 -0000	1.15
***************
*** 15,18 ****
--- 15,22 ----
  import javax.swing.event.TreeSelectionEvent;
  import javax.swing.event.TreeSelectionListener;
+ import javax.swing.tree.DefaultMutableTreeNode;
+ import javax.swing.tree.DefaultTreeModel;
+ import javax.swing.tree.TreeModel;
+ import javax.swing.tree.TreeNode;
  import javax.swing.tree.TreePath;
  import javax.swing.tree.TreeSelectionModel;
***************
*** 26,30 ****
--- 30,37 ----
  import org.crosswire.jsword.book.BookList;
  import org.crosswire.jsword.book.BookMetaData;
+ import org.crosswire.jsword.book.BookMetaDataSet;
  import org.crosswire.jsword.book.Books;
+ import org.crosswire.jsword.book.BooksEvent;
+ import org.crosswire.jsword.book.BooksListener;
  import org.crosswire.jsword.book.install.InstallException;
  import org.crosswire.jsword.book.install.Installer;
***************
*** 87,90 ****
--- 94,98 ----
          {
              bl = Books.installed();
+             bl.addBooksListener(new CustomBooksListener());
          }
  
***************
*** 114,121 ****
      private void updateDescription()
      {
          if (installer == null)
          {
              int bookCount = Books.installed().getBookMetaDatas().size();
!             lblDesc.setText(Msg.INSTALLED_DESC.toString(new Object[] { new Integer(bookCount) }));
          }
          else
--- 122,131 ----
      private void updateDescription()
      {
+         String desc = "#ERROR#"; //$NON-NLS-1$
+ 
          if (installer == null)
          {
              int bookCount = Books.installed().getBookMetaDatas().size();
!             desc = Msg.INSTALLED_DESC.toString(new Object[] { new Integer(bookCount) });
          }
          else
***************
*** 124,134 ****
              if (bookCount == 0)
              {
!                 lblDesc.setText(Msg.NONE_AVAILABLE_DESC.toString());
              }
              else
              {
!                 lblDesc.setText(Msg.AVAILABLE_DESC.toString(new Object[] { new Integer(bookCount) }));
              }
          }
      }
  
--- 134,146 ----
              if (bookCount == 0)
              {
!                 desc = Msg.NONE_AVAILABLE_DESC.toString();
              }
              else
              {
!                 desc = Msg.AVAILABLE_DESC.toString(new Object[] { new Integer(bookCount) });
              }
          }
+ 
+         lblDesc.setText(desc);
      }
  
***************
*** 193,197 ****
      {
          treAvailable = new JTree();
!         treAvailable.setModel(new BooksTreeModel(books));
          treAvailable.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
          treAvailable.setCellEditor(null);
--- 205,211 ----
      {
          treAvailable = new JTree();
!         setTreeModel(books);
!         // Add lines if viewed in Java Look & Feel
!         treAvailable.putClientProperty("JTree.lineStyle", "Angled"); //$NON-NLS-1$ //$NON-NLS-2$
          treAvailable.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
          treAvailable.setCellEditor(null);
***************
*** 212,215 ****
--- 226,253 ----
      }
  
+     private TreeModel createTreeModel(BookList books)
+     {
+         // return new BooksTreeModel(books);
+         BookMetaDataSet bmds = new BookMetaDataSet(books.getBookMetaDatas());
+         TreeNode bookRoot = new BookNode("root", bmds, new Object[] { BookMetaData.KEY_TYPE, BookMetaData.KEY_LANGUAGE }, 0); //$NON-NLS-1$
+         return new DefaultTreeModel(bookRoot);  
+     }
+ 
+     // provide for backward compatibility
+     private BookMetaData getBookMetaData(Object obj)
+     {
+         // new way
+         if (obj instanceof DefaultMutableTreeNode)
+         {
+             obj = ((DefaultMutableTreeNode)obj).getUserObject();
+         }
+         // Old way
+         if (obj instanceof BookMetaData)
+         {
+             return (BookMetaData) obj;
+         }
+         return null;
+     }
+ 
      /**
       *
***************
*** 248,253 ****
              {
                  installer.reloadBookList();
! 
!                 treAvailable.setModel(new BooksTreeModel(installer));
              }
              catch (InstallException ex)
--- 286,290 ----
              {
                  installer.reloadBookList();
!                 setTreeModel(installer);
              }
              catch (InstallException ex)
***************
*** 269,273 ****
              {
                  Object last = path.getLastPathComponent();
!                 BookMetaData name = (BookMetaData) last;
  
                  try
--- 306,310 ----
              {
                  Object last = path.getLastPathComponent();
!                 BookMetaData name = getBookMetaData(last);
  
                  try
***************
*** 309,313 ****
              try
              {
!                 BookMetaData bmd = (BookMetaData) path.getLastPathComponent();
                  IndexDownloader.downloadIndex(bmd, installer);
              }
--- 346,351 ----
              try
              {
!                 Object last = path.getLastPathComponent();
!                 BookMetaData bmd = getBookMetaData(last);
                  IndexDownloader.downloadIndex(bmd, installer);
              }
***************
*** 331,338 ****
          {
              Object last = path.getLastPathComponent();
! 
!             if (last instanceof BookMetaData)
              {
!                 mtm = new BookMetaDataTableModel((BookMetaData) last);
                  bookSelected = true;
              }
--- 369,376 ----
          {
              Object last = path.getLastPathComponent();
!             BookMetaData bmd = getBookMetaData(last);
!             if (bmd != null)
              {
!                 mtm = new BookMetaDataTableModel(bmd);
                  bookSelected = true;
              }
***************
*** 345,348 ****
--- 383,414 ----
      }
  
+     public void setTreeModel(BookList books)
+     {
+         treAvailable.setModel(createTreeModel(books));
+     }
+     
+     /**
+      * When new books are added we need to relfect the change in this tree.
+      */
+     private final class CustomBooksListener implements BooksListener
+     {
+         /* (non-Javadoc)
+          * @see org.crosswire.jsword.book.BooksListener#bookAdded(org.crosswire.jsword.book.BooksEvent)
+          */
+         public void bookAdded(BooksEvent ev)
+         {
+             setTreeModel((BookList) ev.getSource());
+         }
+ 
+         /* (non-Javadoc)
+          * @see org.crosswire.jsword.book.BooksListener#bookRemoved(org.crosswire.jsword.book.BooksEvent)
+          */
+         public void bookRemoved(BooksEvent ev)
+         {
+             setTreeModel((BookList) ev.getSource());
+         }
+     }
+ 
+ 
      private static final String INSTALLED_BOOKS_LABEL = "InstalledBooksLabel"; //$NON-NLS-1$
      private static final String AVAILABLE_BOOKS_LABEL = "AvailableBooksLabel"; //$NON-NLS-1$
***************
*** 372,377 ****
  
      /**
!      * SERIALUID(dms): A placeholder for the ultimate version id.
       */
!     private static final long serialVersionUID = 1L;
  }
\ No newline at end of file
--- 438,443 ----
  
      /**
!      * Serialization ID
       */
!     private static final long serialVersionUID = 3616445692051075634L;
  }
\ No newline at end of file



More information about the jsword-svn mailing list