156 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.core.common.ui;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.ui.table.TableCellRendererUtils;
|
|
|
17 |
|
|
|
18 |
import java.awt.Component;
|
|
|
19 |
import java.text.DecimalFormat;
|
|
|
20 |
|
|
|
21 |
import javax.swing.JLabel;
|
|
|
22 |
import javax.swing.JTable;
|
|
|
23 |
import javax.swing.SwingConstants;
|
|
|
24 |
import javax.swing.table.DefaultTableCellRenderer;
|
|
|
25 |
|
|
|
26 |
public class NumberCellRenderer extends DefaultTableCellRenderer {
|
|
|
27 |
DecimalFormat decimalFormat = new DecimalFormat("##,##0.00");
|
|
|
28 |
private final String suffix;
|
|
|
29 |
|
|
|
30 |
public NumberCellRenderer() {
|
|
|
31 |
this("");
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public NumberCellRenderer(String suffix) {
|
|
|
35 |
super();
|
|
|
36 |
this.suffix = suffix;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
@Override
|
|
|
40 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
|
|
|
41 |
final Component res = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
|
|
|
42 |
TableCellRendererUtils.setColors(res, table, isSelected);
|
|
|
43 |
((JLabel) res).setHorizontalAlignment(SwingConstants.RIGHT);
|
|
|
44 |
if (value == null) {
|
|
|
45 |
((JLabel) res).setText("");
|
|
|
46 |
} else {
|
|
|
47 |
((JLabel) res).setText(decimalFormat.format(((Number) value).doubleValue()) + this.suffix);
|
|
|
48 |
}
|
|
|
49 |
return res;
|
|
|
50 |
}
|
|
|
51 |
}
|