2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2005, 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 |
* ExperimentClusterTableViewer.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
* Created on April 26, 2004, 1:59 PM |
2 |
26 Feb 07 |
jari |
9 |
*/ |
2 |
26 Feb 07 |
jari |
10 |
|
2 |
26 Feb 07 |
jari |
11 |
package org.tigr.microarray.mev.cluster.gui.helpers; |
2 |
26 Feb 07 |
jari |
12 |
|
2 |
26 Feb 07 |
jari |
13 |
import java.awt.*; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.event.*; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
16 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
17 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
18 |
|
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.*; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JTable; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.border.Border; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.table.*; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.clusterUtil.*; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.util.QSort; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
/** |
2 |
26 Feb 07 |
jari |
39 |
* |
2 |
26 Feb 07 |
jari |
* @author nbhagaba |
2 |
26 Feb 07 |
jari |
41 |
*/ |
2 |
26 Feb 07 |
jari |
42 |
public class ExperimentClusterTableViewer implements IViewer { |
2 |
26 Feb 07 |
jari |
43 |
|
2 |
26 Feb 07 |
jari |
44 |
private static final String NO_GENES_STR = "No Genes in Cluster!"; |
2 |
26 Feb 07 |
jari |
45 |
private static final Font ERROR_FONT = new Font("monospaced", Font.BOLD, 20); |
2 |
26 Feb 07 |
jari |
46 |
protected static final String STORE_CLUSTER_CMD = "store-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
47 |
protected static final String STORE_SELECTED_ROWS_CMD = "store-selected-rows-cmd"; |
2 |
26 Feb 07 |
jari |
48 |
protected static final String SET_DEF_COLOR_CMD = "set-def-color-cmd"; |
2 |
26 Feb 07 |
jari |
49 |
protected static final String SAVE_CLUSTER_CMD = "save-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
50 |
protected static final String SAVE_ALL_CLUSTERS_CMD = "save-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
51 |
protected static final String LAUNCH_NEW_SESSION_CMD = "launch-new-session-cmd"; |
2 |
26 Feb 07 |
jari |
52 |
protected static final String LAUNCH_NEW_SESSION_WITH_SEL_ROWS_CMD = "launch-new-session-with-sel-rows-cmd"; |
2 |
26 Feb 07 |
jari |
53 |
protected static final String SEARCH_CMD = "search-cmd"; |
2 |
26 Feb 07 |
jari |
54 |
protected static final String CLEAR_ALL_CMD = "clear-all-cmd"; |
2 |
26 Feb 07 |
jari |
55 |
protected static final String SELECT_ALL_CMD = "select-all-cmd"; |
2 |
26 Feb 07 |
jari |
56 |
protected static final String SORT_ORIG_ORDER_CMD = "sort-orig-order-cmd"; |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
public static final int INTEGER_TYPE = 10; |
2 |
26 Feb 07 |
jari |
59 |
public static final int FLOAT_TYPE = 11; |
2 |
26 Feb 07 |
jari |
60 |
public static final int DOUBLE_TYPE = 12; |
2 |
26 Feb 07 |
jari |
61 |
public static final int STRING_TYPE = 13; |
2 |
26 Feb 07 |
jari |
62 |
public static final int BOOLEAN_TYPE = 14; |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
private JComponent header; |
2 |
26 Feb 07 |
jari |
65 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
66 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
67 |
private IFramework framework; |
2 |
26 Feb 07 |
jari |
68 |
private IData data; |
2 |
26 Feb 07 |
jari |
69 |
private int clusterIndex; |
2 |
26 Feb 07 |
jari |
70 |
private int[][] clusters; |
2 |
26 Feb 07 |
jari |
71 |
private int[][] sortedClusters; |
2 |
26 Feb 07 |
jari |
//private int[] samplesOrder; |
2 |
26 Feb 07 |
jari |
73 |
private String[] auxTitles;//, fieldNames; |
2 |
26 Feb 07 |
jari |
74 |
private Object[][] auxData; |
2 |
26 Feb 07 |
jari |
//private Object[][] origData; |
2 |
26 Feb 07 |
jari |
76 |
private boolean[][] sortedAscending; |
2 |
26 Feb 07 |
jari |
77 |
private JTable clusterTable; |
2 |
26 Feb 07 |
jari |
78 |
private ExperimentClusterTableModel clusterModel; |
2 |
26 Feb 07 |
jari |
79 |
private ClusterTableSearchDialog searchDialog; |
2 |
26 Feb 07 |
jari |
80 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
// public String[] getAuxTitles() {return auxTitles;} |
2 |
26 Feb 07 |
jari |
// public Object[][] getAuxData() {return auxData;} |
2 |
26 Feb 07 |
jari |
// public int[][] getSortedClusters() {return sortedClusters;} |
2 |
26 Feb 07 |
jari |
85 |
public int getExptID() {return exptID;} |
2 |
26 Feb 07 |
jari |
86 |
/** |
2 |
26 Feb 07 |
jari |
* This constructor creates a new object identical to the one saved to the |
2 |
26 Feb 07 |
jari |
* xml file by XMLEncoder and IViewerPersistenceDelegate |
2 |
26 Feb 07 |
jari |
89 |
* |
2 |
26 Feb 07 |
jari |
* @param clusters |
2 |
26 Feb 07 |
jari |
* @param auxTitles |
2 |
26 Feb 07 |
jari |
* @param auxData |
2 |
26 Feb 07 |
jari |
* @param sortedClusters |
2 |
26 Feb 07 |
jari |
* @param exptID |
2 |
26 Feb 07 |
jari |
95 |
|
2 |
26 Feb 07 |
jari |
public ExperimentClusterTableViewer(int[][] clusters, String[] auxTitles, |
2 |
26 Feb 07 |
jari |
Object[][] auxData, int[][] sortedClusters, Integer exptID) { |
2 |
26 Feb 07 |
jari |
this.clusters = clusters; |
2 |
26 Feb 07 |
jari |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
this.sortedClusters = sortedClusters; |
2 |
26 Feb 07 |
jari |
this.exptID = exptID.intValue(); |
2 |
26 Feb 07 |
jari |
103 |
|
2 |
26 Feb 07 |
jari |
this.clusterModel = new ExperimentClusterTableModel(); |
2 |
26 Feb 07 |
jari |
this.clusterTable = new JTable(clusterModel); |
2 |
26 Feb 07 |
jari |
clusterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); |
2 |
26 Feb 07 |
jari |
TableColumn column = null; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < clusterModel.getColumnCount(); i++) { |
2 |
26 Feb 07 |
jari |
column = clusterTable.getColumnModel().getColumn(i); |
2 |
26 Feb 07 |
jari |
column.setMinWidth(30); |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
this.sortedAscending = new boolean[clusters.length][clusterModel.getColumnCount()]; |
2 |
26 Feb 07 |
jari |
for (int i = 0; i < sortedAscending.length; i++) { |
2 |
26 Feb 07 |
jari |
for (int j = 0; j < sortedAscending[i].length; j++) { |
2 |
26 Feb 07 |
jari |
sortedAscending[i][j] = false; |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
addMouseListenerToHeaderInTable(clusterTable); |
2 |
26 Feb 07 |
jari |
header = clusterTable.getTableHeader(); |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
searchDialog = new ClusterTableSearchDialog(JOptionPane.getFrameForComponent(clusterTable), clusterTable, false); |
2 |
26 Feb 07 |
jari |
setMaxWidth(getContentComponent(), getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
//getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
clusterTable.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
}*/ |
2 |
26 Feb 07 |
jari |
//EH testing |
2 |
26 Feb 07 |
jari |
132 |
/** |
2 |
26 Feb 07 |
jari |
* @inheritdoc |
2 |
26 Feb 07 |
jari |
134 |
*/ |
2 |
26 Feb 07 |
jari |
135 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
136 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
// new Object[]{clusters, auxTitles, auxData, this.sortedClusters, new Integer(this.exptID)}); |
2 |
26 Feb 07 |
jari |
138 |
new Object[]{experiment, clusters, data, auxTitles, auxData}); |
2 |
26 Feb 07 |
jari |
139 |
} |
2 |
26 Feb 07 |
jari |
140 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of ExperimentClusterTableViewer */ |
2 |
26 Feb 07 |
jari |
142 |
public ExperimentClusterTableViewer(Experiment experiment, int[][] clusters, IData data, String[] auxTitles, Object[][] auxData) { |
2 |
26 Feb 07 |
jari |
143 |
if (experiment == null) { |
2 |
26 Feb 07 |
jari |
144 |
throw new IllegalArgumentException("experiment == null"); |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
// this.data = data; |
2 |
26 Feb 07 |
jari |
147 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
148 |
this.clusters = clusters; |
2 |
26 Feb 07 |
jari |
//this.fieldNames = data.getFieldNames(); |
2 |
26 Feb 07 |
jari |
150 |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
151 |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
152 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
this.sortedClusters = new int[clusters.length][]; |
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
156 |
for (int i = 0; i < sortedClusters.length; i++) { |
2 |
26 Feb 07 |
jari |
157 |
sortedClusters[i] = new int[clusters[i].length]; |
2 |
26 Feb 07 |
jari |
158 |
} |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
for (int i = 0; i < sortedClusters.length; i++) { |
2 |
26 Feb 07 |
jari |
161 |
for (int j = 0; j < sortedClusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
162 |
sortedClusters[i][j] = clusters[i][j]; |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
} |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
this.clusterModel = new ExperimentClusterTableModel(); |
2 |
26 Feb 07 |
jari |
167 |
this.clusterTable = new JTable(clusterModel); |
2 |
26 Feb 07 |
jari |
168 |
clusterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); |
2 |
26 Feb 07 |
jari |
169 |
TableColumn column = null; |
2 |
26 Feb 07 |
jari |
170 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) { |
2 |
26 Feb 07 |
jari |
171 |
column = clusterTable.getColumnModel().getColumn(i); |
2 |
26 Feb 07 |
jari |
172 |
column.setMinWidth(30); |
2 |
26 Feb 07 |
jari |
173 |
} |
2 |
26 Feb 07 |
jari |
174 |
|
2 |
26 Feb 07 |
jari |
175 |
this.sortedAscending = new boolean[clusters.length][clusterModel.getColumnCount()]; |
2 |
26 Feb 07 |
jari |
176 |
for (int i = 0; i < sortedAscending.length; i++) { |
2 |
26 Feb 07 |
jari |
177 |
for (int j = 0; j < sortedAscending[i].length; j++) { |
2 |
26 Feb 07 |
jari |
178 |
sortedAscending[i][j] = false; |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
addMouseListenerToHeaderInTable(clusterTable); |
2 |
26 Feb 07 |
jari |
182 |
header = clusterTable.getTableHeader(); |
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
184 |
searchDialog = new ClusterTableSearchDialog(JOptionPane.getFrameForComponent(clusterTable), clusterTable, false); |
2 |
26 Feb 07 |
jari |
185 |
setMaxWidth(getContentComponent(), getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
186 |
|
2 |
26 Feb 07 |
jari |
187 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
188 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
//getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
190 |
clusterTable.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
|
2 |
26 Feb 07 |
jari |
193 |
public ExperimentClusterTableViewer(Experiment experiment, int[][] clusters, IData data) { |
2 |
26 Feb 07 |
jari |
194 |
this(experiment, clusters, data, new String[0], new Object[0][0]); |
2 |
26 Feb 07 |
jari |
195 |
} |
2 |
26 Feb 07 |
jari |
196 |
|
2 |
26 Feb 07 |
jari |
197 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into scroll pane view port. |
2 |
26 Feb 07 |
jari |
199 |
*/ |
2 |
26 Feb 07 |
jari |
200 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
201 |
|
2 |
26 Feb 07 |
jari |
202 |
JPanel panel = new JPanel(); |
2 |
26 Feb 07 |
jari |
203 |
panel.setBackground(Color.gray); |
2 |
26 Feb 07 |
jari |
204 |
GridBagConstraints constraints = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
205 |
GridBagLayout gridbag = new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
206 |
panel.setLayout(gridbag); |
2 |
26 Feb 07 |
jari |
207 |
constraints.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
208 |
constraints.anchor = GridBagConstraints.NORTH; |
2 |
26 Feb 07 |
jari |
209 |
|
2 |
26 Feb 07 |
jari |
//clusterTable.addMouseListener(new Listener()); |
2 |
26 Feb 07 |
jari |
211 |
|
2 |
26 Feb 07 |
jari |
212 |
buildConstraints(constraints, 0, 0, 1, 1, 100, 100); |
2 |
26 Feb 07 |
jari |
213 |
gridbag.setConstraints(clusterTable, constraints); |
2 |
26 Feb 07 |
jari |
214 |
|
2 |
26 Feb 07 |
jari |
215 |
panel.add(clusterTable); |
2 |
26 Feb 07 |
jari |
//panel.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
217 |
return panel; |
2 |
26 Feb 07 |
jari |
218 |
} |
2 |
26 Feb 07 |
jari |
219 |
|
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 |
222 |
*/ |
2 |
26 Feb 07 |
jari |
223 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
224 |
return null; |
2 |
26 Feb 07 |
jari |
225 |
} |
2 |
26 Feb 07 |
jari |
226 |
|
2 |
26 Feb 07 |
jari |
227 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into scroll pane header. |
2 |
26 Feb 07 |
jari |
229 |
*/ |
2 |
26 Feb 07 |
jari |
230 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
231 |
JPanel panel = new JPanel(); |
2 |
26 Feb 07 |
jari |
232 |
panel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
233 |
GridBagConstraints constraints = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
234 |
GridBagLayout gridbag = new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
235 |
panel.setLayout(gridbag); |
2 |
26 Feb 07 |
jari |
236 |
constraints.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
237 |
buildConstraints(constraints, 0, 0, 1, 1, 100, 100); |
2 |
26 Feb 07 |
jari |
238 |
gridbag.setConstraints(header, constraints); |
2 |
26 Feb 07 |
jari |
239 |
panel.add(header); |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
241 |
return panel; |
2 |
26 Feb 07 |
jari |
242 |
} |
2 |
26 Feb 07 |
jari |
243 |
|
2 |
26 Feb 07 |
jari |
244 |
void buildConstraints(GridBagConstraints gbc, int gx, int gy, |
2 |
26 Feb 07 |
jari |
245 |
int gw, int gh, int wx, int wy) { |
2 |
26 Feb 07 |
jari |
246 |
|
2 |
26 Feb 07 |
jari |
247 |
gbc.gridx = gx; |
2 |
26 Feb 07 |
jari |
248 |
gbc.gridy = gy; |
2 |
26 Feb 07 |
jari |
249 |
gbc.gridwidth = gw; |
2 |
26 Feb 07 |
jari |
250 |
gbc.gridheight = gh; |
2 |
26 Feb 07 |
jari |
251 |
gbc.weightx = wx; |
2 |
26 Feb 07 |
jari |
252 |
gbc.weighty = wy; |
2 |
26 Feb 07 |
jari |
253 |
} |
2 |
26 Feb 07 |
jari |
254 |
|
2 |
26 Feb 07 |
jari |
/** Invoked by the framework to save or to print viewer image. |
2 |
26 Feb 07 |
jari |
256 |
*/ |
2 |
26 Feb 07 |
jari |
257 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
258 |
return null; |
2 |
26 Feb 07 |
jari |
259 |
} |
2 |
26 Feb 07 |
jari |
260 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
262 |
*/ |
2 |
26 Feb 07 |
jari |
263 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
264 |
return null; |
2 |
26 Feb 07 |
jari |
265 |
} |
2 |
26 Feb 07 |
jari |
266 |
|
2 |
26 Feb 07 |
jari |
/** Invoked when the framework is going to be closed. |
2 |
26 Feb 07 |
jari |
268 |
*/ |
2 |
26 Feb 07 |
jari |
269 |
public void onClosed() { |
2 |
26 Feb 07 |
jari |
270 |
} |
2 |
26 Feb 07 |
jari |
271 |
|
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 |
275 |
*/ |
2 |
26 Feb 07 |
jari |
276 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
277 |
this.data = data; |
2 |
26 Feb 07 |
jari |
278 |
} |
2 |
26 Feb 07 |
jari |
279 |
|
2 |
26 Feb 07 |
jari |
/** Invoked by the framework when this viewer was deselected. |
2 |
26 Feb 07 |
jari |
281 |
*/ |
2 |
26 Feb 07 |
jari |
282 |
public void onDeselected() { |
2 |
26 Feb 07 |
jari |
283 |
} |
2 |
26 Feb 07 |
jari |
284 |
|
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 |
288 |
*/ |
2 |
26 Feb 07 |
jari |
289 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
290 |
} |
2 |
26 Feb 07 |
jari |
291 |
|
2 |
26 Feb 07 |
jari |
/** Invoked by the framework when this viewer is selected. |
2 |
26 Feb 07 |
jari |
293 |
*/ |
2 |
26 Feb 07 |
jari |
294 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
295 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
296 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
297 |
IDisplayMenu menu = framework.getDisplayMenu(); |
2 |
26 Feb 07 |
jari |
298 |
Integer userObject = (Integer)framework.getUserObject(); |
2 |
26 Feb 07 |
jari |
299 |
setClusterIndex(userObject == null ? 0 : userObject.intValue()); |
2 |
26 Feb 07 |
jari |
300 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
301 |
} |
2 |
26 Feb 07 |
jari |
302 |
|
2 |
26 Feb 07 |
jari |
303 |
/** |
2 |
26 Feb 07 |
jari |
* Sets cluster index to be displayed. |
2 |
26 Feb 07 |
jari |
305 |
*/ |
2 |
26 Feb 07 |
jari |
306 |
|
2 |
26 Feb 07 |
jari |
307 |
public void setClusterIndex(int clusterIndex) { |
2 |
26 Feb 07 |
jari |
308 |
this.clusterIndex = clusterIndex; |
2 |
26 Feb 07 |
jari |
309 |
} |
2 |
26 Feb 07 |
jari |
310 |
|
2 |
26 Feb 07 |
jari |
311 |
/** |
2 |
26 Feb 07 |
jari |
* Returns index of current cluster. |
2 |
26 Feb 07 |
jari |
313 |
*/ |
2 |
26 Feb 07 |
jari |
314 |
|
2 |
26 Feb 07 |
jari |
315 |
public int getClusterIndex() { |
2 |
26 Feb 07 |
jari |
316 |
return clusterIndex; |
2 |
26 Feb 07 |
jari |
317 |
} |
2 |
26 Feb 07 |
jari |
318 |
|
2 |
26 Feb 07 |
jari |
319 |
/** |
2 |
26 Feb 07 |
jari |
* Returns indices of current cluster. |
2 |
26 Feb 07 |
jari |
321 |
*/ |
2 |
26 Feb 07 |
jari |
322 |
public int[] getCluster() { |
2 |
26 Feb 07 |
jari |
323 |
return clusters[this.clusterIndex]; |
2 |
26 Feb 07 |
jari |
324 |
} |
2 |
26 Feb 07 |
jari |
325 |
|
2 |
26 Feb 07 |
jari |
326 |
/** |
2 |
26 Feb 07 |
jari |
* Returns all the clusters. |
2 |
26 Feb 07 |
jari |
328 |
*/ |
2 |
26 Feb 07 |
jari |
329 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
330 |
return clusters; |
2 |
26 Feb 07 |
jari |
331 |
} |
2 |
26 Feb 07 |
jari |
332 |
|
2 |
26 Feb 07 |
jari |
333 |
public int[] getSortedCluster() { |
2 |
26 Feb 07 |
jari |
334 |
return sortedClusters[this.clusterIndex]; |
2 |
26 Feb 07 |
jari |
335 |
} |
2 |
26 Feb 07 |
jari |
336 |
|
2 |
26 Feb 07 |
jari |
337 |
/** |
2 |
26 Feb 07 |
jari |
* Returns index of a gene in the current cluster. |
2 |
26 Feb 07 |
jari |
339 |
*/ |
2 |
26 Feb 07 |
jari |
340 |
protected int getProbe(int row) { |
2 |
26 Feb 07 |
jari |
341 |
return this.experiment.getGeneIndexMappedToData(row); |
2 |
26 Feb 07 |
jari |
342 |
} |
2 |
26 Feb 07 |
jari |
343 |
|
2 |
26 Feb 07 |
jari |
344 |
/** |
2 |
26 Feb 07 |
jari |
* Returns wrapped experiment. |
2 |
26 Feb 07 |
jari |
346 |
*/ |
2 |
26 Feb 07 |
jari |
347 |
|
2 |
26 Feb 07 |
jari |
348 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
349 |
return experiment; |
2 |
26 Feb 07 |
jari |
350 |
} |
2 |
26 Feb 07 |
jari |
351 |
|
2 |
26 Feb 07 |
jari |
352 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the data. |
2 |
26 Feb 07 |
jari |
354 |
*/ |
2 |
26 Feb 07 |
jari |
355 |
public IData getData() { |
2 |
26 Feb 07 |
jari |
356 |
return data; |
2 |
26 Feb 07 |
jari |
357 |
} |
2 |
26 Feb 07 |
jari |
358 |
|
2 |
26 Feb 07 |
jari |
359 |
class ExperimentClusterTableModel extends AbstractTableModel { |
2 |
26 Feb 07 |
jari |
360 |
String[] columnNames; |
2 |
26 Feb 07 |
jari |
361 |
|
2 |
26 Feb 07 |
jari |
362 |
public ExperimentClusterTableModel() { |
2 |
26 Feb 07 |
jari |
363 |
columnNames = new String[2 + auxTitles.length]; |
2 |
26 Feb 07 |
jari |
//int counter; |
2 |
26 Feb 07 |
jari |
365 |
columnNames[0] = "Stored Color"; |
2 |
26 Feb 07 |
jari |
366 |
columnNames[1] = "Sample Name"; |
2 |
26 Feb 07 |
jari |
367 |
for (int i = 2; i < columnNames.length; i++) { |
2 |
26 Feb 07 |
jari |
368 |
columnNames[i] = auxTitles[i - 2]; |
2 |
26 Feb 07 |
jari |
369 |
} |
2 |
26 Feb 07 |
jari |
370 |
} |
2 |
26 Feb 07 |
jari |
371 |
|
2 |
26 Feb 07 |
jari |
372 |
public int getColumnCount() { |
2 |
26 Feb 07 |
jari |
373 |
return columnNames.length; |
2 |
26 Feb 07 |
jari |
374 |
} |
2 |
26 Feb 07 |
jari |
375 |
|
2 |
26 Feb 07 |
jari |
376 |
public int getRowCount() { |
2 |
26 Feb 07 |
jari |
377 |
return getCluster().length; |
2 |
26 Feb 07 |
jari |
378 |
} |
2 |
26 Feb 07 |
jari |
379 |
|
2 |
26 Feb 07 |
jari |
380 |
public String getColumnName(int col) { |
2 |
26 Feb 07 |
jari |
381 |
return columnNames[col]; |
2 |
26 Feb 07 |
jari |
382 |
} |
2 |
26 Feb 07 |
jari |
383 |
|
2 |
26 Feb 07 |
jari |
384 |
public Object getValueAt(int row, int col) { |
2 |
26 Feb 07 |
jari |
385 |
if (col == 0) { |
2 |
26 Feb 07 |
jari |
386 |
return data.getExperimentColor(getSortedCluster()[row]) == null? Color.white : data.getExperimentColor(getSortedCluster()[row]); |
2 |
26 Feb 07 |
jari |
387 |
} else if (col == 1) { |
2 |
26 Feb 07 |
jari |
388 |
return data.getFullSampleName(experiment.getSampleIndex(getSortedCluster()[row])); |
2 |
26 Feb 07 |
jari |
389 |
} else { |
2 |
26 Feb 07 |
jari |
390 |
return String.valueOf(auxData[getSortedCluster()[row]][col - 2]); |
2 |
26 Feb 07 |
jari |
391 |
} |
2 |
26 Feb 07 |
jari |
392 |
} |
2 |
26 Feb 07 |
jari |
393 |
|
2 |
26 Feb 07 |
jari |
394 |
public Class getColumnClass(int c) { |
2 |
26 Feb 07 |
jari |
395 |
return getValueAt(0, c).getClass(); |
2 |
26 Feb 07 |
jari |
396 |
} |
2 |
26 Feb 07 |
jari |
397 |
} |
2 |
26 Feb 07 |
jari |
398 |
|
2 |
26 Feb 07 |
jari |
399 |
|
2 |
26 Feb 07 |
jari |
400 |
private int[] reverse(int[] arr) { |
2 |
26 Feb 07 |
jari |
401 |
int[] revArr = new int[arr.length]; |
2 |
26 Feb 07 |
jari |
402 |
int revCount = 0; |
2 |
26 Feb 07 |
jari |
403 |
int count = arr.length - 1; |
2 |
26 Feb 07 |
jari |
404 |
for (int i=0; i < arr.length; i++) { |
2 |
26 Feb 07 |
jari |
405 |
revArr[revCount] = arr[count]; |
2 |
26 Feb 07 |
jari |
406 |
revCount++; |
2 |
26 Feb 07 |
jari |
407 |
count--; |
2 |
26 Feb 07 |
jari |
408 |
} |
2 |
26 Feb 07 |
jari |
409 |
return revArr; |
2 |
26 Feb 07 |
jari |
410 |
} |
2 |
26 Feb 07 |
jari |
411 |
|
2 |
26 Feb 07 |
jari |
412 |
public void addMouseListenerToHeaderInTable(JTable table) { |
2 |
26 Feb 07 |
jari |
//final TableSorter sorter = this; |
2 |
26 Feb 07 |
jari |
414 |
final JTable tableView = table; |
2 |
26 Feb 07 |
jari |
415 |
tableView.setColumnSelectionAllowed(false); |
2 |
26 Feb 07 |
jari |
416 |
MouseAdapter listMouseListener = new MouseAdapter() { |
2 |
26 Feb 07 |
jari |
417 |
public void mouseClicked(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
418 |
TableColumnModel columnModel = tableView.getColumnModel(); |
2 |
26 Feb 07 |
jari |
419 |
int viewColumn = columnModel.getColumnIndexAtX(e.getX()); |
2 |
26 Feb 07 |
jari |
420 |
int column = tableView.convertColumnIndexToModel(viewColumn); |
2 |
26 Feb 07 |
jari |
421 |
if (e.getClickCount() == 1 && column != -1) { |
2 |
26 Feb 07 |
jari |
422 |
int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; |
2 |
26 Feb 07 |
jari |
423 |
int controlPressed = e.getModifiers()&InputEvent.CTRL_MASK; |
2 |
26 Feb 07 |
jari |
424 |
boolean originalOrder = (controlPressed != 0); |
2 |
26 Feb 07 |
jari |
425 |
sortByColumn(column, !(sortedAscending[getClusterIndex()][column]), originalOrder); |
2 |
26 Feb 07 |
jari |
426 |
sortedAscending[getClusterIndex()][column] = !(sortedAscending[getClusterIndex()][column]); |
2 |
26 Feb 07 |
jari |
427 |
if (originalOrder) { |
2 |
26 Feb 07 |
jari |
428 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) |
2 |
26 Feb 07 |
jari |
429 |
sortedAscending[getClusterIndex()][i] = false; |
2 |
26 Feb 07 |
jari |
430 |
} |
2 |
26 Feb 07 |
jari |
431 |
} |
2 |
26 Feb 07 |
jari |
//tableView.repaint(); |
2 |
26 Feb 07 |
jari |
433 |
} |
2 |
26 Feb 07 |
jari |
434 |
}; |
2 |
26 Feb 07 |
jari |
435 |
JTableHeader th = tableView.getTableHeader(); |
2 |
26 Feb 07 |
jari |
//tableView.repaint(); |
2 |
26 Feb 07 |
jari |
437 |
th.addMouseListener(listMouseListener); |
2 |
26 Feb 07 |
jari |
438 |
} |
2 |
26 Feb 07 |
jari |
439 |
|
2 |
26 Feb 07 |
jari |
440 |
public void sortByColumn(int column, boolean ascending, boolean originalOrder) { |
2 |
26 Feb 07 |
jari |
441 |
if (originalOrder) { |
2 |
26 Feb 07 |
jari |
442 |
for (int i = 0; i < getSortedCluster().length; i++) { |
2 |
26 Feb 07 |
jari |
443 |
sortedClusters[this.clusterIndex][i] = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
444 |
} |
2 |
26 Feb 07 |
jari |
445 |
|
2 |
26 Feb 07 |
jari |
446 |
clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
447 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
448 |
return; |
2 |
26 Feb 07 |
jari |
449 |
} |
2 |
26 Feb 07 |
jari |
450 |
|
2 |
26 Feb 07 |
jari |
451 |
int[] sortedIndices = new int[getCluster().length]; |
2 |
26 Feb 07 |
jari |
452 |
if (column == 0) { |
2 |
26 Feb 07 |
jari |
453 |
double[] origArray = new double[getCluster().length]; |
2 |
26 Feb 07 |
jari |
454 |
for (int i = 0; i < origArray.length; i++) { |
2 |
26 Feb 07 |
jari |
455 |
Color currColor = data.getExperimentColor(getCluster()[i]) == null? Color.white : data.getExperimentColor(getCluster()[i]); |
2 |
26 Feb 07 |
jari |
456 |
origArray[i] = (double)(currColor.getRGB()); |
2 |
26 Feb 07 |
jari |
457 |
} |
2 |
26 Feb 07 |
jari |
458 |
QSort sortArray = new QSort(origArray); |
2 |
26 Feb 07 |
jari |
459 |
int[] sortedPrimaryIndices = sortArray.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
460 |
for (int i = 0; i < sortedPrimaryIndices.length; i++) { |
2 |
26 Feb 07 |
jari |
461 |
sortedIndices[i] = getCluster()[sortedPrimaryIndices[i]]; |
2 |
26 Feb 07 |
jari |
462 |
} |
2 |
26 Feb 07 |
jari |
463 |
|
2 |
26 Feb 07 |
jari |
464 |
} else if (column == 1) { |
2 |
26 Feb 07 |
jari |
465 |
SortableField[] sortFields = new SortableField[getCluster().length]; |
2 |
26 Feb 07 |
jari |
466 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
467 |
int currIndex = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
//String currField = data.getElementAttribute(experiment.getGeneIndexMappedToData(getCluster()[i]), column - 1); |
2 |
26 Feb 07 |
jari |
469 |
String currField = data.getFullSampleName(experiment.getSampleIndex(getCluster()[i])); |
2 |
26 Feb 07 |
jari |
470 |
sortFields[i] = new SortableField(currIndex, currField); |
2 |
26 Feb 07 |
jari |
471 |
} |
2 |
26 Feb 07 |
jari |
472 |
|
2 |
26 Feb 07 |
jari |
473 |
Arrays.sort(sortFields); |
2 |
26 Feb 07 |
jari |
474 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
475 |
sortedIndices[i] = sortFields[i].getIndex(); |
2 |
26 Feb 07 |
jari |
476 |
} |
2 |
26 Feb 07 |
jari |
477 |
|
2 |
26 Feb 07 |
jari |
478 |
} else { |
2 |
26 Feb 07 |
jari |
479 |
int obType = getObjectType(auxData[0][column - 2]); |
2 |
26 Feb 07 |
jari |
480 |
if ((obType == ExperimentUtil.DOUBLE_TYPE) || (obType == ExperimentUtil.FLOAT_TYPE) || (obType == ExperimentUtil.INTEGER_TYPE)) { |
2 |
26 Feb 07 |
jari |
481 |
double[] origArray = new double[getCluster().length]; |
2 |
26 Feb 07 |
jari |
482 |
for (int i = 0; i < origArray.length; i++) { |
2 |
26 Feb 07 |
jari |
483 |
if (obType == ExperimentUtil.DOUBLE_TYPE) { |
2 |
26 Feb 07 |
jari |
484 |
origArray[i] = ((Double)(auxData[getCluster()[i]][column - 2])).doubleValue(); |
2 |
26 Feb 07 |
jari |
485 |
} else if (obType == ExperimentUtil.FLOAT_TYPE) { |
2 |
26 Feb 07 |
jari |
486 |
origArray[i] = ((Float)(auxData[getCluster()[i]][column - 2])).doubleValue(); |
2 |
26 Feb 07 |
jari |
487 |
} else if (obType == ExperimentUtil.INTEGER_TYPE) { |
2 |
26 Feb 07 |
jari |
488 |
origArray[i] = ((Integer)(auxData[getCluster()[i]][column - 2])).doubleValue(); |
2 |
26 Feb 07 |
jari |
489 |
} |
2 |
26 Feb 07 |
jari |
490 |
} |
2 |
26 Feb 07 |
jari |
491 |
QSort sortArray = new QSort(origArray); |
2 |
26 Feb 07 |
jari |
492 |
int[] sortedPrimaryIndices = sortArray.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
493 |
for (int i = 0; i < sortedPrimaryIndices.length; i++) { |
2 |
26 Feb 07 |
jari |
494 |
sortedIndices[i] = getCluster()[sortedPrimaryIndices[i]]; |
2 |
26 Feb 07 |
jari |
495 |
} |
2 |
26 Feb 07 |
jari |
496 |
} else if (obType == ExperimentUtil.BOOLEAN_TYPE) { |
2 |
26 Feb 07 |
jari |
497 |
SortableField[] sortFields = new SortableField[getCluster().length]; |
2 |
26 Feb 07 |
jari |
498 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
499 |
int currIndex = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
500 |
String currField = ((Boolean)(auxData[getCluster()[i]][column - 2])).toString(); |
2 |
26 Feb 07 |
jari |
501 |
sortFields[i] = new SortableField(currIndex, currField); |
2 |
26 Feb 07 |
jari |
502 |
} |
2 |
26 Feb 07 |
jari |
503 |
|
2 |
26 Feb 07 |
jari |
504 |
Arrays.sort(sortFields); |
2 |
26 Feb 07 |
jari |
505 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
506 |
sortedIndices[i] = sortFields[i].getIndex(); |
2 |
26 Feb 07 |
jari |
507 |
} |
2 |
26 Feb 07 |
jari |
508 |
|
2 |
26 Feb 07 |
jari |
509 |
} else if (obType == ExperimentUtil.STRING_TYPE) { |
2 |
26 Feb 07 |
jari |
510 |
SortableField[] sortFields = new SortableField[getCluster().length]; |
2 |
26 Feb 07 |
jari |
511 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
512 |
int currIndex = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
513 |
String currField = (String)(auxData[getCluster()[i]][column - 2]); |
2 |
26 Feb 07 |
jari |
514 |
sortFields[i] = new SortableField(currIndex, currField); |
2 |
26 Feb 07 |
jari |
515 |
} |
2 |
26 Feb 07 |
jari |
516 |
|
2 |
26 Feb 07 |
jari |
517 |
Arrays.sort(sortFields); |
2 |
26 Feb 07 |
jari |
518 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
519 |
sortedIndices[i] = sortFields[i].getIndex(); |
2 |
26 Feb 07 |
jari |
520 |
} |
2 |
26 Feb 07 |
jari |
521 |
} |
2 |
26 Feb 07 |
jari |
522 |
} |
2 |
26 Feb 07 |
jari |
523 |
|
2 |
26 Feb 07 |
jari |
524 |
if (!ascending) { |
2 |
26 Feb 07 |
jari |
525 |
sortedIndices = reverse(sortedIndices); |
2 |
26 Feb 07 |
jari |
526 |
} |
2 |
26 Feb 07 |
jari |
527 |
|
2 |
26 Feb 07 |
jari |
528 |
for (int i = 0; i < getSortedCluster().length; i++) { |
2 |
26 Feb 07 |
jari |
529 |
sortedClusters[this.clusterIndex][i] = sortedIndices[i]; |
2 |
26 Feb 07 |
jari |
530 |
} |
2 |
26 Feb 07 |
jari |
531 |
clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
532 |
clusterTable.removeRowSelectionInterval(0, clusterTable.getRowCount() - 1); |
2 |
26 Feb 07 |
jari |
533 |
} |
2 |
26 Feb 07 |
jari |
534 |
|
2 |
26 Feb 07 |
jari |
535 |
|
2 |
26 Feb 07 |
jari |
536 |
private class SortableField implements Comparable { |
2 |
26 Feb 07 |
jari |
537 |
private String field; |
2 |
26 Feb 07 |
jari |
538 |
private int index; |
2 |
26 Feb 07 |
jari |
539 |
|
2 |
26 Feb 07 |
jari |
540 |
SortableField(int index, String field) { |
2 |
26 Feb 07 |
jari |
541 |
this.index = index; |
2 |
26 Feb 07 |
jari |
542 |
this.field = field; |
2 |
26 Feb 07 |
jari |
//System.out.println("SortableField[" + index + "][" + column + "]: index = " + index + ", field = " + field); |
2 |
26 Feb 07 |
jari |
544 |
} |
2 |
26 Feb 07 |
jari |
545 |
|
2 |
26 Feb 07 |
jari |
546 |
public int compareTo(Object other) { |
2 |
26 Feb 07 |
jari |
547 |
SortableField otherField = (SortableField)other; |
2 |
26 Feb 07 |
jari |
548 |
return this.field.compareTo(otherField.getField()); |
2 |
26 Feb 07 |
jari |
549 |
} |
2 |
26 Feb 07 |
jari |
550 |
|
2 |
26 Feb 07 |
jari |
551 |
public int getIndex() { |
2 |
26 Feb 07 |
jari |
552 |
return this.index; |
2 |
26 Feb 07 |
jari |
553 |
} |
2 |
26 Feb 07 |
jari |
554 |
public String getField() { |
2 |
26 Feb 07 |
jari |
555 |
return this.field; |
2 |
26 Feb 07 |
jari |
556 |
} |
2 |
26 Feb 07 |
jari |
557 |
} |
2 |
26 Feb 07 |
jari |
558 |
|
2 |
26 Feb 07 |
jari |
559 |
|
2 |
26 Feb 07 |
jari |
560 |
private static int[] getTypes (Object[][] objData) { |
2 |
26 Feb 07 |
jari |
561 |
int[] types = new int[objData[0].length]; |
2 |
26 Feb 07 |
jari |
562 |
for (int i = 0; i < types.length; i++) { |
2 |
26 Feb 07 |
jari |
563 |
types[i] = getObjectType(objData[0][i]); |
2 |
26 Feb 07 |
jari |
//Object |
2 |
26 Feb 07 |
jari |
565 |
} |
2 |
26 Feb 07 |
jari |
566 |
return types; |
2 |
26 Feb 07 |
jari |
567 |
} |
2 |
26 Feb 07 |
jari |
568 |
|
2 |
26 Feb 07 |
jari |
569 |
private static int getObjectType(Object obj) { |
2 |
26 Feb 07 |
jari |
570 |
int obType = -1; |
2 |
26 Feb 07 |
jari |
571 |
if (obj instanceof Boolean) { |
2 |
26 Feb 07 |
jari |
572 |
return ExperimentUtil.BOOLEAN_TYPE; |
2 |
26 Feb 07 |
jari |
573 |
} else if (obj instanceof Double) { |
2 |
26 Feb 07 |
jari |
574 |
return ExperimentUtil.DOUBLE_TYPE; |
2 |
26 Feb 07 |
jari |
575 |
} else if (obj instanceof Float) { |
2 |
26 Feb 07 |
jari |
576 |
return ExperimentUtil.FLOAT_TYPE; |
2 |
26 Feb 07 |
jari |
577 |
} else if (obj instanceof Integer) { |
2 |
26 Feb 07 |
jari |
578 |
return ExperimentUtil.INTEGER_TYPE; |
2 |
26 Feb 07 |
jari |
579 |
} else if (obj instanceof String) { |
2 |
26 Feb 07 |
jari |
580 |
return ExperimentUtil.STRING_TYPE; |
2 |
26 Feb 07 |
jari |
581 |
} else { |
2 |
26 Feb 07 |
jari |
582 |
return obType; |
2 |
26 Feb 07 |
jari |
583 |
} |
2 |
26 Feb 07 |
jari |
584 |
} |
2 |
26 Feb 07 |
jari |
585 |
|
2 |
26 Feb 07 |
jari |
586 |
private void searchTable(){ |
2 |
26 Feb 07 |
jari |
587 |
|
2 |
26 Feb 07 |
jari |
588 |
searchDialog.setVisible(true); |
2 |
26 Feb 07 |
jari |
589 |
searchDialog.toFront(); |
2 |
26 Feb 07 |
jari |
//searchDialog.requestFocus(); |
2 |
26 Feb 07 |
jari |
591 |
searchDialog.setLocation(clusterTable.getLocation().x + 100, clusterTable.getLocation().y +100); |
2 |
26 Feb 07 |
jari |
592 |
|
2 |
26 Feb 07 |
jari |
593 |
} |
2 |
26 Feb 07 |
jari |
594 |
|
2 |
26 Feb 07 |
jari |
595 |
/** |
2 |
26 Feb 07 |
jari |
* Synchronize content and header sizes. |
2 |
26 Feb 07 |
jari |
597 |
*/ |
2 |
26 Feb 07 |
jari |
598 |
private void setMaxWidth(JComponent content, JComponent header) { |
2 |
26 Feb 07 |
jari |
599 |
int c_width = content.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
600 |
int h_width = header.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
601 |
if (c_width > h_width) { |
2 |
26 Feb 07 |
jari |
602 |
header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
603 |
} else { |
2 |
26 Feb 07 |
jari |
604 |
content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
605 |
} |
2 |
26 Feb 07 |
jari |
606 |
} |
2 |
26 Feb 07 |
jari |
607 |
|
2 |
26 Feb 07 |
jari |
608 |
/** |
2 |
26 Feb 07 |
jari |
* Sets public color for the current cluster. |
2 |
26 Feb 07 |
jari |
610 |
*/ |
2 |
26 Feb 07 |
jari |
611 |
|
2 |
26 Feb 07 |
jari |
612 |
/* |
2 |
26 Feb 07 |
jari |
public void setClusterColor(Color color) { |
2 |
26 Feb 07 |
jari |
if(color ==null){ //indicates removal of cluster |
2 |
26 Feb 07 |
jari |
framework.removeCluster(getCluster(), experiment, ClusterRepository.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
616 |
} |
2 |
26 Feb 07 |
jari |
617 |
} |
2 |
26 Feb 07 |
jari |
618 |
*/ |
2 |
26 Feb 07 |
jari |
619 |
|
2 |
26 Feb 07 |
jari |
620 |
/** |
2 |
26 Feb 07 |
jari |
* Sets public color for the current cluster. |
2 |
26 Feb 07 |
jari |
622 |
*/ |
2 |
26 Feb 07 |
jari |
623 |
|
2 |
26 Feb 07 |
jari |
624 |
public void setClusterColor(Color color) { |
2 |
26 Feb 07 |
jari |
625 |
if(color ==null){ //indicates removal of cluster |
2 |
26 Feb 07 |
jari |
//framework.removeCluster(getArrayMappedToData(), experiment, ClusterRepository.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
627 |
boolean success = framework.removeSubCluster(getArrayMappedToSelectedIndices(), experiment, ClusterRepository.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
628 |
if (!success) { |
2 |
26 Feb 07 |
jari |
629 |
JOptionPane.showMessageDialog(null, "Cluster not deleted! Selected rows must exactly correspond to a cluster created in the current algorithm run", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
630 |
} |
2 |
26 Feb 07 |
jari |
631 |
} |
2 |
26 Feb 07 |
jari |
632 |
} |
2 |
26 Feb 07 |
jari |
633 |
|
2 |
26 Feb 07 |
jari |
634 |
/** |
2 |
26 Feb 07 |
jari |
* Sets cluster color |
2 |
26 Feb 07 |
jari |
636 |
*/ |
2 |
26 Feb 07 |
jari |
637 |
public void storeCluster(){ |
2 |
26 Feb 07 |
jari |
638 |
framework.storeCluster(getCluster(), experiment, ClusterRepository.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
639 |
onDataChanged(this.data); |
2 |
26 Feb 07 |
jari |
640 |
} |
2 |
26 Feb 07 |
jari |
641 |
|
2 |
26 Feb 07 |
jari |
642 |
public void storeSelectedRowsAsCluster() { |
2 |
26 Feb 07 |
jari |
643 |
if (getArrayMappedToSelectedIndices().length == 0) { |
2 |
26 Feb 07 |
jari |
644 |
JOptionPane.showMessageDialog(null, "No rows selected! Cluster will not be saved", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
645 |
} else { |
2 |
26 Feb 07 |
jari |
646 |
framework.storeSubCluster(getArrayMappedToSelectedIndices(), experiment, ClusterRepository.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
647 |
onDataChanged(this.data); |
2 |
26 Feb 07 |
jari |
648 |
} |
2 |
26 Feb 07 |
jari |
649 |
} |
2 |
26 Feb 07 |
jari |
650 |
|
2 |
26 Feb 07 |
jari |
651 |
/** |
2 |
26 Feb 07 |
jari |
* Launches a new <code>MultipleExperimentViewer</code> containing the current cluster |
2 |
26 Feb 07 |
jari |
653 |
*/ |
2 |
26 Feb 07 |
jari |
654 |
public void launchNewSession(){ |
2 |
26 Feb 07 |
jari |
655 |
framework.launchNewMAV(getCluster(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
656 |
} |
2 |
26 Feb 07 |
jari |
657 |
|
2 |
26 Feb 07 |
jari |
658 |
public void launchNewSessionWithSelectedRows() { |
2 |
26 Feb 07 |
jari |
659 |
framework.launchNewMAV(getArrayMappedToSelectedIndices(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.EXPERIMENT_CLUSTER); |
2 |
26 Feb 07 |
jari |
660 |
} |
2 |
26 Feb 07 |
jari |
661 |
|
2 |
26 Feb 07 |
jari |
662 |
public void sortInOrigOrder() { |
2 |
26 Feb 07 |
jari |
663 |
for (int i = 0; i < getSortedCluster().length; i++) { |
2 |
26 Feb 07 |
jari |
664 |
sortedClusters[this.clusterIndex][i] = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
665 |
} |
2 |
26 Feb 07 |
jari |
666 |
|
2 |
26 Feb 07 |
jari |
667 |
clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
668 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
669 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) |
2 |
26 Feb 07 |
jari |
670 |
sortedAscending[getClusterIndex()][i] = false; |
2 |
26 Feb 07 |
jari |
671 |
} |
2 |
26 Feb 07 |
jari |
672 |
|
2 |
26 Feb 07 |
jari |
673 |
/* |
2 |
26 Feb 07 |
jari |
private int [] getArrayMappedToData(){ |
2 |
26 Feb 07 |
jari |
int [] clusterIndices = getCluster(); |
2 |
26 Feb 07 |
jari |
if( clusterIndices == null || clusterIndices.length < 1) |
2 |
26 Feb 07 |
jari |
return clusterIndices; |
2 |
26 Feb 07 |
jari |
678 |
|
2 |
26 Feb 07 |
jari |
int [] dataIndices = new int [clusterIndices.length]; |
2 |
26 Feb 07 |
jari |
for(int i = 0; i < clusterIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
dataIndices[i] = this.experiment.getGeneIndexMappedToData(clusterIndices[i]); |
2 |
26 Feb 07 |
jari |
682 |
} |
2 |
26 Feb 07 |
jari |
return dataIndices; |
2 |
26 Feb 07 |
jari |
684 |
} |
2 |
26 Feb 07 |
jari |
685 |
*/ |
2 |
26 Feb 07 |
jari |
686 |
|
2 |
26 Feb 07 |
jari |
687 |
private int[] getArrayMappedToSelectedIndices() { |
2 |
26 Feb 07 |
jari |
688 |
int[] selectedRows = clusterTable.getSelectedRows(); |
2 |
26 Feb 07 |
jari |
689 |
if ((selectedRows == null) || (selectedRows.length == 0)) { |
2 |
26 Feb 07 |
jari |
690 |
return new int[0]; |
2 |
26 Feb 07 |
jari |
691 |
} |
2 |
26 Feb 07 |
jari |
692 |
|
2 |
26 Feb 07 |
jari |
693 |
int[] dataIndices = new int[selectedRows.length]; |
2 |
26 Feb 07 |
jari |
694 |
for (int i = 0; i < dataIndices.length; i++) { |
2 |
26 Feb 07 |
jari |
695 |
dataIndices[i] = getSortedCluster()[selectedRows[i]]; |
2 |
26 Feb 07 |
jari |
696 |
} |
2 |
26 Feb 07 |
jari |
697 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
698 |
} |
2 |
26 Feb 07 |
jari |
699 |
|
2 |
26 Feb 07 |
jari |
700 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
702 |
*/ |
2 |
26 Feb 07 |
jari |
703 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
704 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
705 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
706 |
return popup; |
2 |
26 Feb 07 |
jari |
707 |
} |
2 |
26 Feb 07 |
jari |
708 |
|
2 |
26 Feb 07 |
jari |
709 |
protected void addMenuItems(JPopupMenu menu, ActionListener listener) { |
2 |
26 Feb 07 |
jari |
710 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
711 |
menuItem = new JMenuItem("Store entire cluster", GUIFactory.getIcon("new16.gif")); |
2 |
26 Feb 07 |
jari |
712 |
menuItem.setActionCommand(STORE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
713 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
714 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
715 |
|
2 |
26 Feb 07 |
jari |
//menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
717 |
|
2 |
26 Feb 07 |
jari |
718 |
menuItem = new JMenuItem("Store selected rows as cluster", GUIFactory.getIcon("new16.gif")); |
2 |
26 Feb 07 |
jari |
719 |
menuItem.setActionCommand(STORE_SELECTED_ROWS_CMD); |
2 |
26 Feb 07 |
jari |
720 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
721 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
722 |
|
2 |
26 Feb 07 |
jari |
723 |
menuItem = new JMenuItem("Delete cluster composed of selected rows", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
724 |
menuItem.setActionCommand(SET_DEF_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
725 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
726 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
727 |
|
2 |
26 Feb 07 |
jari |
728 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
729 |
|
2 |
26 Feb 07 |
jari |
730 |
menuItem = new JMenuItem("Launch new session with entire cluster", GUIFactory.getIcon("launch_new_mav.gif")); |
2 |
26 Feb 07 |
jari |
731 |
menuItem.setActionCommand(LAUNCH_NEW_SESSION_CMD); |
2 |
26 Feb 07 |
jari |
732 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
733 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
734 |
|
2 |
26 Feb 07 |
jari |
//menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
736 |
|
2 |
26 Feb 07 |
jari |
737 |
menuItem = new JMenuItem("Launch new session with selected rows", GUIFactory.getIcon("launch_new_mav.gif")); |
2 |
26 Feb 07 |
jari |
738 |
menuItem.setActionCommand(LAUNCH_NEW_SESSION_WITH_SEL_ROWS_CMD); |
2 |
26 Feb 07 |
jari |
739 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
740 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
741 |
|
2 |
26 Feb 07 |
jari |
//menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
743 |
|
2 |
26 Feb 07 |
jari |
744 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
745 |
|
2 |
26 Feb 07 |
jari |
746 |
|
2 |
26 Feb 07 |
jari |
747 |
menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
748 |
menuItem.setActionCommand(SAVE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
749 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
750 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
751 |
|
2 |
26 Feb 07 |
jari |
752 |
menuItem = new JMenuItem("Save all clusters...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
753 |
menuItem.setActionCommand(SAVE_ALL_CLUSTERS_CMD); |
2 |
26 Feb 07 |
jari |
754 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
755 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
756 |
|
2 |
26 Feb 07 |
jari |
757 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
758 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
759 |
|
2 |
26 Feb 07 |
jari |
760 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
761 |
|
2 |
26 Feb 07 |
jari |
762 |
menuItem = new JMenuItem("Search...", GUIFactory.getIcon("ClusterInformationResult.gif")); |
2 |
26 Feb 07 |
jari |
763 |
menuItem.setActionCommand(SEARCH_CMD); |
2 |
26 Feb 07 |
jari |
764 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
765 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
766 |
|
2 |
26 Feb 07 |
jari |
767 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
768 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
769 |
|
2 |
26 Feb 07 |
jari |
770 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
771 |
|
2 |
26 Feb 07 |
jari |
772 |
menuItem = new JMenuItem("Select all rows...", GUIFactory.getIcon("TableViewerResult.gif")); |
2 |
26 Feb 07 |
jari |
773 |
menuItem.setActionCommand(SELECT_ALL_CMD); |
2 |
26 Feb 07 |
jari |
774 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
775 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
776 |
|
2 |
26 Feb 07 |
jari |
777 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
778 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
779 |
|
2 |
26 Feb 07 |
jari |
780 |
menuItem = new JMenuItem("Clear all selections...", GUIFactory.getIcon("TableViewerResult.gif")); |
2 |
26 Feb 07 |
jari |
781 |
menuItem.setActionCommand(CLEAR_ALL_CMD); |
2 |
26 Feb 07 |
jari |
782 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
783 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
784 |
|
2 |
26 Feb 07 |
jari |
785 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
786 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
787 |
|
2 |
26 Feb 07 |
jari |
788 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
789 |
|
2 |
26 Feb 07 |
jari |
790 |
menuItem = new JMenuItem("Sort table in original experiment order...", GUIFactory.getIcon("TableViewerResult.gif")); |
2 |
26 Feb 07 |
jari |
791 |
menuItem.setActionCommand(SORT_ORIG_ORDER_CMD); |
2 |
26 Feb 07 |
jari |
792 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
793 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
794 |
|
2 |
26 Feb 07 |
jari |
795 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
796 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
797 |
|
2 |
26 Feb 07 |
jari |
798 |
} |
2 |
26 Feb 07 |
jari |
799 |
|
2 |
26 Feb 07 |
jari |
800 |
private void onSaveClusters() { |
2 |
26 Feb 07 |
jari |
801 |
Frame frame = JOptionPane.getFrameForComponent(clusterTable); |
2 |
26 Feb 07 |
jari |
802 |
try { |
2 |
26 Feb 07 |
jari |
803 |
if (auxTitles.length == 0) { |
2 |
26 Feb 07 |
jari |
//ExperimentUtil.saveExperiment(frame, getExperiment(), getData(), getClusters()); |
2 |
26 Feb 07 |
jari |
805 |
ExperimentUtil.saveAllExperimentClusters(frame, getExperiment(), getData(), getClusters()); |
2 |
26 Feb 07 |
jari |
806 |
} else { |
2 |
26 Feb 07 |
jari |
807 |
ExperimentUtil.saveAllExperimentClustersWithAux(frame, this.getExperiment(), this.getData(), this.getClusters(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
808 |
} |
2 |
26 Feb 07 |
jari |
//getContentComponent().repaint(); |
2 |
26 Feb 07 |
jari |
810 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
811 |
JOptionPane.showMessageDialog(frame, "Can not save clusters!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
812 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
813 |
} |
2 |
26 Feb 07 |
jari |
814 |
} |
2 |
26 Feb 07 |
jari |
815 |
|
2 |
26 Feb 07 |
jari |
816 |
private void onSaveCluster() { |
2 |
26 Feb 07 |
jari |
817 |
Frame frame = JOptionPane.getFrameForComponent(clusterTable); |
2 |
26 Feb 07 |
jari |
818 |
try { |
2 |
26 Feb 07 |
jari |
819 |
if (auxTitles.length == 0) { |
2 |
26 Feb 07 |
jari |
820 |
ExperimentUtil.saveExperimentCluster(frame, getExperiment(), getData(), getCluster()); |
2 |
26 Feb 07 |
jari |
821 |
} else { |
2 |
26 Feb 07 |
jari |
822 |
ExperimentUtil.saveExperimentClusterWithAux(frame, this.getExperiment(), this.getData(), this.getCluster(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
823 |
} |
2 |
26 Feb 07 |
jari |
824 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
825 |
JOptionPane.showMessageDialog(frame, "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
826 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
827 |
} |
2 |
26 Feb 07 |
jari |
828 |
} |
2 |
26 Feb 07 |
jari |
829 |
|
2 |
26 Feb 07 |
jari |
830 |
/** |
2 |
26 Feb 07 |
jari |
* Removes a public color. |
2 |
26 Feb 07 |
jari |
832 |
*/ |
2 |
26 Feb 07 |
jari |
833 |
private void onSetDefaultColor() { |
2 |
26 Feb 07 |
jari |
834 |
setClusterColor(null); |
2 |
26 Feb 07 |
jari |
835 |
} |
2 |
26 Feb 07 |
jari |
836 |
/* |
2 |
26 Feb 07 |
jari |
private static int[][] defSamplesOrder(int size) { |
2 |
26 Feb 07 |
jari |
int[][] order = new int[1][size]; |
2 |
26 Feb 07 |
jari |
for (int i=0; i<order[0].length; i++) { |
2 |
26 Feb 07 |
jari |
order[0][i] = i; |
2 |
26 Feb 07 |
jari |
841 |
} |
2 |
26 Feb 07 |
jari |
return order; |
2 |
26 Feb 07 |
jari |
843 |
} |
2 |
26 Feb 07 |
jari |
844 |
*/ |
2 |
26 Feb 07 |
jari |
845 |
|
2 |
26 Feb 07 |
jari |
846 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to mouse and action events. |
2 |
26 Feb 07 |
jari |
848 |
*/ |
2 |
26 Feb 07 |
jari |
849 |
private class Listener extends MouseAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
850 |
|
2 |
26 Feb 07 |
jari |
851 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
852 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
853 |
if (command.equals(SAVE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
854 |
onSaveCluster(); |
2 |
26 Feb 07 |
jari |
//getContentComponent().validate(); |
2 |
26 Feb 07 |
jari |
856 |
} else if (command.equals(SAVE_ALL_CLUSTERS_CMD)) { |
2 |
26 Feb 07 |
jari |
857 |
onSaveClusters(); |
2 |
26 Feb 07 |
jari |
//getContentComponent().validate(); |
2 |
26 Feb 07 |
jari |
859 |
} else if (command.equals(STORE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
860 |
storeCluster(); |
2 |
26 Feb 07 |
jari |
861 |
} else if (command.equals(STORE_SELECTED_ROWS_CMD)) { |
2 |
26 Feb 07 |
jari |
862 |
storeSelectedRowsAsCluster(); |
2 |
26 Feb 07 |
jari |
863 |
} else if (command.equals(SET_DEF_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
864 |
onSetDefaultColor(); |
2 |
26 Feb 07 |
jari |
865 |
} else if(command.equals(LAUNCH_NEW_SESSION_CMD)){ |
2 |
26 Feb 07 |
jari |
866 |
launchNewSession(); |
2 |
26 Feb 07 |
jari |
867 |
} else if(command.equals(LAUNCH_NEW_SESSION_WITH_SEL_ROWS_CMD)){ |
2 |
26 Feb 07 |
jari |
868 |
launchNewSessionWithSelectedRows(); |
2 |
26 Feb 07 |
jari |
869 |
} else if (command.equals(SEARCH_CMD)) { |
2 |
26 Feb 07 |
jari |
870 |
searchTable(); |
2 |
26 Feb 07 |
jari |
871 |
} else if (command.equals(CLEAR_ALL_CMD)) { |
2 |
26 Feb 07 |
jari |
872 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
873 |
} else if (command.equals(SELECT_ALL_CMD)) { |
2 |
26 Feb 07 |
jari |
874 |
clusterTable.selectAll(); |
2 |
26 Feb 07 |
jari |
875 |
} else if (command.equals(SORT_ORIG_ORDER_CMD)) { |
2 |
26 Feb 07 |
jari |
876 |
sortInOrigOrder(); |
2 |
26 Feb 07 |
jari |
877 |
} |
2 |
26 Feb 07 |
jari |
878 |
} |
2 |
26 Feb 07 |
jari |
879 |
|
2 |
26 Feb 07 |
jari |
880 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
881 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
882 |
} |
2 |
26 Feb 07 |
jari |
883 |
|
2 |
26 Feb 07 |
jari |
884 |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
885 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
886 |
} |
2 |
26 Feb 07 |
jari |
887 |
|
2 |
26 Feb 07 |
jari |
888 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
889 |
if (!e.isPopupTrigger() || getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
890 |
return; |
2 |
26 Feb 07 |
jari |
891 |
} |
2 |
26 Feb 07 |
jari |
892 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
893 |
} |
2 |
26 Feb 07 |
jari |
894 |
} |
2 |
26 Feb 07 |
jari |
895 |
|
2 |
26 Feb 07 |
jari |
896 |
public class ColorRenderer extends JLabel implements TableCellRenderer { |
2 |
26 Feb 07 |
jari |
897 |
Border unselectedBorder = null; |
2 |
26 Feb 07 |
jari |
898 |
Border selectedBorder = null; |
2 |
26 Feb 07 |
jari |
899 |
boolean isBordered = true; |
2 |
26 Feb 07 |
jari |
900 |
|
2 |
26 Feb 07 |
jari |
901 |
public ColorRenderer(boolean isBordered) { |
2 |
26 Feb 07 |
jari |
902 |
this.isBordered = isBordered; |
2 |
26 Feb 07 |
jari |
903 |
setOpaque(true); //MUST do this for background to show up. |
2 |
26 Feb 07 |
jari |
904 |
} |
2 |
26 Feb 07 |
jari |
905 |
|
2 |
26 Feb 07 |
jari |
906 |
public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) { |
2 |
26 Feb 07 |
jari |
907 |
Color newColor = (Color)color; |
2 |
26 Feb 07 |
jari |
908 |
setBackground(newColor); |
2 |
26 Feb 07 |
jari |
909 |
if (isBordered) { |
2 |
26 Feb 07 |
jari |
910 |
if (isSelected) { |
2 |
26 Feb 07 |
jari |
911 |
if (selectedBorder == null) { |
2 |
26 Feb 07 |
jari |
912 |
selectedBorder = BorderFactory.createMatteBorder(2,5,2,5, |
2 |
26 Feb 07 |
jari |
913 |
table.getSelectionBackground()); |
2 |
26 Feb 07 |
jari |
914 |
} |
2 |
26 Feb 07 |
jari |
915 |
setBorder(selectedBorder); |
2 |
26 Feb 07 |
jari |
916 |
} else { |
2 |
26 Feb 07 |
jari |
917 |
if (unselectedBorder == null) { |
2 |
26 Feb 07 |
jari |
918 |
unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5, |
2 |
26 Feb 07 |
jari |
919 |
table.getBackground()); |
2 |
26 Feb 07 |
jari |
920 |
} |
2 |
26 Feb 07 |
jari |
921 |
setBorder(unselectedBorder); |
2 |
26 Feb 07 |
jari |
922 |
} |
2 |
26 Feb 07 |
jari |
923 |
} |
2 |
26 Feb 07 |
jari |
//setToolTipText(...); //Discussed in the following section |
2 |
26 Feb 07 |
jari |
925 |
return this; |
2 |
26 Feb 07 |
jari |
926 |
} |
2 |
26 Feb 07 |
jari |
927 |
} |
2 |
26 Feb 07 |
jari |
928 |
|
2 |
26 Feb 07 |
jari |
929 |
private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException { |
2 |
26 Feb 07 |
jari |
930 |
oos.writeObject(experiment); |
2 |
26 Feb 07 |
jari |
931 |
oos.writeObject(clusters); |
2 |
26 Feb 07 |
jari |
932 |
oos.writeObject(header); |
2 |
26 Feb 07 |
jari |
933 |
oos.writeObject(popup); |
2 |
26 Feb 07 |
jari |
934 |
|
2 |
26 Feb 07 |
jari |
//oos.writeObject(framework); |
2 |
26 Feb 07 |
jari |
//oos.writeObject(data); |
2 |
26 Feb 07 |
jari |
937 |
oos.writeInt(clusterIndex); |
2 |
26 Feb 07 |
jari |
938 |
oos.writeObject(sortedClusters); |
2 |
26 Feb 07 |
jari |
//oos.writeObject(samplesOrder); |
2 |
26 Feb 07 |
jari |
940 |
oos.writeObject(auxTitles); |
2 |
26 Feb 07 |
jari |
//oos.writeObject(fieldNames); |
2 |
26 Feb 07 |
jari |
942 |
oos.writeObject(auxData); |
2 |
26 Feb 07 |
jari |
//oos.writeObject(origData); |
2 |
26 Feb 07 |
jari |
944 |
oos.writeObject(sortedAscending); |
2 |
26 Feb 07 |
jari |
945 |
oos.writeObject(clusterTable); |
2 |
26 Feb 07 |
jari |
946 |
oos.writeObject(clusterModel); |
2 |
26 Feb 07 |
jari |
947 |
oos.writeObject(searchDialog); |
2 |
26 Feb 07 |
jari |
948 |
} |
2 |
26 Feb 07 |
jari |
949 |
|
2 |
26 Feb 07 |
jari |
950 |
private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, ClassNotFoundException { |
2 |
26 Feb 07 |
jari |
951 |
this.experiment = (Experiment)ois.readObject(); |
2 |
26 Feb 07 |
jari |
952 |
this.clusters = (int [][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
953 |
this.header = (JComponent)ois.readObject(); |
2 |
26 Feb 07 |
jari |
954 |
this.popup = (JPopupMenu)ois.readObject(); |
2 |
26 Feb 07 |
jari |
955 |
|
2 |
26 Feb 07 |
jari |
//this.framework = (IFramework)ois.readObject(); |
2 |
26 Feb 07 |
jari |
//this.data = (IData)ois.readObject(); |
2 |
26 Feb 07 |
jari |
958 |
this.clusterIndex = ois.readInt(); |
2 |
26 Feb 07 |
jari |
959 |
this.sortedClusters = (int[][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
//this.samplesOrder = (int[])ois.readObject(); |
2 |
26 Feb 07 |
jari |
961 |
this.auxTitles = (String[])ois.readObject(); |
2 |
26 Feb 07 |
jari |
//this.fieldNames = (String[])ois.readObject(); // need to serilaize this? |
2 |
26 Feb 07 |
jari |
963 |
this.auxData = (Object[][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
//this.origData = |
2 |
26 Feb 07 |
jari |
965 |
this.sortedAscending = (boolean[][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
966 |
this.clusterTable = (JTable)ois.readObject(); |
2 |
26 Feb 07 |
jari |
967 |
this.clusterModel = (ExperimentClusterTableModel)ois.readObject(); |
2 |
26 Feb 07 |
jari |
968 |
this.searchDialog = (ClusterTableSearchDialog)ois.readObject(); |
2 |
26 Feb 07 |
jari |
969 |
|
2 |
26 Feb 07 |
jari |
//this.fieldNames = data.getFieldNames(); |
2 |
26 Feb 07 |
jari |
971 |
|
2 |
26 Feb 07 |
jari |
972 |
clusterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); |
2 |
26 Feb 07 |
jari |
973 |
TableColumn column = null; |
2 |
26 Feb 07 |
jari |
974 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) { |
2 |
26 Feb 07 |
jari |
975 |
column = clusterTable.getColumnModel().getColumn(i); |
2 |
26 Feb 07 |
jari |
976 |
column.setMinWidth(30); |
2 |
26 Feb 07 |
jari |
977 |
} |
2 |
26 Feb 07 |
jari |
978 |
|
2 |
26 Feb 07 |
jari |
979 |
this.sortedAscending = new boolean[clusters.length][clusterModel.getColumnCount()]; |
2 |
26 Feb 07 |
jari |
980 |
for (int i = 0; i < sortedAscending.length; i++) { |
2 |
26 Feb 07 |
jari |
981 |
for (int j = 0; j < sortedAscending[i].length; j++) { |
2 |
26 Feb 07 |
jari |
982 |
sortedAscending[i][j] = false; |
2 |
26 Feb 07 |
jari |
983 |
} |
2 |
26 Feb 07 |
jari |
984 |
} |
2 |
26 Feb 07 |
jari |
985 |
addMouseListenerToHeaderInTable(clusterTable); |
2 |
26 Feb 07 |
jari |
986 |
header = clusterTable.getTableHeader(); |
2 |
26 Feb 07 |
jari |
987 |
|
2 |
26 Feb 07 |
jari |
988 |
searchDialog = new ClusterTableSearchDialog(JOptionPane.getFrameForComponent(clusterTable), clusterTable, false); |
2 |
26 Feb 07 |
jari |
989 |
setMaxWidth(getContentComponent(), getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
990 |
|
2 |
26 Feb 07 |
jari |
991 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
992 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
//getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
994 |
clusterTable.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
995 |
} |
2 |
26 Feb 07 |
jari |
996 |
|
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 |
999 |
*/ |
2 |
26 Feb 07 |
jari |
1000 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
1001 |
return Cluster.EXPERIMENT_CLUSTER; |
2 |
26 Feb 07 |
jari |
1002 |
} |
2 |
26 Feb 07 |
jari |
1003 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperiment(org.tigr.microarray.mev.cluster.gui.Experiment) |
2 |
26 Feb 07 |
jari |
1006 |
*/ |
2 |
26 Feb 07 |
jari |
1007 |
public void setExperiment(Experiment e) { |
2 |
26 Feb 07 |
jari |
1008 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
1009 |
} |
2 |
26 Feb 07 |
jari |
1010 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#getExperimentID() |
2 |
26 Feb 07 |
jari |
1013 |
*/ |
2 |
26 Feb 07 |
jari |
1014 |
public int getExperimentID() { |
2 |
26 Feb 07 |
jari |
1015 |
return exptID; |
2 |
26 Feb 07 |
jari |
1016 |
} |
2 |
26 Feb 07 |
jari |
1017 |
|
2 |
26 Feb 07 |
jari |
/* (non-Javadoc) |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#setExperimentID(int) |
2 |
26 Feb 07 |
jari |
1020 |
*/ |
2 |
26 Feb 07 |
jari |
1021 |
public void setExperimentID(int id) { |
2 |
26 Feb 07 |
jari |
1022 |
this.exptID = id; |
2 |
26 Feb 07 |
jari |
1023 |
} |
2 |
26 Feb 07 |
jari |
1024 |
|
2 |
26 Feb 07 |
jari |
1025 |
} |