2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-20034, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: ValuesViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.6 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/03/24 15:51:05 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.cluster.gui.impl.pca; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
19 |
import java.text.DecimalFormat; |
2 |
26 Feb 07 |
jari |
20 |
|
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JTextArea; |
2 |
26 Feb 07 |
jari |
25 |
|
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.gui.impl.ViewerAdapter; |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
public class ValuesViewer extends ViewerAdapter implements java.io.Serializable { |
2 |
26 Feb 07 |
jari |
30 |
public static final long serialVersionUID = 202011050001L; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
private JComponent header; |
2 |
26 Feb 07 |
jari |
33 |
private JComponent content; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>ValuesViewer</code> with specified S-matrix. |
2 |
26 Feb 07 |
jari |
37 |
*/ |
2 |
26 Feb 07 |
jari |
38 |
public ValuesViewer(FloatMatrix S) { |
2 |
26 Feb 07 |
jari |
39 |
content = createContent(S); |
2 |
26 Feb 07 |
jari |
40 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
41 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
42 |
} |
2 |
26 Feb 07 |
jari |
43 |
public ValuesViewer(JComponent content, JComponent header){ |
2 |
26 Feb 07 |
jari |
44 |
this.content = content; |
2 |
26 Feb 07 |
jari |
45 |
this.header = header; |
2 |
26 Feb 07 |
jari |
46 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
47 |
} |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the viewer content. |
2 |
26 Feb 07 |
jari |
51 |
*/ |
2 |
26 Feb 07 |
jari |
52 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
53 |
return content; |
2 |
26 Feb 07 |
jari |
54 |
} |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the viewer header. |
2 |
26 Feb 07 |
jari |
58 |
*/ |
2 |
26 Feb 07 |
jari |
59 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
60 |
return header; |
2 |
26 Feb 07 |
jari |
61 |
} |
2 |
26 Feb 07 |
jari |
62 |
|
2 |
26 Feb 07 |
jari |
63 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer header. |
2 |
26 Feb 07 |
jari |
65 |
*/ |
2 |
26 Feb 07 |
jari |
66 |
private JComponent createHeader() { |
2 |
26 Feb 07 |
jari |
67 |
JPanel panel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
68 |
panel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
69 |
JLabel label = new JLabel("<html><body bgcolor='#FFFFFF'><font face='serif' size='5' color='#000080'><b>Eigenvalues</b></font></body></html>"); |
2 |
26 Feb 07 |
jari |
70 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
71 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
72 |
gbc.insets = new Insets(10, 0, 10, 0); |
2 |
26 Feb 07 |
jari |
73 |
panel.add(label, gbc); |
2 |
26 Feb 07 |
jari |
74 |
return panel; |
2 |
26 Feb 07 |
jari |
75 |
} |
2 |
26 Feb 07 |
jari |
76 |
|
2 |
26 Feb 07 |
jari |
77 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer content. |
2 |
26 Feb 07 |
jari |
79 |
*/ |
2 |
26 Feb 07 |
jari |
80 |
private JComponent createContent(FloatMatrix S) { |
2 |
26 Feb 07 |
jari |
81 |
JTextArea area = new JTextArea(); |
2 |
26 Feb 07 |
jari |
82 |
area.setEditable(false); |
2 |
26 Feb 07 |
jari |
83 |
area.setMargin(new Insets(0, 10, 0, 0)); |
2 |
26 Feb 07 |
jari |
84 |
DecimalFormat format = new DecimalFormat(); |
2 |
26 Feb 07 |
jari |
85 |
format.setMinimumIntegerDigits(2); |
2 |
26 Feb 07 |
jari |
86 |
format.setMaximumFractionDigits(3); |
2 |
26 Feb 07 |
jari |
87 |
format.setMinimumFractionDigits(3); |
2 |
26 Feb 07 |
jari |
88 |
format.setGroupingUsed(false); |
2 |
26 Feb 07 |
jari |
89 |
float sum = 0f; |
2 |
26 Feb 07 |
jari |
90 |
final int columns = S.getColumnDimension(); |
2 |
26 Feb 07 |
jari |
91 |
for (int i=0; i<columns; i++) { |
2 |
26 Feb 07 |
jari |
92 |
sum += S.get(i, i); |
2 |
26 Feb 07 |
jari |
93 |
} |
2 |
26 Feb 07 |
jari |
94 |
float factor = 100f/sum; |
2 |
26 Feb 07 |
jari |
95 |
for (int i=0; i<columns; i++) { |
2 |
26 Feb 07 |
jari |
96 |
area.append("Principal Component "+new Integer(i+1).toString()+"\t"+format.format(S.get(i,i))+"\t"+format.format(S.get(i,i)*factor)+" %\n"); |
2 |
26 Feb 07 |
jari |
97 |
} |
2 |
26 Feb 07 |
jari |
98 |
if (columns > 1) { |
2 |
26 Feb 07 |
jari |
99 |
area.append("\n"); |
2 |
26 Feb 07 |
jari |
100 |
area.append("First 2 components: "+format.format((S.get(0,0)+S.get(1,1))*factor)+" %\n"); |
2 |
26 Feb 07 |
jari |
101 |
if (columns > 2) { |
2 |
26 Feb 07 |
jari |
102 |
area.append("First 3 components: "+format.format((S.get(0,0)+S.get(1,1)+S.get(2,2))*factor)+" %\n"); |
2 |
26 Feb 07 |
jari |
103 |
} |
2 |
26 Feb 07 |
jari |
104 |
} |
2 |
26 Feb 07 |
jari |
105 |
return area; |
2 |
26 Feb 07 |
jari |
106 |
} |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
/** |
2 |
26 Feb 07 |
jari |
* Synchronize header and content sizes. |
2 |
26 Feb 07 |
jari |
110 |
*/ |
2 |
26 Feb 07 |
jari |
111 |
private void setMaxWidth(JComponent content, JComponent header) { |
2 |
26 Feb 07 |
jari |
112 |
int c_width = content.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
113 |
int h_width = header.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
114 |
if (c_width > h_width) { |
2 |
26 Feb 07 |
jari |
115 |
header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
116 |
} else { |
2 |
26 Feb 07 |
jari |
117 |
content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
} |
2 |
26 Feb 07 |
jari |
120 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
122 |
*/ |
2 |
26 Feb 07 |
jari |
123 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
124 |
return null; |
2 |
26 Feb 07 |
jari |
125 |
} |
2 |
26 Feb 07 |
jari |
126 |
|
2 |
26 Feb 07 |
jari |
127 |
} |