2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2004, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: RelNetExperimentClusterViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.8 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/08/22 18:02:32 $ |
2 |
26 Feb 07 |
jari |
* $Author: eleanorahowe $ |
2 |
26 Feb 07 |
jari |
* $State: Exp $ |
2 |
26 Feb 07 |
jari |
11 |
*/ |
2 |
26 Feb 07 |
jari |
12 |
package org.tigr.microarray.mev.cluster.gui.impl.rn; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JColorChooser; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.gui.Experiment; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.gui.helpers.CentroidViewer; |
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterHeader; |
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentClusterViewer; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
public class RelNetExperimentClusterViewer extends ExperimentClusterViewer { |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
private static final String SET_COLOR_CMD = "set-color-cmd"; |
2 |
26 Feb 07 |
jari |
36 |
private static final String SET_DEF_COLOR_CMD = "set-def-color-cmd"; |
2 |
26 Feb 07 |
jari |
37 |
private static final String SAVE_CLUSTER_CMD = "save-cluster-cmd"; |
2 |
26 Feb 07 |
jari |
38 |
private static final String SAVE_ALL_CLUSTERS_CMD = "save-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>RelNetExperimentViewer</code> with specified |
2 |
26 Feb 07 |
jari |
* experiment and clusters. |
2 |
26 Feb 07 |
jari |
45 |
*/ |
2 |
26 Feb 07 |
jari |
46 |
public RelNetExperimentClusterViewer(Experiment experiment, int[][] clusters) { |
2 |
26 Feb 07 |
jari |
47 |
super(experiment, clusters); |
2 |
26 Feb 07 |
jari |
48 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
49 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
50 |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
51 |
getHeaderComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
52 |
} |
2 |
26 Feb 07 |
jari |
53 |
/** |
2 |
26 Feb 07 |
jari |
* State-saving constructor |
2 |
26 Feb 07 |
jari |
* @param clusters |
2 |
26 Feb 07 |
jari |
* @param genesOrder |
2 |
26 Feb 07 |
jari |
* @param drawAnnotations |
2 |
26 Feb 07 |
jari |
* @param offset |
2 |
26 Feb 07 |
jari |
* @param header |
2 |
26 Feb 07 |
jari |
* @param hasCentroid |
2 |
26 Feb 07 |
jari |
* @param centroids |
2 |
26 Feb 07 |
jari |
* @param elementSize |
2 |
26 Feb 07 |
jari |
* @param labelIndex |
2 |
26 Feb 07 |
jari |
* @param exptID |
2 |
26 Feb 07 |
jari |
65 |
*/ |
2 |
26 Feb 07 |
jari |
66 |
public RelNetExperimentClusterViewer(Experiment e, int[][] clusters, int[] genesOrder, Boolean drawAnnotations, |
2 |
26 Feb 07 |
jari |
67 |
Integer offset){ |
2 |
26 Feb 07 |
jari |
68 |
super(e, clusters, genesOrder, drawAnnotations, offset); |
2 |
26 Feb 07 |
jari |
69 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
70 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
71 |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
72 |
getHeaderComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
73 |
} |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
77 |
*/ |
2 |
26 Feb 07 |
jari |
78 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
79 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
80 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
81 |
return popup; |
2 |
26 Feb 07 |
jari |
82 |
} |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
/** |
2 |
26 Feb 07 |
jari |
* Adds the viewer specific menu items. |
2 |
26 Feb 07 |
jari |
86 |
*/ |
2 |
26 Feb 07 |
jari |
87 |
private void addMenuItems(JPopupMenu menu, Listener listener) { |
2 |
26 Feb 07 |
jari |
88 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
menuItem = new JMenuItem("Set public cluster...", GUIFactory.getIcon("new16.gif")); |
2 |
26 Feb 07 |
jari |
91 |
menuItem.setActionCommand(SET_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
92 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
93 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
menuItem = new JMenuItem("Delete public cluster", GUIFactory.getIcon("delete16.gif")); |
2 |
26 Feb 07 |
jari |
96 |
menuItem.setActionCommand(SET_DEF_COLOR_CMD); |
2 |
26 Feb 07 |
jari |
97 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
98 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
menuItem = new JMenuItem("Save cluster...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
101 |
menuItem.setActionCommand(SAVE_CLUSTER_CMD); |
2 |
26 Feb 07 |
jari |
102 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
103 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
menuItem = new JMenuItem("Save all clusters...", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
106 |
menuItem.setActionCommand(SAVE_ALL_CLUSTERS_CMD); |
2 |
26 Feb 07 |
jari |
107 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
108 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
109 |
} |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
/** |
2 |
26 Feb 07 |
jari |
* Saves clusters. |
2 |
26 Feb 07 |
jari |
113 |
*/ |
2 |
26 Feb 07 |
jari |
114 |
private void onSaveClusters() { |
2 |
26 Feb 07 |
jari |
115 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
116 |
try { |
2 |
26 Feb 07 |
jari |
117 |
saveClusters(frame); |
2 |
26 Feb 07 |
jari |
118 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
119 |
JOptionPane.showMessageDialog(frame, "Can not save clusters!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
120 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
} |
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
124 |
/** |
2 |
26 Feb 07 |
jari |
* Save the viewer cluster. |
2 |
26 Feb 07 |
jari |
126 |
*/ |
2 |
26 Feb 07 |
jari |
127 |
private void onSaveCluster() { |
2 |
26 Feb 07 |
jari |
128 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
129 |
try { |
2 |
26 Feb 07 |
jari |
130 |
saveCluster(frame); |
2 |
26 Feb 07 |
jari |
131 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
132 |
JOptionPane.showMessageDialog(frame, "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
133 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
134 |
} |
2 |
26 Feb 07 |
jari |
135 |
} |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
/** |
2 |
26 Feb 07 |
jari |
* Sets a public color. |
2 |
26 Feb 07 |
jari |
139 |
*/ |
2 |
26 Feb 07 |
jari |
140 |
private void onSetColor() { |
2 |
26 Feb 07 |
jari |
141 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
142 |
Color newColor = JColorChooser.showDialog(frame, "Choose color", CentroidViewer.DEF_CLUSTER_COLOR); |
2 |
26 Feb 07 |
jari |
143 |
if (newColor != null) { |
2 |
26 Feb 07 |
jari |
144 |
setClusterColor(newColor); |
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 |
* Removes a public color. |
2 |
26 Feb 07 |
jari |
150 |
*/ |
2 |
26 Feb 07 |
jari |
151 |
private void onSetDefaultColor() { |
2 |
26 Feb 07 |
jari |
152 |
setClusterColor(null); |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
155 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to mouse and action events. |
2 |
26 Feb 07 |
jari |
157 |
*/ |
2 |
26 Feb 07 |
jari |
158 |
private class Listener extends MouseAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
161 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
162 |
if (command.equals(SAVE_CLUSTER_CMD)) { |
2 |
26 Feb 07 |
jari |
163 |
onSaveCluster(); |
2 |
26 Feb 07 |
jari |
164 |
} else if (command.equals(SAVE_ALL_CLUSTERS_CMD)) { |
2 |
26 Feb 07 |
jari |
165 |
onSaveClusters(); |
2 |
26 Feb 07 |
jari |
166 |
} else if (command.equals(SET_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
167 |
onSetColor(); |
2 |
26 Feb 07 |
jari |
168 |
} else if (command.equals(SET_DEF_COLOR_CMD)) { |
2 |
26 Feb 07 |
jari |
169 |
onSetDefaultColor(); |
2 |
26 Feb 07 |
jari |
170 |
} |
2 |
26 Feb 07 |
jari |
171 |
} |
2 |
26 Feb 07 |
jari |
172 |
|
2 |
26 Feb 07 |
jari |
173 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
174 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
178 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
|
2 |
26 Feb 07 |
jari |
181 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
if (!e.isPopupTrigger() || getCluster() == null || getCluster().length == 0) { |
2 |
26 Feb 07 |
jari |
184 |
return; |
2 |
26 Feb 07 |
jari |
185 |
} |
2 |
26 Feb 07 |
jari |
186 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
187 |
} |
2 |
26 Feb 07 |
jari |
188 |
} |
2 |
26 Feb 07 |
jari |
189 |
} |