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: SOTAGeneTreeViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.10 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/02 16:57:35 $ |
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.sota; |
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.Component; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
25 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
26 |
import java.util.ArrayList; |
2 |
26 Feb 07 |
jari |
27 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JColorChooser; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
35 |
import javax.swing.SwingUtilities; |
2 |
26 Feb 07 |
jari |
36 |
import javax.swing.tree.DefaultMutableTreeNode; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.microarray.mev.cluster.Cluster; |
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.cluster.Node; |
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.cluster.NodeValueList; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
42 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
44 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
45 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
46 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
47 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLCluster; |
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLExperimentHeader; |
2 |
26 Feb 07 |
jari |
49 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTree; |
2 |
26 Feb 07 |
jari |
50 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTreeData; |
2 |
26 Feb 07 |
jari |
51 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
public class SOTAGeneTreeViewer extends JPanel implements IViewer { |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
protected static String SET_CLUSTER_CMD = "set-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
57 |
protected static String SET_CLUSTER_TEXT_CMD = "set-cluster-text-cmd"; |
2 |
26 Feb 07 |
jari |
58 |
protected static String SAVE_CLUSTER_CMD = "save-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
59 |
protected static String DELETE_CLUSTER_CMD = "delete-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
60 |
protected static String DELETE_ALL_CLUSTERS_CMD = "delete-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
61 |
protected static String SOTA_TREE_PROPERTIES_CMD = "gene-tree-properties-cmd"; |
2 |
26 Feb 07 |
jari |
62 |
protected static String SAMPLE_TREE_PROPERTIES_CMD = "sample-tree-properties-cmd"; |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
private int numberOfCells; |
2 |
26 Feb 07 |
jari |
65 |
private int numberOfSamples; |
2 |
26 Feb 07 |
jari |
66 |
private Experiment centroidData; |
2 |
26 Feb 07 |
jari |
67 |
private SOTATree sotaTree; |
2 |
26 Feb 07 |
jari |
68 |
private FloatMatrix clusterDivFM; |
2 |
26 Feb 07 |
jari |
69 |
private int [] clusterPop; |
2 |
26 Feb 07 |
jari |
70 |
private int [][] clusterIndices; |
2 |
26 Feb 07 |
jari |
71 |
private ArrayList selectedClusterList = new ArrayList(); |
2 |
26 Feb 07 |
jari |
72 |
|
2 |
26 Feb 07 |
jari |
73 |
private SOTACentroidExpressionViewer expViewer; |
2 |
26 Feb 07 |
jari |
74 |
private Dimension elementSize; |
2 |
26 Feb 07 |
jari |
75 |
private IFramework framework; |
2 |
26 Feb 07 |
jari |
76 |
private IData data; |
2 |
26 Feb 07 |
jari |
77 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
78 |
private HCLExperimentHeader header; |
2 |
26 Feb 07 |
jari |
79 |
protected HCLTree sampleTree; |
2 |
26 Feb 07 |
jari |
80 |
private int elementHeight; |
2 |
26 Feb 07 |
jari |
81 |
private int elementWidth; |
2 |
26 Feb 07 |
jari |
82 |
private Listener listener; |
2 |
26 Feb 07 |
jari |
83 |
private int function; |
2 |
26 Feb 07 |
jari |
84 |
private int currClusterNum = -1; |
2 |
26 Feb 07 |
jari |
85 |
private DefaultMutableTreeNode expImageNode; |
2 |
26 Feb 07 |
jari |
86 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
87 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
88 |
private int[] samplesOrder = null; |
2 |
26 Feb 07 |
jari |
89 |
private Cluster hclSampleTree; |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a new instance of SOTAViewer |
2 |
26 Feb 07 |
jari |
* @param result result of SOTA clustering |
2 |
26 Feb 07 |
jari |
* @param sota SOTA tree data structure |
2 |
26 Feb 07 |
jari |
* @param hclSampleTree result from clustering samples by Hierarchical Clustering |
2 |
26 Feb 07 |
jari |
* @param clusters Cluster gene indicies |
2 |
26 Feb 07 |
jari |
97 |
*/ |
2 |
26 Feb 07 |
jari |
98 |
public SOTAGeneTreeViewer(Experiment experiment, SOTATreeData sotaTreeData, Cluster hclSampleTree, int[][] clusters) { |
2 |
26 Feb 07 |
jari |
99 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
100 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
101 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
clusterPop = sotaTreeData.clusterPopulation; |
2 |
26 Feb 07 |
jari |
104 |
clusterDivFM = sotaTreeData.clusterDiversity; |
2 |
26 Feb 07 |
jari |
105 |
clusterIndices = clusters; |
2 |
26 Feb 07 |
jari |
106 |
this.hclSampleTree = hclSampleTree; |
2 |
26 Feb 07 |
jari |
107 |
function = sotaTreeData.function; |
2 |
26 Feb 07 |
jari |
108 |
numberOfSamples = experiment.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
109 |
numberOfCells = sotaTreeData.clusterPopulation.length; |
2 |
26 Feb 07 |
jari |
110 |
sotaTree = new SOTATree(sotaTreeData, true); |
2 |
26 Feb 07 |
jari |
111 |
if(sotaTree != null) |
2 |
26 Feb 07 |
jari |
112 |
sotaTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
113 |
sampleTree = null; |
2 |
26 Feb 07 |
jari |
114 |
if(hclSampleTree != null){ |
2 |
26 Feb 07 |
jari |
115 |
Node sampleTreeNode = hclSampleTree.getNodeList().getNode(0); |
2 |
26 Feb 07 |
jari |
116 |
sampleTree = new HCLTree(getResult(sampleTreeNode,0), HCLTree.VERTICAL); |
2 |
26 Feb 07 |
jari |
117 |
samplesOrder = getLeafOrder(getResult(sampleTreeNode,0) , null); |
2 |
26 Feb 07 |
jari |
118 |
sampleTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
119 |
} |
2 |
26 Feb 07 |
jari |
120 |
centroidData = new Experiment(sotaTreeData.centroidMatrix, samplesOrder != null ? samplesOrder : experiment.getColumnIndicesCopy()); |
2 |
26 Feb 07 |
jari |
121 |
numberOfSamples = centroidData.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
122 |
expViewer = new SOTACentroidExpressionViewer( centroidData, null, samplesOrder, sotaTreeData.clusterPopulation, sotaTreeData.clusterDiversity, selectedClusterList); |
2 |
26 Feb 07 |
jari |
123 |
expViewer.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
124 |
header = new HCLExperimentHeader(expViewer.getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
125 |
header.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
126 |
addComponents(sotaTree, expViewer, sampleTree); |
2 |
26 Feb 07 |
jari |
127 |
this.setLocation(0,0); |
2 |
26 Feb 07 |
jari |
128 |
addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
129 |
popup = this.createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
130 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
131 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
132 |
} |
2 |
26 Feb 07 |
jari |
133 |
/** |
2 |
26 Feb 07 |
jari |
* XMLEncoder/XMLDecoder constructor |
2 |
26 Feb 07 |
jari |
* @param exptID |
2 |
26 Feb 07 |
jari |
* @param sotaTreeData |
2 |
26 Feb 07 |
jari |
* @param hclSampleTree |
2 |
26 Feb 07 |
jari |
* @param clusters |
2 |
26 Feb 07 |
jari |
* @deprecated |
2 |
26 Feb 07 |
jari |
140 |
*/ |
2 |
26 Feb 07 |
jari |
141 |
public SOTAGeneTreeViewer(Integer exptID, SOTATreeData sotaTreeData, |
2 |
26 Feb 07 |
jari |
142 |
Cluster hclSampleTree, int[][] clusters) { //, SOTACentroidExpressionViewer scev){ |
2 |
26 Feb 07 |
jari |
143 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
144 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
145 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
146 |
|
2 |
26 Feb 07 |
jari |
147 |
clusterPop = sotaTreeData.clusterPopulation; |
2 |
26 Feb 07 |
jari |
148 |
clusterDivFM = sotaTreeData.clusterDiversity; |
2 |
26 Feb 07 |
jari |
149 |
clusterIndices = clusters; |
2 |
26 Feb 07 |
jari |
150 |
function = sotaTreeData.function; |
2 |
26 Feb 07 |
jari |
//this.expViewer = scev; |
2 |
26 Feb 07 |
jari |
152 |
|
2 |
26 Feb 07 |
jari |
153 |
numberOfCells = sotaTreeData.clusterPopulation.length; |
2 |
26 Feb 07 |
jari |
154 |
int [] samplesOrder = null; |
2 |
26 Feb 07 |
jari |
155 |
this.exptID = exptID.intValue(); |
2 |
26 Feb 07 |
jari |
156 |
|
2 |
26 Feb 07 |
jari |
157 |
this.sotaTree = new SOTATree(sotaTreeData, true); |
2 |
26 Feb 07 |
jari |
158 |
if(sotaTree != null) |
2 |
26 Feb 07 |
jari |
159 |
sotaTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
//this.sampleTree = sampleTree; |
2 |
26 Feb 07 |
jari |
161 |
this.sampleTree = null; |
2 |
26 Feb 07 |
jari |
162 |
if(hclSampleTree != null){ |
2 |
26 Feb 07 |
jari |
163 |
Node sampleTreeNode = hclSampleTree.getNodeList().getNode(0); |
2 |
26 Feb 07 |
jari |
164 |
sampleTree = new HCLTree(getResult(sampleTreeNode,0), HCLTree.VERTICAL); |
2 |
26 Feb 07 |
jari |
165 |
samplesOrder = getLeafOrder(getResult(sampleTreeNode,0) , null); |
2 |
26 Feb 07 |
jari |
166 |
sampleTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
167 |
} |
2 |
26 Feb 07 |
jari |
168 |
} |
2 |
26 Feb 07 |
jari |
169 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
170 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
171 |
new Object[]{this.experiment, this.sotaTree.getSotaTreeData(), this.sampleTree, this.getClusters()}); //, eccv.getExpViewer()}); |
2 |
26 Feb 07 |
jari |
172 |
} |
2 |
26 Feb 07 |
jari |
173 |
|
2 |
26 Feb 07 |
jari |
174 |
public void setExperiment(Experiment e){ |
2 |
26 Feb 07 |
jari |
175 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
176 |
this.exptID = e.getId(); |
2 |
26 Feb 07 |
jari |
177 |
numberOfSamples = e.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
178 |
SOTATreeData sotaTreeData = sotaTree.getSotaTreeData(); |
2 |
26 Feb 07 |
jari |
179 |
this.centroidData = new Experiment(sotaTreeData.centroidMatrix, samplesOrder != null ? samplesOrder : experiment.getColumnIndicesCopy()); |
2 |
26 Feb 07 |
jari |
180 |
numberOfSamples = centroidData.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
181 |
this.expViewer = new SOTACentroidExpressionViewer( centroidData, null, samplesOrder, sotaTreeData.clusterPopulation, sotaTreeData.clusterDiversity, selectedClusterList); |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
expViewer.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
184 |
header = new HCLExperimentHeader(expViewer.getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
185 |
header.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
186 |
addComponents(sotaTree, expViewer, sampleTree); |
2 |
26 Feb 07 |
jari |
187 |
this.setLocation(0,0); |
2 |
26 Feb 07 |
jari |
188 |
addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
189 |
popup = this.createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
|
2 |
26 Feb 07 |
jari |
193 |
public int getExperimentID(){return this.exptID;} |
2 |
26 Feb 07 |
jari |
194 |
public void setExperimentID(int e){this.exptID = e;} |
2 |
26 Feb 07 |
jari |
195 |
|
2 |
26 Feb 07 |
jari |
196 |
/** |
2 |
26 Feb 07 |
jari |
* sets a node to reference when jumping to expression images |
2 |
26 Feb 07 |
jari |
198 |
*/ |
2 |
26 Feb 07 |
jari |
199 |
public void associateExpressionImageNode(DefaultMutableTreeNode ExpressionImageNode){ |
2 |
26 Feb 07 |
jari |
200 |
expImageNode = ExpressionImageNode; |
2 |
26 Feb 07 |
jari |
201 |
} |
2 |
26 Feb 07 |
jari |
202 |
|
2 |
26 Feb 07 |
jari |
203 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a hcl tree data from the specified cluster node. |
2 |
26 Feb 07 |
jari |
205 |
*/ |
2 |
26 Feb 07 |
jari |
206 |
private HCLTreeData getResult(Node clusterNode, int pos) { |
2 |
26 Feb 07 |
jari |
207 |
HCLTreeData data = new HCLTreeData(); |
2 |
26 Feb 07 |
jari |
208 |
NodeValueList valueList = clusterNode.getValues(); |
2 |
26 Feb 07 |
jari |
209 |
data.child_1_array = (int[])valueList.getNodeValue(pos).value; |
2 |
26 Feb 07 |
jari |
210 |
data.child_2_array = (int[])valueList.getNodeValue(pos+1).value; |
2 |
26 Feb 07 |
jari |
211 |
data.node_order = (int[])valueList.getNodeValue(pos+2).value; |
2 |
26 Feb 07 |
jari |
212 |
data.height = (float[])valueList.getNodeValue(pos+3).value; |
2 |
26 Feb 07 |
jari |
213 |
return data; |
2 |
26 Feb 07 |
jari |
214 |
} |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
|
2 |
26 Feb 07 |
jari |
217 |
int [] getSamplesOrder(int numSamples){ |
2 |
26 Feb 07 |
jari |
218 |
int [] order = new int[numSamples]; |
2 |
26 Feb 07 |
jari |
219 |
|
2 |
26 Feb 07 |
jari |
220 |
for(int i = 0; i < numSamples; i++){ |
2 |
26 Feb 07 |
jari |
221 |
order[i] = i; |
2 |
26 Feb 07 |
jari |
222 |
} |
2 |
26 Feb 07 |
jari |
223 |
return order; |
2 |
26 Feb 07 |
jari |
224 |
} |
2 |
26 Feb 07 |
jari |
225 |
|
2 |
26 Feb 07 |
jari |
226 |
|
2 |
26 Feb 07 |
jari |
227 |
protected void addComponents( JComponent sotaTree, JComponent expViewer, JComponent sTree){// ,JComponent cBar) { |
2 |
26 Feb 07 |
jari |
228 |
final int rows = sTree == null ? 1 : 2; |
2 |
26 Feb 07 |
jari |
229 |
final int cols = 2; |
2 |
26 Feb 07 |
jari |
230 |
|
2 |
26 Feb 07 |
jari |
231 |
if(sTree != null) |
2 |
26 Feb 07 |
jari |
232 |
add(sTree, new GridBagConstraints(cols-1, rows-2, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
233 |
|
2 |
26 Feb 07 |
jari |
234 |
if (sotaTree != null) { |
2 |
26 Feb 07 |
jari |
235 |
add(sotaTree, new GridBagConstraints(cols-2, rows-1, 1, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
236 |
} |
2 |
26 Feb 07 |
jari |
237 |
add(expViewer, new GridBagConstraints(cols-1, rows-1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
238 |
} |
2 |
26 Feb 07 |
jari |
239 |
|
2 |
26 Feb 07 |
jari |
240 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when display menu is changed, |
2 |
26 Feb 07 |
jari |
* if this viewer is selected. |
2 |
26 Feb 07 |
jari |
* @see IDisplayMenu |
2 |
26 Feb 07 |
jari |
244 |
*/ |
2 |
26 Feb 07 |
jari |
245 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
246 |
this.sotaTree.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
247 |
this.expViewer.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
248 |
if(sampleTree != null) |
2 |
26 Feb 07 |
jari |
249 |
this.sampleTree.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
250 |
this.header.setHeaderPosition(this.sotaTree.getTreeHeight()-10); //move by inset of viewer |
2 |
26 Feb 07 |
jari |
251 |
this.header.updateSize(getCommonWidth(), elementSize.width); |
2 |
26 Feb 07 |
jari |
252 |
} |
2 |
26 Feb 07 |
jari |
253 |
|
2 |
26 Feb 07 |
jari |
254 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer was deselected. |
2 |
26 Feb 07 |
jari |
256 |
*/ |
2 |
26 Feb 07 |
jari |
257 |
public void onDeselected() { |
2 |
26 Feb 07 |
jari |
258 |
} |
2 |
26 Feb 07 |
jari |
259 |
|
2 |
26 Feb 07 |
jari |
260 |
|
2 |
26 Feb 07 |
jari |
261 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer is selected. |
2 |
26 Feb 07 |
jari |
263 |
*/ |
2 |
26 Feb 07 |
jari |
264 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
265 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
266 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
268 |
IDisplayMenu menu = framework.getDisplayMenu(); |
2 |
26 Feb 07 |
jari |
269 |
elementSize = menu.getElementSize(); |
2 |
26 Feb 07 |
jari |
270 |
if(this.expViewer.isVisible()) |
2 |
26 Feb 07 |
jari |
271 |
this.expViewer.onSelected(framework); |
2 |
26 Feb 07 |
jari |
272 |
if(sampleTree != null) |
2 |
26 Feb 07 |
jari |
273 |
this.sampleTree.onSelected(framework); |
2 |
26 Feb 07 |
jari |
274 |
this.sotaTree.onSelected(framework); |
2 |
26 Feb 07 |
jari |
275 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
276 |
|
2 |
26 Feb 07 |
jari |
277 |
verifyClusterExistence(data); |
2 |
26 Feb 07 |
jari |
278 |
verifyClusterMembership(data); |
2 |
26 Feb 07 |
jari |
//Only do this if we have a visible viewer |
2 |
26 Feb 07 |
jari |
280 |
this.header.setHeaderPosition(this.sotaTree.getTreeHeight()-10); //move by inset of viewer |
2 |
26 Feb 07 |
jari |
281 |
|
2 |
26 Feb 07 |
jari |
//expImageNode is null after de-serialization and must be reset |
2 |
26 Feb 07 |
jari |
283 |
if(this.expImageNode == null){ |
2 |
26 Feb 07 |
jari |
284 |
DefaultMutableTreeNode node = framework.getCurrentNode(); |
2 |
26 Feb 07 |
jari |
285 |
if(node != null) |
2 |
26 Feb 07 |
jari |
286 |
node = (DefaultMutableTreeNode)node.getParent(); |
2 |
26 Feb 07 |
jari |
287 |
if(node != null) |
2 |
26 Feb 07 |
jari |
288 |
node = (DefaultMutableTreeNode)node.getChildAt(1); |
2 |
26 Feb 07 |
jari |
289 |
if(node != null) |
2 |
26 Feb 07 |
jari |
290 |
this.expImageNode = node; |
2 |
26 Feb 07 |
jari |
291 |
} |
2 |
26 Feb 07 |
jari |
292 |
} |
2 |
26 Feb 07 |
jari |
293 |
|
2 |
26 Feb 07 |
jari |
294 |
/** |
2 |
26 Feb 07 |
jari |
* Calculate the viewer width. |
2 |
26 Feb 07 |
jari |
296 |
*/ |
2 |
26 Feb 07 |
jari |
297 |
public int getCommonWidth() { |
2 |
26 Feb 07 |
jari |
298 |
int width = 0; |
2 |
26 Feb 07 |
jari |
299 |
if (this.sotaTree != null) { |
2 |
26 Feb 07 |
jari |
300 |
width += this.sotaTree.getTreeHeight(); |
2 |
26 Feb 07 |
jari |
301 |
} |
2 |
26 Feb 07 |
jari |
302 |
|
2 |
26 Feb 07 |
jari |
303 |
width += this.expViewer.getWidth(); |
2 |
26 Feb 07 |
jari |
304 |
|
2 |
26 Feb 07 |
jari |
305 |
return width; |
2 |
26 Feb 07 |
jari |
306 |
} |
2 |
26 Feb 07 |
jari |
307 |
|
2 |
26 Feb 07 |
jari |
308 |
public int getCommonHeight(){ |
2 |
26 Feb 07 |
jari |
309 |
int height = 0; |
2 |
26 Feb 07 |
jari |
310 |
if(this.sotaTree != null){ |
2 |
26 Feb 07 |
jari |
311 |
height += this.sotaTree.getTreeWidth(); |
2 |
26 Feb 07 |
jari |
312 |
} |
2 |
26 Feb 07 |
jari |
313 |
height += this.header.getHeight(); |
2 |
26 Feb 07 |
jari |
314 |
return height; |
2 |
26 Feb 07 |
jari |
315 |
} |
2 |
26 Feb 07 |
jari |
316 |
|
2 |
26 Feb 07 |
jari |
317 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked when the framework is going to be closed. |
2 |
26 Feb 07 |
jari |
319 |
*/ |
2 |
26 Feb 07 |
jari |
320 |
public void onClosed() { |
2 |
26 Feb 07 |
jari |
321 |
} |
2 |
26 Feb 07 |
jari |
322 |
|
2 |
26 Feb 07 |
jari |
323 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane view port. |
2 |
26 Feb 07 |
jari |
325 |
*/ |
2 |
26 Feb 07 |
jari |
326 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
327 |
return this; |
2 |
26 Feb 07 |
jari |
328 |
} |
2 |
26 Feb 07 |
jari |
329 |
|
2 |
26 Feb 07 |
jari |
330 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework to save or to print viewer image. |
2 |
26 Feb 07 |
jari |
332 |
*/ |
2 |
26 Feb 07 |
jari |
333 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
334 |
return null; |
2 |
26 Feb 07 |
jari |
335 |
} |
2 |
26 Feb 07 |
jari |
336 |
|
2 |
26 Feb 07 |
jari |
337 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when data is changed, |
2 |
26 Feb 07 |
jari |
* if this viewer is selected. |
2 |
26 Feb 07 |
jari |
* @see IData |
2 |
26 Feb 07 |
jari |
341 |
*/ |
2 |
26 Feb 07 |
jari |
342 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
343 |
this.data = data; |
2 |
26 Feb 07 |
jari |
344 |
verifyClusterExistence(data); |
2 |
26 Feb 07 |
jari |
345 |
} |
2 |
26 Feb 07 |
jari |
346 |
|
2 |
26 Feb 07 |
jari |
347 |
private void verifyClusterExistence(IData data){ |
2 |
26 Feb 07 |
jari |
348 |
Color [] colors = data.getColors(); |
2 |
26 Feb 07 |
jari |
349 |
if(colors.length == 0){ |
2 |
26 Feb 07 |
jari |
350 |
this.selectedClusterList.clear(); |
2 |
26 Feb 07 |
jari |
351 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
352 |
} |
2 |
26 Feb 07 |
jari |
353 |
} |
2 |
26 Feb 07 |
jari |
354 |
|
2 |
26 Feb 07 |
jari |
355 |
|
2 |
26 Feb 07 |
jari |
356 |
private void verifyClusterMembership(IData data){ |
2 |
26 Feb 07 |
jari |
357 |
Color [] colors = data.getColors(); |
2 |
26 Feb 07 |
jari |
358 |
Color currColor = null; |
2 |
26 Feb 07 |
jari |
359 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
360 |
boolean aMemberChanged = false; |
2 |
26 Feb 07 |
jari |
361 |
boolean membershipChanged = false; |
2 |
26 Feb 07 |
jari |
362 |
boolean [] alteredMembership = new boolean[selectedClusterList.size()]; |
2 |
26 Feb 07 |
jari |
363 |
|
2 |
26 Feb 07 |
jari |
364 |
int index; |
2 |
26 Feb 07 |
jari |
365 |
for(int c = 0; c < this.selectedClusterList.size(); c++){ |
2 |
26 Feb 07 |
jari |
366 |
cluster = (HCLCluster)this.selectedClusterList.get(c); |
2 |
26 Feb 07 |
jari |
367 |
currColor = cluster.color; |
2 |
26 Feb 07 |
jari |
368 |
index = cluster.root; |
2 |
26 Feb 07 |
jari |
369 |
membershipChanged = false; |
2 |
26 Feb 07 |
jari |
370 |
for(int exp = 0; exp < this.clusterIndices[index].length ; exp++){ |
2 |
26 Feb 07 |
jari |
371 |
if(!(currColor.equals(data.getProbeColor(this.clusterIndices[index][exp])))){ |
2 |
26 Feb 07 |
jari |
372 |
aMemberChanged = true; |
2 |
26 Feb 07 |
jari |
373 |
membershipChanged = true; |
2 |
26 Feb 07 |
jari |
374 |
break; |
2 |
26 Feb 07 |
jari |
375 |
} |
2 |
26 Feb 07 |
jari |
376 |
} |
2 |
26 Feb 07 |
jari |
377 |
if(membershipChanged) |
2 |
26 Feb 07 |
jari |
378 |
alteredMembership[c] = true; |
2 |
26 Feb 07 |
jari |
379 |
} |
2 |
26 Feb 07 |
jari |
380 |
|
2 |
26 Feb 07 |
jari |
381 |
for(int i = selectedClusterList.size()-1; i >=0 ;i--){ |
2 |
26 Feb 07 |
jari |
382 |
if(alteredMembership[i]) |
2 |
26 Feb 07 |
jari |
383 |
selectedClusterList.remove(i); |
2 |
26 Feb 07 |
jari |
384 |
} |
2 |
26 Feb 07 |
jari |
385 |
if(aMemberChanged) |
2 |
26 Feb 07 |
jari |
386 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
387 |
} |
2 |
26 Feb 07 |
jari |
388 |
|
2 |
26 Feb 07 |
jari |
389 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane header. |
2 |
26 Feb 07 |
jari |
391 |
*/ |
2 |
26 Feb 07 |
jari |
392 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
393 |
return this.header; |
2 |
26 Feb 07 |
jari |
394 |
} |
2 |
26 Feb 07 |
jari |
395 |
|
2 |
26 Feb 07 |
jari |
396 |
|
2 |
26 Feb 07 |
jari |
397 |
private int[] getLeafOrder(HCLTreeData result, int[] indices) { |
2 |
26 Feb 07 |
jari |
398 |
if (result == null || result.node_order.length < 2) { |
2 |
26 Feb 07 |
jari |
399 |
return null; |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
return getLeafOrder(result.node_order, result.child_1_array, result.child_2_array, indices); |
2 |
26 Feb 07 |
jari |
402 |
} |
2 |
26 Feb 07 |
jari |
403 |
|
2 |
26 Feb 07 |
jari |
404 |
private int[] getLeafOrder(int[] nodeOrder, int[] child1, int[] child2, int[] indices) { |
2 |
26 Feb 07 |
jari |
405 |
int[] leafOrder = new int[nodeOrder.length]; |
2 |
26 Feb 07 |
jari |
406 |
Arrays.fill(leafOrder, -1); |
2 |
26 Feb 07 |
jari |
407 |
|
2 |
26 Feb 07 |
jari |
408 |
fillLeafOrder(leafOrder, child1, child2, 0, child1.length-2, indices); |
2 |
26 Feb 07 |
jari |
409 |
return leafOrder; |
2 |
26 Feb 07 |
jari |
410 |
} |
2 |
26 Feb 07 |
jari |
411 |
|
2 |
26 Feb 07 |
jari |
412 |
private int fillLeafOrder(int[] leafOrder, int[] child1, int[] child2, int pos, int index, int[] indices) { |
2 |
26 Feb 07 |
jari |
413 |
if (child1[index] != -1) { |
2 |
26 Feb 07 |
jari |
414 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child1[index], indices); |
2 |
26 Feb 07 |
jari |
415 |
} |
2 |
26 Feb 07 |
jari |
416 |
if (child2[index] != -1) { |
2 |
26 Feb 07 |
jari |
417 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child2[index], indices); |
2 |
26 Feb 07 |
jari |
418 |
} else { |
2 |
26 Feb 07 |
jari |
419 |
leafOrder[pos] = indices == null ? index : indices[index]; |
2 |
26 Feb 07 |
jari |
420 |
pos++; |
2 |
26 Feb 07 |
jari |
421 |
} |
2 |
26 Feb 07 |
jari |
422 |
return pos; |
2 |
26 Feb 07 |
jari |
423 |
} |
2 |
26 Feb 07 |
jari |
424 |
|
2 |
26 Feb 07 |
jari |
425 |
private Frame getFrame() { |
2 |
26 Feb 07 |
jari |
426 |
return JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
427 |
} |
2 |
26 Feb 07 |
jari |
428 |
|
2 |
26 Feb 07 |
jari |
429 |
private void setSOTATreeProperties() { |
2 |
26 Feb 07 |
jari |
430 |
Frame frame = JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
431 |
SOTAConfigDialog dialog = new SOTAConfigDialog(frame, 0, sotaTree.getMinDistance(), sotaTree.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
432 |
if (dialog.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
433 |
sotaTree.setProperties(dialog.getZeroThreshold(), dialog.getMinDistance(), dialog.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
434 |
} |
2 |
26 Feb 07 |
jari |
435 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
436 |
this.header.setHeaderPosition(this.sotaTree.getTreeHeight()-10); |
2 |
26 Feb 07 |
jari |
437 |
revalidate(); |
2 |
26 Feb 07 |
jari |
438 |
} |
2 |
26 Feb 07 |
jari |
439 |
|
2 |
26 Feb 07 |
jari |
/* public void onSampleTreeProperties() { |
2 |
26 Feb 07 |
jari |
setTreeProperties(this.sampleTree); |
2 |
26 Feb 07 |
jari |
revalidate(); |
2 |
26 Feb 07 |
jari |
443 |
} |
2 |
26 Feb 07 |
jari |
444 |
*/ |
2 |
26 Feb 07 |
jari |
/* private void setTreeProperties(HCLTree tree) { |
2 |
26 Feb 07 |
jari |
Frame frame = JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
HCLConfigDialog dialog = new HCLConfigDialog(frame, tree.getZeroThreshold(), tree.getMinDistance(), tree.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
if (dialog.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
tree.setProperties(dialog.getZeroThreshold(), dialog.getMinDistance(), dialog.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
450 |
} |
2 |
26 Feb 07 |
jari |
451 |
} |
2 |
26 Feb 07 |
jari |
452 |
*/ |
2 |
26 Feb 07 |
jari |
453 |
|
2 |
26 Feb 07 |
jari |
454 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
455 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
456 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
457 |
return popup; |
2 |
26 Feb 07 |
jari |
458 |
} |
2 |
26 Feb 07 |
jari |
459 |
|
2 |
26 Feb 07 |
jari |
460 |
private void showClusterInfo(int clusterNumber){ |
2 |
26 Feb 07 |
jari |
461 |
float neighborDist; |
2 |
26 Feb 07 |
jari |
462 |
int neighbor = getClosestCentroid(clusterNumber); |
2 |
26 Feb 07 |
jari |
463 |
|
2 |
26 Feb 07 |
jari |
464 |
if(neighbor == clusterNumber) return; |
2 |
26 Feb 07 |
jari |
465 |
|
2 |
26 Feb 07 |
jari |
466 |
neighborDist = org.tigr.microarray.mev.cluster.algorithm.impl.ExperimentUtil.geneDistance(centroidData.getMatrix(), |
2 |
26 Feb 07 |
jari |
467 |
null, clusterNumber, neighbor, function, (float)1.0, false); |
2 |
26 Feb 07 |
jari |
468 |
|
2 |
26 Feb 07 |
jari |
//Code to put selected viewer into scroll pane |
2 |
26 Feb 07 |
jari |
470 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode)(expImageNode.getChildAt(clusterNumber)); |
2 |
26 Feb 07 |
jari |
471 |
|
2 |
26 Feb 07 |
jari |
472 |
if(this.framework != null) |
2 |
26 Feb 07 |
jari |
473 |
framework.setTreeNode(node); |
2 |
26 Feb 07 |
jari |
474 |
} |
2 |
26 Feb 07 |
jari |
475 |
|
2 |
26 Feb 07 |
jari |
476 |
|
2 |
26 Feb 07 |
jari |
477 |
|
2 |
26 Feb 07 |
jari |
478 |
private int getClosestCentroid(int centroidNum){ |
2 |
26 Feb 07 |
jari |
479 |
float minDist = Float.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
480 |
float currDist; |
2 |
26 Feb 07 |
jari |
481 |
int closestCentroid = centroidNum; |
2 |
26 Feb 07 |
jari |
482 |
for(int i = 0; i < this.numberOfCells ;i++){ |
2 |
26 Feb 07 |
jari |
483 |
currDist = org.tigr.microarray.mev.cluster.algorithm.impl.ExperimentUtil.geneDistance(centroidData.getMatrix(), |
2 |
26 Feb 07 |
jari |
484 |
null, centroidNum, i, function, (float)1.0 , false); |
2 |
26 Feb 07 |
jari |
485 |
|
2 |
26 Feb 07 |
jari |
486 |
if(currDist < minDist && i != centroidNum){ |
2 |
26 Feb 07 |
jari |
487 |
minDist = currDist; |
2 |
26 Feb 07 |
jari |
488 |
closestCentroid = i; |
2 |
26 Feb 07 |
jari |
489 |
} |
2 |
26 Feb 07 |
jari |
490 |
} |
2 |
26 Feb 07 |
jari |
491 |
return closestCentroid; |
2 |
26 Feb 07 |
jari |
492 |
} |
2 |
26 Feb 07 |
jari |
493 |
|
2 |
26 Feb 07 |
jari |
494 |
|
2 |
26 Feb 07 |
jari |
495 |
private void onSaveCluster(int cNum){ |
2 |
26 Feb 07 |
jari |
496 |
try { |
2 |
26 Feb 07 |
jari |
497 |
org.tigr.microarray.mev.cluster.gui.helpers.ExperimentUtil.saveExperiment(getFrame(), this.experiment, this.data, clusterIndices[cNum]); |
2 |
26 Feb 07 |
jari |
498 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
499 |
JOptionPane.showMessageDialog(getFrame(), "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
500 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
501 |
} |
2 |
26 Feb 07 |
jari |
502 |
} |
2 |
26 Feb 07 |
jari |
503 |
|
2 |
26 Feb 07 |
jari |
504 |
/** |
2 |
26 Feb 07 |
jari |
* Sets cluster color |
2 |
26 Feb 07 |
jari |
506 |
*/ |
2 |
26 Feb 07 |
jari |
507 |
private void onSetCluster(int currCluster){ |
2 |
26 Feb 07 |
jari |
508 |
|
2 |
26 Feb 07 |
jari |
509 |
Color newColor = JColorChooser.showDialog(getFrame(), "Choose color", new Color(128, 128, 128)); |
2 |
26 Feb 07 |
jari |
510 |
if (newColor == null || currCluster == -1) { |
2 |
26 Feb 07 |
jari |
511 |
return; |
2 |
26 Feb 07 |
jari |
512 |
} |
2 |
26 Feb 07 |
jari |
513 |
|
2 |
26 Feb 07 |
jari |
514 |
HCLCluster cluster = new HCLCluster(currCluster, currCluster-1, currCluster+1); |
2 |
26 Feb 07 |
jari |
515 |
selectedClusterList.add(cluster); |
2 |
26 Feb 07 |
jari |
516 |
cluster.color = newColor; |
2 |
26 Feb 07 |
jari |
517 |
this.header.updateSize(getCommonWidth(), this.elementSize.width); |
2 |
26 Feb 07 |
jari |
518 |
revalidate(); |
2 |
26 Feb 07 |
jari |
519 |
this.data.setProbesColor( getIDataRowIndices(clusterIndices[currCluster]), newColor); |
2 |
26 Feb 07 |
jari |
520 |
repaint(); |
2 |
26 Feb 07 |
jari |
521 |
} |
2 |
26 Feb 07 |
jari |
522 |
|
2 |
26 Feb 07 |
jari |
523 |
/** |
2 |
26 Feb 07 |
jari |
* Converts cluster indicies from the experiment to IData rows which could be different |
2 |
26 Feb 07 |
jari |
525 |
*/ |
2 |
26 Feb 07 |
jari |
526 |
private int [] getIDataRowIndices(int [] expIndices){ |
2 |
26 Feb 07 |
jari |
527 |
int [] dataIndices = new int[expIndices.length]; |
2 |
26 Feb 07 |
jari |
528 |
for(int i = 0; i < expIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
529 |
dataIndices[i] = experiment.getGeneIndexMappedToData(expIndices[i]); |
2 |
26 Feb 07 |
jari |
530 |
} |
2 |
26 Feb 07 |
jari |
531 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
532 |
} |
2 |
26 Feb 07 |
jari |
533 |
|
2 |
26 Feb 07 |
jari |
534 |
/** |
2 |
26 Feb 07 |
jari |
* Deletes indicated cluster |
2 |
26 Feb 07 |
jari |
536 |
*/ |
2 |
26 Feb 07 |
jari |
537 |
private void onDeleteCluster(int clusterIndex){ |
2 |
26 Feb 07 |
jari |
538 |
HCLCluster currCluster; |
2 |
26 Feb 07 |
jari |
539 |
|
2 |
26 Feb 07 |
jari |
540 |
for(int i = 0; i < selectedClusterList.size(); i++){ |
2 |
26 Feb 07 |
jari |
541 |
currCluster = (HCLCluster)selectedClusterList.get(i); |
2 |
26 Feb 07 |
jari |
542 |
if(currCluster.root == clusterIndex){ |
2 |
26 Feb 07 |
jari |
543 |
this.data.setProbesColor( clusterIndices[clusterIndex], null); |
2 |
26 Feb 07 |
jari |
544 |
selectedClusterList.remove(i); |
2 |
26 Feb 07 |
jari |
545 |
} |
2 |
26 Feb 07 |
jari |
546 |
} |
2 |
26 Feb 07 |
jari |
547 |
repaint(); |
2 |
26 Feb 07 |
jari |
548 |
} |
2 |
26 Feb 07 |
jari |
549 |
|
2 |
26 Feb 07 |
jari |
550 |
/** |
2 |
26 Feb 07 |
jari |
* Clears cluster colors |
2 |
26 Feb 07 |
jari |
552 |
*/ |
2 |
26 Feb 07 |
jari |
553 |
private void onDeleteAllClusters(){ |
2 |
26 Feb 07 |
jari |
554 |
selectedClusterList.clear(); |
2 |
26 Feb 07 |
jari |
555 |
this.data.deleteColors(); |
2 |
26 Feb 07 |
jari |
556 |
repaint(); |
2 |
26 Feb 07 |
jari |
557 |
} |
2 |
26 Feb 07 |
jari |
558 |
|
2 |
26 Feb 07 |
jari |
559 |
|
2 |
26 Feb 07 |
jari |
560 |
/** |
2 |
26 Feb 07 |
jari |
* Adds menu items to the specified popup menu. |
2 |
26 Feb 07 |
jari |
562 |
*/ |
2 |
26 Feb 07 |
jari |
563 |
protected void addMenuItems(JPopupMenu menu, Listener listener) { |
2 |
26 Feb 07 |
jari |
564 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
565 |
/* |
2 |
26 Feb 07 |
jari |
menuItem = new JMenuItem("Set cluster...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
menuItem.setActionCommand(SET_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
571 |
*/ |
2 |
26 Feb 07 |
jari |
572 |
/* |
2 |
26 Feb 07 |
jari |
menuItem = new JMenuItem("Set cluster text...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
menuItem.setActionCommand(SET_CLUSTER_TEXT_CMD); |
2 |
26 Feb 07 |
jari |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
578 |
*/ |
2 |
26 Feb 07 |
jari |
579 |
menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
580 |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
581 |
menuItem.setActionCommand(SAVE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
582 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
583 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
584 |
/* |
2 |
26 Feb 07 |
jari |
menuItem = new JMenuItem("Delete cluster", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
menuItem.setActionCommand(DELETE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
590 |
|
2 |
26 Feb 07 |
jari |
menuItem = new JMenuItem("Delete all clusters", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
menuItem.setActionCommand(DELETE_ALL_CLUSTERS_CMD); |
2 |
26 Feb 07 |
jari |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
596 |
*/ |
2 |
26 Feb 07 |
jari |
597 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
598 |
|
2 |
26 Feb 07 |
jari |
599 |
menuItem = new JMenuItem("SOTATree properties...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
600 |
menuItem.setEnabled(this.sotaTree != null); |
2 |
26 Feb 07 |
jari |
601 |
menuItem.setActionCommand(SOTA_TREE_PROPERTIES_CMD); |
2 |
26 Feb 07 |
jari |
602 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
603 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
604 |
|
2 |
26 Feb 07 |
jari |
// menuItem = new JMenuItem("SampleTree properties...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
// menuItem.setEnabled(this.sampleTree != null); |
2 |
26 Feb 07 |
jari |
// menuItem.setActionCommand(SAMPLE_TREE_PROPERTIES_CMD); |
2 |
26 Feb 07 |
jari |
// menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
// menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
610 |
} |
2 |
26 Feb 07 |
jari |
611 |
|
2 |
26 Feb 07 |
jari |
612 |
|
2 |
26 Feb 07 |
jari |
613 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a menu item by specified action command. |
2 |
26 Feb 07 |
jari |
* @return null, if menu item was not found. |
2 |
26 Feb 07 |
jari |
616 |
*/ |
2 |
26 Feb 07 |
jari |
617 |
protected JMenuItem getJMenuItem(String command) { |
2 |
26 Feb 07 |
jari |
618 |
JMenuItem item; |
2 |
26 Feb 07 |
jari |
619 |
Component[] components = popup.getComponents(); |
2 |
26 Feb 07 |
jari |
620 |
for (int i=0; i<components.length; i++) { |
2 |
26 Feb 07 |
jari |
621 |
if (components[i] instanceof JMenuItem) { |
2 |
26 Feb 07 |
jari |
622 |
if (((JMenuItem)components[i]).getActionCommand().equals(command)) |
2 |
26 Feb 07 |
jari |
623 |
return(JMenuItem)components[i]; |
2 |
26 Feb 07 |
jari |
624 |
} |
2 |
26 Feb 07 |
jari |
625 |
} |
2 |
26 Feb 07 |
jari |
626 |
return null; |
2 |
26 Feb 07 |
jari |
627 |
} |
2 |
26 Feb 07 |
jari |
628 |
|
2 |
26 Feb 07 |
jari |
629 |
/** |
2 |
26 Feb 07 |
jari |
* Sets menu enabled flag. |
2 |
26 Feb 07 |
jari |
631 |
*/ |
2 |
26 Feb 07 |
jari |
632 |
protected void setEnableMenuItem(String command, boolean enable) { |
2 |
26 Feb 07 |
jari |
633 |
JMenuItem item = getJMenuItem(command); |
2 |
26 Feb 07 |
jari |
634 |
if (item == null) { |
2 |
26 Feb 07 |
jari |
635 |
return; |
2 |
26 Feb 07 |
jari |
636 |
} |
2 |
26 Feb 07 |
jari |
637 |
item.setEnabled(enable); |
2 |
26 Feb 07 |
jari |
638 |
} |
2 |
26 Feb 07 |
jari |
639 |
|
2 |
26 Feb 07 |
jari |
640 |
private boolean isClusterSet(int clusterIndex){ |
2 |
26 Feb 07 |
jari |
641 |
HCLCluster currCluster; |
2 |
26 Feb 07 |
jari |
642 |
|
2 |
26 Feb 07 |
jari |
643 |
for(int i = 0; i < selectedClusterList.size(); i++){ |
2 |
26 Feb 07 |
jari |
644 |
currCluster = (HCLCluster)selectedClusterList.get(i); |
2 |
26 Feb 07 |
jari |
645 |
if(currCluster.root == clusterIndex) |
2 |
26 Feb 07 |
jari |
646 |
return true; |
2 |
26 Feb 07 |
jari |
647 |
} |
2 |
26 Feb 07 |
jari |
648 |
return false; |
2 |
26 Feb 07 |
jari |
649 |
} |
2 |
26 Feb 07 |
jari |
650 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
652 |
*/ |
2 |
26 Feb 07 |
jari |
653 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
654 |
return null; |
2 |
26 Feb 07 |
jari |
655 |
} |
2 |
26 Feb 07 |
jari |
656 |
|
2 |
26 Feb 07 |
jari |
/** Returns the corner component corresponding to the indicated corner, |
2 |
26 Feb 07 |
jari |
* posibly null |
2 |
26 Feb 07 |
jari |
659 |
*/ |
2 |
26 Feb 07 |
jari |
660 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
661 |
return null; |
2 |
26 Feb 07 |
jari |
662 |
} |
2 |
26 Feb 07 |
jari |
663 |
|
2 |
26 Feb 07 |
jari |
664 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
665 |
return null; |
2 |
26 Feb 07 |
jari |
666 |
} |
2 |
26 Feb 07 |
jari |
667 |
|
2 |
26 Feb 07 |
jari |
668 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
669 |
return null; |
2 |
26 Feb 07 |
jari |
670 |
} |
2 |
26 Feb 07 |
jari |
671 |
|
2 |
26 Feb 07 |
jari |
/** Returns int value indicating viewer type |
2 |
26 Feb 07 |
jari |
* Cluster.GENE_CLUSTER, Cluster.EXPERIMENT_CLUSTER, or -1 for both or unspecified |
2 |
26 Feb 07 |
jari |
674 |
*/ |
2 |
26 Feb 07 |
jari |
675 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
676 |
return -1; |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
|
2 |
26 Feb 07 |
jari |
679 |
private class Listener extends MouseAdapter implements ActionListener{ |
2 |
26 Feb 07 |
jari |
680 |
|
2 |
26 Feb 07 |
jari |
681 |
public void actionPerformed(java.awt.event.ActionEvent actionEvent) { |
2 |
26 Feb 07 |
jari |
682 |
String actionCmd = actionEvent.getActionCommand(); |
2 |
26 Feb 07 |
jari |
683 |
if(actionCmd.equals(SOTAGeneTreeViewer.SOTA_TREE_PROPERTIES_CMD)){ |
2 |
26 Feb 07 |
jari |
684 |
setSOTATreeProperties(); |
2 |
26 Feb 07 |
jari |
685 |
|
2 |
26 Feb 07 |
jari |
686 |
} |
2 |
26 Feb 07 |
jari |
// else if(actionCmd.equals(SOTAGeneTreeViewer.SAMPLE_TREE_PROPERTIES_CMD)){ |
2 |
26 Feb 07 |
jari |
// onSampleTreeProperties(); |
2 |
26 Feb 07 |
jari |
689 |
// } |
2 |
26 Feb 07 |
jari |
690 |
else if(actionCmd.equals(SOTAGeneTreeViewer.SET_CLUSTER_CMD)){ |
2 |
26 Feb 07 |
jari |
691 |
if(currClusterNum != -1) |
2 |
26 Feb 07 |
jari |
692 |
onSetCluster(currClusterNum); |
2 |
26 Feb 07 |
jari |
693 |
} |
2 |
26 Feb 07 |
jari |
694 |
else if(actionCmd.equals(SOTAGeneTreeViewer.SAVE_CLUSTER_CMD)){ |
2 |
26 Feb 07 |
jari |
695 |
if(currClusterNum != -1) |
2 |
26 Feb 07 |
jari |
696 |
onSaveCluster(currClusterNum); |
2 |
26 Feb 07 |
jari |
697 |
} |
2 |
26 Feb 07 |
jari |
698 |
else if(actionCmd.equals(SOTAGeneTreeViewer.DELETE_CLUSTER_CMD)){ |
2 |
26 Feb 07 |
jari |
699 |
if(currClusterNum != -1) |
2 |
26 Feb 07 |
jari |
700 |
onDeleteCluster(currClusterNum); |
2 |
26 Feb 07 |
jari |
701 |
} |
2 |
26 Feb 07 |
jari |
702 |
else if(actionCmd.equals(SOTAGeneTreeViewer.DELETE_ALL_CLUSTERS_CMD)){ |
2 |
26 Feb 07 |
jari |
703 |
onDeleteAllClusters(); |
2 |
26 Feb 07 |
jari |
704 |
} |
2 |
26 Feb 07 |
jari |
705 |
} |
2 |
26 Feb 07 |
jari |
706 |
|
2 |
26 Feb 07 |
jari |
707 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
708 |
|
2 |
26 Feb 07 |
jari |
709 |
if(!maybeShowPopup(event) && SwingUtilities.isLeftMouseButton(event)){ |
2 |
26 Feb 07 |
jari |
710 |
currClusterNum = expViewer.getCurrentCentroidNumber(); |
2 |
26 Feb 07 |
jari |
711 |
|
2 |
26 Feb 07 |
jari |
712 |
if(currClusterNum != -1){ |
2 |
26 Feb 07 |
jari |
713 |
showClusterInfo(currClusterNum); |
2 |
26 Feb 07 |
jari |
714 |
} |
2 |
26 Feb 07 |
jari |
715 |
} |
2 |
26 Feb 07 |
jari |
716 |
} |
2 |
26 Feb 07 |
jari |
717 |
|
2 |
26 Feb 07 |
jari |
718 |
|
2 |
26 Feb 07 |
jari |
719 |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
720 |
|
2 |
26 Feb 07 |
jari |
721 |
if(!maybeShowPopup(event) && SwingUtilities.isLeftMouseButton(event)){ |
2 |
26 Feb 07 |
jari |
722 |
currClusterNum = expViewer.getCurrentCentroidNumber(); |
2 |
26 Feb 07 |
jari |
723 |
|
2 |
26 Feb 07 |
jari |
724 |
if(currClusterNum != -1){ |
2 |
26 Feb 07 |
jari |
725 |
showClusterInfo(currClusterNum); |
2 |
26 Feb 07 |
jari |
726 |
} |
2 |
26 Feb 07 |
jari |
727 |
} |
2 |
26 Feb 07 |
jari |
728 |
} |
2 |
26 Feb 07 |
jari |
729 |
|
2 |
26 Feb 07 |
jari |
730 |
|
2 |
26 Feb 07 |
jari |
731 |
|
2 |
26 Feb 07 |
jari |
732 |
private boolean maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
733 |
if (!e.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
734 |
return false; |
2 |
26 Feb 07 |
jari |
735 |
} |
2 |
26 Feb 07 |
jari |
736 |
currClusterNum = expViewer.getCurrentCentroidNumber(); |
2 |
26 Feb 07 |
jari |
737 |
setEnableMenuItem(SET_CLUSTER_CMD, currClusterNum != -1); |
2 |
26 Feb 07 |
jari |
738 |
setEnableMenuItem(DELETE_CLUSTER_CMD, currClusterNum != -1 && isClusterSet(currClusterNum)); |
2 |
26 Feb 07 |
jari |
739 |
setEnableMenuItem(DELETE_ALL_CLUSTERS_CMD, !selectedClusterList.isEmpty()); |
2 |
26 Feb 07 |
jari |
740 |
setEnableMenuItem(SAVE_CLUSTER_CMD, currClusterNum != -1); |
2 |
26 Feb 07 |
jari |
741 |
|
2 |
26 Feb 07 |
jari |
742 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
743 |
return true; |
2 |
26 Feb 07 |
jari |
744 |
} |
2 |
26 Feb 07 |
jari |
745 |
} |
2 |
26 Feb 07 |
jari |
746 |
|
2 |
26 Feb 07 |
jari |
747 |
} |