Clover coverage report - baseCode - 0.2.5 Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT FRAMES NO FRAMES |
file stats: | LOC: | 109 |  | Methods: | 6
| NCLOC: | 66 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
JMatrixCellRenderer.java | 0% | 0% | 0% | 0% |

1 |  |
     package baseCode.gui.table;
2 |  |
3 |  |
     import java.awt.Color;
4 |  |
     import java.awt.Component;
5 |  |
     import java.awt.Point;
6 |  |
     import java.text.DecimalFormat;
7 |  |
8 |  |
     import javax.swing.JLabel;
9 |  |
     import javax.swing.JTable;
10 |  |
     import javax.swing.table.TableCellRenderer;
11 |  |
12 |  |
     import baseCode.gui.JMatrixDisplay;
13 |  |
14 |  |
     /**
15 |  |
      * @author Will Braynen
16 |  |
      * @version $Id: JMatrixCellRenderer.java,v 1.3 2004/07/27 03:18:58 pavlidis Exp $
17 |  |
      */
18 |  |
     public class JMatrixCellRenderer extends JLabel implements TableCellRenderer {
19 |  |
20 |  |
        JMatrixDisplay m_matrixDisplay;
21 |  |
22 |  |
        // to format tooltips
23 |  |
        DecimalFormat m_scientificNotation = new DecimalFormat( "0.##E0" );
24 |  |
        DecimalFormat m_regular = new DecimalFormat();
25 |  |
26 | 0 |
        public JMatrixCellRenderer( JMatrixDisplay matrixDisplay ) {
27 |  |
28 | 0 |
           m_matrixDisplay = matrixDisplay;
29 | 0 |
           setOpaque( true );
30 |  |
31 |  |
           // for tooltips
32 | 0 |
           m_regular.setMaximumFractionDigits( 3 );
33 |  |
        }
34 |  |
35 |  |
        // This method is called each time a cell in a column
36 |  |
        // using this renderer needs to be rendered.
37 | 0 |
        public Component getTableCellRendererComponent( JTable table,
38 |  |
              Object tableCellValue, boolean isSelected, boolean hasFocus,
39 |  |
              int displayedRow, int displayedColumn ) {
40 |  |
           // 'value' is value contained in the cell located at
41 |  |
           // (rowIndex, vColIndex)
42 |  |
43 | 0 |
           if ( isSelected ) {
44 |  |
              // cell (and perhaps other cells) are selected
45 |  |
           }
46 |  |
47 | 0 |
           if ( hasFocus ) {
48 |  |
              // this cell is the anchor and the table has the focus
49 |  |
           }
50 |  |
51 | 0 |
           Point coords = ( Point ) tableCellValue;
52 | 0 |
           int row = coords.x;
53 | 0 |
           int column = coords.y;
54 |  |
55 |  |
           // Set the color
56 | 0 |
           Color matrixColor;
57 | 0 |
           try {
58 | 0 |
              matrixColor = m_matrixDisplay.getColor( row, column );
59 |  |
           } catch ( ArrayIndexOutOfBoundsException e ) {
60 | 0 |
              matrixColor = m_matrixDisplay.getMissingColor();
61 |  |
           }
62 | 0 |
           setBackground( matrixColor );
63 |  |
64 |  |
           // The tooltip should always show the actual (non-normalized) value
65 | 0 |
           double matrixValue;
66 | 0 |
           boolean isStandardized = m_matrixDisplay.getStandardizedEnabled();
67 | 0 |
           m_matrixDisplay.setStandardizedEnabled( false );
68 |  |
           {
69 | 0 |
              try {
70 | 0 |
                 matrixValue = m_matrixDisplay.getValue( row, column );
71 |  |
              } catch ( ArrayIndexOutOfBoundsException e ) {
72 | 0 |
                 matrixValue = Double.NaN;
73 |  |
              }
74 |  |
           }
75 | 0 |
           m_matrixDisplay.setStandardizedEnabled( isStandardized ); // return to
76 |  |
           // previous
77 |  |
           // state
78 |  |
79 |  |
           // Only very small and very large numbers should be displayed in
80 |  |
           // scientific notation
81 | 0 |
           String value;
82 | 0 |
           if ( Math.abs( matrixValue ) < 0.01 || Math.abs( matrixValue ) > 100000 ) {
83 | 0 |
              value = m_scientificNotation.format( matrixValue );
84 |  |
           } else {
85 | 0 |
              value = m_regular.format( matrixValue );
86 |  |
           }
87 | 0 |
           setToolTipText( value );
88 |  |
89 |  |
           // Since the renderer is a component, return itself
90 | 0 |
           return this;
91 |  |
        }
92 |  |
93 |  |
        // The following methods override the defaults for performance reasons
94 | 0 |
        public void validate() {
95 |  |
        }
96 |  |
97 | 0 |
        public void revalidate() {
98 |  |
        }
99 |  |
100 | 0 |
        protected void firePropertyChange( String propertyName, Object oldValue,
101 |  |
              Object newValue ) {
102 |  |
        }
103 |  |
104 | 0 |
        public void firePropertyChange( String propertyName, boolean oldValue,
105 |  |
              boolean newValue ) {
106 |  |
        }
107 |  |
108 |  |
     } // end class MatrixDisplayCellRenderer
109 |  |