2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2003, The Institute for Genomic Research (TIGR). |
2 |
26 Feb 07 |
jari |
All rights reserved. |
2 |
26 Feb 07 |
jari |
4 |
*/ |
2 |
26 Feb 07 |
jari |
5 |
/* |
2 |
26 Feb 07 |
jari |
* $RCSfile: PTMCentroidsViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.6 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/03/24 15:51:08 $ |
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.ptm; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.event.MouseAdapter; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.event.MouseEvent; |
2 |
26 Feb 07 |
jari |
19 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
20 |
|
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JMenuItem; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JPopupMenu; |
2 |
26 Feb 07 |
jari |
24 |
|
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.helpers.CentroidViewer; |
2 |
26 Feb 07 |
jari |
27 |
import org.tigr.microarray.mev.cluster.gui.helpers.CentroidsViewer; |
2 |
26 Feb 07 |
jari |
28 |
import org.tigr.microarray.mev.cluster.gui.helpers.ExperimentUtil; |
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 |
public class PTMCentroidsViewer extends CentroidsViewer { //PTMSubCentroidsViewer { |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
private static final String SAVE_ALL_CLUSTERS_CMD = "save-all-clusters-cmd"; |
2 |
26 Feb 07 |
jari |
34 |
private static final String SET_Y_TO_EXPERIMENT_MAX_CMD = "set-y-to-exp-max-cmd"; |
2 |
26 Feb 07 |
jari |
35 |
private static final String SET_Y_TO_CLUSTER_MAX_CMD = "set-y-to-cluster-max-cmd"; |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
private JPopupMenu popup; |
2 |
26 Feb 07 |
jari |
38 |
private JMenuItem setOverallMaxMenuItem; |
2 |
26 Feb 07 |
jari |
39 |
private JMenuItem setClusterMaxMenuItem; |
2 |
26 Feb 07 |
jari |
40 |
private String[] auxTitles; |
2 |
26 Feb 07 |
jari |
41 |
private Object[][] auxData; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>PTMCentroidsViewer</code> for specified experiment |
2 |
26 Feb 07 |
jari |
* and clusters. |
2 |
26 Feb 07 |
jari |
46 |
*/ |
2 |
26 Feb 07 |
jari |
47 |
public PTMCentroidsViewer(Experiment experiment, int[][] clusters, Vector templateVector, String[] auxTitles, Object[][] auxData) { |
2 |
26 Feb 07 |
jari |
48 |
super(experiment, clusters); |
2 |
26 Feb 07 |
jari |
49 |
this.auxTitles = auxTitles; |
2 |
26 Feb 07 |
jari |
50 |
this.auxData = auxData; |
2 |
26 Feb 07 |
jari |
51 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
52 |
this.popup = createJPopupMenu(listener); |
2 |
26 Feb 07 |
jari |
53 |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
54 |
} |
2 |
26 Feb 07 |
jari |
55 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>CentroidsViewer</code> for specified experiment |
2 |
26 Feb 07 |
jari |
* and clusters. |
2 |
26 Feb 07 |
jari |
58 |
*/ |
2 |
26 Feb 07 |
jari |
59 |
public PTMCentroidsViewer(CentroidViewer cv) { |
2 |
26 Feb 07 |
jari |
60 |
super(cv); |
2 |
26 Feb 07 |
jari |
61 |
} |
2 |
26 Feb 07 |
jari |
62 |
|
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
/** |
2 |
26 Feb 07 |
jari |
* Creates a popup menu. |
2 |
26 Feb 07 |
jari |
66 |
*/ |
2 |
26 Feb 07 |
jari |
67 |
private JPopupMenu createJPopupMenu(Listener listener) { |
2 |
26 Feb 07 |
jari |
68 |
JPopupMenu popup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
69 |
addMenuItems(popup, listener); |
2 |
26 Feb 07 |
jari |
70 |
return popup; |
2 |
26 Feb 07 |
jari |
71 |
} |
2 |
26 Feb 07 |
jari |
72 |
|
2 |
26 Feb 07 |
jari |
73 |
/** |
2 |
26 Feb 07 |
jari |
* Adds the viewer specific menu items. |
2 |
26 Feb 07 |
jari |
75 |
*/ |
2 |
26 Feb 07 |
jari |
76 |
private void addMenuItems(JPopupMenu menu, Listener listener) { |
2 |
26 Feb 07 |
jari |
77 |
JMenuItem menuItem; |
2 |
26 Feb 07 |
jari |
78 |
menuItem = new JMenuItem("Save all clusters", GUIFactory.getIcon("save16.gif")); |
2 |
26 Feb 07 |
jari |
79 |
menuItem.setActionCommand(SAVE_ALL_CLUSTERS_CMD); |
2 |
26 Feb 07 |
jari |
80 |
menuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
81 |
menu.add(menuItem); |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
setOverallMaxMenuItem = new JMenuItem("Set Y to overall max...", GUIFactory.getIcon("Y_range_expand.gif")); |
2 |
26 Feb 07 |
jari |
84 |
setOverallMaxMenuItem.setActionCommand(SET_Y_TO_EXPERIMENT_MAX_CMD); |
2 |
26 Feb 07 |
jari |
85 |
setOverallMaxMenuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
86 |
setOverallMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
87 |
menu.add(setOverallMaxMenuItem); |
2 |
26 Feb 07 |
jari |
88 |
|
2 |
26 Feb 07 |
jari |
89 |
setClusterMaxMenuItem = new JMenuItem("Set Y to cluster max...", GUIFactory.getIcon("Y_range_expand.gif")); |
2 |
26 Feb 07 |
jari |
90 |
setClusterMaxMenuItem.setActionCommand(SET_Y_TO_CLUSTER_MAX_CMD); |
2 |
26 Feb 07 |
jari |
91 |
setClusterMaxMenuItem.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
92 |
menu.add(setClusterMaxMenuItem); |
2 |
26 Feb 07 |
jari |
93 |
} |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
/** |
2 |
26 Feb 07 |
jari |
* Saves all clusters. |
2 |
26 Feb 07 |
jari |
97 |
*/ |
2 |
26 Feb 07 |
jari |
98 |
private void onSaveClusters() { |
2 |
26 Feb 07 |
jari |
99 |
Frame frame = JOptionPane.getFrameForComponent(getContentComponent()); |
2 |
26 Feb 07 |
jari |
100 |
try { |
2 |
26 Feb 07 |
jari |
101 |
ExperimentUtil.saveAllGeneClustersWithAux(frame, getExperiment(), getData(), getClusters(), auxTitles, auxData); |
2 |
26 Feb 07 |
jari |
102 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
103 |
JOptionPane.showMessageDialog(frame, "Can not save cluster!", e.toString(), JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
104 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
105 |
} |
2 |
26 Feb 07 |
jari |
106 |
} |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
private void setAllYRanges(int yRangeOption){ |
2 |
26 Feb 07 |
jari |
109 |
int numClusters = getClusters().length; |
2 |
26 Feb 07 |
jari |
110 |
for(int i = 0; i < numClusters; i++){ |
2 |
26 Feb 07 |
jari |
111 |
centroidViewer.setClusterIndex(i); |
2 |
26 Feb 07 |
jari |
112 |
centroidViewer.setYRangeOption(yRangeOption); |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
} |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
116 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to mouse and action events. |
2 |
26 Feb 07 |
jari |
118 |
*/ |
2 |
26 Feb 07 |
jari |
119 |
private class Listener extends MouseAdapter implements ActionListener { |
2 |
26 Feb 07 |
jari |
120 |
|
2 |
26 Feb 07 |
jari |
121 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
122 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
123 |
if (command.equals(SAVE_ALL_CLUSTERS_CMD)) { |
2 |
26 Feb 07 |
jari |
124 |
onSaveClusters(); |
2 |
26 Feb 07 |
jari |
125 |
} else if(command.equals(SET_Y_TO_EXPERIMENT_MAX_CMD)){ |
2 |
26 Feb 07 |
jari |
126 |
setAllYRanges(CentroidViewer.USE_EXPERIMENT_MAX); |
2 |
26 Feb 07 |
jari |
127 |
setClusterMaxMenuItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
128 |
setOverallMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
129 |
repaint(); |
2 |
26 Feb 07 |
jari |
130 |
} else if(command.equals(SET_Y_TO_CLUSTER_MAX_CMD)){ |
2 |
26 Feb 07 |
jari |
131 |
setAllYRanges(CentroidViewer.USE_CLUSTER_MAX); |
2 |
26 Feb 07 |
jari |
132 |
setClusterMaxMenuItem.setEnabled(false); |
2 |
26 Feb 07 |
jari |
133 |
setOverallMaxMenuItem.setEnabled(true); |
2 |
26 Feb 07 |
jari |
134 |
repaint(); |
2 |
26 Feb 07 |
jari |
135 |
} |
2 |
26 Feb 07 |
jari |
136 |
} |
2 |
26 Feb 07 |
jari |
137 |
|
2 |
26 Feb 07 |
jari |
138 |
public void mouseReleased(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
139 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
140 |
} |
2 |
26 Feb 07 |
jari |
141 |
|
2 |
26 Feb 07 |
jari |
142 |
public void mousePressed(MouseEvent event) { |
2 |
26 Feb 07 |
jari |
143 |
maybeShowPopup(event); |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
|
2 |
26 Feb 07 |
jari |
146 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
147 |
if (!e.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
148 |
return; |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
popup.show(e.getComponent(), e.getX(), e.getY()); |
2 |
26 Feb 07 |
jari |
151 |
} |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
} |