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: KMCInitDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.5 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/02/23 20:59:52 $ |
2 |
26 Feb 07 |
jari |
* $Author: caliente $ |
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.kmc; |
2 |
26 Feb 07 |
jari |
13 |
|
2 |
26 Feb 07 |
jari |
14 |
import java.awt.BorderLayout; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
22 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
23 |
|
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.ButtonGroup; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JRadioButton; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.UIManager; |
2 |
26 Feb 07 |
jari |
32 |
|
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DistanceMetricPanel; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.HCLSelectionPanel; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel; |
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.SampleSelectionPanel; |
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
41 |
public class KMCInitDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
42 |
private int result; |
2 |
26 Feb 07 |
jari |
43 |
private int k, iter; |
2 |
26 Feb 07 |
jari |
44 |
private JTextField textField1; |
2 |
26 Feb 07 |
jari |
45 |
private JTextField textField2; |
2 |
26 Feb 07 |
jari |
46 |
private JRadioButton calcMeans; |
2 |
26 Feb 07 |
jari |
47 |
private JRadioButton calcMedians; |
2 |
26 Feb 07 |
jari |
48 |
private ButtonGroup meanMedianGroup; |
2 |
26 Feb 07 |
jari |
49 |
private SampleSelectionPanel sampleSelectionPanel; |
2 |
26 Feb 07 |
jari |
50 |
private HCLSelectionPanel hclPanel; |
2 |
26 Feb 07 |
jari |
51 |
private DistanceMetricPanel metricPanel; |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>KMCInitDialog</code> with specified clusters and |
2 |
26 Feb 07 |
jari |
* iterations parameters. |
2 |
26 Feb 07 |
jari |
56 |
*/ |
2 |
26 Feb 07 |
jari |
57 |
public KMCInitDialog(javax.swing.JFrame parent, int clusters, int iterations, String globalMetricName, boolean globalAbsoluteValue) { |
2 |
26 Feb 07 |
jari |
58 |
super(parent, "KMC: K-Means/K-Medians", true); |
2 |
26 Feb 07 |
jari |
59 |
k = clusters; |
2 |
26 Feb 07 |
jari |
60 |
iter = iterations; |
2 |
26 Feb 07 |
jari |
61 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
62 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
sampleSelectionPanel = new SampleSelectionPanel(Color.white, UIManager.getColor("Label.foreground"),true,"Sample Selection"); |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
metricPanel = new DistanceMetricPanel(globalMetricName, globalAbsoluteValue, "Euclidean Distance", "KMC", true, true); |
2 |
26 Feb 07 |
jari |
67 |
|
2 |
26 Feb 07 |
jari |
68 |
meanMedianGroup = new ButtonGroup(); |
2 |
26 Feb 07 |
jari |
69 |
calcMeans = new JRadioButton("Calculate K-Means", true); |
2 |
26 Feb 07 |
jari |
70 |
calcMeans.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
71 |
calcMeans.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
72 |
calcMeans.setForeground(UIManager.getColor("Label.foreground")); |
2 |
26 Feb 07 |
jari |
73 |
calcMedians = new JRadioButton("Calculate K-Medians", false); |
2 |
26 Feb 07 |
jari |
74 |
calcMedians.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
75 |
calcMedians.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
76 |
calcMedians.setForeground(UIManager.getColor("Label.foreground")); |
2 |
26 Feb 07 |
jari |
77 |
meanMedianGroup.add(calcMeans); |
2 |
26 Feb 07 |
jari |
78 |
meanMedianGroup.add(calcMedians); |
2 |
26 Feb 07 |
jari |
79 |
|
2 |
26 Feb 07 |
jari |
80 |
ParameterPanel parameters = new ParameterPanel(); |
2 |
26 Feb 07 |
jari |
81 |
parameters.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
82 |
parameters.add(calcMeans, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(5,0,0,10),0,0)); |
2 |
26 Feb 07 |
jari |
83 |
parameters.add(calcMedians, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(5,10,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
84 |
parameters.add(new JLabel("Number of clusters"), new GridBagConstraints(0,1,1,1,0.0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(10,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
85 |
parameters.add(new JLabel("Maximum iterations"), new GridBagConstraints(0,2,1,1,0.0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(5,0,5,0),0,0)); |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
textField1 = new JTextField(String.valueOf(clusters), 7); |
2 |
26 Feb 07 |
jari |
88 |
textField2 = new JTextField(String.valueOf(iterations), 7); |
2 |
26 Feb 07 |
jari |
89 |
parameters.add(textField1, new GridBagConstraints(1,1,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.VERTICAL,new Insets(10,10,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
90 |
parameters.add(textField2, new GridBagConstraints(1,2,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.VERTICAL,new Insets(5,10,5,0),0,0)); |
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
92 |
hclPanel = new HCLSelectionPanel(); |
2 |
26 Feb 07 |
jari |
93 |
|
2 |
26 Feb 07 |
jari |
//construct mainPanel |
2 |
26 Feb 07 |
jari |
95 |
JPanel mainPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
96 |
mainPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
97 |
mainPanel.add(sampleSelectionPanel, new GridBagConstraints(0,0,1,1,1.0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
98 |
mainPanel.add(metricPanel, new GridBagConstraints(0,1,1,1,1.0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
99 |
mainPanel.add(parameters, new GridBagConstraints(0,2,1,1,1.0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
100 |
mainPanel.add(hclPanel, new GridBagConstraints(0,3,1,1,1.0,0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
102 |
JPanel controlPanel = new JPanel(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
103 |
controlPanel.setForeground(Color.white); |
2 |
26 Feb 07 |
jari |
104 |
controlPanel.setBorder(BorderFactory.createLineBorder(Color.gray)); |
2 |
26 Feb 07 |
jari |
105 |
controlPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
106 |
controlPanel.add(mainPanel, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
addContent(controlPanel); |
2 |
26 Feb 07 |
jari |
109 |
okButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
110 |
cancelButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
111 |
resetButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
112 |
infoButton.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
113 |
validate(); |
2 |
26 Feb 07 |
jari |
114 |
setSize(420, 410); |
2 |
26 Feb 07 |
jari |
115 |
setResizable(false); |
2 |
26 Feb 07 |
jari |
116 |
pack(); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
121 |
*/ |
2 |
26 Feb 07 |
jari |
122 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
123 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
124 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
125 |
show(); |
2 |
26 Feb 07 |
jari |
126 |
return result; |
2 |
26 Feb 07 |
jari |
127 |
} |
2 |
26 Feb 07 |
jari |
128 |
|
2 |
26 Feb 07 |
jari |
129 |
/** |
2 |
26 Feb 07 |
jari |
* Returns count of clusters. |
2 |
26 Feb 07 |
jari |
131 |
*/ |
2 |
26 Feb 07 |
jari |
132 |
public int getClusters() { |
2 |
26 Feb 07 |
jari |
133 |
return Integer.parseInt(textField1.getText()); |
2 |
26 Feb 07 |
jari |
134 |
} |
2 |
26 Feb 07 |
jari |
135 |
|
2 |
26 Feb 07 |
jari |
136 |
/** |
2 |
26 Feb 07 |
jari |
* Returns count of iterations. |
2 |
26 Feb 07 |
jari |
138 |
*/ |
2 |
26 Feb 07 |
jari |
139 |
public int getIterations() { |
2 |
26 Feb 07 |
jari |
140 |
return Integer.parseInt(textField2.getText()); |
2 |
26 Feb 07 |
jari |
141 |
} |
2 |
26 Feb 07 |
jari |
142 |
|
2 |
26 Feb 07 |
jari |
143 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if the hierarchical checkbox is selected. |
2 |
26 Feb 07 |
jari |
145 |
*/ |
2 |
26 Feb 07 |
jari |
146 |
public boolean isHierarchicalTree() { |
2 |
26 Feb 07 |
jari |
147 |
return hclPanel.isHCLSelected(); |
2 |
26 Feb 07 |
jari |
148 |
} |
2 |
26 Feb 07 |
jari |
149 |
|
2 |
26 Feb 07 |
jari |
150 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if calculate k-means is selected, false |
2 |
26 Feb 07 |
jari |
* if k-medians is selected |
2 |
26 Feb 07 |
jari |
153 |
*/ |
2 |
26 Feb 07 |
jari |
154 |
public boolean calculateMeans(){ |
2 |
26 Feb 07 |
jari |
155 |
return calcMeans.isSelected(); |
2 |
26 Feb 07 |
jari |
156 |
} |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
/** |
2 |
26 Feb 07 |
jari |
159 |
* |
2 |
26 Feb 07 |
jari |
160 |
*/ |
2 |
26 Feb 07 |
jari |
161 |
public boolean isClusterGenesSelected(){ |
2 |
26 Feb 07 |
jari |
162 |
return this.sampleSelectionPanel.isClusterGenesSelected(); |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
|
2 |
26 Feb 07 |
jari |
165 |
/** |
2 |
26 Feb 07 |
jari |
* Resets the controls |
2 |
26 Feb 07 |
jari |
167 |
*/ |
2 |
26 Feb 07 |
jari |
168 |
private void onReset(){ |
2 |
26 Feb 07 |
jari |
169 |
textField1.setText(String.valueOf(k)); |
2 |
26 Feb 07 |
jari |
170 |
textField2.setText(String.valueOf(iter)); |
2 |
26 Feb 07 |
jari |
171 |
sampleSelectionPanel.setClusterGenesSelected(true); |
2 |
26 Feb 07 |
jari |
172 |
hclPanel.setHCLSelected(false); |
2 |
26 Feb 07 |
jari |
173 |
calcMeans.setSelected(true); |
2 |
26 Feb 07 |
jari |
174 |
metricPanel.reset(); |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the currently selected metric |
2 |
26 Feb 07 |
jari |
179 |
*/ |
2 |
26 Feb 07 |
jari |
180 |
public int getDistanceMetric() { |
2 |
26 Feb 07 |
jari |
181 |
return metricPanel.getMetricIndex(); |
2 |
26 Feb 07 |
jari |
182 |
} |
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
184 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if the absolute checkbox is selected, else false |
2 |
26 Feb 07 |
jari |
186 |
*/ |
2 |
26 Feb 07 |
jari |
187 |
public boolean isAbsoluteDistance() { |
2 |
26 Feb 07 |
jari |
188 |
return metricPanel.getAbsoluteSelection(); |
2 |
26 Feb 07 |
jari |
189 |
} |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
191 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to the dialog events. |
2 |
26 Feb 07 |
jari |
193 |
*/ |
2 |
26 Feb 07 |
jari |
194 |
private class Listener extends DialogListener { |
2 |
26 Feb 07 |
jari |
195 |
|
2 |
26 Feb 07 |
jari |
196 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
197 |
Object source = e.getSource(); |
2 |
26 Feb 07 |
jari |
198 |
if (source == okButton) { |
2 |
26 Feb 07 |
jari |
199 |
try { |
2 |
26 Feb 07 |
jari |
200 |
int k = Integer.parseInt(textField1.getText()); |
2 |
26 Feb 07 |
jari |
201 |
if(k < 1){ |
2 |
26 Feb 07 |
jari |
202 |
textField1.requestFocus(); |
2 |
26 Feb 07 |
jari |
203 |
textField1.selectAll(); |
2 |
26 Feb 07 |
jari |
204 |
JOptionPane.showMessageDialog(KMCInitDialog.this, "Number of clusters must be greater than 0!", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
205 |
return; |
2 |
26 Feb 07 |
jari |
206 |
} |
2 |
26 Feb 07 |
jari |
207 |
|
2 |
26 Feb 07 |
jari |
208 |
int i = Integer.parseInt(textField2.getText()); |
2 |
26 Feb 07 |
jari |
209 |
if(i < 1){ |
2 |
26 Feb 07 |
jari |
210 |
textField2.requestFocus(); |
2 |
26 Feb 07 |
jari |
211 |
textField2.selectAll(); |
2 |
26 Feb 07 |
jari |
212 |
JOptionPane.showMessageDialog(KMCInitDialog.this, "Number of iterations must be greater than 0!", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
213 |
return; |
2 |
26 Feb 07 |
jari |
214 |
} |
2 |
26 Feb 07 |
jari |
215 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
216 |
} catch (NumberFormatException exception) { |
2 |
26 Feb 07 |
jari |
217 |
JOptionPane.showMessageDialog(KMCInitDialog.this, "Entry format error.", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
218 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
219 |
return; |
2 |
26 Feb 07 |
jari |
220 |
} |
2 |
26 Feb 07 |
jari |
221 |
dispose(); |
2 |
26 Feb 07 |
jari |
222 |
} else if (source == cancelButton) { |
2 |
26 Feb 07 |
jari |
223 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
224 |
dispose(); |
2 |
26 Feb 07 |
jari |
225 |
} |
2 |
26 Feb 07 |
jari |
226 |
else if (source == resetButton) { |
2 |
26 Feb 07 |
jari |
227 |
onReset(); |
2 |
26 Feb 07 |
jari |
228 |
} |
2 |
26 Feb 07 |
jari |
229 |
else if (source == infoButton){ |
2 |
26 Feb 07 |
jari |
230 |
HelpWindow hw = new HelpWindow(KMCInitDialog.this, "KMC Initialization Dialog"); |
2 |
26 Feb 07 |
jari |
231 |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
232 |
hw.setSize(450,650); |
2 |
26 Feb 07 |
jari |
233 |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
234 |
hw.show(); |
2 |
26 Feb 07 |
jari |
235 |
} |
2 |
26 Feb 07 |
jari |
236 |
else { |
2 |
26 Feb 07 |
jari |
237 |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
238 |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
239 |
} |
2 |
26 Feb 07 |
jari |
240 |
} |
2 |
26 Feb 07 |
jari |
241 |
} |
2 |
26 Feb 07 |
jari |
242 |
|
2 |
26 Feb 07 |
jari |
243 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
244 |
result = JOptionPane.CLOSED_OPTION; |
2 |
26 Feb 07 |
jari |
245 |
dispose(); |
2 |
26 Feb 07 |
jari |
246 |
} |
2 |
26 Feb 07 |
jari |
247 |
} |
2 |
26 Feb 07 |
jari |
248 |
|
2 |
26 Feb 07 |
jari |
249 |
public static void main(String[] args) { |
2 |
26 Feb 07 |
jari |
250 |
KMCInitDialog dlg = new KMCInitDialog(new javax.swing.JFrame(), 10 , 50, "Pearson Correlation", true); |
2 |
26 Feb 07 |
jari |
251 |
|
2 |
26 Feb 07 |
jari |
252 |
dlg.showModal(); |
2 |
26 Feb 07 |
jari |
253 |
System.exit(0); |
2 |
26 Feb 07 |
jari |
254 |
} |
2 |
26 Feb 07 |
jari |
255 |
|
2 |
26 Feb 07 |
jari |
256 |
protected void disposeDialog() { |
2 |
26 Feb 07 |
jari |
257 |
} |
2 |
26 Feb 07 |
jari |
258 |
|
2 |
26 Feb 07 |
jari |
259 |
} |