1 /*
2 * Copyright (C) 2000 Bill Bereza
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Bill Bereza
19 * email : bereza@pobox.com
20 * url : http://www.pobox.com/~bereza/
21 */
22 package net.bereza.gui;
23
24 import java.text.Format;
25
26 import javax.swing.JTable;
27 import javax.swing.table.AbstractTableModel;
28 import javax.swing.DefaultCellEditor;
29 import javax.swing.table.TableCellRenderer;
30 import javax.swing.table.DefaultTableCellRenderer;
31 import javax.swing.BorderFactory;
32 import javax.swing.border.Border;
33 import javax.swing.JLabel;
34
35 /**
36 * FormatRenderer is a TableCellRender which displays numbers in
37 * format format.
38 *
39 * @author $Author: bereza $
40 * @version $Revision: 1.4 $
41 * <p>
42 * $Log: FormatRenderer.java,v $
43 * Revision 1.4 2000/03/30 01:57:21 bereza
44 * Added copyright header
45 *
46 * Revision 1.3 2000/03/29 02:10:27 bereza
47 * *** empty log message ***
48 *
49 * Revision 1.2 2000/03/12 15:54:16 bereza
50 * checking if value is null
51 *
52 * Revision 1.1 2000/03/12 15:12:10 bereza
53 * Initial revision
54 *
55 * <p>
56 * $Id: FormatRenderer.java,v 1.4 2000/03/30 01:57:21 bereza Exp $
57 */
58 public class FormatRenderer extends DefaultTableCellRenderer
59 {
60 /** Formatter */
61 protected Format form;
62
63 public FormatRenderer(Format f)
64 {
65 super();
66 form=f;
67 }
68
69 public java.awt.Component getTableCellRendererComponent(
70 JTable table, Object value,
71 boolean isSelected, boolean hasFocus,
72 int row, int column)
73 {
74 DefaultTableCellRenderer me=(DefaultTableCellRenderer)super.
75 getTableCellRendererComponent(table, value, isSelected, hasFocus,
76 row, column);
77
78
79 if(value != null)
80 {
81 me.setText(form.format(value));
82 }
83 else
84 {
85 me.setText("");
86 }
87
88 return me;
89 }
90 }
91