Revision 47436 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 | ||
---|---|---|
6 | 6 |
import java.text.NumberFormat; |
7 | 7 |
import java.text.SimpleDateFormat; |
8 | 8 |
import java.util.Date; |
9 |
import javax.swing.JLabel; |
|
9 | 10 |
import javax.swing.JTable; |
10 | 11 |
import javax.swing.SwingConstants; |
11 | 12 |
import org.apache.commons.lang3.StringUtils; |
... | ... | |
13 | 14 |
@SuppressWarnings("UseSpecificCatch") |
14 | 15 |
public class FormattedCellRenderer extends FeatureAttributeCellRenderer { |
15 | 16 |
|
16 |
private final DecimalFormat decimalFormat;
|
|
17 |
private final SimpleDateFormat dateFormat;
|
|
17 |
private DecimalFormat decimalFormat; |
|
18 |
private SimpleDateFormat dateFormat; |
|
18 | 19 |
|
19 |
public FormattedCellRenderer(ConfigurableFeatureTableModel tableModel) { |
|
20 |
super(tableModel); |
|
21 |
this.decimalFormat = (DecimalFormat) NumberFormat.getInstance(this.tableModel.getLocaleOfData()); |
|
22 |
this.dateFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM, this.tableModel.getLocaleOfData()); |
|
20 |
public FormattedCellRenderer() { |
|
23 | 21 |
} |
24 | 22 |
|
25 | 23 |
@Override |
26 | 24 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { |
27 |
super.getTableCellRendererComponent(table,value, isSelected, hasFocus,row, column); |
|
25 |
JLabel c = (JLabel) super.getTableCellRendererComponent(table,value, isSelected, hasFocus,row, column);
|
|
28 | 26 |
try { |
27 |
ConfigurableFeatureTableModel tableModel = this.getTableModel(table); |
|
28 |
if(this.decimalFormat == null){ |
|
29 |
this.decimalFormat = (DecimalFormat) NumberFormat.getInstance(tableModel.getLocaleOfData()); |
|
30 |
this.dateFormat = (SimpleDateFormat) DateFormat.getDateInstance(DateFormat.MEDIUM, tableModel.getLocaleOfData()); |
|
31 |
} |
|
29 | 32 |
if ( value instanceof Number ) { |
30 |
String pattern = this.tableModel.getFormattingPattern(column);
|
|
33 |
String pattern = this.getTableModel(table).getFormattingPattern(column);
|
|
31 | 34 |
if ( !StringUtils.isBlank(pattern) ) { |
32 | 35 |
this.decimalFormat.applyPattern(pattern); |
33 | 36 |
String formated = this.decimalFormat.format(value); |
34 |
this.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
35 |
this.setText(formated);
|
|
37 |
c.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
38 |
c.setText(formated);
|
|
36 | 39 |
return this; |
37 | 40 |
} |
38 | 41 |
} |
39 | 42 |
if ( value instanceof Date ) { |
40 |
String pattern = this.tableModel.getFormattingPattern(column);
|
|
43 |
String pattern = this.getTableModel(table).getFormattingPattern(column);
|
|
41 | 44 |
if ( !StringUtils.isBlank(pattern) ) { |
42 | 45 |
this.dateFormat.applyPattern(pattern); |
43 | 46 |
String formated = this.dateFormat.format(value); |
44 |
this.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
45 |
this.setText(formated);
|
|
47 |
c.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
48 |
c.setText(formated);
|
|
46 | 49 |
return this; |
47 | 50 |
} |
48 | 51 |
} |
49 | 52 |
} catch (Exception ex) { |
50 | 53 |
// Do nothing, use values from default renderer |
51 | 54 |
} |
52 |
return this;
|
|
55 |
return c;
|
|
53 | 56 |
} |
54 | 57 |
|
55 | 58 |
} |
Also available in: Unified diff