2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, 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: SOTAExperimentTreeViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.9 $ |
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.Node; |
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.cluster.NodeValueList; |
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
42 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
44 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
45 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
46 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLCluster; |
2 |
26 Feb 07 |
jari |
47 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLExperimentHeader; |
2 |
26 Feb 07 |
jari |
48 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTree; |
2 |
26 Feb 07 |
jari |
49 |
import org.tigr.microarray.mev.cluster.gui.impl.hcl.HCLTreeData; |
2 |
26 Feb 07 |
jari |
50 |
import org.tigr.util.FloatMatrix; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
public class SOTAExperimentTreeViewer extends JPanel implements IViewer{ |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
protected static String SET_CLUSTER_CMD = "set-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
56 |
protected static String SET_CLUSTER_TEXT_CMD = "set-cluster-text-cmd"; |
2 |
26 Feb 07 |
jari |
57 |
protected static String SAVE_CLUSTER_CMD = "save-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
58 |
protected static String DELETE_CLUSTER_CMD = "delete-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
59 |
protected static String DELETE_ALL_CLUSTERS_CMD = "delete-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
60 |
protected static String SOTA_TREE_PROPERTIES_CMD = "gene-tree-properties-cmd"; |
2 |
26 Feb 07 |
jari |
61 |
protected static String SAMPLE_TREE_PROPERTIES_CMD = "sample-tree-properties-cmd"; |
2 |
26 Feb 07 |
jari |
62 |
|
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 SOTAExpCentroidExpressionViewer 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 SOTACentroidInfoDialog centroidDialog; |
2 |
26 Feb 07 |
jari |
79 |
private HCLExperimentHeader header; |
2 |
26 Feb 07 |
jari |
80 |
protected HCLTree sampleTree; |
2 |
26 Feb 07 |
jari |
81 |
private int elementHeight; |
2 |
26 Feb 07 |
jari |
82 |
private int elementWidth; |
2 |
26 Feb 07 |
jari |
83 |
private Listener listener; |
2 |
26 Feb 07 |
jari |
84 |
private int function; |
2 |
26 Feb 07 |
jari |
85 |
private int currClusterNum = -1; |
2 |
26 Feb 07 |
jari |
86 |
private DefaultMutableTreeNode expImageNode; |
2 |
26 Feb 07 |
jari |
87 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
//EH |
2 |
26 Feb 07 |
jari |
89 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
90 |
|
2 |
26 Feb 07 |
jari |
91 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a new instance of SOTAExperimentTreeViewer |
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 SOTAExperimentTreeViewer(Experiment experiment, SOTATreeData sotaTreeData, 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 |
clusterPop = sotaTreeData.clusterPopulation; |
2 |
26 Feb 07 |
jari |
103 |
clusterDivFM = sotaTreeData.clusterDiversity; |
2 |
26 Feb 07 |
jari |
104 |
clusterIndices = clusters; |
2 |
26 Feb 07 |
jari |
105 |
function = sotaTreeData.function; |
2 |
26 Feb 07 |
jari |
106 |
numberOfSamples = experiment.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
107 |
numberOfCells = sotaTreeData.clusterPopulation.length; |
2 |
26 Feb 07 |
jari |
108 |
sotaTree = new SOTATree(sotaTreeData, false); |
2 |
26 Feb 07 |
jari |
109 |
if(sotaTree != null) |
2 |
26 Feb 07 |
jari |
110 |
sotaTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
111 |
int [] samplesOrder = null; |
2 |
26 Feb 07 |
jari |
112 |
centroidDialog = null; |
2 |
26 Feb 07 |
jari |
113 |
centroidData = new Experiment(sotaTreeData.centroidMatrix.transpose(), samplesOrder != null ? samplesOrder : getSamplesOrder(numberOfSamples)); |
2 |
26 Feb 07 |
jari |
114 |
numberOfSamples = centroidData.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
115 |
expViewer = new SOTAExpCentroidExpressionViewer( centroidData, experiment, null, samplesOrder, sotaTreeData.clusterPopulation, sotaTreeData.clusterDiversity, selectedClusterList); |
2 |
26 Feb 07 |
jari |
116 |
expViewer.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
117 |
addComponents(sotaTree, expViewer); |
2 |
26 Feb 07 |
jari |
118 |
addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
119 |
popup = this.createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
120 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
121 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
122 |
} |
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
124 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a new instance of SOTAExperimentTreeViewer from xml-saved data |
2 |
26 Feb 07 |
jari |
* written by XMLEncoder/XMLDecoder and IViewerPersistenceDelegate |
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 |
* @deprecated |
2 |
26 Feb 07 |
jari |
132 |
*/ |
2 |
26 Feb 07 |
jari |
133 |
public SOTAExperimentTreeViewer(Integer exptID, SOTATreeData sotaTreeData, |
2 |
26 Feb 07 |
jari |
134 |
int[][] clusterIndices) { |
2 |
26 Feb 07 |
jari |
135 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
136 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
137 |
listener = new Listener(); |
2 |
26 Feb 07 |
jari |
138 |
clusterPop = sotaTreeData.clusterPopulation; |
2 |
26 Feb 07 |
jari |
139 |
clusterDivFM = sotaTreeData.clusterDiversity; |
2 |
26 Feb 07 |
jari |
140 |
this.clusterIndices = clusterIndices; |
2 |
26 Feb 07 |
jari |
141 |
function = sotaTreeData.function; |
2 |
26 Feb 07 |
jari |
142 |
numberOfCells = sotaTreeData.clusterPopulation.length; |
2 |
26 Feb 07 |
jari |
143 |
sotaTree = new SOTATree(sotaTreeData, false); |
2 |
26 Feb 07 |
jari |
144 |
if(sotaTree != null) |
2 |
26 Feb 07 |
jari |
145 |
sotaTree.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
146 |
centroidDialog = null; |
2 |
26 Feb 07 |
jari |
147 |
this.exptID = exptID.intValue(); |
2 |
26 Feb 07 |
jari |
148 |
} |
2 |
26 Feb 07 |
jari |
149 |
|
2 |
26 Feb 07 |
jari |
150 |
public SOTATreeData getSOTATreeData(){return sotaTree.getSotaTreeData();} |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
152 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
153 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
154 |
new Object[]{this.experiment, this.sotaTree.getSotaTreeData(), this.clusterIndices}); |
2 |
26 Feb 07 |
jari |
155 |
} |
2 |
26 Feb 07 |
jari |
156 |
public int getExperimentID(){return exptID;} |
2 |
26 Feb 07 |
jari |
157 |
public void setExperimentID(int e){ |
2 |
26 Feb 07 |
jari |
158 |
exptID = e; |
2 |
26 Feb 07 |
jari |
159 |
expViewer.setExperimentID(e); |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
161 |
public void setExperiment(Experiment e){ |
2 |
26 Feb 07 |
jari |
162 |
experiment = e; |
2 |
26 Feb 07 |
jari |
163 |
exptID = e.getId(); |
2 |
26 Feb 07 |
jari |
164 |
numberOfSamples = experiment.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
165 |
centroidData = new Experiment(sotaTree.getSotaTreeData().centroidMatrix.transpose(), getSamplesOrder(numberOfSamples)); |
2 |
26 Feb 07 |
jari |
166 |
|
2 |
26 Feb 07 |
jari |
167 |
numberOfSamples = centroidData.getNumberOfSamples(); |
2 |
26 Feb 07 |
jari |
168 |
this.expViewer = new SOTAExpCentroidExpressionViewer(centroidData, experiment, null, getSamplesOrder(numberOfSamples), sotaTree.getSotaTreeData().clusterPopulation, sotaTree.getSotaTreeData().clusterDiversity, selectedClusterList); |
2 |
26 Feb 07 |
jari |
169 |
this.expViewer.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
170 |
this.expViewer.setExperiment(e); |
2 |
26 Feb 07 |
jari |
171 |
|
2 |
26 Feb 07 |
jari |
172 |
addComponents(sotaTree, expViewer); |
2 |
26 Feb 07 |
jari |
173 |
addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
174 |
popup = this.createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
} |
2 |
26 Feb 07 |
jari |
177 |
/** |
2 |
26 Feb 07 |
jari |
* sets a node to reference when jumping to expression images |
2 |
26 Feb 07 |
jari |
179 |
*/ |
2 |
26 Feb 07 |
jari |
180 |
public void associateExpressionImageNode(DefaultMutableTreeNode ExpressionImageNode){ |
2 |
26 Feb 07 |
jari |
181 |
expImageNode = ExpressionImageNode; |
2 |
26 Feb 07 |
jari |
182 |
} |
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
184 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a hcl tree data from the specified cluster node. |
2 |
26 Feb 07 |
jari |
186 |
*/ |
2 |
26 Feb 07 |
jari |
187 |
private HCLTreeData getResult(Node clusterNode, int pos) { |
2 |
26 Feb 07 |
jari |
188 |
HCLTreeData data = new HCLTreeData(); |
2 |
26 Feb 07 |
jari |
189 |
NodeValueList valueList = clusterNode.getValues(); |
2 |
26 Feb 07 |
jari |
190 |
data.child_1_array = (int[])valueList.getNodeValue(pos).value; |
2 |
26 Feb 07 |
jari |
191 |
data.child_2_array = (int[])valueList.getNodeValue(pos+1).value; |
2 |
26 Feb 07 |
jari |
192 |
data.node_order = (int[])valueList.getNodeValue(pos+2).value; |
2 |
26 Feb 07 |
jari |
193 |
data.height = (float[])valueList.getNodeValue(pos+3).value; |
2 |
26 Feb 07 |
jari |
194 |
return data; |
2 |
26 Feb 07 |
jari |
195 |
} |
2 |
26 Feb 07 |
jari |
196 |
|
2 |
26 Feb 07 |
jari |
197 |
|
2 |
26 Feb 07 |
jari |
198 |
int [] getSamplesOrder(int numSamples){ |
2 |
26 Feb 07 |
jari |
199 |
int [] order = new int[numSamples]; |
2 |
26 Feb 07 |
jari |
200 |
|
2 |
26 Feb 07 |
jari |
201 |
for(int i = 0; i < numSamples; i++){ |
2 |
26 Feb 07 |
jari |
202 |
order[i] = i; |
2 |
26 Feb 07 |
jari |
203 |
} |
2 |
26 Feb 07 |
jari |
204 |
return order; |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
206 |
|
2 |
26 Feb 07 |
jari |
207 |
|
2 |
26 Feb 07 |
jari |
208 |
protected void addComponents( JComponent sotaTree, JComponent expViewer){// ,JComponent cBar) { |
2 |
26 Feb 07 |
jari |
209 |
|
2 |
26 Feb 07 |
jari |
210 |
if (sotaTree != null) { |
2 |
26 Feb 07 |
jari |
211 |
add(sotaTree, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
212 |
} |
2 |
26 Feb 07 |
jari |
213 |
add(expViewer, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); |
2 |
26 Feb 07 |
jari |
214 |
} |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
/** |
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 |
220 |
*/ |
2 |
26 Feb 07 |
jari |
221 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
222 |
this.sotaTree.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
223 |
this.expViewer.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
224 |
if(sampleTree != null) |
2 |
26 Feb 07 |
jari |
225 |
this.sampleTree.onMenuChanged(menu); |
2 |
26 Feb 07 |
jari |
226 |
verifyClusterExistence(data); |
2 |
26 Feb 07 |
jari |
227 |
|
2 |
26 Feb 07 |
jari |
//this.header.setHeaderPosition(this.sotaTree.getTreeHeight()-10); //move by inset of viewer |
2 |
26 Feb 07 |
jari |
//this.header.updateSize(getCommonWidth()); |
2 |
26 Feb 07 |
jari |
230 |
} |
2 |
26 Feb 07 |
jari |
231 |
|
2 |
26 Feb 07 |
jari |
232 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer was deselected. |
2 |
26 Feb 07 |
jari |
234 |
*/ |
2 |
26 Feb 07 |
jari |
235 |
public void onDeselected() { |
2 |
26 Feb 07 |
jari |
236 |
} |
2 |
26 Feb 07 |
jari |
237 |
|
2 |
26 Feb 07 |
jari |
238 |
|
2 |
26 Feb 07 |
jari |
239 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer is selected. |
2 |
26 Feb 07 |
jari |
241 |
*/ |
2 |
26 Feb 07 |
jari |
242 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
243 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
244 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
245 |
|
2 |
26 Feb 07 |
jari |
246 |
IDisplayMenu menu = framework.getDisplayMenu(); |
2 |
26 Feb 07 |
jari |
247 |
elementSize = menu.getElementSize(); |
2 |
26 Feb 07 |
jari |
248 |
if(this.expViewer.isVisible()) |
2 |
26 Feb 07 |
jari |
249 |
this.expViewer.onSelected(framework); |
2 |
26 Feb 07 |
jari |
250 |
if(sampleTree != null) |
2 |
26 Feb 07 |
jari |
251 |
this.sampleTree.onSelected(framework); |
2 |
26 Feb 07 |
jari |
252 |
this.sotaTree.onSelected(framework); |
2 |
26 Feb 07 |
jari |
253 |
verifyClusterExistence(data); |
2 |
26 Feb 07 |
jari |
254 |
verifyClusterMembership(data); |
2 |
26 Feb 07 |
jari |
255 |
|
2 |
26 Feb 07 |
jari |
//expImageNode is null after de-serialization and must be reset |
2 |
26 Feb 07 |
jari |
257 |
if(this.expImageNode == null){ |
2 |
26 Feb 07 |
jari |
258 |
DefaultMutableTreeNode node = framework.getCurrentNode(); |
2 |
26 Feb 07 |
jari |
259 |
if(node != null) |
2 |
26 Feb 07 |
jari |
260 |
node = (DefaultMutableTreeNode)node.getParent(); |
2 |
26 Feb 07 |
jari |
261 |
if(node != null) |
2 |
26 Feb 07 |
jari |
262 |
node = (DefaultMutableTreeNode)node.getChildAt(1); |
2 |
26 Feb 07 |
jari |
263 |
if(node != null) |
2 |
26 Feb 07 |
jari |
264 |
this.expImageNode = node; |
2 |
26 Feb 07 |
jari |
265 |
} |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
|
2 |
26 Feb 07 |
jari |
268 |
/** |
2 |
26 Feb 07 |
jari |
* Calculate the viewer width. |
2 |
26 Feb 07 |
jari |
270 |
*/ |
2 |
26 Feb 07 |
jari |
271 |
public int getCommonWidth() { |
2 |
26 Feb 07 |
jari |
272 |
int width = 0; |
2 |
26 Feb 07 |
jari |
273 |
if (this.sotaTree != null) { |
2 |
26 Feb 07 |
jari |
274 |
width += this.sotaTree.getTreeHeight(); |
2 |
26 Feb 07 |
jari |
275 |
} |
2 |
26 Feb 07 |
jari |
276 |
|
2 |
26 Feb 07 |
jari |
277 |
width += this.expViewer.getWidth(); |
2 |
26 Feb 07 |
jari |
278 |
|
2 |
26 Feb 07 |
jari |
279 |
return width; |
2 |
26 Feb 07 |
jari |
280 |
} |
2 |
26 Feb 07 |
jari |
281 |
|
2 |
26 Feb 07 |
jari |
282 |
public int getCommonHeight(){ |
2 |
26 Feb 07 |
jari |
283 |
int height = 0; |
2 |
26 Feb 07 |
jari |
284 |
if(this.sotaTree != null){ |
2 |
26 Feb 07 |
jari |
285 |
height += this.sotaTree.getTreeWidth(); |
2 |
26 Feb 07 |
jari |
286 |
} |
2 |
26 Feb 07 |
jari |
287 |
height += this.header.getHeight(); |
2 |
26 Feb 07 |
jari |
288 |
return height; |
2 |
26 Feb 07 |
jari |
289 |
} |
2 |
26 Feb 07 |
jari |
290 |
|
2 |
26 Feb 07 |
jari |
291 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked when the framework is going to be closed. |
2 |
26 Feb 07 |
jari |
293 |
*/ |
2 |
26 Feb 07 |
jari |
294 |
public void onClosed() { |
2 |
26 Feb 07 |
jari |
295 |
} |
2 |
26 Feb 07 |
jari |
296 |
|
2 |
26 Feb 07 |
jari |
297 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane view port. |
2 |
26 Feb 07 |
jari |
299 |
*/ |
2 |
26 Feb 07 |
jari |
300 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
301 |
return this; |
2 |
26 Feb 07 |
jari |
302 |
} |
2 |
26 Feb 07 |
jari |
303 |
|
2 |
26 Feb 07 |
jari |
304 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework to save or to print viewer image. |
2 |
26 Feb 07 |
jari |
306 |
*/ |
2 |
26 Feb 07 |
jari |
307 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
308 |
return null; |
2 |
26 Feb 07 |
jari |
309 |
} |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
311 |
/** |
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 |
315 |
*/ |
2 |
26 Feb 07 |
jari |
316 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
317 |
this.data = data; |
2 |
26 Feb 07 |
jari |
318 |
verifyClusterExistence(data); |
2 |
26 Feb 07 |
jari |
319 |
} |
2 |
26 Feb 07 |
jari |
320 |
|
2 |
26 Feb 07 |
jari |
321 |
|
2 |
26 Feb 07 |
jari |
322 |
private void verifyClusterExistence(IData data){ |
2 |
26 Feb 07 |
jari |
323 |
Color [] colors = data.getExperimentColors(); |
2 |
26 Feb 07 |
jari |
324 |
if(colors.length == 0){ |
2 |
26 Feb 07 |
jari |
325 |
this.selectedClusterList.clear(); |
2 |
26 Feb 07 |
jari |
326 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
327 |
} |
2 |
26 Feb 07 |
jari |
328 |
} |
2 |
26 Feb 07 |
jari |
329 |
|
2 |
26 Feb 07 |
jari |
330 |
private void verifyClusterMembership(IData data){ |
2 |
26 Feb 07 |
jari |
331 |
Color [] colors = data.getExperimentColors(); |
2 |
26 Feb 07 |
jari |
332 |
Color currColor = null; |
2 |
26 Feb 07 |
jari |
333 |
HCLCluster cluster; |
2 |
26 Feb 07 |
jari |
334 |
boolean aMemberChanged = false; |
2 |
26 Feb 07 |
jari |
335 |
boolean membershipChanged = false; |
2 |
26 Feb 07 |
jari |
336 |
boolean [] alteredMembership = new boolean[selectedClusterList.size()]; |
2 |
26 Feb 07 |
jari |
337 |
|
2 |
26 Feb 07 |
jari |
338 |
int index; |
2 |
26 Feb 07 |
jari |
339 |
for(int c = 0; c < this.selectedClusterList.size(); c++){ |
2 |
26 Feb 07 |
jari |
340 |
cluster = (HCLCluster)this.selectedClusterList.get(c); |
2 |
26 Feb 07 |
jari |
341 |
currColor = cluster.color; |
2 |
26 Feb 07 |
jari |
342 |
index = cluster.root; |
2 |
26 Feb 07 |
jari |
343 |
membershipChanged = false; |
2 |
26 Feb 07 |
jari |
344 |
for(int exp = 0; exp < this.clusterIndices[index].length ; exp++){ |
2 |
26 Feb 07 |
jari |
345 |
if(!(currColor.equals(data.getExperimentColor(this.clusterIndices[index][exp])))){ |
2 |
26 Feb 07 |
jari |
346 |
aMemberChanged = true; |
2 |
26 Feb 07 |
jari |
347 |
membershipChanged = true; |
2 |
26 Feb 07 |
jari |
348 |
break; |
2 |
26 Feb 07 |
jari |
349 |
} |
2 |
26 Feb 07 |
jari |
350 |
} |
2 |
26 Feb 07 |
jari |
351 |
if(membershipChanged) |
2 |
26 Feb 07 |
jari |
352 |
alteredMembership[c] = true; |
2 |
26 Feb 07 |
jari |
353 |
} |
2 |
26 Feb 07 |
jari |
354 |
|
2 |
26 Feb 07 |
jari |
355 |
for(int i = selectedClusterList.size()-1; i >=0 ;i--){ |
2 |
26 Feb 07 |
jari |
356 |
if(alteredMembership[i]) |
2 |
26 Feb 07 |
jari |
357 |
selectedClusterList.remove(i); |
2 |
26 Feb 07 |
jari |
358 |
} |
2 |
26 Feb 07 |
jari |
359 |
if(aMemberChanged) |
2 |
26 Feb 07 |
jari |
360 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
361 |
} |
2 |
26 Feb 07 |
jari |
362 |
|
2 |
26 Feb 07 |
jari |
363 |
|
2 |
26 Feb 07 |
jari |
364 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane header. |
2 |
26 Feb 07 |
jari |
366 |
*/ |
2 |
26 Feb 07 |
jari |
367 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
368 |
return this.expViewer.getHeaderComponent(); |
2 |
26 Feb 07 |
jari |
369 |
} |
2 |
26 Feb 07 |
jari |
370 |
|
2 |
26 Feb 07 |
jari |
371 |
|
2 |
26 Feb 07 |
jari |
372 |
private int[] getLeafOrder(HCLTreeData result, int[] indices) { |
2 |
26 Feb 07 |
jari |
373 |
if (result == null || result.node_order.length < 2) { |
2 |
26 Feb 07 |
jari |
374 |
return null; |
2 |
26 Feb 07 |
jari |
375 |
} |
2 |
26 Feb 07 |
jari |
376 |
return getLeafOrder(result.node_order, result.child_1_array, result.child_2_array, indices); |
2 |
26 Feb 07 |
jari |
377 |
} |
2 |
26 Feb 07 |
jari |
378 |
|
2 |
26 Feb 07 |
jari |
379 |
private int[] getLeafOrder(int[] nodeOrder, int[] child1, int[] child2, int[] indices) { |
2 |
26 Feb 07 |
jari |
380 |
int[] leafOrder = new int[nodeOrder.length]; |
2 |
26 Feb 07 |
jari |
381 |
Arrays.fill(leafOrder, -1); |
2 |
26 Feb 07 |
jari |
382 |
|
2 |
26 Feb 07 |
jari |
383 |
fillLeafOrder(leafOrder, child1, child2, 0, child1.length-2, indices); |
2 |
26 Feb 07 |
jari |
384 |
return leafOrder; |
2 |
26 Feb 07 |
jari |
385 |
} |
2 |
26 Feb 07 |
jari |
386 |
|
2 |
26 Feb 07 |
jari |
387 |
private int fillLeafOrder(int[] leafOrder, int[] child1, int[] child2, int pos, int index, int[] indices) { |
2 |
26 Feb 07 |
jari |
388 |
if (child1[index] != -1) { |
2 |
26 Feb 07 |
jari |
389 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child1[index], indices); |
2 |
26 Feb 07 |
jari |
390 |
} |
2 |
26 Feb 07 |
jari |
391 |
if (child2[index] != -1) { |
2 |
26 Feb 07 |
jari |
392 |
pos = fillLeafOrder(leafOrder, child1, child2, pos, child2[index], indices); |
2 |
26 Feb 07 |
jari |
393 |
} else { |
2 |
26 Feb 07 |
jari |
394 |
leafOrder[pos] = indices == null ? index : indices[index]; |
2 |
26 Feb 07 |
jari |
395 |
pos++; |
2 |
26 Feb 07 |
jari |
396 |
} |
2 |
26 Feb 07 |
jari |
397 |
return pos; |
2 |
26 Feb 07 |
jari |
398 |
} |
2 |
26 Feb 07 |
jari |
399 |
|
2 |
26 Feb 07 |
jari |
400 |
private Frame getFrame() { |
2 |
26 Feb 07 |
jari |
401 |
return JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
402 |
} |
2 |
26 Feb 07 |
jari |
403 |
|
2 |
26 Feb 07 |
jari |
404 |
private void setSOTATreeProperties() { |
2 |
26 Feb 07 |
jari |
405 |
Frame frame = JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
406 |
SOTAConfigDialog dialog = new SOTAConfigDialog(frame, 0, sotaTree.getMinDistance(), sotaTree.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
407 |
if (dialog.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
408 |
sotaTree.setProperties(dialog.getZeroThreshold(), dialog.getMinDistance(), dialog.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
409 |
} |
2 |
26 Feb 07 |
jari |
410 |
revalidate(); |
2 |
26 Feb 07 |
jari |
411 |
} |
2 |
26 Feb 07 |
jari |
412 |
|
2 |
26 Feb 07 |
jari |
413 |
public void onSampleTreeProperties() { |
2 |
26 Feb 07 |
jari |
414 |
setTreeProperties(this.sampleTree); |
2 |
26 Feb 07 |
jari |
415 |
revalidate(); |
2 |
26 Feb 07 |
jari |
416 |
} |
2 |
26 Feb 07 |
jari |
417 |
|
2 |
26 Feb 07 |
jari |
418 |
private void setTreeProperties(HCLTree tree) { |
2 |
26 Feb 07 |
jari |
419 |
Frame frame = JOptionPane.getFrameForComponent(this); |
2 |
26 Feb 07 |
jari |
420 |
SOTAConfigDialog dialog = new SOTAConfigDialog(frame, tree.getZeroThreshold(), tree.getMinDistance(), tree.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
421 |
if (dialog.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
422 |
tree.setProperties(dialog.getZeroThreshold(), dialog.getMinDistance(), dialog.getMaxDistance()); |
2 |
26 Feb 07 |
jari |
423 |
} |
2 |
26 Feb 07 |
jari |
424 |
} |
2 |
26 Feb 07 |
jari |
425 |
|
2 |
26 Feb 07 |
jari |
426 |
|
2 |
26 Feb 07 |
jari |
427 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
428 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
429 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
430 |
return popup; |
2 |
26 Feb 07 |
jari |
431 |
} |
2 |
26 Feb 07 |
jari |
432 |
|
2 |
26 Feb 07 |
jari |
433 |
private void showClusterInfo(int clusterNumber){ |
2 |
26 Feb 07 |
jari |
434 |
float neighborDist; |
2 |
26 Feb 07 |
jari |
435 |
int neighbor = getClosestCentroid(clusterNumber); |
2 |
26 Feb 07 |
jari |
436 |
|
2 |
26 Feb 07 |
jari |
437 |
if(neighbor == clusterNumber) return; |
2 |
26 Feb 07 |
jari |
438 |
|
2 |
26 Feb 07 |
jari |
439 |
neighborDist = org.tigr.microarray.mev.cluster.algorithm.impl.ExperimentUtil.geneDistance(centroidData.getMatrix(), |
2 |
26 Feb 07 |
jari |
440 |
null, clusterNumber, neighbor, function, (float)1.0, false); |
2 |
26 Feb 07 |
jari |
441 |
|
2 |
26 Feb 07 |
jari |
//Code to put selected viewer into scroll pane |
2 |
26 Feb 07 |
jari |
443 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode)(expImageNode.getChildAt(clusterNumber)); |
2 |
26 Feb 07 |
jari |
444 |
|
2 |
26 Feb 07 |
jari |
445 |
if(this.framework != null) |
2 |
26 Feb 07 |
jari |
446 |
framework.setTreeNode(node); |
2 |
26 Feb 07 |
jari |
447 |
} |
2 |
26 Feb 07 |
jari |
448 |
|
2 |
26 Feb 07 |
jari |
449 |
|
2 |
26 Feb 07 |
jari |
450 |
|
2 |
26 Feb 07 |
jari |
451 |
private int getClosestCentroid(int centroidNum){ |
2 |
26 Feb 07 |
jari |
452 |
float minDist = Float.POSITIVE_INFINITY; |
2 |
26 Feb 07 |
jari |
453 |
float currDist; |
2 |
26 Feb 07 |
jari |
454 |
int closestCentroid = centroidNum; |
2 |
26 Feb 07 |
jari |
455 |
for(int i = 0; i < this.numberOfCells ;i++){ |
2 |
26 Feb 07 |
jari |
456 |
currDist = org.tigr.microarray.mev.cluster.algorithm.impl.ExperimentUtil.geneDistance(centroidData.getMatrix(), |
2 |
26 Feb 07 |
jari |
457 |
null, centroidNum, i, function, (float)1.0 , false); |
2 |
26 Feb 07 |
jari |
458 |
|
2 |
26 Feb 07 |
jari |
459 |
if(currDist < minDist && i != centroidNum){ |
2 |
26 Feb 07 |
jari |
460 |
minDist = currDist; |
2 |
26 Feb 07 |
jari |
461 |
closestCentroid = i; |
2 |
26 Feb 07 |
jari |
462 |
} |
2 |
26 Feb 07 |
jari |
463 |
} |
2 |
26 Feb 07 |
jari |
464 |
return closestCentroid; |
2 |
26 Feb 07 |
jari |
465 |
} |
2 |
26 Feb 07 |
jari |
466 |
|
2 |
26 Feb 07 |
jari |
467 |
|
2 |
26 Feb 07 |
jari |
468 |
private void onSaveCluster(int cNum){ |
2 |
26 Feb 07 |
jari |
469 |
try { |
2 |
26 Feb 07 |
jari |
470 |
org.tigr.microarray.mev.cluster.gui.helpers.ExperimentUtil.saveExperimentCluster(getFrame(), this.experiment, this.data, clusterIndices[cNum]); |
2 |
26 Feb 07 |
jari |
471 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
472 |
JOptionPane.showMessageDialog(getFrame(), "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
473 |
e.printStackTrace(); |
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 |
* Sets cluster color |
2 |
26 Feb 07 |
jari |
479 |
*/ |
2 |
26 Feb 07 |
jari |
480 |
private void onSetCluster(int currCluster){ |
2 |
26 Feb 07 |
jari |
481 |
|
2 |
26 Feb 07 |
jari |
482 |
Color newColor = JColorChooser.showDialog(getFrame(), "Choose color", new Color(128, 128, 128)); |
2 |
26 Feb 07 |
jari |
483 |
if (newColor == null || currCluster == -1) { |
2 |
26 Feb 07 |
jari |
484 |
return; |
2 |
26 Feb 07 |
jari |
485 |
} |
2 |
26 Feb 07 |
jari |
486 |
HCLCluster cluster = new HCLCluster(currCluster, currCluster-1, currCluster+1); |
2 |
26 Feb 07 |
jari |
487 |
selectedClusterList.add(cluster); |
2 |
26 Feb 07 |
jari |
488 |
cluster.color = newColor; |
2 |
26 Feb 07 |
jari |
489 |
revalidate(); |
2 |
26 Feb 07 |
jari |
// this.expViewer.setClusterColor(newColor); |
2 |
26 Feb 07 |
jari |
491 |
this.data.setExperimentColor( getIDataRowIndices(clusterIndices[currCluster]), newColor); |
2 |
26 Feb 07 |
jari |
492 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
493 |
repaint(); |
2 |
26 Feb 07 |
jari |
494 |
} |
2 |
26 Feb 07 |
jari |
495 |
|
2 |
26 Feb 07 |
jari |
496 |
/** |
2 |
26 Feb 07 |
jari |
* Converts cluster indicies from the experiment to IData rows which could be different |
2 |
26 Feb 07 |
jari |
498 |
*/ |
2 |
26 Feb 07 |
jari |
499 |
private int [] getIDataRowIndices(int [] expIndices){ |
2 |
26 Feb 07 |
jari |
500 |
int [] dataIndices = new int[expIndices.length]; |
2 |
26 Feb 07 |
jari |
501 |
for(int i = 0; i < expIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
502 |
dataIndices[i] = experiment.getGeneIndexMappedToData(expIndices[i]); |
2 |
26 Feb 07 |
jari |
503 |
} |
2 |
26 Feb 07 |
jari |
504 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
505 |
} |
2 |
26 Feb 07 |
jari |
506 |
|
2 |
26 Feb 07 |
jari |
507 |
/** |
2 |
26 Feb 07 |
jari |
* Deletes indicated cluster |
2 |
26 Feb 07 |
jari |
509 |
*/ |
2 |
26 Feb 07 |
jari |
510 |
private void onDeleteCluster(int clusterIndex){ |
2 |
26 Feb 07 |
jari |
511 |
HCLCluster currCluster; |
2 |
26 Feb 07 |
jari |
512 |
|
2 |
26 Feb 07 |
jari |
513 |
for(int i = 0; i < selectedClusterList.size(); i++){ |
2 |
26 Feb 07 |
jari |
514 |
currCluster = (HCLCluster)selectedClusterList.get(i); |
2 |
26 Feb 07 |
jari |
515 |
if(currCluster.root == clusterIndex){ |
2 |
26 Feb 07 |
jari |
516 |
this.data.setExperimentColor( clusterIndices[clusterIndex], null); |
2 |
26 Feb 07 |
jari |
517 |
selectedClusterList.remove(i); |
2 |
26 Feb 07 |
jari |
518 |
} |
2 |
26 Feb 07 |
jari |
519 |
} |
2 |
26 Feb 07 |
jari |
520 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
521 |
repaint(); |
2 |
26 Feb 07 |
jari |
522 |
} |
2 |
26 Feb 07 |
jari |
523 |
|
2 |
26 Feb 07 |
jari |
524 |
/** |
2 |
26 Feb 07 |
jari |
* Clears cluster colors |
2 |
26 Feb 07 |
jari |
526 |
*/ |
2 |
26 Feb 07 |
jari |
527 |
private void onDeleteAllClusters(){ |
2 |
26 Feb 07 |
jari |
528 |
selectedClusterList.clear(); |
2 |
26 Feb 07 |
jari |
529 |
this.data.deleteExperimentColors(); |
2 |
26 Feb 07 |
jari |
530 |
this.expViewer.onDataChanged(data); |
2 |
26 Feb 07 |
jari |
531 |
repaint(); |
2 |
26 Feb 07 |
jari |
532 |
} |
2 |
26 Feb 07 |
jari |
533 |
|
2 |
26 Feb 07 |
jari |
534 |
|
2 |
26 Feb 07 |
jari |
535 |
/** |
2 |
26 Feb 07 |
jari |
* Adds menu items to the specified popup menu. |
2 |
26 Feb 07 |
jari |
537 |
*/ |
2 |
26 Feb 07 |
jari |
538 |
protected void addMenuItems(JPopupMenu menu, Listener listener) { |
2 |
26 Feb 07 |
jari |
539 |
|
2 |
26 Feb 07 |
jari |
540 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
541 |
|
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 |
547 |
|
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 |
553 |
|
2 |
26 Feb 07 |
jari |
554 |
menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
555 |
menuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
556 |
menuItem.setActionCommand(SAVE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
557 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
558 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
559 |
|
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 |
565 |
|
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 |
571 |
|
2 |
26 Feb 07 |
jari |
572 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
573 |
|
2 |
26 Feb 07 |
jari |
574 |
menuItem = new JMenuItem("SOTATree properties...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
575 |
menuItem.setEnabled(this.sotaTree != null); |
2 |
26 Feb 07 |
jari |
576 |
menuItem.setActionCommand(SOTA_TREE_PROPERTIES_CMD); |
2 |
26 Feb 07 |
jari |
577 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
578 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
579 |
|
2 |
26 Feb 07 |
jari |
580 |
menuItem = new JMenuItem("SampleTree properties...", GUIFactory.getIcon("edit16.gif")); |
2 |
26 Feb 07 |
jari |
581 |
menuItem.setEnabled(this.sampleTree != null); |
2 |
26 Feb 07 |
jari |
582 |
menuItem.setActionCommand(SAMPLE_TREE_PROPERTIES_CMD); |
2 |
26 Feb 07 |
jari |
583 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
584 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
585 |
} |
2 |
26 Feb 07 |
jari |
586 |
|
2 |
26 Feb 07 |
jari |
587 |
|
2 |
26 Feb 07 |
jari |
588 |
/** |
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 |
591 |
*/ |
2 |
26 Feb 07 |
jari |
592 |
protected JMenuItem getJMenuItem(String command) { |
2 |
26 Feb 07 |
jari |
593 |
JMenuItem item; |
2 |
26 Feb 07 |
jari |
594 |
Component[] components = popup.getComponents(); |
2 |
26 Feb 07 |
jari |
595 |
for (int i=0; i<components.length; i++) { |
2 |
26 Feb 07 |
jari |
596 |
if (components[i] instanceof JMenuItem) { |
2 |
26 Feb 07 |
jari |
597 |
if (((JMenuItem)components[i]).getActionCommand().equals(command)) |
2 |
26 Feb 07 |
jari |
598 |
return(JMenuItem)components[i]; |
2 |
26 Feb 07 |
jari |
599 |
} |
2 |
26 Feb 07 |
jari |
600 |
} |
2 |
26 Feb 07 |
jari |
601 |
return null; |
2 |
26 Feb 07 |
jari |
602 |
} |
2 |
26 Feb 07 |
jari |
603 |
|
2 |
26 Feb 07 |
jari |
604 |
/** |
2 |
26 Feb 07 |
jari |
* Sets menu enabled flag. |
2 |
26 Feb 07 |
jari |
606 |
*/ |
2 |
26 Feb 07 |
jari |
607 |
protected void setEnableMenuItem(String command, boolean enable) { |
2 |
26 Feb 07 |
jari |
608 |
JMenuItem item = getJMenuItem(command); |
2 |
26 Feb 07 |
jari |
609 |
if (item == null) { |
2 |
26 Feb 07 |
jari |
610 |
return; |
2 |
26 Feb 07 |
jari |
611 |
} |
2 |
26 Feb 07 |
jari |
612 |
item.setEnabled(enable); |
2 |
26 Feb 07 |
jari |
613 |
} |
2 |
26 Feb 07 |
jari |
614 |
|
2 |
26 Feb 07 |
jari |
615 |
private boolean isClusterSet(int clusterIndex){ |
2 |
26 Feb 07 |
jari |
616 |
HCLCluster currCluster; |
2 |
26 Feb 07 |
jari |
617 |
|
2 |
26 Feb 07 |
jari |
618 |
for(int i = 0; i < selectedClusterList.size(); i++){ |
2 |
26 Feb 07 |
jari |
619 |
currCluster = (HCLCluster)selectedClusterList.get(i); |
2 |
26 Feb 07 |
jari |
620 |
if(currCluster.root == clusterIndex) |
2 |
26 Feb 07 |
jari |
621 |
return true; |
2 |
26 Feb 07 |
jari |
622 |
} |
2 |
26 Feb 07 |
jari |
623 |
return false; |
2 |
26 Feb 07 |
jari |
624 |
} |
2 |
26 Feb 07 |
jari |
625 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
627 |
*/ |
2 |
26 Feb 07 |
jari |
628 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
629 |
return null; |
2 |
26 Feb 07 |
jari |
630 |
} |
2 |
26 Feb 07 |
jari |
631 |
|
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 |
634 |
*/ |
2 |
26 Feb 07 |
jari |
635 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
636 |
return null; |
2 |
26 Feb 07 |
jari |
637 |
} |
2 |
26 Feb 07 |
jari |
638 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's clusters or null |
2 |
26 Feb 07 |
jari |
640 |
*/ |
2 |
26 Feb 07 |
jari |
641 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
642 |
return null; |
2 |
26 Feb 07 |
jari |
643 |
} |
2 |
26 Feb 07 |
jari |
644 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's experiment or null |
2 |
26 Feb 07 |
jari |
646 |
*/ |
2 |
26 Feb 07 |
jari |
647 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
648 |
return null; |
2 |
26 Feb 07 |
jari |
649 |
} |
2 |
26 Feb 07 |
jari |
650 |
|
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 |
653 |
*/ |
2 |
26 Feb 07 |
jari |
654 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
655 |
return -1; |
2 |
26 Feb 07 |
jari |
656 |
} |
2 |
26 Feb 07 |
jari |
657 |
|
2 |
26 Feb 07 |
jari |
658 |
private class Listener extends MouseAdapter implements ActionListener{ |
2 |
26 Feb 07 |
jari |
659 |
|
2 |
26 Feb 07 |
jari |
660 |
public void actionPerformed(java.awt.event.ActionEvent actionEvent) { |
2 |
26 Feb 07 |
jari |
661 |
String actionCmd = actionEvent.getActionCommand(); |
2 |
26 Feb 07 |
jari |
662 |
if(actionCmd.equals(SOTAExperimentTreeViewer.SOTA_TREE_PROPERTIES_CMD)){ |
2 |
26 Feb 07 |
jari |
663 |
setSOTATreeProperties(); |
2 |
26 Feb 07 |
jari |
664 |
} |
2 |
26 Feb 07 |
jari |
665 |
/* |
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 |
668 |
} |
2 |
26 Feb 07 |
jari |
669 |
*/ |
2 |
26 Feb 07 |
jari |
670 |
else if(actionCmd.equals(SOTAExperimentTreeViewer.SET_CLUSTER_CMD)){ |
2 |
26 Feb 07 |
jari |
671 |
if(currClusterNum != -1) |
2 |
26 Feb 07 |
jari |
672 |
onSetCluster(currClusterNum); |
2 |
26 Feb 07 |
jari |
673 |
} |
2 |
26 Feb 07 |
jari |
674 |
else if(actionCmd.equals(SOTAExperimentTreeViewer.SAVE_CLUSTER_CMD)){ |
2 |
26 Feb 07 |
jari |
675 |
if(currClusterNum != -1) |
2 |
26 Feb 07 |
jari |
676 |
onSaveCluster(currClusterNum); |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
else if(actionCmd.equals(SOTAExperimentTreeViewer.DELETE_CLUSTER_CMD)){ |
2 |
26 Feb 07 |
jari |
679 |
if(currClusterNum != -1) |
2 |
26 Feb 07 |
jari |
680 |
onDeleteCluster(currClusterNum); |
2 |
26 Feb 07 |
jari |
681 |
} |
2 |
26 Feb 07 |
jari |
682 |
|
2 |
26 Feb 07 |
jari |
683 |
else if(actionCmd.equals(SOTAExperimentTreeViewer.DELETE_ALL_CLUSTERS_CMD)){ |
2 |
26 Feb 07 |
jari |
684 |
onDeleteAllClusters(); |
2 |
26 Feb 07 |
jari |
685 |
} |
2 |
26 Feb 07 |
jari |
686 |
} |
2 |
26 Feb 07 |
jari |
687 |
|
2 |
26 Feb 07 |
jari |
688 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
689 |
|
2 |
26 Feb 07 |
jari |
690 |
if(!maybeShowPopup(event) && SwingUtilities.isLeftMouseButton(event)){ |
2 |
26 Feb 07 |
jari |
691 |
currClusterNum = expViewer.getCurrentCentroidNumber(); |
2 |
26 Feb 07 |
jari |
692 |
|
2 |
26 Feb 07 |
jari |
693 |
if(currClusterNum != -1){ |
2 |
26 Feb 07 |
jari |
694 |
showClusterInfo(currClusterNum); |
2 |
26 Feb 07 |
jari |
695 |
} |
2 |
26 Feb 07 |
jari |
696 |
} |
2 |
26 Feb 07 |
jari |
697 |
} |
2 |
26 Feb 07 |
jari |
698 |
|
2 |
26 Feb 07 |
jari |
699 |
|
2 |
26 Feb 07 |
jari |
700 |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
701 |
|
2 |
26 Feb 07 |
jari |
702 |
if(!maybeShowPopup(event) && SwingUtilities.isLeftMouseButton(event)){ |
2 |
26 Feb 07 |
jari |
703 |
currClusterNum = expViewer.getCurrentCentroidNumber(); |
2 |
26 Feb 07 |
jari |
704 |
|
2 |
26 Feb 07 |
jari |
705 |
if(currClusterNum != -1){ |
2 |
26 Feb 07 |
jari |
706 |
showClusterInfo(currClusterNum); |
2 |
26 Feb 07 |
jari |
707 |
} |
2 |
26 Feb 07 |
jari |
708 |
} |
2 |
26 Feb 07 |
jari |
709 |
} |
2 |
26 Feb 07 |
jari |
710 |
|
2 |
26 Feb 07 |
jari |
711 |
|
2 |
26 Feb 07 |
jari |
712 |
|
2 |
26 Feb 07 |
jari |
713 |
private boolean maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
714 |
if (!e.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
715 |
return false; |
2 |
26 Feb 07 |
jari |
716 |
} |
2 |
26 Feb 07 |
jari |
717 |
currClusterNum = expViewer.getCurrentCentroidNumber(); |
2 |
26 Feb 07 |
jari |
718 |
setEnableMenuItem(SET_CLUSTER_CMD, currClusterNum != -1); |
2 |
26 Feb 07 |
jari |
719 |
setEnableMenuItem(DELETE_CLUSTER_CMD, currClusterNum != -1 && isClusterSet(currClusterNum)); |
2 |
26 Feb 07 |
jari |
720 |
setEnableMenuItem(DELETE_ALL_CLUSTERS_CMD, !selectedClusterList.isEmpty()); |
2 |
26 Feb 07 |
jari |
721 |
setEnableMenuItem(SAVE_CLUSTER_CMD, currClusterNum != -1); |
2 |
26 Feb 07 |
jari |
722 |
|
2 |
26 Feb 07 |
jari |
723 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
724 |
return true; |
2 |
26 Feb 07 |
jari |
725 |
} |
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 |
} |