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: RNElementSeedInfoViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.6 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/02 16:57:04 $ |
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.rn; |
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 |
|
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JTextArea; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
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 |
/** |
2 |
26 Feb 07 |
jari |
* A viewer for Relevance Networks seed information. |
2 |
26 Feb 07 |
jari |
30 |
* |
2 |
26 Feb 07 |
jari |
31 |
*/ |
2 |
26 Feb 07 |
jari |
32 |
public class RNElementSeedInfoViewer extends ViewerAdapter { |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
private JComponent header; |
2 |
26 Feb 07 |
jari |
35 |
private JTextArea content; |
2 |
26 Feb 07 |
jari |
36 |
private boolean clusterGenes; |
2 |
26 Feb 07 |
jari |
37 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
38 |
private int [] indices; |
2 |
26 Feb 07 |
jari |
39 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>RNElementSeedInfoViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* clusters and number of genes. |
2 |
26 Feb 07 |
jari |
42 |
*/ |
2 |
26 Feb 07 |
jari |
43 |
public RNElementSeedInfoViewer(int[][] clusters, int genes) { |
2 |
26 Feb 07 |
jari |
44 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
45 |
this.clusterGenes = true; |
2 |
26 Feb 07 |
jari |
46 |
content = createContent(clusters, genes); |
2 |
26 Feb 07 |
jari |
47 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
48 |
} |
2 |
26 Feb 07 |
jari |
49 |
public RNElementSeedInfoViewer(JTextArea content, JComponent header){ |
2 |
26 Feb 07 |
jari |
50 |
this.header = header; |
2 |
26 Feb 07 |
jari |
51 |
this.content = content; |
2 |
26 Feb 07 |
jari |
52 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
53 |
} |
2 |
26 Feb 07 |
jari |
54 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>RNElementSeedInfoViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* clusters and number of genes. |
2 |
26 Feb 07 |
jari |
57 |
*/ |
2 |
26 Feb 07 |
jari |
58 |
public RNElementSeedInfoViewer(int[][] clusters, Experiment experiment, int [] indices, int genes, boolean clusterGenes) { |
2 |
26 Feb 07 |
jari |
59 |
this.indices = indices; |
2 |
26 Feb 07 |
jari |
60 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
61 |
header = createHeader(); |
2 |
26 Feb 07 |
jari |
62 |
this.clusterGenes = clusterGenes; |
2 |
26 Feb 07 |
jari |
63 |
content = createContent(clusters, genes); |
2 |
26 Feb 07 |
jari |
64 |
setMaxWidth(content, header); |
2 |
26 Feb 07 |
jari |
65 |
} |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
/** |
2 |
26 Feb 07 |
jari |
* Returns component to be inserted into the framework scroll pane. |
2 |
26 Feb 07 |
jari |
69 |
*/ |
2 |
26 Feb 07 |
jari |
70 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
71 |
return content; |
2 |
26 Feb 07 |
jari |
72 |
} |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the viewer header. |
2 |
26 Feb 07 |
jari |
76 |
*/ |
2 |
26 Feb 07 |
jari |
77 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
78 |
return header; |
2 |
26 Feb 07 |
jari |
79 |
} |
2 |
26 Feb 07 |
jari |
80 |
|
2 |
26 Feb 07 |
jari |
81 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer header. |
2 |
26 Feb 07 |
jari |
83 |
*/ |
2 |
26 Feb 07 |
jari |
84 |
private JComponent createHeader() { |
2 |
26 Feb 07 |
jari |
85 |
JPanel panel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
86 |
panel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
87 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
88 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
89 |
gbc.insets = new Insets(10, 0, 10, 0); |
2 |
26 Feb 07 |
jari |
90 |
panel.add(new JLabel("<html><body bgcolor='#FFFFFF'><font face='serif' size='5' color='#000080'><b>Element Seed Cluster Information</b></font></body></html>"), gbc); |
2 |
26 Feb 07 |
jari |
91 |
return panel; |
2 |
26 Feb 07 |
jari |
92 |
} |
2 |
26 Feb 07 |
jari |
93 |
|
2 |
26 Feb 07 |
jari |
94 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the viewer content component. |
2 |
26 Feb 07 |
jari |
96 |
*/ |
2 |
26 Feb 07 |
jari |
97 |
private JTextArea createContent(int[][] clusters, int genes) { |
2 |
26 Feb 07 |
jari |
//JTextArea area = new JTextArea(clusters.length*3*10, 20); |
2 |
26 Feb 07 |
jari |
99 |
JTextArea area = new JTextArea(); |
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*6*25); |
2 |
26 Feb 07 |
jari |
103 |
String dummy = ""; |
2 |
26 Feb 07 |
jari |
104 |
int stringLength = 0; |
2 |
26 Feb 07 |
jari |
105 |
if(clusterGenes){ |
2 |
26 Feb 07 |
jari |
106 |
for (int counter = 0; counter < clusters.length; counter++) { |
2 |
26 Feb 07 |
jari |
107 |
dummy = ""; |
2 |
26 Feb 07 |
jari |
108 |
if(clusters[indices[counter]].length > 1){ |
2 |
26 Feb 07 |
jari |
109 |
dummy += ("Seed Gene Index "+(experiment.getGeneIndexMappedToData(clusters[counter][0])+1)); |
2 |
26 Feb 07 |
jari |
110 |
dummy += ("\t"); |
2 |
26 Feb 07 |
jari |
111 |
dummy += ("# of Genes in Cluster: "+clusters[indices[counter]].length); |
2 |
26 Feb 07 |
jari |
112 |
dummy += ("\n\t\t"); |
2 |
26 Feb 07 |
jari |
113 |
dummy += ("% of Genes in Cluster: "+Math.round((float)clusters[indices[counter]].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
114 |
dummy += ("\n\n"); |
2 |
26 Feb 07 |
jari |
115 |
sb.append(dummy); |
2 |
26 Feb 07 |
jari |
116 |
stringLength += dummy.length(); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
} |
2 |
26 Feb 07 |
jari |
120 |
else{ |
2 |
26 Feb 07 |
jari |
121 |
for (int counter = 0; counter < clusters.length; counter++) { |
2 |
26 Feb 07 |
jari |
122 |
dummy = ""; |
2 |
26 Feb 07 |
jari |
123 |
if(clusters[indices[counter]].length > 1){ |
2 |
26 Feb 07 |
jari |
124 |
dummy += ("Seed Experiment Index "+(clusters[counter][0]+1)); |
2 |
26 Feb 07 |
jari |
125 |
dummy += ("\t"); |
2 |
26 Feb 07 |
jari |
126 |
dummy += ("# of Experiments in Cluster: "+clusters[indices[counter]].length); |
2 |
26 Feb 07 |
jari |
127 |
dummy += ("\n\t\t"); |
2 |
26 Feb 07 |
jari |
128 |
dummy += ("% of Experiments in Cluster: "+Math.round((float)clusters[indices[counter]].length/(float)genes*100f)+"%"); |
2 |
26 Feb 07 |
jari |
129 |
dummy += ("\n\n"); |
2 |
26 Feb 07 |
jari |
130 |
sb.append(dummy); |
2 |
26 Feb 07 |
jari |
131 |
stringLength += dummy.length(); |
2 |
26 Feb 07 |
jari |
132 |
} |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
} |
2 |
26 Feb 07 |
jari |
135 |
|
2 |
26 Feb 07 |
jari |
136 |
String str = sb.substring(0, stringLength); |
2 |
26 Feb 07 |
jari |
137 |
area.setText(str); |
2 |
26 Feb 07 |
jari |
138 |
area.setCaretPosition(0); |
2 |
26 Feb 07 |
jari |
139 |
return area; |
2 |
26 Feb 07 |
jari |
140 |
} |
2 |
26 Feb 07 |
jari |
141 |
|
2 |
26 Feb 07 |
jari |
142 |
/** |
2 |
26 Feb 07 |
jari |
* Synchronize content and header sizes. |
2 |
26 Feb 07 |
jari |
144 |
*/ |
2 |
26 Feb 07 |
jari |
145 |
private void setMaxWidth(JComponent content, JComponent header) { |
2 |
26 Feb 07 |
jari |
146 |
int c_width = content.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
147 |
int h_width = header.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
148 |
if (c_width > h_width) { |
2 |
26 Feb 07 |
jari |
149 |
header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
150 |
} else { |
2 |
26 Feb 07 |
jari |
151 |
content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
156 |
*/ |
2 |
26 Feb 07 |
jari |
157 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
158 |
return null; |
2 |
26 Feb 07 |
jari |
159 |
} |
2 |
26 Feb 07 |
jari |
160 |
|
2 |
26 Feb 07 |
jari |
161 |
} |