| NumberCellRenderer.java |
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
26 import javax.swing.DefaultListCellRenderer;
27 import javax.swing.JList;
28
29 import org.crosswire.common.icu.NumberShaper;
30
31 /**
32 * Render a list of numbers
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 NumberCellRenderer extends DefaultListCellRenderer {
39 /**
40 * Constructs a default renderer for a list of numbers.
41 */
42 public NumberCellRenderer() {
43 this.shaper = new NumberShaper();
44 GuiUtil.applyDefaultOrientation(this);
45 }
46
47 /*
48 * (non-Javadoc)
49 *
50 * @see
51 * javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax
52 * .swing.JList, java.lang.Object, int, boolean, boolean)
53 */
54 @Override
55 public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean focus) {
56 // Do the default rendering
57 Component comp = super.getListCellRendererComponent(list, value, index, selected, focus);
58
59 // Do our rendering
60 setToolTipText(null);
61
62 if (value == null) {
63 setText("");
64 setEnabled(false);
65 } else {
66 setText(shaper.shape(value.toString()));
67 }
68
69 GuiUtil.applyDefaultOrientation(comp);
70 return comp;
71 }
72
73 /**
74 * Used to display numbers in the user's expected representations.
75 */
76 private NumberShaper shaper;
77
78 /**
79 * Serialization ID
80 */
81 private static final long serialVersionUID = 3978138859576308017L;
82 }
83