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: CASTInitDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.4 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2005/03/10 20:30:31 $ |
2 |
26 Feb 07 |
jari |
* $Author: braistedj $ |
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.cast; |
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.Font; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
21 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
22 |
|
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.UIManager; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.border.EtchedBorder; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.border.TitledBorder; |
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.DistanceMetricPanel; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.HCLSelectionPanel; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.SampleSelectionPanel; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.util.awt.GBA; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
public class CASTInitDialog extends AlgorithmDialog{ |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
protected GBA gba; |
2 |
26 Feb 07 |
jari |
43 |
protected EventListener eventListener; |
2 |
26 Feb 07 |
jari |
44 |
|
2 |
26 Feb 07 |
jari |
45 |
protected SampleSelectionPanel sampleSelectionPanel; |
2 |
26 Feb 07 |
jari |
46 |
protected HCLSelectionPanel hclOpsPanel; |
2 |
26 Feb 07 |
jari |
47 |
|
2 |
26 Feb 07 |
jari |
48 |
protected JPanel thresholdPanel; |
2 |
26 Feb 07 |
jari |
49 |
protected JLabel thresholdLabel; |
2 |
26 Feb 07 |
jari |
50 |
public JTextField thresholdTextField; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
private DistanceMetricPanel metricPanel; |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
protected JPanel mainPanel; |
2 |
26 Feb 07 |
jari |
55 |
|
2 |
26 Feb 07 |
jari |
56 |
private boolean okPressed = false; |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
public CASTInitDialog(JFrame parent, boolean modal, String globalMetricName, boolean globalAbsoluteValue) { |
2 |
26 Feb 07 |
jari |
59 |
super(parent, "CAST: Cluster Affinity Search Technique", modal); |
2 |
26 Feb 07 |
jari |
60 |
initialize(globalMetricName, globalAbsoluteValue); |
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 |
65 |
protected void initialize(String globalMetricName, boolean globalAbsoluteValue) { |
2 |
26 Feb 07 |
jari |
66 |
gba = new GBA(); |
2 |
26 Feb 07 |
jari |
67 |
eventListener = new EventListener(); |
2 |
26 Feb 07 |
jari |
68 |
sampleSelectionPanel = new SampleSelectionPanel(Color.white, UIManager.getColor("Label.foreground"),true,"Sample Selection"); |
2 |
26 Feb 07 |
jari |
69 |
|
2 |
26 Feb 07 |
jari |
70 |
metricPanel = new DistanceMetricPanel(globalMetricName, globalAbsoluteValue, "Euclidean Distance", "CAST", true, true); |
2 |
26 Feb 07 |
jari |
71 |
|
2 |
26 Feb 07 |
jari |
72 |
thresholdLabel = new JLabel("Threshold"); |
2 |
26 Feb 07 |
jari |
73 |
thresholdTextField = new JTextField(10); |
2 |
26 Feb 07 |
jari |
74 |
thresholdTextField.setText("0.8"); |
2 |
26 Feb 07 |
jari |
75 |
thresholdPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
76 |
thresholdPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
77 |
thresholdPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
78 |
thresholdPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Threshold Parameter", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD,12), Color.black)); |
2 |
26 Feb 07 |
jari |
79 |
gba.add(thresholdPanel, thresholdLabel, 0, 0, 1, 1, 0, 0, GBA.NONE, GBA.C, new Insets(5, 5, 10, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
80 |
gba.add(thresholdPanel, thresholdTextField, 1, 0, 1, 1, 0, 0, GBA.H, GBA.C, new Insets(5, 5, 10, 5), 0, 0); |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
hclOpsPanel = new HCLSelectionPanel(); |
2 |
26 Feb 07 |
jari |
83 |
|
2 |
26 Feb 07 |
jari |
84 |
mainPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
85 |
mainPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
86 |
mainPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
87 |
gba.add(mainPanel, sampleSelectionPanel, 0, 0, 1, 1, 1, 1, GBA.H, GBA.C, new Insets(0, 0, 0, 0), 0, 0); |
2 |
26 Feb 07 |
jari |
88 |
gba.add(mainPanel, metricPanel, 0, 1, 1, 1, 1, 1, GBA.H, GBA.C, new Insets(0, 0, 0, 0), 0, 0); |
2 |
26 Feb 07 |
jari |
89 |
|
2 |
26 Feb 07 |
jari |
90 |
gba.add(mainPanel, thresholdPanel, 0, 2, 1, 1, 1, 1, GBA.H, GBA.C, new Insets(0, 0, 0, 0), 0, 0); |
2 |
26 Feb 07 |
jari |
91 |
gba.add(mainPanel, hclOpsPanel, 0, 3, 1, 1, 1, 1, GBA.H, GBA.C, new Insets(0, 0, 0, 0), 0, 0); |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
this.setResizable(false); |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
setActionListeners(eventListener); |
2 |
26 Feb 07 |
jari |
96 |
addContent(mainPanel); |
2 |
26 Feb 07 |
jari |
97 |
setSize(420, 290); |
2 |
26 Feb 07 |
jari |
98 |
pack(); |
2 |
26 Feb 07 |
jari |
99 |
} |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
public void setVisible(boolean visible) { |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
104 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
106 |
super.setVisible(visible); |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
108 |
if (visible) { |
2 |
26 Feb 07 |
jari |
109 |
okButton.requestFocus(); |
2 |
26 Feb 07 |
jari |
110 |
} |
2 |
26 Feb 07 |
jari |
111 |
} |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
113 |
public boolean isOkPressed() {return this.okPressed;} |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
public boolean isClusterGenes(){ |
2 |
26 Feb 07 |
jari |
116 |
return sampleSelectionPanel.isClusterGenesSelected(); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
public boolean isHCLSelected(){ |
2 |
26 Feb 07 |
jari |
120 |
return hclOpsPanel.isHCLSelected(); |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the currently selected metric |
2 |
26 Feb 07 |
jari |
125 |
*/ |
2 |
26 Feb 07 |
jari |
126 |
public int getDistanceMetric() { |
2 |
26 Feb 07 |
jari |
127 |
return metricPanel.getMetricIndex(); |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if the absolute checkbox is selected, else false |
2 |
26 Feb 07 |
jari |
132 |
*/ |
2 |
26 Feb 07 |
jari |
133 |
public boolean isAbsoluteDistance() { |
2 |
26 Feb 07 |
jari |
134 |
return metricPanel.getAbsoluteSelection(); |
2 |
26 Feb 07 |
jari |
135 |
} |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
public void resetControls(){ |
2 |
26 Feb 07 |
jari |
138 |
sampleSelectionPanel.setClusterGenesSelected(true); |
2 |
26 Feb 07 |
jari |
139 |
hclOpsPanel.setHCLSelected(false); |
2 |
26 Feb 07 |
jari |
140 |
thresholdTextField.setText("0.8"); |
2 |
26 Feb 07 |
jari |
141 |
metricPanel.reset(); |
2 |
26 Feb 07 |
jari |
142 |
} |
2 |
26 Feb 07 |
jari |
143 |
|
2 |
26 Feb 07 |
jari |
144 |
protected class EventListener implements ActionListener { |
2 |
26 Feb 07 |
jari |
145 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
146 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
147 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
148 |
okPressed = true; |
2 |
26 Feb 07 |
jari |
149 |
float val; |
2 |
26 Feb 07 |
jari |
150 |
try{ |
2 |
26 Feb 07 |
jari |
151 |
val = Float.parseFloat(thresholdTextField.getText()); |
2 |
26 Feb 07 |
jari |
152 |
} catch (NumberFormatException e){ |
2 |
26 Feb 07 |
jari |
153 |
JOptionPane.showMessageDialog(CASTInitDialog.this, "Number format error.", "Number Format Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
154 |
thresholdTextField.requestFocus(); |
2 |
26 Feb 07 |
jari |
155 |
thresholdTextField.selectAll(); |
2 |
26 Feb 07 |
jari |
156 |
return; |
2 |
26 Feb 07 |
jari |
157 |
} |
2 |
26 Feb 07 |
jari |
158 |
if(val <= 0 || val > 1){ |
2 |
26 Feb 07 |
jari |
159 |
JOptionPane.showMessageDialog(CASTInitDialog.this, "Threshold must be > 0 and <= 1.0", "Input Value Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
160 |
thresholdTextField.requestFocus(); |
2 |
26 Feb 07 |
jari |
161 |
thresholdTextField.selectAll(); |
2 |
26 Feb 07 |
jari |
162 |
return; |
2 |
26 Feb 07 |
jari |
163 |
} |
2 |
26 Feb 07 |
jari |
164 |
dispose(); |
2 |
26 Feb 07 |
jari |
165 |
} else if (command.equals("cancel-command")){ |
2 |
26 Feb 07 |
jari |
166 |
dispose(); |
2 |
26 Feb 07 |
jari |
167 |
} else if (command.equals("reset-command")){ |
2 |
26 Feb 07 |
jari |
168 |
resetControls(); |
2 |
26 Feb 07 |
jari |
169 |
} else if (command.equals("info-command")){ |
2 |
26 Feb 07 |
jari |
170 |
HelpWindow helpWindow = new HelpWindow(CASTInitDialog.this, "CAST Initialization Dialog"); |
2 |
26 Feb 07 |
jari |
171 |
if(helpWindow.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
172 |
helpWindow.setSize(450, 600); |
2 |
26 Feb 07 |
jari |
173 |
helpWindow.setLocation(); |
2 |
26 Feb 07 |
jari |
174 |
helpWindow.show(); |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
else{ |
2 |
26 Feb 07 |
jari |
177 |
helpWindow.dispose(); |
2 |
26 Feb 07 |
jari |
178 |
} |
2 |
26 Feb 07 |
jari |
179 |
} |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
} |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
184 |
|
2 |
26 Feb 07 |
jari |
185 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
186 |
CASTInitDialog d = new CASTInitDialog(new JFrame(), true, "Euclidean Distance", false); |
2 |
26 Feb 07 |
jari |
187 |
d.show(); |
2 |
26 Feb 07 |
jari |
188 |
System.exit(0); |
2 |
26 Feb 07 |
jari |
189 |
} |
2 |
26 Feb 07 |
jari |
190 |
|
2 |
26 Feb 07 |
jari |
191 |
protected void disposeDialog() { |
2 |
26 Feb 07 |
jari |
192 |
setVisible(false); |
2 |
26 Feb 07 |
jari |
193 |
dispose(); |
2 |
26 Feb 07 |
jari |
194 |
} |
2 |
26 Feb 07 |
jari |
195 |
|
2 |
26 Feb 07 |
jari |
196 |
} |