1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.fts.core; |
22 |
|
|
23 |
|
import java.awt.Component; |
24 |
|
import java.text.DecimalFormat; |
25 |
|
|
26 |
|
import javax.swing.JLabel; |
27 |
|
import javax.swing.JTable; |
28 |
|
import javax.swing.table.DefaultTableCellRenderer; |
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 8 |
Complexity Density: 0.67 |
|
33 |
|
public class DecimalFormatTableCellRenderer extends DefaultTableCellRenderer |
34 |
|
{ |
35 |
|
private DecimalFormat formatter; |
36 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
37 |
0 |
public DecimalFormatTableCellRenderer(boolean isFormated,... |
38 |
|
int significantFigures) |
39 |
|
{ |
40 |
0 |
String integerFormater = isFormated ? "###,##0" : "0"; |
41 |
0 |
String fractionFormater = isFormated ? "###,##0." : "0."; |
42 |
0 |
if (significantFigures > 0) |
43 |
|
{ |
44 |
0 |
StringBuilder significantFigureBuilder = new StringBuilder(); |
45 |
0 |
for (int x = 1; x <= significantFigures; ++x) |
46 |
|
{ |
47 |
0 |
significantFigureBuilder.append("0"); |
48 |
|
} |
49 |
0 |
formatter = new DecimalFormat( |
50 |
|
fractionFormater + significantFigureBuilder.toString()); |
51 |
|
} |
52 |
|
else |
53 |
|
{ |
54 |
0 |
formatter = new DecimalFormat(integerFormater); |
55 |
|
} |
56 |
0 |
super.setHorizontalAlignment(JLabel.RIGHT); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
59 |
0 |
public DecimalFormatTableCellRenderer()... |
60 |
|
{ |
61 |
0 |
super.setHorizontalAlignment(JLabel.RIGHT); |
62 |
|
} |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
68 |
0 |
@Override... |
69 |
|
public Component getTableCellRendererComponent(JTable table, Object value, |
70 |
|
boolean isSelected, boolean hasFocus, int row, int column) |
71 |
|
{ |
72 |
0 |
value = value == null ? "" : formatter.format(value); |
73 |
|
|
74 |
0 |
return super.getTableCellRendererComponent(table, value, isSelected, |
75 |
|
hasFocus, row, column); |
76 |
|
} |
77 |
|
} |