2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2004, 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: KMCSuppInfoViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.6 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/03/24 15:50:54 $ |
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.kmcs; |
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.beans.Expression; |
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.microarray.mev.cluster.gui.impl.ViewerAdapter; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
public class KMCSuppInfoViewer extends ViewerAdapter implements java.io.Serializable { |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
private JComponent header; |
2 |
26 Feb 07 |
jari |
31 |
private JTextArea content; |
2 |
26 Feb 07 |
jari |
32 |
private boolean clusterGenes; |
2 |
26 Feb 07 |
jari |
33 |
private boolean unassignedExists; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>KMCSuppInfoViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* clusters and number of genes. |
2 |
26 Feb 07 |
jari |
38 |
*/ |
2 |
26 Feb 07 |
jari |
39 |
public KMCSuppInfoViewer(int[][] clusters, int genes) { |
2 |
26 Feb 07 |
jari |
40 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
41 |
this.clusterGenes = true; |
2 |
26 Feb 07 |
jari |
42 |
content = createContent(clusters, genes); |
2 |
26 Feb 07 |
jari |
43 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
44 |
} |
2 |
26 Feb 07 |
jari |
45 |
|
2 |
26 Feb 07 |
jari |
46 |
public KMCSuppInfoViewer(JTextArea content, JComponent header, Boolean clusterGenes){ |
2 |
26 Feb 07 |
jari |
47 |
this.content = content; |
2 |
26 Feb 07 |
jari |
48 |
this.header = header; |
2 |
26 Feb 07 |
jari |
49 |
this.clusterGenes = clusterGenes.booleanValue(); |
2 |
26 Feb 07 |
jari |
50 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
51 |
} |
2 |
26 Feb 07 |
jari |
52 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
53 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
54 |
new Object[]{content, header, new Boolean(clusterGenes)}); |
2 |
26 Feb 07 |
jari |
55 |
} |
2 |
26 Feb 07 |
jari |
56 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>KMCSuppInfoViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* clusters and number of genes. |
2 |
26 Feb 07 |
jari |
59 |
*/ |
2 |
26 Feb 07 |
jari |
60 |
public KMCSuppInfoViewer(int[][] clusters, int genes, boolean unassignedExists, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
61 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
62 |
this.unassignedExists = unassignedExists; |
2 |
26 Feb 07 |
jari |
63 |
this.clusterGenes = clusterGenes; |
2 |
26 Feb 07 |
jari |
64 |
content = createContent(clusters, genes); |
2 |
26 Feb 07 |
jari |
65 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
66 |
} |
2 |
26 Feb 07 |
jari |
67 |
|
2 |
26 Feb 07 |
jari |
68 |
/** |
2 |
26 Feb 07 |
jari |
* Returns component to be inserted into the framework scroll pane. |
2 |
26 Feb 07 |
jari |
70 |
*/ |
2 |
26 Feb 07 |
jari |
71 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
72 |
return content; |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the viewer header. |
2 |
26 Feb 07 |
jari |
77 |
*/ |
2 |
26 Feb 07 |
jari |
78 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
79 |
return header; |
2 |
26 Feb 07 |
jari |
80 |
} |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer header. |
2 |
26 Feb 07 |
jari |
84 |
*/ |
2 |
26 Feb 07 |
jari |
85 |
private JComponent createHeader() { |
2 |
26 Feb 07 |
jari |
86 |
JPanel panel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
87 |
panel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
88 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
89 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
90 |
gbc.insets = new Insets(10, 0, 10, 0); |
2 |
26 Feb 07 |
jari |
91 |
panel.add(new JLabel("<html><body bgcolor='#FFFFFF'><font face='serif' size='5' color='#000080'><b>Cluster Information</b></font></body></html>"), gbc); |
2 |
26 Feb 07 |
jari |
92 |
return panel; |
2 |
26 Feb 07 |
jari |
93 |
} |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer content component. |
2 |
26 Feb 07 |
jari |
97 |
*/ |
2 |
26 Feb 07 |
jari |
98 |
private JTextArea createContent(int[][] clusters, int genes) { |
2 |
26 Feb 07 |
jari |
99 |
JTextArea area = new JTextArea(clusters.length*3, 20); |
2 |
26 Feb 07 |
jari |
100 |
area.setEditable(false); |
2 |
26 Feb 07 |
jari |
101 |
area.setMargin(new Insets(0,10,0,0)); |
2 |
26 Feb 07 |
jari |
102 |
StringBuffer sb = new StringBuffer(clusters.length*3*10); |
2 |
26 Feb 07 |
jari |
103 |
int counter; |
2 |
26 Feb 07 |
jari |
104 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
105 |
if(!unassignedExists){ |
2 |
26 Feb 07 |
jari |
106 |
for (counter = 0; counter < clusters.length; counter++) { |
2 |
26 Feb 07 |
jari |
107 |
sb.append("Cluster "+(counter+1)); |
2 |
26 Feb 07 |
jari |
108 |
sb.append("\t"); |
2 |
26 Feb 07 |
jari |
109 |
sb.append("# of Genes in Cluster: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
110 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
111 |
sb.append("% of Genes in Cluster: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
112 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
else{ |
2 |
26 Feb 07 |
jari |
116 |
for (counter = 0; counter < clusters.length-1; counter++) { |
2 |
26 Feb 07 |
jari |
117 |
sb.append("Cluster "+(counter+1)); |
2 |
26 Feb 07 |
jari |
118 |
sb.append("\t"); |
2 |
26 Feb 07 |
jari |
119 |
sb.append("# of Genes in Cluster: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
120 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
121 |
sb.append("% of Genes in Cluster: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
122 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
123 |
} |
2 |
26 Feb 07 |
jari |
124 |
sb.append("Unassigned Genes "); |
2 |
26 Feb 07 |
jari |
125 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
126 |
sb.append("# of Unassighed Genes: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
127 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
128 |
sb.append("% of Genes Unassigned: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
129 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
130 |
} |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
} |
2 |
26 Feb 07 |
jari |
133 |
else{ |
2 |
26 Feb 07 |
jari |
134 |
|
2 |
26 Feb 07 |
jari |
135 |
if(!unassignedExists){ |
2 |
26 Feb 07 |
jari |
136 |
for (counter = 0; counter < clusters.length; counter++) { |
2 |
26 Feb 07 |
jari |
137 |
sb.append("Cluster "+(counter+1)); |
2 |
26 Feb 07 |
jari |
138 |
sb.append("\t"); |
2 |
26 Feb 07 |
jari |
139 |
sb.append("# of Experiments in Cluster: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
140 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
141 |
sb.append("% of Experiments in Cluster: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
142 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
} else { |
2 |
26 Feb 07 |
jari |
145 |
for (counter = 0; counter < clusters.length-1; counter++) { |
2 |
26 Feb 07 |
jari |
146 |
sb.append("Cluster "+(counter+1)); |
2 |
26 Feb 07 |
jari |
147 |
sb.append("\t"); |
2 |
26 Feb 07 |
jari |
148 |
sb.append("# of Experiments in Cluster: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
149 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
150 |
sb.append("% of Experiments in Cluster: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
151 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
sb.append("Unassigned Experiments "); |
2 |
26 Feb 07 |
jari |
154 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
155 |
sb.append("# of Unassiged Experiments: "+clusters[counter].length); |
2 |
26 Feb 07 |
jari |
156 |
sb.append("\n\t"); |
2 |
26 Feb 07 |
jari |
157 |
sb.append("% of Experiments Unassigned: "+Math.round((float)clusters[counter].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
158 |
sb.append("\n\n"); |
2 |
26 Feb 07 |
jari |
159 |
} |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
161 |
area.setText(sb.toString()); |
2 |
26 Feb 07 |
jari |
162 |
area.setCaretPosition(0); |
2 |
26 Feb 07 |
jari |
163 |
return area; |
2 |
26 Feb 07 |
jari |
164 |
} |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
/** |
2 |
26 Feb 07 |
jari |
* Synchronize content and header sizes. |
2 |
26 Feb 07 |
jari |
168 |
*/ |
2 |
26 Feb 07 |
jari |
169 |
private void setMaxWidth(JComponent content, JComponent header) { |
2 |
26 Feb 07 |
jari |
170 |
int c_width = content.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
171 |
int h_width = header.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
172 |
if (c_width > h_width) { |
2 |
26 Feb 07 |
jari |
173 |
header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
174 |
} else { |
2 |
26 Feb 07 |
jari |
175 |
content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
176 |
} |
2 |
26 Feb 07 |
jari |
177 |
} |
2 |
26 Feb 07 |
jari |
178 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
180 |
*/ |
2 |
26 Feb 07 |
jari |
181 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
182 |
return null; |
2 |
26 Feb 07 |
jari |
183 |
} |
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
} |