| 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 |
|
|
| |
|
| 72% |
Uncovered Elements: 7 (25) |
Complexity: 8 |
Complexity Density: 0.67 |
|
| 33 |
|
public class DecimalFormatTableCellRenderer extends DefaultTableCellRenderer |
| 34 |
|
{ |
| 35 |
|
private DecimalFormat formatter; |
| 36 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
| 37 |
5 |
public DecimalFormatTableCellRenderer(boolean isFormated,... |
| 38 |
|
int significantFigures) |
| 39 |
|
{ |
| 40 |
5 |
String integerFormater = isFormated ? "###,##0" : "0"; |
| 41 |
5 |
String fractionFormater = isFormated ? "###,##0." : "0."; |
| 42 |
5 |
if (significantFigures > 0) |
| 43 |
|
{ |
| 44 |
3 |
StringBuilder significantFigureBuilder = new StringBuilder(); |
| 45 |
10 |
for (int x = 1; x <= significantFigures; ++x) |
| 46 |
|
{ |
| 47 |
7 |
significantFigureBuilder.append("0"); |
| 48 |
|
} |
| 49 |
3 |
formatter = new DecimalFormat( |
| 50 |
|
fractionFormater + significantFigureBuilder.toString()); |
| 51 |
|
} |
| 52 |
|
else |
| 53 |
|
{ |
| 54 |
2 |
formatter = new DecimalFormat(integerFormater); |
| 55 |
|
} |
| 56 |
5 |
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 |
|
} |