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: SVMResultViewer.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.9 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/05/02 16:57:36 $ |
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 |
|
2 |
26 Feb 07 |
jari |
13 |
package org.tigr.microarray.mev.cluster.gui.impl.svm; |
2 |
26 Feb 07 |
jari |
14 |
|
2 |
26 Feb 07 |
jari |
15 |
import java.awt.*; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.event.*; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.image.BufferedImage; |
2 |
26 Feb 07 |
jari |
18 |
import java.beans.Expression; |
2 |
26 Feb 07 |
jari |
19 |
|
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.*; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.event.MouseInputAdapter; |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
import org.tigr.microarray.mev.cluster.gui.*; |
2 |
26 Feb 07 |
jari |
24 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
25 |
|
2 |
26 Feb 07 |
jari |
26 |
abstract class SVMResultViewer extends JPanel implements IViewer { |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
private JPopupMenu MyPopup; |
2 |
26 Feb 07 |
jari |
29 |
private JMenuItem menuItem1; |
2 |
26 Feb 07 |
jari |
30 |
protected int labelIndex; |
2 |
26 Feb 07 |
jari |
31 |
protected IFramework framework; |
2 |
26 Feb 07 |
jari |
32 |
protected IData iData; |
2 |
26 Feb 07 |
jari |
33 |
private Experiment experiment; |
2 |
26 Feb 07 |
jari |
34 |
protected String [] fieldNames; |
2 |
26 Feb 07 |
jari |
35 |
protected String annotationLabel = ""; |
2 |
26 Feb 07 |
jari |
36 |
private int exptID = 0; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
JTable resultTable; |
2 |
26 Feb 07 |
jari |
39 |
JScrollPane jsp; |
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
public SVMResultViewer(Experiment e) { |
2 |
26 Feb 07 |
jari |
42 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
43 |
this.exptID = experiment.getId(); |
2 |
26 Feb 07 |
jari |
44 |
this.setAutoscrolls(true); |
2 |
26 Feb 07 |
jari |
45 |
this.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
46 |
resultTable = new JTable(); |
2 |
26 Feb 07 |
jari |
47 |
resultTable.setPreferredScrollableViewportSize(new Dimension(700,500)); |
2 |
26 Feb 07 |
jari |
48 |
resultTable.setAutoResizeMode(3); |
2 |
26 Feb 07 |
jari |
49 |
resultTable.setFont(new Font("monospaced", Font.PLAIN, 12)); |
2 |
26 Feb 07 |
jari |
50 |
MyPopup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
51 |
menuItem1 = new JMenuItem("Save classification...", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
52 |
menuItem1.setActionCommand("save-result-command"); |
2 |
26 Feb 07 |
jari |
53 |
menuItem1.addActionListener( new Listener() ); |
2 |
26 Feb 07 |
jari |
54 |
MyListener listener = new MyListener(); |
2 |
26 Feb 07 |
jari |
55 |
resultTable.addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
56 |
resultTable.addMouseMotionListener(listener); |
2 |
26 Feb 07 |
jari |
57 |
MyPopup.add(menuItem1); |
2 |
26 Feb 07 |
jari |
58 |
} |
2 |
26 Feb 07 |
jari |
59 |
/** |
2 |
26 Feb 07 |
jari |
* @inheritDoc |
2 |
26 Feb 07 |
jari |
* @see org.tigr.microarray.mev.cluster.gui.IViewer#getExpression() |
2 |
26 Feb 07 |
jari |
62 |
*/ |
2 |
26 Feb 07 |
jari |
63 |
public Expression getExpression(){ |
2 |
26 Feb 07 |
jari |
64 |
return new Expression(this, this.getClass(), "new", |
2 |
26 Feb 07 |
jari |
65 |
new Object[]{this.experiment}); |
2 |
26 Feb 07 |
jari |
66 |
} |
2 |
26 Feb 07 |
jari |
67 |
|
2 |
26 Feb 07 |
jari |
68 |
/* |
2 |
26 Feb 07 |
jari |
private void readObject(java.io.ObjectInputStream ois) throws java.io.IOException, ClassNotFoundException { |
2 |
26 Feb 07 |
jari |
this.experiment = (Experiment)ois.readObject(); |
2 |
26 Feb 07 |
jari |
this.Log = (JTextArea)ois.readObject(); |
2 |
26 Feb 07 |
jari |
this.resultPanel = (JPanel)ois.readObject(); |
2 |
26 Feb 07 |
jari |
this.fieldNames = (String [])ois.readObject(); |
2 |
26 Feb 07 |
jari |
this.labelIndex = ois.readInt(); |
2 |
26 Feb 07 |
jari |
75 |
|
2 |
26 Feb 07 |
jari |
MyListener listener = new MyListener(); |
2 |
26 Feb 07 |
jari |
MyPopup = new JPopupMenu(); |
2 |
26 Feb 07 |
jari |
menuItem1 = new JMenuItem("Save classification...", GUIFactory.getIcon("save_as16.gif")); |
2 |
26 Feb 07 |
jari |
menuItem1.setActionCommand("save-result-command"); |
2 |
26 Feb 07 |
jari |
menuItem1.addActionListener( new Listener() ); |
2 |
26 Feb 07 |
jari |
MyPopup.add(menuItem1); |
2 |
26 Feb 07 |
jari |
getContentComponent().addMouseListener(listener); |
2 |
26 Feb 07 |
jari |
83 |
} |
2 |
26 Feb 07 |
jari |
84 |
|
2 |
26 Feb 07 |
jari |
private void writeObject(java.io.ObjectOutputStream oos) throws java.io.IOException { |
2 |
26 Feb 07 |
jari |
oos.writeObject(this.experiment); |
2 |
26 Feb 07 |
jari |
oos.writeObject(this.Log); |
2 |
26 Feb 07 |
jari |
oos.writeObject(this.resultPanel); |
2 |
26 Feb 07 |
jari |
oos.writeObject(this.fieldNames); |
2 |
26 Feb 07 |
jari |
oos.writeInt(this.labelIndex); |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
*/ |
2 |
26 Feb 07 |
jari |
93 |
public void setExperimentID(int i){this.exptID = i;} |
2 |
26 Feb 07 |
jari |
94 |
public void setExperiment(Experiment e) { |
2 |
26 Feb 07 |
jari |
95 |
this.experiment = e; |
2 |
26 Feb 07 |
jari |
96 |
this.exptID = e.getId(); |
2 |
26 Feb 07 |
jari |
97 |
} |
2 |
26 Feb 07 |
jari |
98 |
public int getExperimentID(){return exptID;} |
2 |
26 Feb 07 |
jari |
99 |
public void onSelected(IFramework frm){ |
2 |
26 Feb 07 |
jari |
100 |
this.framework = frm; |
2 |
26 Feb 07 |
jari |
101 |
this.iData = frm.getData(); |
2 |
26 Feb 07 |
jari |
102 |
annotationLabel = framework.getData().getFieldNames()[framework.getDisplayMenu().getLabelIndex()]; |
2 |
26 Feb 07 |
jari |
103 |
} |
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
protected abstract void displayData(); |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
protected abstract void onSaveResult(); |
2 |
26 Feb 07 |
jari |
108 |
|
2 |
26 Feb 07 |
jari |
// IViewer interface |
2 |
26 Feb 07 |
jari |
110 |
public JComponent getContentComponent() { |
2 |
26 Feb 07 |
jari |
111 |
return this; |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
|
2 |
26 Feb 07 |
jari |
114 |
public JComponent getHeaderComponent() { |
2 |
26 Feb 07 |
jari |
115 |
return null; |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
|
2 |
26 Feb 07 |
jari |
118 |
public BufferedImage getImage() { |
2 |
26 Feb 07 |
jari |
119 |
return null; |
2 |
26 Feb 07 |
jari |
120 |
} |
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
|
2 |
26 Feb 07 |
jari |
124 |
public void onDataChanged(IData data) {} |
2 |
26 Feb 07 |
jari |
125 |
|
2 |
26 Feb 07 |
jari |
126 |
public void onMenuChanged(IDisplayMenu menu) { |
2 |
26 Feb 07 |
jari |
127 |
try { |
2 |
26 Feb 07 |
jari |
128 |
annotationLabel = framework.getData().getFieldNames()[framework.getDisplayMenu().getLabelIndex()]; |
2 |
26 Feb 07 |
jari |
129 |
labelIndex = framework.getDisplayMenu().getLabelIndex(); |
2 |
26 Feb 07 |
jari |
130 |
} catch (NullPointerException npe){ |
2 |
26 Feb 07 |
jari |
131 |
labelIndex = 0; |
2 |
26 Feb 07 |
jari |
132 |
annotationLabel = ""; |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
displayData(); |
2 |
26 Feb 07 |
jari |
135 |
updateSize(); |
2 |
26 Feb 07 |
jari |
136 |
} |
2 |
26 Feb 07 |
jari |
137 |
|
2 |
26 Feb 07 |
jari |
138 |
public void onDeselected() {} |
2 |
26 Feb 07 |
jari |
139 |
public void onClosed() {} |
2 |
26 Feb 07 |
jari |
140 |
protected abstract Dimension updateSize(); |
2 |
26 Feb 07 |
jari |
141 |
|
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the row (index) within the main iData which corresponds to |
2 |
26 Feb 07 |
jari |
* the passed index |
2 |
26 Feb 07 |
jari |
146 |
*/ |
2 |
26 Feb 07 |
jari |
147 |
protected int getMultipleArrayDataRow(int row) { |
2 |
26 Feb 07 |
jari |
148 |
return experiment.getGeneIndexMappedToData(row); |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
|
2 |
26 Feb 07 |
jari |
/** Returns a component to be inserted into the scroll pane row header |
2 |
26 Feb 07 |
jari |
152 |
*/ |
2 |
26 Feb 07 |
jari |
153 |
public JComponent getRowHeaderComponent() { |
2 |
26 Feb 07 |
jari |
154 |
return null; |
2 |
26 Feb 07 |
jari |
155 |
} |
2 |
26 Feb 07 |
jari |
156 |
|
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 |
159 |
*/ |
2 |
26 Feb 07 |
jari |
160 |
public JComponent getCornerComponent(int cornerIndex) { |
2 |
26 Feb 07 |
jari |
161 |
return null; |
2 |
26 Feb 07 |
jari |
162 |
} |
2 |
26 Feb 07 |
jari |
163 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's clusters or null |
2 |
26 Feb 07 |
jari |
165 |
*/ |
2 |
26 Feb 07 |
jari |
166 |
public int[][] getClusters() { |
2 |
26 Feb 07 |
jari |
167 |
return null; |
2 |
26 Feb 07 |
jari |
168 |
} |
2 |
26 Feb 07 |
jari |
169 |
|
2 |
26 Feb 07 |
jari |
/** Returns the viewer's experiment or null |
2 |
26 Feb 07 |
jari |
171 |
*/ |
2 |
26 Feb 07 |
jari |
172 |
public Experiment getExperiment() { |
2 |
26 Feb 07 |
jari |
173 |
return this.experiment; |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
|
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 |
178 |
*/ |
2 |
26 Feb 07 |
jari |
179 |
public int getViewerType() { |
2 |
26 Feb 07 |
jari |
180 |
return -1; |
2 |
26 Feb 07 |
jari |
181 |
} |
2 |
26 Feb 07 |
jari |
// GUI Listener class helpers |
2 |
26 Feb 07 |
jari |
183 |
class MyListener extends MouseInputAdapter { |
2 |
26 Feb 07 |
jari |
184 |
public void mousePressed(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
185 |
maybeShowPopup(e); |
2 |
26 Feb 07 |
jari |
186 |
} |
2 |
26 Feb 07 |
jari |
187 |
|
2 |
26 Feb 07 |
jari |
188 |
public void mouseReleased(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
189 |
maybeShowPopup(e); |
2 |
26 Feb 07 |
jari |
190 |
} |
2 |
26 Feb 07 |
jari |
191 |
|
2 |
26 Feb 07 |
jari |
192 |
private void maybeShowPopup(MouseEvent e) { |
2 |
26 Feb 07 |
jari |
193 |
if (e.isPopupTrigger()) { |
2 |
26 Feb 07 |
jari |
194 |
MyPopup.show(e.getComponent(),e.getX(),e.getY()); |
2 |
26 Feb 07 |
jari |
195 |
} |
2 |
26 Feb 07 |
jari |
196 |
} |
2 |
26 Feb 07 |
jari |
197 |
} |
2 |
26 Feb 07 |
jari |
198 |
|
2 |
26 Feb 07 |
jari |
199 |
class Listener implements ActionListener { |
2 |
26 Feb 07 |
jari |
200 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
201 |
AbstractButton source = (AbstractButton)e.getSource(); |
2 |
26 Feb 07 |
jari |
202 |
if (source.getActionCommand().equals("save-result-command")) { |
2 |
26 Feb 07 |
jari |
203 |
onSaveResult(); |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
206 |
} |
2 |
26 Feb 07 |
jari |
207 |
} |
2 |
26 Feb 07 |
jari |
208 |
|