Revision 45779 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/dal/feature/swing/table/FormattedCellRenderer.java
FormattedCellRenderer.java | ||
---|---|---|
8 | 8 |
import java.util.Date; |
9 | 9 |
import javax.swing.JTable; |
10 | 10 |
import javax.swing.SwingConstants; |
11 |
import javax.swing.table.DefaultTableCellRenderer; |
|
12 | 11 |
import org.apache.commons.lang3.StringUtils; |
13 | 12 |
|
14 |
public class FormattedCellRenderer extends DefaultTableCellRenderer { |
|
13 |
@SuppressWarnings("UseSpecificCatch") |
|
14 |
public class FormattedCellRenderer extends FeatureAttributeCellRenderer { |
|
15 | 15 |
|
16 |
private static final long serialVersionUID = -162038647556726890L; |
|
17 |
private ConfigurableFeatureTableModel tableModel; |
|
18 |
private DecimalFormat decimalFormat; |
|
19 |
private SimpleDateFormat dateFormat; |
|
16 |
private final DecimalFormat decimalFormat; |
|
17 |
private final SimpleDateFormat dateFormat; |
|
20 | 18 |
|
21 | 19 |
public FormattedCellRenderer(ConfigurableFeatureTableModel tableModel) { |
22 |
this.tableModel = tableModel;
|
|
20 |
super(tableModel);
|
|
23 | 21 |
this.decimalFormat = (DecimalFormat) NumberFormat.getInstance(this.tableModel.getLocaleOfData()); |
24 | 22 |
this.dateFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM, this.tableModel.getLocaleOfData()); |
25 | 23 |
} |
26 | 24 |
|
25 |
@Override |
|
27 | 26 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
28 | 27 |
super.getTableCellRendererComponent(table,value, isSelected, hasFocus,row, column); |
29 | 28 |
try { |
... | ... | |
31 | 30 |
String pattern = this.tableModel.getFormattingPattern(column); |
32 | 31 |
if ( !StringUtils.isBlank(pattern) ) { |
33 | 32 |
this.decimalFormat.applyPattern(pattern); |
34 |
String formated = this.decimalFormat.format(value).toString();
|
|
33 |
String formated = this.decimalFormat.format(value); |
|
35 | 34 |
this.setHorizontalAlignment(SwingConstants.RIGHT); |
36 | 35 |
this.setText(formated); |
37 | 36 |
return this; |
... | ... | |
41 | 40 |
String pattern = this.tableModel.getFormattingPattern(column); |
42 | 41 |
if ( !StringUtils.isBlank(pattern) ) { |
43 | 42 |
this.dateFormat.applyPattern(pattern); |
44 |
String formated = this.dateFormat.format(value).toString();
|
|
43 |
String formated = this.dateFormat.format(value); |
|
45 | 44 |
this.setHorizontalAlignment(SwingConstants.RIGHT); |
46 | 45 |
this.setText(formated); |
47 | 46 |
return this; |
Also available in: Unified diff