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
23 DecimalFormat m_scientificNotation = new DecimalFormat( "0.##E0" );
24 DecimalFormat m_regular = new DecimalFormat();
25
26 public JMatrixCellRenderer( JMatrixDisplay matrixDisplay ) {
27
28 m_matrixDisplay = matrixDisplay;
29 setOpaque( true );
30
31
32 m_regular.setMaximumFractionDigits( 3 );
33 }
34
35
36
37 public Component getTableCellRendererComponent( JTable table,
38 Object tableCellValue, boolean isSelected, boolean hasFocus,
39 int displayedRow, int displayedColumn ) {
40
41
42
43 if ( isSelected ) {
44
45 }
46
47 if ( hasFocus ) {
48
49 }
50
51 Point coords = ( Point ) tableCellValue;
52 int row = coords.x;
53 int column = coords.y;
54
55
56 Color matrixColor;
57 try {
58 matrixColor = m_matrixDisplay.getColor( row, column );
59 } catch ( ArrayIndexOutOfBoundsException e ) {
60 matrixColor = m_matrixDisplay.getMissingColor();
61 }
62 setBackground( matrixColor );
63
64
65 double matrixValue;
66 boolean isStandardized = m_matrixDisplay.getStandardizedEnabled();
67 m_matrixDisplay.setStandardizedEnabled( false );
68 {
69 try {
70 matrixValue = m_matrixDisplay.getValue( row, column );
71 } catch ( ArrayIndexOutOfBoundsException e ) {
72 matrixValue = Double.NaN;
73 }
74 }
75 m_matrixDisplay.setStandardizedEnabled( isStandardized );
76
77
78
79
80
81 String value;
82 if ( Math.abs( matrixValue ) < 0.01 || Math.abs( matrixValue ) > 100000 ) {
83 value = m_scientificNotation.format( matrixValue );
84 } else {
85 value = m_regular.format( matrixValue );
86 }
87 setToolTipText( value );
88
89
90 return this;
91 }
92
93
94 public void validate() {
95 }
96
97 public void revalidate() {
98 }
99
100 protected void firePropertyChange( String propertyName, Object oldValue,
101 Object newValue ) {
102 }
103
104 public void firePropertyChange( String propertyName, boolean oldValue,
105 boolean newValue ) {
106 }
107
108 }