Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.fts.core

File DecimalFormatTableCellRenderer.java

 

Coverage histogram

../../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

10
12
3
1
77
43
8
0.67
4
3
2.67

Classes

Class Line # Actions
DecimalFormatTableCellRenderer 33 12 8
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
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    * The class to handle the formatting of the double values for JTable cells.
32    */
 
33    public class DecimalFormatTableCellRenderer extends DefaultTableCellRenderer
34    {
35    private DecimalFormat formatter;
36   
 
37  0 toggle 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   
 
59  0 toggle public DecimalFormatTableCellRenderer()
60    {
61  0 super.setHorizontalAlignment(JLabel.RIGHT);
62    }
63   
64    /**
65    * Adapts the default method to ensure that double values are formatted for
66    * display
67    */
 
68  0 toggle @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    }