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: 2007
18   *     The copyright to this program is held by it's authors.
19   *
20   * ID: $Id: BibleNameCellRenderer.java 1471 2007-07-03 21:01:02Z dmsmith $
21   */
22  package org.crosswire.common.swing;
23  
24  import java.awt.Component;
25  import java.util.Map;
26  import java.util.Map.Entry;
27  
28  import javax.swing.DefaultListCellRenderer;
29  import javax.swing.JList;
30  
31  /**
32   * Render a Map Entry as it's value.
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 MapEntryRenderer extends DefaultListCellRenderer {
39      /*
40       * (non-Javadoc)
41       * 
42       * @see
43       * javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax
44       * .swing.JList, java.lang.Object, int, boolean, boolean)
45       */
46      @Override
47      public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focus) {
48          Object displayObject = value;
49          if (value instanceof Map.Entry<?, ?>) {
50              Map.Entry<?, ?> mapEntry = (Entry<?, ?>) value;
51              displayObject = mapEntry.getValue();
52          }
53  
54          Component comp = super.getListCellRendererComponent(list, displayObject, index, selected, focus);
55          GuiUtil.applyDefaultOrientation(comp);
56          return comp;
57      }
58  
59      /**
60       * Serialization ID
61       */
62      private static final long serialVersionUID = 3978138859576308017L;
63  }
64