2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* ClusterTableViewer.java |
2 |
26 Feb 07 |
jari |
3 |
* |
2 |
26 Feb 07 |
jari |
* Created on March 9, 2004, 11:47 AM |
2 |
26 Feb 07 |
jari |
5 |
*/ |
2 |
26 Feb 07 |
jari |
6 |
|
2 |
26 Feb 07 |
jari |
7 |
package org.tigr.microarray.mev.cluster.gui.helpers; |
2 |
26 Feb 07 |
jari |
8 |
|
2 |
26 Feb 07 |
jari |
9 |
import java.awt.*; |
2 |
26 Feb 07 |
jari |
10 |
import java.awt.event.*; |
2 |
26 Feb 07 |
jari |
11 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
12 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
13 |
import java.util.Arrays; |
2 |
26 Feb 07 |
jari |
14 |
|
2 |
26 Feb 07 |
jari |
15 |
import javax.swing.*; |
2 |
26 Feb 07 |
jari |
16 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
17 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
18 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.JTable; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JComponent; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.border.Border; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.table.*; |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
import org.tigr.microarray.mev.cluster.gui.IViewer; |
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
26 |
import org.tigr.microarray.mev.cluster.gui.IDisplayMenu; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.gui.IData; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.gui.IFramework; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
30 |
|
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.clusterUtil.*; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.util.QSort; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
/** |
2 |
26 Feb 07 |
jari |
35 |
* |
2 |
26 Feb 07 |
jari |
* @author nbhagaba |
2 |
26 Feb 07 |
jari |
37 |
*/ |
2 |
26 Feb 07 |
jari |
38 |
public class ClusterTableViewer implements IViewer { |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
private static final String NO_GENES_STR = "No Genes in Cluster!"; |
2 |
26 Feb 07 |
jari |
41 |
private static final Font ERROR_FONT = new Font("monospaced", Font.BOLD, 20); |
2 |
26 Feb 07 |
jari |
42 |
protected static final String STORE_CLUSTER_CMD = "store-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
43 |
protected static final String STORE_SELECTED_ROWS_CMD = "store-selected-rows-cmd"; |
2 |
26 Feb 07 |
jari |
44 |
protected static final String SET_DEF_COLOR_CMD = "set-def-color-cmd"; |
2 |
26 Feb 07 |
jari |
45 |
protected static final String SAVE_CLUSTER_CMD = "save-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
46 |
protected static final String SAVE_ALL_CLUSTERS_CMD = "save-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
47 |
protected static final String LAUNCH_NEW_SESSION_CMD = "launch-new-session-cmd"; |
2 |
26 Feb 07 |
jari |
48 |
protected static final String LAUNCH_NEW_SESSION_WITH_SEL_ROWS_CMD = "launch-new-session-with-sel-rows-cmd"; |
2 |
26 Feb 07 |
jari |
49 |
protected static final String SEARCH_CMD = "search-cmd"; |
2 |
26 Feb 07 |
jari |
50 |
protected static final String CLEAR_ALL_CMD = "clear-all-cmd"; |
2 |
26 Feb 07 |
jari |
51 |
protected static final String SELECT_ALL_CMD = "select-all-cmd"; |
2 |
26 Feb 07 |
jari |
52 |
protected static final String SORT_ORIG_ORDER_CMD = "sort-orig-order-cmd"; |
2 |
26 Feb 07 |
jari |
53 |
protected static final String LINK_TO_URL_CMD = "link-to-url-cmd"; |
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
public static final int INTEGER_TYPE = 10; |
2 |
26 Feb 07 |
jari |
56 |
public static final int FLOAT_TYPE = 11; |
2 |
26 Feb 07 |
jari |
57 |
public static final int DOUBLE_TYPE = 12; |
2 |
26 Feb 07 |
jari |
58 |
public static final int STRING_TYPE = 13; |
2 |
26 Feb 07 |
jari |
59 |
public static final int BOOLEAN_TYPE = 14; |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
private JComponent header; |
2 |
26 Feb 07 |
jari |
62 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
63 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
64 |
private IFramework framework; |
2 |
26 Feb 07 |
jari |
65 |
private IData data; |
2 |
26 Feb 07 |
jari |
66 |
private int clusterIndex, xColumn; |
2 |
26 Feb 07 |
jari |
//private int xRow; |
2 |
26 Feb 07 |
jari |
68 |
private int[][] clusters; |
2 |
26 Feb 07 |
jari |
69 |
private int[][] sortedClusters; |
2 |
26 Feb 07 |
jari |
70 |
private int[] samplesOrder; |
2 |
26 Feb 07 |
jari |
71 |
private int[] lastSelectedAnnotationIndices; |
2 |
26 Feb 07 |
jari |
72 |
private String[] auxTitles, fieldNames; |
2 |
26 Feb 07 |
jari |
73 |
private Object[][] auxData; |
2 |
26 Feb 07 |
jari |
//private Object[][] origData; |
2 |
26 Feb 07 |
jari |
75 |
private boolean[][] sortedAscending; |
2 |
26 Feb 07 |
jari |
76 |
private JTable clusterTable; |
2 |
26 Feb 07 |
jari |
77 |
private ClusterTableModel clusterModel; |
2 |
26 Feb 07 |
jari |
78 |
private ClusterTableSearchDialog searchDialog; |
2 |
26 Feb 07 |
jari |
79 |
private JMenuItem urlMenuItem; |
2 |
26 Feb 07 |
jari |
80 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
public ClusterTableViewer(Experiment experiment, int[][] clusters, IData data) { |
2 |
26 Feb 07 |
jari |
85 |
this(experiment, clusters, data, new String[0], new Object[0][0]); |
2 |
26 Feb 07 |
jari |
86 |
} |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
|
2 |
26 Feb 07 |
jari |
89 |
public ClusterTableViewer(Experiment experiment, int[][] clusters, IData data, String[] auxTitles, Object[][] auxData) { |
2 |
26 Feb 07 |
jari |
90 |
if (experiment == null) { |
2 |
26 Feb 07 |
jari |
91 |
throw new IllegalArgumentException("experiment == null"); |
2 |
26 Feb 07 |
jari |
92 |
} |
2 |
26 Feb 07 |
jari |
93 |
this.data = data; |
2 |
26 Feb 07 |
jari |
94 |
this.experiment = experiment; |
2 |
26 Feb 07 |
jari |
95 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
96 |
this.clusters = clusters; |
2 |
26 Feb 07 |
jari |
97 |
this.fieldNames = data.getFieldNames(); |
2 |
26 Feb 07 |
jari |
98 |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
99 |
if(this.auxTitles == null) { |
2 |
26 Feb 07 |
jari |
100 |
this.auxTitles = new String[0]; |
2 |
26 Feb 07 |
jari |
101 |
} |
2 |
26 Feb 07 |
jari |
102 |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
103 |
this.lastSelectedAnnotationIndices = new int[2]; |
2 |
26 Feb 07 |
jari |
//this.xRow = -1; |
2 |
26 Feb 07 |
jari |
105 |
this.xColumn = -1; |
2 |
26 Feb 07 |
jari |
106 |
for (int i = 0; i < lastSelectedAnnotationIndices.length; i++) { |
2 |
26 Feb 07 |
jari |
107 |
lastSelectedAnnotationIndices[1] = 0; |
2 |
26 Feb 07 |
jari |
108 |
} |
2 |
26 Feb 07 |
jari |
109 |
|
2 |
26 Feb 07 |
jari |
110 |
this.sortedClusters = new int[clusters.length][]; |
2 |
26 Feb 07 |
jari |
111 |
|
2 |
26 Feb 07 |
jari |
112 |
for (int i = 0; i < sortedClusters.length; i++) { |
2 |
26 Feb 07 |
jari |
113 |
sortedClusters[i] = new int[clusters[i].length]; |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
for (int i = 0; i < sortedClusters.length; i++) { |
2 |
26 Feb 07 |
jari |
117 |
for (int j = 0; j < sortedClusters[i].length; j++) { |
2 |
26 Feb 07 |
jari |
118 |
sortedClusters[i][j] = clusters[i][j]; |
2 |
26 Feb 07 |
jari |
119 |
} |
2 |
26 Feb 07 |
jari |
120 |
} |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
this.clusterModel = new ClusterTableModel(); |
2 |
26 Feb 07 |
jari |
123 |
this.clusterTable = new JTable(clusterModel); |
2 |
26 Feb 07 |
jari |
124 |
clusterTable.setCellSelectionEnabled(true); |
2 |
26 Feb 07 |
jari |
125 |
clusterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); |
2 |
26 Feb 07 |
jari |
126 |
TableColumn column = null; |
2 |
26 Feb 07 |
jari |
127 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) { |
2 |
26 Feb 07 |
jari |
128 |
column = clusterTable.getColumnModel().getColumn(i); |
2 |
26 Feb 07 |
jari |
129 |
column.setMinWidth(30); |
2 |
26 Feb 07 |
jari |
130 |
} |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
this.sortedAscending = new boolean[clusters.length][clusterModel.getColumnCount()]; |
2 |
26 Feb 07 |
jari |
133 |
for (int i = 0; i < sortedAscending.length; i++) { |
2 |
26 Feb 07 |
jari |
134 |
for (int j = 0; j < sortedAscending[i].length; j++) { |
2 |
26 Feb 07 |
jari |
135 |
sortedAscending[i][j] = false; |
2 |
26 Feb 07 |
jari |
136 |
} |
2 |
26 Feb 07 |
jari |
137 |
} |
2 |
26 Feb 07 |
jari |
138 |
/* |
2 |
26 Feb 07 |
jari |
clusterTable.addMouseListener(new MouseAdapter() { |
2 |
26 Feb 07 |
jari |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
if (!event.isPopupTrigger()){ |
2 |
26 Feb 07 |
jari |
xRow = clusterTable.rowAtPoint(event.getPoint()); |
2 |
26 Feb 07 |
jari |
xColumn = clusterTable.columnAtPoint(event.getPoint()); |
2 |
26 Feb 07 |
jari |
System.out.println("xRow = " + xRow + ", xCol = " + xColumn); |
2 |
26 Feb 07 |
jari |
145 |
} |
2 |
26 Feb 07 |
jari |
146 |
} |
2 |
26 Feb 07 |
jari |
147 |
}); |
2 |
26 Feb 07 |
jari |
148 |
*/ |
2 |
26 Feb 07 |
jari |
149 |
addMouseListenerToHeaderInTable(clusterTable); |
2 |
26 Feb 07 |
jari |
150 |
header = clusterTable.getTableHeader(); |
2 |
26 Feb 07 |
jari |
151 |
|
2 |
26 Feb 07 |
jari |
152 |
searchDialog = new ClusterTableSearchDialog(JOptionPane.getFrameForComponent(clusterTable), clusterTable, false); |
2 |
26 Feb 07 |
jari |
153 |
setMaxWidth(getContentComponent(), getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
155 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
156 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
157 |
clusterTable.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
158 |
} |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
161 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
162 |
new Object[]{this.experiment, this.clusters, this.data, this.auxTitles, this.auxData}); |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
164 |
} |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
public void setExperiment(Experiment e) { |
2 |
26 Feb 07 |
jari |
167 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
168 |
this.exptID = e.getId(); |
2 |
26 Feb 07 |
jari |
169 |
} |
2 |
26 Feb 07 |
jari |
170 |
|
2 |
26 Feb 07 |
jari |
171 |
public int getExperimentID() { |
2 |
26 Feb 07 |
jari |
172 |
return this.exptID; |
2 |
26 Feb 07 |
jari |
173 |
} |
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 |
176 |
*/ |
2 |
26 Feb 07 |
jari |
177 |
public void setExperimentID(int id) { |
2 |
26 Feb 07 |
jari |
178 |
this.exptID = id; |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
//EH end state-saving additions |
2 |
26 Feb 07 |
jari |
181 |
|
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane view port. |
2 |
26 Feb 07 |
jari |
185 |
* |
2 |
26 Feb 07 |
jari |
186 |
*/ |
2 |
26 Feb 07 |
jari |
187 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
188 |
|
2 |
26 Feb 07 |
jari |
189 |
JPanel panel = new JPanel(); |
2 |
26 Feb 07 |
jari |
190 |
panel.setBackground(Color.gray); |
2 |
26 Feb 07 |
jari |
191 |
GridBagConstraints constraints = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
192 |
GridBagLayout gridbag = new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
193 |
panel.setLayout(gridbag); |
2 |
26 Feb 07 |
jari |
194 |
constraints.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
195 |
constraints.anchor = GridBagConstraints.NORTH; |
2 |
26 Feb 07 |
jari |
196 |
|
2 |
26 Feb 07 |
jari |
197 |
|
2 |
26 Feb 07 |
jari |
198 |
buildConstraints(constraints, 0, 0, 1, 1, 100, 100); |
2 |
26 Feb 07 |
jari |
199 |
gridbag.setConstraints(clusterTable, constraints); |
2 |
26 Feb 07 |
jari |
200 |
|
2 |
26 Feb 07 |
jari |
201 |
panel.add(clusterTable); |
2 |
26 Feb 07 |
jari |
//panel.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
203 |
return panel; |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
|
2 |
26 Feb 07 |
jari |
206 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the corner component corresponding to the indicated corner, |
2 |
26 Feb 07 |
jari |
208 |
* |
2 |
26 Feb 07 |
jari |
* posibly null |
2 |
26 Feb 07 |
jari |
210 |
* |
2 |
26 Feb 07 |
jari |
211 |
*/ |
2 |
26 Feb 07 |
jari |
212 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
213 |
return null; |
2 |
26 Feb 07 |
jari |
214 |
} |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
|
2 |
26 Feb 07 |
jari |
217 |
|
2 |
26 Feb 07 |
jari |
218 |
|
2 |
26 Feb 07 |
jari |
219 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into scroll pane header. |
2 |
26 Feb 07 |
jari |
221 |
* |
2 |
26 Feb 07 |
jari |
222 |
*/ |
2 |
26 Feb 07 |
jari |
223 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
224 |
|
2 |
26 Feb 07 |
jari |
225 |
JPanel panel = new JPanel(); |
2 |
26 Feb 07 |
jari |
226 |
panel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
227 |
GridBagConstraints constraints = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
228 |
GridBagLayout gridbag = new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
229 |
panel.setLayout(gridbag); |
2 |
26 Feb 07 |
jari |
230 |
constraints.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
231 |
buildConstraints(constraints, 0, 0, 1, 1, 100, 100); |
2 |
26 Feb 07 |
jari |
232 |
gridbag.setConstraints(header, constraints); |
2 |
26 Feb 07 |
jari |
233 |
panel.add(header); |
2 |
26 Feb 07 |
jari |
234 |
|
2 |
26 Feb 07 |
jari |
235 |
return panel; |
2 |
26 Feb 07 |
jari |
236 |
|
2 |
26 Feb 07 |
jari |
//return header; |
2 |
26 Feb 07 |
jari |
238 |
} |
2 |
26 Feb 07 |
jari |
239 |
|
2 |
26 Feb 07 |
jari |
240 |
void buildConstraints(GridBagConstraints gbc, int gx, int gy, |
2 |
26 Feb 07 |
jari |
241 |
int gw, int gh, int wx, int wy) { |
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
243 |
gbc.gridx = gx; |
2 |
26 Feb 07 |
jari |
244 |
gbc.gridy = gy; |
2 |
26 Feb 07 |
jari |
245 |
gbc.gridwidth = gw; |
2 |
26 Feb 07 |
jari |
246 |
gbc.gridheight = gh; |
2 |
26 Feb 07 |
jari |
247 |
gbc.weightx = wx; |
2 |
26 Feb 07 |
jari |
248 |
gbc.weighty = wy; |
2 |
26 Feb 07 |
jari |
249 |
} |
2 |
26 Feb 07 |
jari |
250 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework to save or to print viewer image. |
2 |
26 Feb 07 |
jari |
252 |
* |
2 |
26 Feb 07 |
jari |
253 |
*/ |
2 |
26 Feb 07 |
jari |
254 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
255 |
return null; |
2 |
26 Feb 07 |
jari |
256 |
} |
2 |
26 Feb 07 |
jari |
257 |
|
2 |
26 Feb 07 |
jari |
258 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
260 |
* |
2 |
26 Feb 07 |
jari |
261 |
*/ |
2 |
26 Feb 07 |
jari |
262 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
263 |
return null; |
2 |
26 Feb 07 |
jari |
264 |
} |
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 |
*/ |
2 |
26 Feb 07 |
jari |
270 |
public void onClosed() { |
2 |
26 Feb 07 |
jari |
271 |
} |
2 |
26 Feb 07 |
jari |
272 |
|
2 |
26 Feb 07 |
jari |
273 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when data is changed, |
2 |
26 Feb 07 |
jari |
275 |
* |
2 |
26 Feb 07 |
jari |
* if this viewer is selected. |
2 |
26 Feb 07 |
jari |
277 |
* |
2 |
26 Feb 07 |
jari |
* @see IData |
2 |
26 Feb 07 |
jari |
279 |
* |
2 |
26 Feb 07 |
jari |
280 |
*/ |
2 |
26 Feb 07 |
jari |
281 |
public void onDataChanged(IData data) { |
2 |
26 Feb 07 |
jari |
282 |
this.data = data; |
2 |
26 Feb 07 |
jari |
//clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
284 |
} |
2 |
26 Feb 07 |
jari |
285 |
|
2 |
26 Feb 07 |
jari |
286 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer was deselected. |
2 |
26 Feb 07 |
jari |
288 |
* |
2 |
26 Feb 07 |
jari |
289 |
*/ |
2 |
26 Feb 07 |
jari |
290 |
public void onDeselected() { |
2 |
26 Feb 07 |
jari |
//clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
292 |
} |
2 |
26 Feb 07 |
jari |
293 |
|
2 |
26 Feb 07 |
jari |
294 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when display menu is changed, |
2 |
26 Feb 07 |
jari |
296 |
* |
2 |
26 Feb 07 |
jari |
* if this viewer is selected. |
2 |
26 Feb 07 |
jari |
298 |
* |
2 |
26 Feb 07 |
jari |
* @see IDisplayMenu |
2 |
26 Feb 07 |
jari |
300 |
* |
2 |
26 Feb 07 |
jari |
301 |
*/ |
2 |
26 Feb 07 |
jari |
302 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
303 |
} |
2 |
26 Feb 07 |
jari |
304 |
|
2 |
26 Feb 07 |
jari |
305 |
/** |
2 |
26 Feb 07 |
jari |
* Invoked by the framework when this viewer is selected. |
2 |
26 Feb 07 |
jari |
307 |
* |
2 |
26 Feb 07 |
jari |
308 |
*/ |
2 |
26 Feb 07 |
jari |
309 |
public void onSelected(IFramework framework) { |
2 |
26 Feb 07 |
jari |
310 |
this.framework = framework; |
2 |
26 Feb 07 |
jari |
311 |
this.data = framework.getData(); |
2 |
26 Feb 07 |
jari |
312 |
IDisplayMenu menu = framework.getDisplayMenu(); |
2 |
26 Feb 07 |
jari |
313 |
Integer userObject = (Integer)framework.getUserObject(); |
2 |
26 Feb 07 |
jari |
314 |
setClusterIndex(userObject == null ? 0 : userObject.intValue()); |
2 |
26 Feb 07 |
jari |
315 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
316 |
} |
2 |
26 Feb 07 |
jari |
317 |
|
2 |
26 Feb 07 |
jari |
318 |
/** |
2 |
26 Feb 07 |
jari |
* Sets cluster index to be displayed. |
2 |
26 Feb 07 |
jari |
320 |
*/ |
2 |
26 Feb 07 |
jari |
321 |
|
2 |
26 Feb 07 |
jari |
322 |
public void setClusterIndex(int clusterIndex) { |
2 |
26 Feb 07 |
jari |
323 |
this.clusterIndex = 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 index of current cluster. |
2 |
26 Feb 07 |
jari |
328 |
*/ |
2 |
26 Feb 07 |
jari |
329 |
|
2 |
26 Feb 07 |
jari |
330 |
public int getClusterIndex() { |
2 |
26 Feb 07 |
jari |
331 |
return clusterIndex; |
2 |
26 Feb 07 |
jari |
332 |
} |
2 |
26 Feb 07 |
jari |
333 |
|
2 |
26 Feb 07 |
jari |
334 |
/** |
2 |
26 Feb 07 |
jari |
* Returns indices of current cluster. |
2 |
26 Feb 07 |
jari |
336 |
*/ |
2 |
26 Feb 07 |
jari |
337 |
public int[] getCluster() { |
2 |
26 Feb 07 |
jari |
338 |
return clusters[this.clusterIndex]; |
2 |
26 Feb 07 |
jari |
339 |
} |
2 |
26 Feb 07 |
jari |
340 |
|
2 |
26 Feb 07 |
jari |
341 |
/** |
2 |
26 Feb 07 |
jari |
* Returns all the clusters. |
2 |
26 Feb 07 |
jari |
343 |
*/ |
2 |
26 Feb 07 |
jari |
344 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
345 |
return clusters; |
2 |
26 Feb 07 |
jari |
346 |
} |
2 |
26 Feb 07 |
jari |
347 |
|
2 |
26 Feb 07 |
jari |
348 |
public int[] getSortedCluster() { |
2 |
26 Feb 07 |
jari |
349 |
return sortedClusters[this.clusterIndex]; |
2 |
26 Feb 07 |
jari |
350 |
} |
2 |
26 Feb 07 |
jari |
351 |
|
2 |
26 Feb 07 |
jari |
352 |
/** |
2 |
26 Feb 07 |
jari |
353 |
|
2 |
26 Feb 07 |
jari |
* Returns the row index in the experiment's <code>FloatMatrix<\code> |
2 |
26 Feb 07 |
jari |
355 |
|
2 |
26 Feb 07 |
jari |
* corresponding to the passed index to the clusters array |
2 |
26 Feb 07 |
jari |
357 |
|
2 |
26 Feb 07 |
jari |
358 |
*/ |
2 |
26 Feb 07 |
jari |
359 |
|
2 |
26 Feb 07 |
jari |
360 |
private int getExperimentRow(int row){ |
2 |
26 Feb 07 |
jari |
361 |
return this.clusters[this.clusterIndex][row]; |
2 |
26 Feb 07 |
jari |
362 |
} |
2 |
26 Feb 07 |
jari |
363 |
|
2 |
26 Feb 07 |
jari |
364 |
/** |
2 |
26 Feb 07 |
jari |
* Returns index of a gene in the current cluster. |
2 |
26 Feb 07 |
jari |
366 |
*/ |
2 |
26 Feb 07 |
jari |
367 |
|
2 |
26 Feb 07 |
jari |
368 |
protected int getProbe(int row) { |
2 |
26 Feb 07 |
jari |
369 |
return this.clusters[this.clusterIndex][row]; |
2 |
26 Feb 07 |
jari |
370 |
} |
2 |
26 Feb 07 |
jari |
371 |
|
2 |
26 Feb 07 |
jari |
372 |
|
2 |
26 Feb 07 |
jari |
373 |
private int getColumn(int column) { |
2 |
26 Feb 07 |
jari |
374 |
return samplesOrder[column]; |
2 |
26 Feb 07 |
jari |
375 |
} |
2 |
26 Feb 07 |
jari |
376 |
|
2 |
26 Feb 07 |
jari |
377 |
/** |
2 |
26 Feb 07 |
jari |
* Returns wrapped experiment. |
2 |
26 Feb 07 |
jari |
379 |
*/ |
2 |
26 Feb 07 |
jari |
380 |
|
2 |
26 Feb 07 |
jari |
381 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
382 |
return experiment; |
2 |
26 Feb 07 |
jari |
383 |
} |
2 |
26 Feb 07 |
jari |
384 |
|
2 |
26 Feb 07 |
jari |
385 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the data. |
2 |
26 Feb 07 |
jari |
387 |
*/ |
2 |
26 Feb 07 |
jari |
388 |
public IData getData() { |
2 |
26 Feb 07 |
jari |
389 |
return data; |
2 |
26 Feb 07 |
jari |
390 |
} |
2 |
26 Feb 07 |
jari |
391 |
|
2 |
26 Feb 07 |
jari |
392 |
/** |
2 |
26 Feb 07 |
jari |
* Converts cluster indicies from the experiment to IData rows which could be different |
2 |
26 Feb 07 |
jari |
394 |
*/ |
2 |
26 Feb 07 |
jari |
395 |
|
2 |
26 Feb 07 |
jari |
396 |
private int [] getIDataRowIndices(int [] expIndices){ |
2 |
26 Feb 07 |
jari |
397 |
int [] dataIndices = new int[expIndices.length]; |
2 |
26 Feb 07 |
jari |
398 |
for(int i = 0; i < expIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
399 |
dataIndices[i] = this.getMultipleArrayDataRow(i); |
2 |
26 Feb 07 |
jari |
400 |
} |
2 |
26 Feb 07 |
jari |
401 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
402 |
} |
2 |
26 Feb 07 |
jari |
403 |
|
2 |
26 Feb 07 |
jari |
404 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the row (index) within the main iData which corresponds to |
2 |
26 Feb 07 |
jari |
* the passed index to the clusters array |
2 |
26 Feb 07 |
jari |
407 |
*/ |
2 |
26 Feb 07 |
jari |
408 |
private int getMultipleArrayDataRow(int clusterArrayRow) { |
2 |
26 Feb 07 |
jari |
409 |
return experiment.getGeneIndexMappedToData(this.clusters[this.clusterIndex][clusterArrayRow]); |
2 |
26 Feb 07 |
jari |
410 |
} |
2 |
26 Feb 07 |
jari |
411 |
|
2 |
26 Feb 07 |
jari |
412 |
class ClusterTableModel extends AbstractTableModel { |
2 |
26 Feb 07 |
jari |
413 |
String[] columnNames; |
2 |
26 Feb 07 |
jari |
414 |
private String NO_ANNOTATION = "No Annotation Loaded"; |
2 |
26 Feb 07 |
jari |
415 |
boolean hasAnnotation = true; |
2 |
26 Feb 07 |
jari |
416 |
|
2 |
26 Feb 07 |
jari |
417 |
public ClusterTableModel() { |
2 |
26 Feb 07 |
jari |
418 |
if(fieldNames.length + auxTitles.length == 0){ //No annotation loaded |
2 |
26 Feb 07 |
jari |
419 |
columnNames = new String[2]; |
2 |
26 Feb 07 |
jari |
420 |
columnNames[1] = NO_ANNOTATION; |
2 |
26 Feb 07 |
jari |
421 |
hasAnnotation = false; |
2 |
26 Feb 07 |
jari |
422 |
} else { |
2 |
26 Feb 07 |
jari |
423 |
columnNames = new String[1 + fieldNames.length + auxTitles.length]; |
2 |
26 Feb 07 |
jari |
424 |
int counter; |
2 |
26 Feb 07 |
jari |
425 |
for (counter = 1; counter < fieldNames.length + 1; counter++) { |
2 |
26 Feb 07 |
jari |
426 |
columnNames[counter] = fieldNames[counter - 1]; |
2 |
26 Feb 07 |
jari |
427 |
} |
2 |
26 Feb 07 |
jari |
428 |
for (int i = counter; i < columnNames.length; i++) { |
2 |
26 Feb 07 |
jari |
429 |
columnNames[i] = auxTitles[i - counter]; |
2 |
26 Feb 07 |
jari |
430 |
} |
2 |
26 Feb 07 |
jari |
431 |
} |
2 |
26 Feb 07 |
jari |
432 |
columnNames[0] = "Stored Color"; |
2 |
26 Feb 07 |
jari |
433 |
} |
2 |
26 Feb 07 |
jari |
434 |
|
2 |
26 Feb 07 |
jari |
435 |
public int getColumnCount() { |
2 |
26 Feb 07 |
jari |
436 |
return columnNames.length; |
2 |
26 Feb 07 |
jari |
437 |
} |
2 |
26 Feb 07 |
jari |
438 |
|
2 |
26 Feb 07 |
jari |
439 |
public int getRowCount() { |
2 |
26 Feb 07 |
jari |
440 |
return getCluster().length; |
2 |
26 Feb 07 |
jari |
441 |
} |
2 |
26 Feb 07 |
jari |
442 |
|
2 |
26 Feb 07 |
jari |
443 |
public String getColumnName(int col) { |
2 |
26 Feb 07 |
jari |
444 |
return columnNames[col]; |
2 |
26 Feb 07 |
jari |
445 |
} |
2 |
26 Feb 07 |
jari |
446 |
|
2 |
26 Feb 07 |
jari |
447 |
public Object getValueAt(int row, int col) { |
2 |
26 Feb 07 |
jari |
448 |
if (col == 0) { |
2 |
26 Feb 07 |
jari |
449 |
return data.getProbeColor(experiment.getGeneIndexMappedToData(getSortedCluster()[row])) == null? Color.white : data.getProbeColor(experiment.getGeneIndexMappedToData(getSortedCluster()[row])); |
2 |
26 Feb 07 |
jari |
450 |
} else if(!hasAnnotation){ |
2 |
26 Feb 07 |
jari |
451 |
return new Integer(row+1); |
2 |
26 Feb 07 |
jari |
452 |
} else if (col < fieldNames.length + 1) { |
2 |
26 Feb 07 |
jari |
453 |
return data.getElementAttribute(experiment.getGeneIndexMappedToData(getSortedCluster()[row]), col - 1); |
2 |
26 Feb 07 |
jari |
454 |
} else { |
2 |
26 Feb 07 |
jari |
455 |
return String.valueOf(auxData[getSortedCluster()[row]][col - (fieldNames.length + 1)]); |
2 |
26 Feb 07 |
jari |
456 |
} |
2 |
26 Feb 07 |
jari |
457 |
} |
2 |
26 Feb 07 |
jari |
458 |
|
2 |
26 Feb 07 |
jari |
459 |
public Class getColumnClass(int c) { |
2 |
26 Feb 07 |
jari |
460 |
return getValueAt(0, c).getClass(); |
2 |
26 Feb 07 |
jari |
461 |
} |
2 |
26 Feb 07 |
jari |
462 |
/* |
2 |
26 Feb 07 |
jari |
public void setValueAt(Object value, int row, int col) { |
2 |
26 Feb 07 |
jari |
//tableData[row][col] = value; |
2 |
26 Feb 07 |
jari |
fireTableCellUpdated(row, col); |
2 |
26 Feb 07 |
jari |
466 |
} |
2 |
26 Feb 07 |
jari |
467 |
*/ |
2 |
26 Feb 07 |
jari |
468 |
|
2 |
26 Feb 07 |
jari |
469 |
|
2 |
26 Feb 07 |
jari |
470 |
} |
2 |
26 Feb 07 |
jari |
471 |
|
2 |
26 Feb 07 |
jari |
472 |
|
2 |
26 Feb 07 |
jari |
473 |
|
2 |
26 Feb 07 |
jari |
474 |
private int[] reverse(int[] arr) { |
2 |
26 Feb 07 |
jari |
475 |
int[] revArr = new int[arr.length]; |
2 |
26 Feb 07 |
jari |
476 |
int revCount = 0; |
2 |
26 Feb 07 |
jari |
477 |
int count = arr.length - 1; |
2 |
26 Feb 07 |
jari |
478 |
for (int i=0; i < arr.length; i++) { |
2 |
26 Feb 07 |
jari |
479 |
revArr[revCount] = arr[count]; |
2 |
26 Feb 07 |
jari |
480 |
revCount++; |
2 |
26 Feb 07 |
jari |
481 |
count--; |
2 |
26 Feb 07 |
jari |
482 |
} |
2 |
26 Feb 07 |
jari |
483 |
return revArr; |
2 |
26 Feb 07 |
jari |
484 |
} |
2 |
26 Feb 07 |
jari |
485 |
|
2 |
26 Feb 07 |
jari |
486 |
public void addMouseListenerToHeaderInTable(JTable table) { |
2 |
26 Feb 07 |
jari |
//final TableSorter sorter = this; |
2 |
26 Feb 07 |
jari |
488 |
final JTable tableView = table; |
2 |
26 Feb 07 |
jari |
489 |
tableView.setColumnSelectionAllowed(false); |
2 |
26 Feb 07 |
jari |
490 |
MouseAdapter listMouseListener = new MouseAdapter() { |
2 |
26 Feb 07 |
jari |
491 |
public void mouseClicked(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
492 |
TableColumnModel columnModel = tableView.getColumnModel(); |
2 |
26 Feb 07 |
jari |
493 |
int viewColumn = columnModel.getColumnIndexAtX(e.getX()); |
2 |
26 Feb 07 |
jari |
494 |
int column = tableView.convertColumnIndexToModel(viewColumn); |
2 |
26 Feb 07 |
jari |
495 |
if (e.getClickCount() == 1 && column != -1) { |
2 |
26 Feb 07 |
jari |
496 |
int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; |
2 |
26 Feb 07 |
jari |
497 |
int controlPressed = e.getModifiers()&InputEvent.CTRL_MASK; |
2 |
26 Feb 07 |
jari |
498 |
boolean originalOrder = (controlPressed != 0); |
2 |
26 Feb 07 |
jari |
499 |
sortByColumn(column, !(sortedAscending[getClusterIndex()][column]), originalOrder); |
2 |
26 Feb 07 |
jari |
500 |
sortedAscending[getClusterIndex()][column] = !(sortedAscending[getClusterIndex()][column]); |
2 |
26 Feb 07 |
jari |
501 |
if (originalOrder) { |
2 |
26 Feb 07 |
jari |
502 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) |
2 |
26 Feb 07 |
jari |
503 |
sortedAscending[getClusterIndex()][i] = false; |
2 |
26 Feb 07 |
jari |
504 |
} |
2 |
26 Feb 07 |
jari |
505 |
} |
2 |
26 Feb 07 |
jari |
//tableView.repaint(); |
2 |
26 Feb 07 |
jari |
507 |
} |
2 |
26 Feb 07 |
jari |
508 |
}; |
2 |
26 Feb 07 |
jari |
509 |
JTableHeader th = tableView.getTableHeader(); |
2 |
26 Feb 07 |
jari |
//tableView.repaint(); |
2 |
26 Feb 07 |
jari |
511 |
th.addMouseListener(listMouseListener); |
2 |
26 Feb 07 |
jari |
512 |
} |
2 |
26 Feb 07 |
jari |
513 |
|
2 |
26 Feb 07 |
jari |
514 |
public void sortByColumn(int column, boolean ascending, boolean originalOrder) { |
2 |
26 Feb 07 |
jari |
//if (column == 0) return; |
2 |
26 Feb 07 |
jari |
516 |
if (originalOrder) { |
2 |
26 Feb 07 |
jari |
517 |
for (int i = 0; i < getSortedCluster().length; i++) { |
2 |
26 Feb 07 |
jari |
518 |
sortedClusters[this.clusterIndex][i] = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
519 |
} |
2 |
26 Feb 07 |
jari |
520 |
|
2 |
26 Feb 07 |
jari |
521 |
clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
522 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
523 |
return; |
2 |
26 Feb 07 |
jari |
524 |
} |
2 |
26 Feb 07 |
jari |
525 |
|
2 |
26 Feb 07 |
jari |
526 |
int[] sortedIndices = new int[getCluster().length]; |
2 |
26 Feb 07 |
jari |
527 |
if (column == 0) { |
2 |
26 Feb 07 |
jari |
528 |
double[] origArray = new double[getCluster().length]; |
2 |
26 Feb 07 |
jari |
529 |
for (int i = 0; i < origArray.length; i++) { |
2 |
26 Feb 07 |
jari |
530 |
Color currColor = data.getProbeColor(experiment.getGeneIndexMappedToData(getCluster()[i])) == null? Color.white : data.getProbeColor(experiment.getGeneIndexMappedToData(getCluster()[i])); |
2 |
26 Feb 07 |
jari |
531 |
origArray[i] = (double)(currColor.getRGB()); |
2 |
26 Feb 07 |
jari |
532 |
} |
2 |
26 Feb 07 |
jari |
533 |
QSort sortArray = new QSort(origArray); |
2 |
26 Feb 07 |
jari |
534 |
int[] sortedPrimaryIndices = sortArray.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
535 |
for (int i = 0; i < sortedPrimaryIndices.length; i++) { |
2 |
26 Feb 07 |
jari |
536 |
sortedIndices[i] = getCluster()[sortedPrimaryIndices[i]]; |
2 |
26 Feb 07 |
jari |
537 |
} |
2 |
26 Feb 07 |
jari |
538 |
|
2 |
26 Feb 07 |
jari |
539 |
} else if (column < fieldNames.length +1) { |
2 |
26 Feb 07 |
jari |
540 |
SortableField[] sortFields = new SortableField[getCluster().length]; |
2 |
26 Feb 07 |
jari |
541 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
542 |
int currIndex = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
543 |
String currField = data.getElementAttribute(experiment.getGeneIndexMappedToData(getCluster()[i]), column - 1); |
2 |
26 Feb 07 |
jari |
544 |
sortFields[i] = new SortableField(currIndex, currField); |
2 |
26 Feb 07 |
jari |
545 |
} |
2 |
26 Feb 07 |
jari |
546 |
|
2 |
26 Feb 07 |
jari |
547 |
Arrays.sort(sortFields); |
2 |
26 Feb 07 |
jari |
548 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
549 |
sortedIndices[i] = sortFields[i].getIndex(); |
2 |
26 Feb 07 |
jari |
550 |
} |
2 |
26 Feb 07 |
jari |
551 |
} else { |
2 |
26 Feb 07 |
jari |
552 |
int obType = getObjectType(auxData[0][column - (fieldNames.length +1)]); |
2 |
26 Feb 07 |
jari |
553 |
if ((obType == ExperimentUtil.DOUBLE_TYPE) || (obType == ExperimentUtil.FLOAT_TYPE) || (obType == ExperimentUtil.INTEGER_TYPE)) { |
2 |
26 Feb 07 |
jari |
554 |
double[] origArray = new double[getCluster().length]; |
2 |
26 Feb 07 |
jari |
555 |
for (int i = 0; i < origArray.length; i++) { |
2 |
26 Feb 07 |
jari |
556 |
if (obType == ExperimentUtil.DOUBLE_TYPE) { |
2 |
26 Feb 07 |
jari |
557 |
origArray[i] = ((Double)(auxData[getCluster()[i]][column - (fieldNames.length + 1)])).doubleValue(); |
2 |
26 Feb 07 |
jari |
558 |
} else if (obType == ExperimentUtil.FLOAT_TYPE) { |
2 |
26 Feb 07 |
jari |
559 |
origArray[i] = ((Float)(auxData[getCluster()[i]][column - (fieldNames.length + 1)])).doubleValue(); |
2 |
26 Feb 07 |
jari |
560 |
} else if (obType == ExperimentUtil.INTEGER_TYPE) { |
2 |
26 Feb 07 |
jari |
561 |
origArray[i] = ((Integer)(auxData[getCluster()[i]][column - (fieldNames.length + 1)])).doubleValue(); |
2 |
26 Feb 07 |
jari |
562 |
} |
2 |
26 Feb 07 |
jari |
563 |
} |
2 |
26 Feb 07 |
jari |
564 |
QSort sortArray = new QSort(origArray); |
2 |
26 Feb 07 |
jari |
565 |
int[] sortedPrimaryIndices = sortArray.getOrigIndx(); |
2 |
26 Feb 07 |
jari |
566 |
for (int i = 0; i < sortedPrimaryIndices.length; i++) { |
2 |
26 Feb 07 |
jari |
567 |
sortedIndices[i] = getCluster()[sortedPrimaryIndices[i]]; |
2 |
26 Feb 07 |
jari |
568 |
} |
2 |
26 Feb 07 |
jari |
569 |
} else if (obType == ExperimentUtil.BOOLEAN_TYPE) { |
2 |
26 Feb 07 |
jari |
570 |
SortableField[] sortFields = new SortableField[getCluster().length]; |
2 |
26 Feb 07 |
jari |
571 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
572 |
int currIndex = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
573 |
String currField = ((Boolean)(auxData[getCluster()[i]][column - (fieldNames.length + 1)])).toString(); |
2 |
26 Feb 07 |
jari |
574 |
sortFields[i] = new SortableField(currIndex, currField); |
2 |
26 Feb 07 |
jari |
575 |
} |
2 |
26 Feb 07 |
jari |
576 |
|
2 |
26 Feb 07 |
jari |
577 |
Arrays.sort(sortFields); |
2 |
26 Feb 07 |
jari |
578 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
579 |
sortedIndices[i] = sortFields[i].getIndex(); |
2 |
26 Feb 07 |
jari |
580 |
} |
2 |
26 Feb 07 |
jari |
581 |
} else if (obType == ExperimentUtil.STRING_TYPE) { |
2 |
26 Feb 07 |
jari |
582 |
SortableField[] sortFields = new SortableField[getCluster().length]; |
2 |
26 Feb 07 |
jari |
583 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
584 |
int currIndex = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
585 |
String currField = (String)(auxData[getCluster()[i]][column - (fieldNames.length + 1)]); |
2 |
26 Feb 07 |
jari |
586 |
sortFields[i] = new SortableField(currIndex, currField); |
2 |
26 Feb 07 |
jari |
587 |
} |
2 |
26 Feb 07 |
jari |
588 |
|
2 |
26 Feb 07 |
jari |
589 |
Arrays.sort(sortFields); |
2 |
26 Feb 07 |
jari |
590 |
for (int i = 0; i < sortFields.length; i++) { |
2 |
26 Feb 07 |
jari |
591 |
sortedIndices[i] = sortFields[i].getIndex(); |
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 |
596 |
if (!ascending) { |
2 |
26 Feb 07 |
jari |
597 |
sortedIndices = reverse(sortedIndices); |
2 |
26 Feb 07 |
jari |
598 |
} |
2 |
26 Feb 07 |
jari |
599 |
|
2 |
26 Feb 07 |
jari |
600 |
for (int i = 0; i < getSortedCluster().length; i++) { |
2 |
26 Feb 07 |
jari |
601 |
sortedClusters[this.clusterIndex][i] = sortedIndices[i]; |
2 |
26 Feb 07 |
jari |
602 |
} |
2 |
26 Feb 07 |
jari |
603 |
clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
604 |
clusterTable.removeRowSelectionInterval(0, clusterTable.getRowCount() - 1); |
2 |
26 Feb 07 |
jari |
605 |
} |
2 |
26 Feb 07 |
jari |
606 |
|
2 |
26 Feb 07 |
jari |
607 |
private class SortableField implements Comparable { |
2 |
26 Feb 07 |
jari |
608 |
private String field; |
2 |
26 Feb 07 |
jari |
609 |
private int index; |
2 |
26 Feb 07 |
jari |
610 |
|
2 |
26 Feb 07 |
jari |
611 |
SortableField(int index, String field) { |
2 |
26 Feb 07 |
jari |
612 |
this.index = index; |
2 |
26 Feb 07 |
jari |
613 |
this.field = field; |
2 |
26 Feb 07 |
jari |
//System.out.println("SortableField[" + index + "][" + column + "]: index = " + index + ", field = " + field); |
2 |
26 Feb 07 |
jari |
615 |
} |
2 |
26 Feb 07 |
jari |
616 |
|
2 |
26 Feb 07 |
jari |
617 |
public int compareTo(Object other) { |
2 |
26 Feb 07 |
jari |
618 |
SortableField otherField = (SortableField)other; |
2 |
26 Feb 07 |
jari |
619 |
return this.field.compareTo(otherField.getField()); |
2 |
26 Feb 07 |
jari |
620 |
} |
2 |
26 Feb 07 |
jari |
621 |
|
2 |
26 Feb 07 |
jari |
622 |
public int getIndex() { |
2 |
26 Feb 07 |
jari |
623 |
return this.index; |
2 |
26 Feb 07 |
jari |
624 |
} |
2 |
26 Feb 07 |
jari |
625 |
public String getField() { |
2 |
26 Feb 07 |
jari |
626 |
return this.field; |
2 |
26 Feb 07 |
jari |
627 |
} |
2 |
26 Feb 07 |
jari |
628 |
} |
2 |
26 Feb 07 |
jari |
629 |
|
2 |
26 Feb 07 |
jari |
630 |
|
2 |
26 Feb 07 |
jari |
631 |
private static int[] getTypes (Object[][] objData) { |
2 |
26 Feb 07 |
jari |
632 |
int[] types = new int[objData[0].length]; |
2 |
26 Feb 07 |
jari |
633 |
for (int i = 0; i < types.length; i++) { |
2 |
26 Feb 07 |
jari |
634 |
types[i] = getObjectType(objData[0][i]); |
2 |
26 Feb 07 |
jari |
//Object |
2 |
26 Feb 07 |
jari |
636 |
} |
2 |
26 Feb 07 |
jari |
637 |
return types; |
2 |
26 Feb 07 |
jari |
638 |
} |
2 |
26 Feb 07 |
jari |
639 |
|
2 |
26 Feb 07 |
jari |
640 |
private static int getObjectType(Object obj) { |
2 |
26 Feb 07 |
jari |
641 |
int obType = -1; |
2 |
26 Feb 07 |
jari |
642 |
if (obj instanceof Boolean) { |
2 |
26 Feb 07 |
jari |
643 |
return ExperimentUtil.BOOLEAN_TYPE; |
2 |
26 Feb 07 |
jari |
644 |
} else if (obj instanceof Double) { |
2 |
26 Feb 07 |
jari |
645 |
return ExperimentUtil.DOUBLE_TYPE; |
2 |
26 Feb 07 |
jari |
646 |
} else if (obj instanceof Float) { |
2 |
26 Feb 07 |
jari |
647 |
return ExperimentUtil.FLOAT_TYPE; |
2 |
26 Feb 07 |
jari |
648 |
} else if (obj instanceof Integer) { |
2 |
26 Feb 07 |
jari |
649 |
return ExperimentUtil.INTEGER_TYPE; |
2 |
26 Feb 07 |
jari |
650 |
} else if (obj instanceof String) { |
2 |
26 Feb 07 |
jari |
651 |
return ExperimentUtil.STRING_TYPE; |
2 |
26 Feb 07 |
jari |
652 |
} else { |
2 |
26 Feb 07 |
jari |
653 |
return obType; |
2 |
26 Feb 07 |
jari |
654 |
} |
2 |
26 Feb 07 |
jari |
655 |
} |
2 |
26 Feb 07 |
jari |
656 |
|
2 |
26 Feb 07 |
jari |
657 |
private void searchTable(){ |
2 |
26 Feb 07 |
jari |
658 |
|
2 |
26 Feb 07 |
jari |
659 |
searchDialog.setVisible(true); |
2 |
26 Feb 07 |
jari |
660 |
searchDialog.toFront(); |
2 |
26 Feb 07 |
jari |
//searchDialog.requestFocus(); |
2 |
26 Feb 07 |
jari |
662 |
searchDialog.setLocation(clusterTable.getLocation().x + 100, clusterTable.getLocation().y +100); |
2 |
26 Feb 07 |
jari |
663 |
|
2 |
26 Feb 07 |
jari |
664 |
} |
2 |
26 Feb 07 |
jari |
665 |
|
2 |
26 Feb 07 |
jari |
666 |
/** |
2 |
26 Feb 07 |
jari |
* Synchronize content and header sizes. |
2 |
26 Feb 07 |
jari |
668 |
*/ |
2 |
26 Feb 07 |
jari |
669 |
private void setMaxWidth(JComponent content, JComponent header) { |
2 |
26 Feb 07 |
jari |
670 |
int c_width = content.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
671 |
int h_width = header.getPreferredSize().width; |
2 |
26 Feb 07 |
jari |
672 |
if (c_width > h_width) { |
2 |
26 Feb 07 |
jari |
673 |
header.setPreferredSize(new Dimension(c_width, header.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
674 |
} else { |
2 |
26 Feb 07 |
jari |
675 |
content.setPreferredSize(new Dimension(h_width, content.getPreferredSize().height)); |
2 |
26 Feb 07 |
jari |
676 |
} |
2 |
26 Feb 07 |
jari |
677 |
} |
2 |
26 Feb 07 |
jari |
678 |
|
2 |
26 Feb 07 |
jari |
679 |
/** |
2 |
26 Feb 07 |
jari |
* Sets public color for the current cluster. |
2 |
26 Feb 07 |
jari |
681 |
*/ |
2 |
26 Feb 07 |
jari |
682 |
|
2 |
26 Feb 07 |
jari |
683 |
public void setClusterColor(Color color) { |
2 |
26 Feb 07 |
jari |
684 |
if(color ==null){ //indicates removal of cluster |
2 |
26 Feb 07 |
jari |
//framework.removeCluster(getArrayMappedToData(), experiment, ClusterRepository.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
686 |
boolean success = framework.removeSubCluster(getArrayMappedToSelectedIndices(), experiment, ClusterRepository.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
687 |
if (!success) { |
2 |
26 Feb 07 |
jari |
688 |
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 |
689 |
} |
2 |
26 Feb 07 |
jari |
690 |
} |
2 |
26 Feb 07 |
jari |
691 |
} |
2 |
26 Feb 07 |
jari |
692 |
|
2 |
26 Feb 07 |
jari |
693 |
/** |
2 |
26 Feb 07 |
jari |
* Sets cluster color |
2 |
26 Feb 07 |
jari |
695 |
*/ |
2 |
26 Feb 07 |
jari |
696 |
public void storeCluster(){ |
2 |
26 Feb 07 |
jari |
697 |
framework.storeSubCluster(getArrayMappedToData(), experiment, ClusterRepository.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
698 |
onDataChanged(this.data); |
2 |
26 Feb 07 |
jari |
699 |
} |
2 |
26 Feb 07 |
jari |
700 |
|
2 |
26 Feb 07 |
jari |
701 |
public void storeSelectedRowsAsCluster() { |
2 |
26 Feb 07 |
jari |
702 |
if (getArrayMappedToSelectedIndices().length == 0) { |
2 |
26 Feb 07 |
jari |
703 |
JOptionPane.showMessageDialog(null, "No rows selected! Cluster will not be saved", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
704 |
} else { |
2 |
26 Feb 07 |
jari |
705 |
framework.storeSubCluster(getArrayMappedToSelectedIndices(), experiment, ClusterRepository.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
706 |
onDataChanged(this.data); |
2 |
26 Feb 07 |
jari |
707 |
} |
2 |
26 Feb 07 |
jari |
708 |
} |
2 |
26 Feb 07 |
jari |
709 |
/** |
2 |
26 Feb 07 |
jari |
* Launches a new <code>MultipleExperimentViewer</code> containing the current cluster |
2 |
26 Feb 07 |
jari |
711 |
*/ |
2 |
26 Feb 07 |
jari |
712 |
public void launchNewSession(){ |
2 |
26 Feb 07 |
jari |
713 |
framework.launchNewMAV(getArrayMappedToData(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
714 |
} |
2 |
26 Feb 07 |
jari |
715 |
|
2 |
26 Feb 07 |
jari |
716 |
public void launchNewSessionWithSelectedRows() { |
2 |
26 Feb 07 |
jari |
717 |
framework.launchNewMAV(getArrayMappedToSelectedIndices(), this.experiment, "Multiple Experiment Viewer - Cluster Viewer", Cluster.GENE_CLUSTER); |
2 |
26 Feb 07 |
jari |
718 |
} |
2 |
26 Feb 07 |
jari |
719 |
|
2 |
26 Feb 07 |
jari |
720 |
public void sortInOrigOrder() { |
2 |
26 Feb 07 |
jari |
721 |
for (int i = 0; i < getSortedCluster().length; i++) { |
2 |
26 Feb 07 |
jari |
722 |
sortedClusters[this.clusterIndex][i] = getCluster()[i]; |
2 |
26 Feb 07 |
jari |
723 |
} |
2 |
26 Feb 07 |
jari |
724 |
|
2 |
26 Feb 07 |
jari |
725 |
clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
726 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
727 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) |
2 |
26 Feb 07 |
jari |
728 |
sortedAscending[getClusterIndex()][i] = false; |
2 |
26 Feb 07 |
jari |
729 |
} |
2 |
26 Feb 07 |
jari |
730 |
|
2 |
26 Feb 07 |
jari |
731 |
|
2 |
26 Feb 07 |
jari |
732 |
private int [] getArrayMappedToData(){ |
2 |
26 Feb 07 |
jari |
733 |
int [] clusterIndices = getCluster(); |
2 |
26 Feb 07 |
jari |
734 |
if(clusterIndices == null || clusterIndices.length < 1) |
2 |
26 Feb 07 |
jari |
735 |
return clusterIndices; |
2 |
26 Feb 07 |
jari |
736 |
|
2 |
26 Feb 07 |
jari |
737 |
int [] dataIndices = new int [clusterIndices.length]; |
2 |
26 Feb 07 |
jari |
738 |
for(int i = 0; i < clusterIndices.length; i++){ |
2 |
26 Feb 07 |
jari |
739 |
dataIndices[i] = this.experiment.getGeneIndexMappedToData(clusterIndices[i]); |
2 |
26 Feb 07 |
jari |
740 |
} |
2 |
26 Feb 07 |
jari |
741 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
742 |
} |
2 |
26 Feb 07 |
jari |
743 |
|
2 |
26 Feb 07 |
jari |
744 |
private int[] getArrayMappedToSelectedIndices() { |
2 |
26 Feb 07 |
jari |
745 |
int[] selectedRows = clusterTable.getSelectedRows(); |
2 |
26 Feb 07 |
jari |
746 |
if ((selectedRows == null) || (selectedRows.length == 0)) { |
2 |
26 Feb 07 |
jari |
747 |
return new int[0]; |
2 |
26 Feb 07 |
jari |
748 |
} |
2 |
26 Feb 07 |
jari |
749 |
|
2 |
26 Feb 07 |
jari |
750 |
int[] dataIndices = new int[selectedRows.length]; |
2 |
26 Feb 07 |
jari |
751 |
for (int i = 0; i < dataIndices.length; i++) { |
2 |
26 Feb 07 |
jari |
752 |
dataIndices[i] = this.experiment.getGeneIndexMappedToData(getSortedCluster()[selectedRows[i]]); |
2 |
26 Feb 07 |
jari |
753 |
} |
2 |
26 Feb 07 |
jari |
754 |
return dataIndices; |
2 |
26 Feb 07 |
jari |
755 |
} |
2 |
26 Feb 07 |
jari |
756 |
|
2 |
26 Feb 07 |
jari |
757 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
759 |
*/ |
2 |
26 Feb 07 |
jari |
760 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
761 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
762 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
763 |
return popup; |
2 |
26 Feb 07 |
jari |
764 |
} |
2 |
26 Feb 07 |
jari |
765 |
|
2 |
26 Feb 07 |
jari |
766 |
protected void addMenuItems(JPopupMenu menu, ActionListener listener) { |
2 |
26 Feb 07 |
jari |
767 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
768 |
menuItem = new JMenuItem("Store entire cluster", GUIFactory.getIcon("new16.gif")); |
2 |
26 Feb 07 |
jari |
769 |
menuItem.setActionCommand(STORE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
770 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
771 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
772 |
|
2 |
26 Feb 07 |
jari |
//menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
774 |
|
2 |
26 Feb 07 |
jari |
775 |
menuItem = new JMenuItem("Store selected rows as cluster", GUIFactory.getIcon("new16.gif")); |
2 |
26 Feb 07 |
jari |
776 |
menuItem.setActionCommand(STORE_SELECTED_ROWS_CMD); |
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("Delete cluster composed of selected rows", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
781 |
menuItem.setActionCommand(SET_DEF_COLOR_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 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
786 |
|
2 |
26 Feb 07 |
jari |
787 |
menuItem = new JMenuItem("Launch new session with entire cluster", GUIFactory.getIcon("launch_new_mav.gif")); |
2 |
26 Feb 07 |
jari |
788 |
menuItem.setActionCommand(LAUNCH_NEW_SESSION_CMD); |
2 |
26 Feb 07 |
jari |
789 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
790 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
791 |
|
2 |
26 Feb 07 |
jari |
//menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
793 |
|
2 |
26 Feb 07 |
jari |
794 |
menuItem = new JMenuItem("Launch new session with selected rows", GUIFactory.getIcon("launch_new_mav.gif")); |
2 |
26 Feb 07 |
jari |
795 |
menuItem.setActionCommand(LAUNCH_NEW_SESSION_WITH_SEL_ROWS_CMD); |
2 |
26 Feb 07 |
jari |
796 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
797 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
798 |
|
2 |
26 Feb 07 |
jari |
//menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
800 |
|
2 |
26 Feb 07 |
jari |
801 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
802 |
|
2 |
26 Feb 07 |
jari |
803 |
|
2 |
26 Feb 07 |
jari |
804 |
menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
805 |
menuItem.setActionCommand(SAVE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
806 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
807 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
808 |
|
2 |
26 Feb 07 |
jari |
809 |
menuItem = new JMenuItem("Save all clusters...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
810 |
menuItem.setActionCommand(SAVE_ALL_CLUSTERS_CMD); |
2 |
26 Feb 07 |
jari |
811 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
812 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
813 |
|
2 |
26 Feb 07 |
jari |
//menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
//menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
816 |
|
2 |
26 Feb 07 |
jari |
817 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
818 |
|
2 |
26 Feb 07 |
jari |
819 |
menuItem = new JMenuItem("Search...", GUIFactory.getIcon("ClusterInformationResult.gif")); |
2 |
26 Feb 07 |
jari |
820 |
menuItem.setActionCommand(SEARCH_CMD); |
2 |
26 Feb 07 |
jari |
821 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
822 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
823 |
|
2 |
26 Feb 07 |
jari |
824 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
825 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
826 |
|
2 |
26 Feb 07 |
jari |
827 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
828 |
|
2 |
26 Feb 07 |
jari |
829 |
menuItem = new JMenuItem("Select all rows...", GUIFactory.getIcon("TableViewerResult.gif")); |
2 |
26 Feb 07 |
jari |
830 |
menuItem.setActionCommand(SELECT_ALL_CMD); |
2 |
26 Feb 07 |
jari |
831 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
832 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
833 |
|
2 |
26 Feb 07 |
jari |
834 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
835 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
836 |
|
2 |
26 Feb 07 |
jari |
837 |
menuItem = new JMenuItem("Clear all selections...", GUIFactory.getIcon("TableViewerResult.gif")); |
2 |
26 Feb 07 |
jari |
838 |
menuItem.setActionCommand(CLEAR_ALL_CMD); |
2 |
26 Feb 07 |
jari |
839 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
840 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
841 |
|
2 |
26 Feb 07 |
jari |
//menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
//menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
844 |
|
2 |
26 Feb 07 |
jari |
845 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
846 |
|
2 |
26 Feb 07 |
jari |
847 |
menuItem = new JMenuItem("Sort table in original gene order...", GUIFactory.getIcon("TableViewerResult.gif")); |
2 |
26 Feb 07 |
jari |
848 |
menuItem.setActionCommand(SORT_ORIG_ORDER_CMD); |
2 |
26 Feb 07 |
jari |
849 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
850 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
851 |
|
2 |
26 Feb 07 |
jari |
//menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
//menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
854 |
|
2 |
26 Feb 07 |
jari |
855 |
menu.addSeparator(); |
2 |
26 Feb 07 |
jari |
856 |
|
2 |
26 Feb 07 |
jari |
857 |
urlMenuItem = new JMenuItem("Link to URL ...", GUIFactory.getIcon("ClusterInformationResult.gif")); |
2 |
26 Feb 07 |
jari |
858 |
urlMenuItem.setActionCommand(LINK_TO_URL_CMD); |
2 |
26 Feb 07 |
jari |
859 |
urlMenuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
//if (clusterTable.getSelectedRows().length != 1) |
2 |
26 Feb 07 |
jari |
861 |
menu.add(urlMenuItem); |
2 |
26 Feb 07 |
jari |
862 |
} |
2 |
26 Feb 07 |
jari |
863 |
|
2 |
26 Feb 07 |
jari |
864 |
/** |
2 |
26 Feb 07 |
jari |
* Saves all clusters. |
2 |
26 Feb 07 |
jari |
866 |
*/ |
2 |
26 Feb 07 |
jari |
867 |
private void onSaveClusters() { |
2 |
26 Feb 07 |
jari |
//Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
869 |
Frame frame = JOptionPane.getFrameForComponent(clusterTable); |
2 |
26 Feb 07 |
jari |
870 |
try { |
2 |
26 Feb 07 |
jari |
871 |
if (auxTitles.length == 0) { |
2 |
26 Feb 07 |
jari |
872 |
ExperimentUtil.saveExperiment(frame, getExperiment(), getData(), getClusters()); |
2 |
26 Feb 07 |
jari |
873 |
} else { |
2 |
26 Feb 07 |
jari |
874 |
ExperimentUtil.saveAllGeneClustersWithAux(frame, this.getExperiment(), this.getData(), this.getClusters(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
875 |
} |
2 |
26 Feb 07 |
jari |
//getContentComponent().repaint(); |
2 |
26 Feb 07 |
jari |
877 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
878 |
JOptionPane.showMessageDialog(frame, "Can not save clusters!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
879 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
880 |
} |
2 |
26 Feb 07 |
jari |
//clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
882 |
} |
2 |
26 Feb 07 |
jari |
883 |
|
2 |
26 Feb 07 |
jari |
884 |
/** |
2 |
26 Feb 07 |
jari |
* Save the viewer cluster. |
2 |
26 Feb 07 |
jari |
886 |
*/ |
2 |
26 Feb 07 |
jari |
887 |
private void onSaveCluster() { |
2 |
26 Feb 07 |
jari |
//Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
889 |
Frame frame = JOptionPane.getFrameForComponent(clusterTable); |
2 |
26 Feb 07 |
jari |
890 |
try { |
2 |
26 Feb 07 |
jari |
891 |
if (auxTitles.length == 0) { |
2 |
26 Feb 07 |
jari |
892 |
ExperimentUtil.saveExperiment(frame, getExperiment(), getData(), getCluster()); |
2 |
26 Feb 07 |
jari |
893 |
} else { |
2 |
26 Feb 07 |
jari |
894 |
ExperimentUtil.saveGeneClusterWithAux(frame, this.getExperiment(), this.getData(), this.getCluster(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
895 |
} |
2 |
26 Feb 07 |
jari |
//getContentComponent().repaint(); |
2 |
26 Feb 07 |
jari |
897 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
898 |
JOptionPane.showMessageDialog(frame, "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
899 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
900 |
} |
2 |
26 Feb 07 |
jari |
//clusterTable.repaint(); |
2 |
26 Feb 07 |
jari |
902 |
} |
2 |
26 Feb 07 |
jari |
903 |
|
2 |
26 Feb 07 |
jari |
904 |
private void linkToURL() { |
2 |
26 Feb 07 |
jari |
905 |
JFrame frame = (JFrame)(JOptionPane.getFrameForComponent(clusterTable)); |
2 |
26 Feb 07 |
jari |
//System.out.println("Before linkToURL: ClusterTablerViewer.lastSelectedAnnotationIndices = " + lastSelectedAnnotationIndices[0] + " " + lastSelectedAnnotationIndices[1]); |
2 |
26 Feb 07 |
jari |
907 |
ExperimentUtil.linkToURL(frame, getExperiment(), getData(), getArrayMappedToSelectedIndices()[0], ExperimentUtil.lastSelectedAnnotationIndices); |
2 |
26 Feb 07 |
jari |
//System.out.println("After linkToURL: ClusterTablerViewer.lastSelectedAnnotationIndices = " + lastSelectedAnnotationIndices[0] + " " + lastSelectedAnnotationIndices[1]); |
2 |
26 Feb 07 |
jari |
//lastSelectedAnnotationIndices = ExperimentUtil.getLastSelectedAnnotationIndices(); |
2 |
26 Feb 07 |
jari |
910 |
} |
2 |
26 Feb 07 |
jari |
911 |
|
2 |
26 Feb 07 |
jari |
912 |
private void linkToURL2() { |
2 |
26 Feb 07 |
jari |
913 |
JFrame frame = (JFrame)(JOptionPane.getFrameForComponent(clusterTable)); |
2 |
26 Feb 07 |
jari |
914 |
String colName = clusterTable.getColumnName(xColumn); |
2 |
26 Feb 07 |
jari |
915 |
ExperimentUtil.linkToURL(frame, getExperiment(), getData(), getArrayMappedToSelectedIndices()[0], colName, ExperimentUtil.lastSelectedAnnotationIndices); |
2 |
26 Feb 07 |
jari |
916 |
} |
2 |
26 Feb 07 |
jari |
917 |
|
2 |
26 Feb 07 |
jari |
918 |
/** |
2 |
26 Feb 07 |
jari |
* Removes a public color. |
2 |
26 Feb 07 |
jari |
920 |
*/ |
2 |
26 Feb 07 |
jari |
921 |
private void onSetDefaultColor() { |
2 |
26 Feb 07 |
jari |
922 |
setClusterColor(null); |
2 |
26 Feb 07 |
jari |
923 |
} |
2 |
26 Feb 07 |
jari |
924 |
|
2 |
26 Feb 07 |
jari |
925 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to mouse and action events. |
2 |
26 Feb 07 |
jari |
927 |
*/ |
2 |
26 Feb 07 |
jari |
928 |
private class Listener extends MouseAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
929 |
|
2 |
26 Feb 07 |
jari |
930 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
931 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
932 |
if (command.equals(SAVE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
933 |
onSaveCluster(); |
2 |
26 Feb 07 |
jari |
//getContentComponent().validate(); |
2 |
26 Feb 07 |
jari |
935 |
} else if (command.equals(SAVE_ALL_CLUSTERS_CMD)) { |
2 |
26 Feb 07 |
jari |
936 |
onSaveClusters(); |
2 |
26 Feb 07 |
jari |
//getContentComponent().validate(); |
2 |
26 Feb 07 |
jari |
938 |
} else if (command.equals(STORE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
939 |
storeCluster(); |
2 |
26 Feb 07 |
jari |
940 |
} else if (command.equals(STORE_SELECTED_ROWS_CMD)) { |
2 |
26 Feb 07 |
jari |
941 |
storeSelectedRowsAsCluster(); |
2 |
26 Feb 07 |
jari |
942 |
} else if (command.equals(SET_DEF_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
943 |
onSetDefaultColor(); |
2 |
26 Feb 07 |
jari |
944 |
} else if(command.equals(LAUNCH_NEW_SESSION_CMD)){ |
2 |
26 Feb 07 |
jari |
945 |
launchNewSession(); |
2 |
26 Feb 07 |
jari |
946 |
} else if(command.equals(LAUNCH_NEW_SESSION_WITH_SEL_ROWS_CMD)){ |
2 |
26 Feb 07 |
jari |
947 |
launchNewSessionWithSelectedRows(); |
2 |
26 Feb 07 |
jari |
948 |
} else if (command.equals(SEARCH_CMD)) { |
2 |
26 Feb 07 |
jari |
949 |
searchTable(); |
2 |
26 Feb 07 |
jari |
950 |
} else if (command.equals(CLEAR_ALL_CMD)) { |
2 |
26 Feb 07 |
jari |
951 |
clusterTable.clearSelection(); |
2 |
26 Feb 07 |
jari |
952 |
} else if (command.equals(SELECT_ALL_CMD)) { |
2 |
26 Feb 07 |
jari |
953 |
clusterTable.selectAll(); |
2 |
26 Feb 07 |
jari |
954 |
} else if (command.equals(SORT_ORIG_ORDER_CMD)) { |
2 |
26 Feb 07 |
jari |
955 |
sortInOrigOrder(); |
2 |
26 Feb 07 |
jari |
956 |
} else if (command.equals(LINK_TO_URL_CMD)) { |
2 |
26 Feb 07 |
jari |
957 |
linkToURL2(); |
2 |
26 Feb 07 |
jari |
958 |
} |
2 |
26 Feb 07 |
jari |
959 |
} |
2 |
26 Feb 07 |
jari |
960 |
|
2 |
26 Feb 07 |
jari |
961 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
//System.out.println("Mouse released"); |
2 |
26 Feb 07 |
jari |
963 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
964 |
} |
2 |
26 Feb 07 |
jari |
965 |
|
2 |
26 Feb 07 |
jari |
966 |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
//System.out.println("Mouse pressed"); |
2 |
26 Feb 07 |
jari |
968 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
969 |
} |
2 |
26 Feb 07 |
jari |
970 |
|
2 |
26 Feb 07 |
jari |
971 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
972 |
if (!e.isPopupTrigger() || getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
//xRow = clusterTable.rowAtPoint(e.getPoint()); |
2 |
26 Feb 07 |
jari |
//xColumn = clusterTable.columnAtPoint(e.getPoint()); |
2 |
26 Feb 07 |
jari |
975 |
xColumn = clusterTable.getSelectedColumn(); |
2 |
26 Feb 07 |
jari |
//System.out.println("xRow = " + xRow + ", xCol = " + xColumn); |
2 |
26 Feb 07 |
jari |
977 |
return; |
2 |
26 Feb 07 |
jari |
978 |
} |
2 |
26 Feb 07 |
jari |
979 |
|
2 |
26 Feb 07 |
jari |
980 |
if (clusterTable.getSelectedRowCount() != 1) { |
2 |
26 Feb 07 |
jari |
981 |
urlMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
982 |
} else { |
2 |
26 Feb 07 |
jari |
983 |
urlMenuItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
984 |
} |
2 |
26 Feb 07 |
jari |
985 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
986 |
|
2 |
26 Feb 07 |
jari |
987 |
} |
2 |
26 Feb 07 |
jari |
988 |
} |
2 |
26 Feb 07 |
jari |
989 |
|
2 |
26 Feb 07 |
jari |
990 |
public class ColorRenderer extends JLabel implements TableCellRenderer { |
2 |
26 Feb 07 |
jari |
991 |
Border unselectedBorder = null; |
2 |
26 Feb 07 |
jari |
992 |
Border selectedBorder = null; |
2 |
26 Feb 07 |
jari |
993 |
boolean isBordered = true; |
2 |
26 Feb 07 |
jari |
994 |
|
2 |
26 Feb 07 |
jari |
995 |
public ColorRenderer(boolean isBordered) { |
2 |
26 Feb 07 |
jari |
996 |
this.isBordered = isBordered; |
2 |
26 Feb 07 |
jari |
997 |
setOpaque(true); //MUST do this for background to show up. |
2 |
26 Feb 07 |
jari |
998 |
} |
2 |
26 Feb 07 |
jari |
999 |
|
2 |
26 Feb 07 |
jari |
1000 |
public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) { |
2 |
26 Feb 07 |
jari |
1001 |
Color newColor = (Color)color; |
2 |
26 Feb 07 |
jari |
1002 |
setBackground(newColor); |
2 |
26 Feb 07 |
jari |
1003 |
if (isBordered) { |
2 |
26 Feb 07 |
jari |
1004 |
if (isSelected) { |
2 |
26 Feb 07 |
jari |
1005 |
if (selectedBorder == null) { |
2 |
26 Feb 07 |
jari |
1006 |
selectedBorder = BorderFactory.createMatteBorder(2,5,2,5, |
2 |
26 Feb 07 |
jari |
1007 |
table.getSelectionBackground()); |
2 |
26 Feb 07 |
jari |
1008 |
} |
2 |
26 Feb 07 |
jari |
1009 |
setBorder(selectedBorder); |
2 |
26 Feb 07 |
jari |
1010 |
} else { |
2 |
26 Feb 07 |
jari |
1011 |
if (unselectedBorder == null) { |
2 |
26 Feb 07 |
jari |
1012 |
unselectedBorder = BorderFactory.createMatteBorder(2,5,2,5, |
2 |
26 Feb 07 |
jari |
1013 |
table.getBackground()); |
2 |
26 Feb 07 |
jari |
1014 |
} |
2 |
26 Feb 07 |
jari |
1015 |
setBorder(unselectedBorder); |
2 |
26 Feb 07 |
jari |
1016 |
} |
2 |
26 Feb 07 |
jari |
1017 |
} |
2 |
26 Feb 07 |
jari |
//setToolTipText(...); //Discussed in the following section |
2 |
26 Feb 07 |
jari |
1019 |
return this; |
2 |
26 Feb 07 |
jari |
1020 |
} |
2 |
26 Feb 07 |
jari |
1021 |
} |
2 |
26 Feb 07 |
jari |
1022 |
|
2 |
26 Feb 07 |
jari |
1023 |
private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException { |
2 |
26 Feb 07 |
jari |
1024 |
oos.writeObject(experiment); |
2 |
26 Feb 07 |
jari |
1025 |
oos.writeObject(clusters); |
2 |
26 Feb 07 |
jari |
1026 |
oos.writeObject(header); |
2 |
26 Feb 07 |
jari |
1027 |
oos.writeObject(popup); |
2 |
26 Feb 07 |
jari |
1028 |
|
2 |
26 Feb 07 |
jari |
//oos.writeObject(framework); |
2 |
26 Feb 07 |
jari |
//oos.writeObject(data); |
2 |
26 Feb 07 |
jari |
1031 |
oos.writeInt(clusterIndex); |
2 |
26 Feb 07 |
jari |
1032 |
oos.writeObject(sortedClusters); |
2 |
26 Feb 07 |
jari |
1033 |
oos.writeObject(samplesOrder); |
2 |
26 Feb 07 |
jari |
1034 |
oos.writeObject(auxTitles); |
2 |
26 Feb 07 |
jari |
1035 |
oos.writeObject(fieldNames); |
2 |
26 Feb 07 |
jari |
1036 |
oos.writeObject(auxData); |
2 |
26 Feb 07 |
jari |
//oos.writeObject(origData); |
2 |
26 Feb 07 |
jari |
1038 |
oos.writeObject(sortedAscending); |
2 |
26 Feb 07 |
jari |
1039 |
oos.writeObject(clusterTable); |
2 |
26 Feb 07 |
jari |
1040 |
oos.writeObject(clusterModel); |
2 |
26 Feb 07 |
jari |
1041 |
oos.writeObject(searchDialog); |
2 |
26 Feb 07 |
jari |
1042 |
} |
2 |
26 Feb 07 |
jari |
1043 |
|
2 |
26 Feb 07 |
jari |
1044 |
private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, ClassNotFoundException { |
2 |
26 Feb 07 |
jari |
1045 |
this.experiment = (Experiment)ois.readObject(); |
2 |
26 Feb 07 |
jari |
1046 |
this.clusters = (int [][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
1047 |
this.header = (JComponent)ois.readObject(); |
2 |
26 Feb 07 |
jari |
1048 |
this.popup = (JPopupMenu)ois.readObject(); |
2 |
26 Feb 07 |
jari |
1049 |
|
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 |
1052 |
this.clusterIndex = ois.readInt(); |
2 |
26 Feb 07 |
jari |
1053 |
this.sortedClusters = (int[][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
1054 |
this.samplesOrder = (int[])ois.readObject(); |
2 |
26 Feb 07 |
jari |
1055 |
this.auxTitles = (String[])ois.readObject(); |
2 |
26 Feb 07 |
jari |
1056 |
this.fieldNames = (String[])ois.readObject(); // need to serilaize this? |
2 |
26 Feb 07 |
jari |
1057 |
this.auxData = (Object[][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
//this.origData = |
2 |
26 Feb 07 |
jari |
1059 |
this.sortedAscending = (boolean[][])ois.readObject(); |
2 |
26 Feb 07 |
jari |
1060 |
this.clusterTable = (JTable)ois.readObject(); |
2 |
26 Feb 07 |
jari |
1061 |
this.clusterModel = (ClusterTableModel)ois.readObject(); |
2 |
26 Feb 07 |
jari |
1062 |
this.searchDialog = (ClusterTableSearchDialog)ois.readObject(); |
2 |
26 Feb 07 |
jari |
1063 |
|
2 |
26 Feb 07 |
jari |
//this.fieldNames = data.getFieldNames(); |
2 |
26 Feb 07 |
jari |
1065 |
|
2 |
26 Feb 07 |
jari |
1066 |
clusterTable.setDefaultRenderer(Color.class, new ColorRenderer(true)); |
2 |
26 Feb 07 |
jari |
1067 |
TableColumn column = null; |
2 |
26 Feb 07 |
jari |
1068 |
for (int i = 0; i < clusterModel.getColumnCount(); i++) { |
2 |
26 Feb 07 |
jari |
1069 |
column = clusterTable.getColumnModel().getColumn(i); |
2 |
26 Feb 07 |
jari |
1070 |
column.setMinWidth(30); |
2 |
26 Feb 07 |
jari |
1071 |
} |
2 |
26 Feb 07 |
jari |
1072 |
|
2 |
26 Feb 07 |
jari |
1073 |
this.sortedAscending = new boolean[clusters.length][clusterModel.getColumnCount()]; |
2 |
26 Feb 07 |
jari |
1074 |
for (int i = 0; i < sortedAscending.length; i++) { |
2 |
26 Feb 07 |
jari |
1075 |
for (int j = 0; j < sortedAscending[i].length; j++) { |
2 |
26 Feb 07 |
jari |
1076 |
sortedAscending[i][j] = false; |
2 |
26 Feb 07 |
jari |
1077 |
} |
2 |
26 Feb 07 |
jari |
1078 |
} |
2 |
26 Feb 07 |
jari |
1079 |
addMouseListenerToHeaderInTable(clusterTable); |
2 |
26 Feb 07 |
jari |
1080 |
header = clusterTable.getTableHeader(); |
2 |
26 Feb 07 |
jari |
1081 |
|
2 |
26 Feb 07 |
jari |
1082 |
searchDialog = new ClusterTableSearchDialog(JOptionPane.getFrameForComponent(clusterTable), clusterTable, false); |
2 |
26 Feb 07 |
jari |
1083 |
setMaxWidth(getContentComponent(), getHeaderComponent()); |
2 |
26 Feb 07 |
jari |
1084 |
|
2 |
26 Feb 07 |
jari |
1085 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
1086 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
//getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
1088 |
clusterTable.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
1089 |
} |
2 |
26 Feb 07 |
jari |
1090 |
|
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 |
1093 |
*/ |
2 |
26 Feb 07 |
jari |
1094 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
1095 |
return Cluster.GENE_CLUSTER; |
2 |
26 Feb 07 |
jari |
1096 |
} |
2 |
26 Feb 07 |
jari |
1097 |
|
2 |
26 Feb 07 |
jari |
1098 |
} |