1   /**
2    * Distribution License:
3    * BibleDesktop 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   * Copyright: 2005
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: KeyTreeCellRenderer.java 2050 2010-12-09 15:31:45Z dmsmith $
21   */
22  package org.crosswire.bibledesktop.passage;
23  
24  import java.awt.Component;
25  
26  import javax.swing.JTree;
27  import javax.swing.tree.DefaultTreeCellRenderer;
28  
29  import org.crosswire.common.util.Logger;
30  import org.crosswire.jsword.passage.Key;
31  
32  /**
33   * A specialization of DefaultTreeCellRenderer that knows how to get names from
34   * Keys.
35   * 
36   * @see gnu.gpl.License for license details.<br>
37   *      The copyright to this program is held by it's authors.
38   * @author Joe Walker [joe at eireneh dot com]
39   */
40  public class KeyTreeCellRenderer extends DefaultTreeCellRenderer {
41      /* (non-Javadoc)
42       * @see javax.swing.tree.TreeCellRenderer#getTreeCellRendererComponent(javax.swing.JTree, java.lang.Object, boolean, boolean, boolean, int, boolean)
43       */
44      @Override
45      public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isselected, boolean expanded, boolean leaf, int row, boolean focus) {
46          super.getTreeCellRendererComponent(tree, value, isselected, expanded, leaf, row, focus);
47  
48          if (value instanceof KeyTreeNode) {
49              KeyTreeNode keytn = (KeyTreeNode) value;
50              Key key = keytn.getKey();
51              if (key != null) {
52                  setText(key.getName());
53              }
54          } else { // if (value != null)
55              log.warn("value is not a key: " + value.getClass().getName());
56          }
57  
58          return this;
59      }
60  
61      /**
62       * The log stream
63       */
64      private static final Logger log = Logger.getLogger(KeyTreeCellRenderer.class);
65  
66      /**
67       * Serialization ID
68       */
69      private static final long serialVersionUID = 3545232531516765241L;
70  }
71