1   /**
2    * Distribution Licence:
3    * JSword is free software; you can redistribute it and/or modify it under
4    * the terms of the GNU General Public License, version 2 as published by
5    * the Free Software Foundation. This program is distributed in the hope
6    * that it will be useful, but WITHOUT ANY WARRANTY; without even the
7    * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8    * See the GNU General Public License for more details.
9    * 
10   * The License is available on the internet at:
11   *      http://www.gnu.org/copyleft/gpl.html
12   * or by writing to:
13   *      Free Software Foundation, Inc.
14   *      59 Temple Place - Suite 330
15   *      Boston, MA 02111-1307, USA
16   * 
17   * The copyright to this program is held by it's authors.
18   */
19  
20  package org.crosswire.bibledesktop.book.install;
21  
22  import java.awt.Component;
23  
24  import javax.swing.JTree;
25  import javax.swing.tree.DefaultTreeCellRenderer;
26  
27  import org.crosswire.bibledesktop.BDMsg;
28  import org.crosswire.jsword.book.Book;
29  import org.crosswire.jsword.book.BookCategory;
30  
31  /**
32   * Provides appropriate icons for books.
33   * 
34   * @see gnu.gpl.License for license details.<br>
35   *      The copyright to this program is held by it's authors.
36   * @author DM Smith [dmsmith555 at yahoo dot com]
37   */
38  public class BookTreeCellRenderer extends DefaultTreeCellRenderer {
39  
40      /* (non-Javadoc)
41       * @see javax.swing.tree.DefaultTreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
42       */
43      @Override
44      public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean focus) {
45          String tooltip = null;
46          if (leaf && value instanceof BookNode) {
47              Object obj = ((BookNode) value).getUserObject();
48              if (obj instanceof Book) {
49                  Book book = (Book) obj;
50                  setLeafIcon(BookIcon.getIcon(book));
51  
52                  if (book.isQuestionable()) {
53                      tooltip = BookCategory.QUESTIONABLE.toString();
54                  }
55  
56                  if (!book.isSupported()) {
57                      // TRANSLATOR: The book is not supported by JSword
58                      tooltip = BDMsg.gettext("Unsupported");
59                  } else if (book.isLocked()) {
60                      // TRANSLATOR: The book is enciphered and needs to be unlocked
61                      tooltip = BDMsg.gettext("Locked");
62                  }
63              }
64          }
65  
66          setToolTipText(tooltip);
67          return super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
68      }
69  
70      /**
71       * Serialization ID
72       */
73      private static final long serialVersionUID = -942626483282049048L;
74  
75  }
76