2 |
26 Feb 07 |
jari |
1 |
package org.tigr.microarray.mev; |
2 |
26 Feb 07 |
jari |
2 |
/* |
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 |
* CustomToolbarInitDialog.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
8 |
* |
2 |
26 Feb 07 |
jari |
9 |
*/ |
2 |
26 Feb 07 |
jari |
10 |
|
2 |
26 Feb 07 |
jari |
11 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
12 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Graphics; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.Image; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Point; |
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 |
import java.awt.event.ItemEvent; |
2 |
26 Feb 07 |
jari |
23 |
import java.awt.event.ItemListener; |
2 |
26 Feb 07 |
jari |
24 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
25 |
import java.util.Hashtable; |
2 |
26 Feb 07 |
jari |
26 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
27 |
|
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.Action; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.ButtonGroup; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.Icon; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.JCheckBox; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
34 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
35 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
36 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
37 |
import javax.swing.border.BevelBorder; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
39 |
import org.tigr.microarray.mev.action.ActionManager; |
2 |
26 Feb 07 |
jari |
40 |
import org.tigr.microarray.mev.cluster.gui.IClusterGUI; |
2 |
26 Feb 07 |
jari |
41 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
42 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
43 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener; |
2 |
26 Feb 07 |
jari |
44 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel; |
2 |
26 Feb 07 |
jari |
45 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
46 |
import org.tigr.microarray.mev.script.util.ScriptConstants; |
2 |
26 Feb 07 |
jari |
47 |
|
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
public class CustomToolbarInitDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
50 |
|
2 |
26 Feb 07 |
jari |
/** result |
2 |
26 Feb 07 |
jari |
52 |
*/ |
2 |
26 Feb 07 |
jari |
53 |
private int result; |
2 |
26 Feb 07 |
jari |
/** algorithm index |
2 |
26 Feb 07 |
jari |
55 |
*/ |
2 |
26 Feb 07 |
jari |
56 |
private int algorithmIndex = -1; |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
private String currentAlgorithmName; |
2 |
26 Feb 07 |
jari |
/** main panel for components |
2 |
26 Feb 07 |
jari |
60 |
*/ |
2 |
26 Feb 07 |
jari |
61 |
private JPanel mainPanel; |
2 |
26 Feb 07 |
jari |
/** action manager to accumulate available mev algorithms for presentation |
2 |
26 Feb 07 |
jari |
63 |
*/ |
2 |
26 Feb 07 |
jari |
64 |
private ActionManager actionManager; |
2 |
26 Feb 07 |
jari |
/** analysis algorithm selection controls |
2 |
26 Feb 07 |
jari |
66 |
*/ |
2 |
26 Feb 07 |
jari |
67 |
private AlgorithmSelectionPanel algSelPanel; |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
private JScrollPane sPane; |
2 |
26 Feb 07 |
jari |
/** Creates a new instance of CustomToolbarInitDialog |
2 |
26 Feb 07 |
jari |
* @param manager ActionManager to provide available algorithm |
2 |
26 Feb 07 |
jari |
72 |
*/ |
2 |
26 Feb 07 |
jari |
73 |
public CustomToolbarInitDialog(ActionManager manager) { |
2 |
26 Feb 07 |
jari |
74 |
super(new JFrame(), "Customized MenuToolbar Initialization Dialog", true); |
2 |
26 Feb 07 |
jari |
75 |
this.actionManager = manager; |
2 |
26 Feb 07 |
jari |
76 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
mainPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
79 |
mainPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
80 |
this.setResetButtonText("Select All"); |
2 |
26 Feb 07 |
jari |
//previewPanel = new PreviewPanel(); |
2 |
26 Feb 07 |
jari |
82 |
algSelPanel = new AlgorithmSelectionPanel(actionManager); |
2 |
26 Feb 07 |
jari |
83 |
sPane=new JScrollPane(algSelPanel); |
2 |
26 Feb 07 |
jari |
//mainPanel.add(previewPanel, new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
85 |
mainPanel.add(sPane, new GridBagConstraints(0,0,1,2,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
88 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
89 |
addContent(mainPanel); |
2 |
26 Feb 07 |
jari |
90 |
setActionListeners(listener); |
2 |
26 Feb 07 |
jari |
91 |
pack(); |
2 |
26 Feb 07 |
jari |
92 |
/* |
2 |
26 Feb 07 |
jari |
if(!isAffyData) |
2 |
26 Feb 07 |
jari |
setSize(new Dimension(510, 587)); |
2 |
26 Feb 07 |
jari |
else |
2 |
26 Feb 07 |
jari |
setSize(new Dimension(510, 665)); |
2 |
26 Feb 07 |
jari |
97 |
*/ |
2 |
26 Feb 07 |
jari |
98 |
setSize(new Dimension(520, 665)); |
2 |
26 Feb 07 |
jari |
99 |
} |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
103 |
*/ |
2 |
26 Feb 07 |
jari |
104 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
105 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
106 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
107 |
show(); |
2 |
26 Feb 07 |
jari |
108 |
return result; |
2 |
26 Feb 07 |
jari |
109 |
} |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
|
2 |
26 Feb 07 |
jari |
/** Resets the controls |
2 |
26 Feb 07 |
jari |
113 |
*/ |
2 |
26 Feb 07 |
jari |
114 |
public void onReset() { |
2 |
26 Feb 07 |
jari |
115 |
TMEV.initCustomerAnalysis(getAlgorithmCount(this.actionManager)); |
2 |
26 Feb 07 |
jari |
116 |
|
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
/** returns algorithm name |
2 |
26 Feb 07 |
jari |
120 |
*/ |
2 |
26 Feb 07 |
jari |
121 |
public String getAlgorithmName() { |
2 |
26 Feb 07 |
jari |
122 |
return currentAlgorithmName; |
2 |
26 Feb 07 |
jari |
123 |
} |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
/** returns the algorthms index |
2 |
26 Feb 07 |
jari |
126 |
*/ |
2 |
26 Feb 07 |
jari |
127 |
public int getAlgorithmIndex() { |
2 |
26 Feb 07 |
jari |
128 |
int index; |
2 |
26 Feb 07 |
jari |
129 |
if(currentAlgorithmName != null) { |
2 |
26 Feb 07 |
jari |
130 |
String number = (String)(algSelPanel.indexHash.get(currentAlgorithmName)); |
2 |
26 Feb 07 |
jari |
131 |
if(number != null) { |
2 |
26 Feb 07 |
jari |
132 |
return Integer.parseInt(number); |
2 |
26 Feb 07 |
jari |
133 |
} |
2 |
26 Feb 07 |
jari |
134 |
} |
2 |
26 Feb 07 |
jari |
135 |
return -1; |
2 |
26 Feb 07 |
jari |
136 |
} |
2 |
26 Feb 07 |
jari |
137 |
public int getAlgorithmCount(ActionManager actionManager) { |
2 |
26 Feb 07 |
jari |
138 |
int total=0; |
2 |
26 Feb 07 |
jari |
139 |
Action action; |
2 |
26 Feb 07 |
jari |
140 |
while ((action = actionManager.getAction(ActionManager.ANALYSIS_ACTION+String.valueOf(total)))!=null){ |
2 |
26 Feb 07 |
jari |
141 |
total++; |
2 |
26 Feb 07 |
jari |
142 |
} |
2 |
26 Feb 07 |
jari |
143 |
return total; |
2 |
26 Feb 07 |
jari |
144 |
} |
2 |
26 Feb 07 |
jari |
145 |
public int getSelAlgorithmCount() { |
2 |
26 Feb 07 |
jari |
146 |
int count=0; |
2 |
26 Feb 07 |
jari |
147 |
for(int i=0;i<TMEV.getCustomerAnalysisList().length();i++){ |
2 |
26 Feb 07 |
jari |
148 |
if(TMEV.getCustomerAnalysis()[i]==1) |
2 |
26 Feb 07 |
jari |
149 |
count++; |
2 |
26 Feb 07 |
jari |
150 |
} |
2 |
26 Feb 07 |
jari |
151 |
return count; |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
private class AlgorithmSelectionPanel extends ParameterPanel { |
2 |
26 Feb 07 |
jari |
155 |
Hashtable descriptions; |
2 |
26 Feb 07 |
jari |
//Hashtable locations; |
2 |
26 Feb 07 |
jari |
157 |
Hashtable indexHash; |
2 |
26 Feb 07 |
jari |
158 |
JPanel checkboxPanel; |
2 |
26 Feb 07 |
jari |
159 |
int totalCount; |
2 |
26 Feb 07 |
jari |
160 |
JCheckBox cbox; |
2 |
26 Feb 07 |
jari |
161 |
Icon icon; |
2 |
26 Feb 07 |
jari |
162 |
AlgorithmSelectionPanel(ActionManager actionManager) { |
2 |
26 Feb 07 |
jari |
163 |
super("Algorithm Selection"); |
2 |
26 Feb 07 |
jari |
164 |
setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
165 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
166 |
checkboxPanel=new JPanel(); |
2 |
26 Feb 07 |
jari |
167 |
GridBagLayout gridbag=new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
168 |
checkboxPanel.setLayout(gridbag); |
2 |
26 Feb 07 |
jari |
169 |
Action action; |
2 |
26 Feb 07 |
jari |
170 |
int algCnt = 0,i=0,j=0; |
2 |
26 Feb 07 |
jari |
171 |
CheckboxListener cboxListener; |
2 |
26 Feb 07 |
jari |
172 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
173 |
while ((action = actionManager.getAction(ActionManager.ANALYSIS_ACTION+String.valueOf(totalCount)))!=null){ |
2 |
26 Feb 07 |
jari |
174 |
totalCount++; |
2 |
26 Feb 07 |
jari |
175 |
} |
2 |
26 Feb 07 |
jari |
176 |
while ((action = actionManager.getAction(ActionManager.ANALYSIS_ACTION+String.valueOf(algCnt)))!=null){ |
2 |
26 Feb 07 |
jari |
177 |
boolean select=false; |
2 |
26 Feb 07 |
jari |
178 |
if(action != null) { |
2 |
26 Feb 07 |
jari |
179 |
int m=0,count=TMEV.getCustomerAnalysis().length; |
2 |
26 Feb 07 |
jari |
180 |
if(count!=totalCount){ |
2 |
26 Feb 07 |
jari |
181 |
TMEV.initCustomerAnalysis(totalCount); |
2 |
26 Feb 07 |
jari |
182 |
} |
2 |
26 Feb 07 |
jari |
183 |
int mytag[]=new int[count]; |
2 |
26 Feb 07 |
jari |
184 |
for(m=0;m<count;m++) |
2 |
26 Feb 07 |
jari |
185 |
mytag[m]=TMEV.getCustomerAnalysis()[m]; |
2 |
26 Feb 07 |
jari |
186 |
if(mytag[algCnt]==1) |
2 |
26 Feb 07 |
jari |
187 |
select =true; |
2 |
26 Feb 07 |
jari |
188 |
|
2 |
26 Feb 07 |
jari |
189 |
cbox=new JCheckBox(); |
2 |
26 Feb 07 |
jari |
190 |
cbox.setIcon((Icon)action.getValue(ActionManager.LARGE_ICON)); |
2 |
26 Feb 07 |
jari |
191 |
cbox.setBorderPainted(true); |
2 |
26 Feb 07 |
jari |
192 |
cbox.setSelected(select); |
2 |
26 Feb 07 |
jari |
193 |
cboxListener=new CheckboxListener(totalCount,algCnt); |
2 |
26 Feb 07 |
jari |
194 |
cbox.addItemListener(cboxListener); |
2 |
26 Feb 07 |
jari |
195 |
buildConstraints(gbc,j,i,1,1,25,20); |
2 |
26 Feb 07 |
jari |
196 |
gridbag.setConstraints(cbox,gbc); |
2 |
26 Feb 07 |
jari |
197 |
checkboxPanel.add(cbox); |
2 |
26 Feb 07 |
jari |
198 |
algCnt++; |
2 |
26 Feb 07 |
jari |
199 |
if(j<3) |
2 |
26 Feb 07 |
jari |
200 |
j++; |
2 |
26 Feb 07 |
jari |
201 |
else{ |
2 |
26 Feb 07 |
jari |
202 |
j=0; |
2 |
26 Feb 07 |
jari |
203 |
i++; |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
206 |
} |
2 |
26 Feb 07 |
jari |
207 |
add(checkboxPanel, new GridBagConstraints(0,0,1,1,1,1,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0,0,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
//descriptions = new Hashtable(); |
2 |
26 Feb 07 |
jari |
//indexHash = new Hashtable(); |
2 |
26 Feb 07 |
jari |
// locations = new Hashtable(); |
2 |
26 Feb 07 |
jari |
211 |
|
2 |
26 Feb 07 |
jari |
212 |
} |
2 |
26 Feb 07 |
jari |
213 |
void buildConstraints(GridBagConstraints gbc, int gx, int gy, |
2 |
26 Feb 07 |
jari |
214 |
int gw, int gh, int wx, int wy) { |
2 |
26 Feb 07 |
jari |
215 |
|
2 |
26 Feb 07 |
jari |
216 |
gbc.gridx = gx; |
2 |
26 Feb 07 |
jari |
217 |
gbc.gridy = gy; |
2 |
26 Feb 07 |
jari |
218 |
gbc.gridwidth = gw; |
2 |
26 Feb 07 |
jari |
219 |
gbc.gridheight = gh; |
2 |
26 Feb 07 |
jari |
220 |
gbc.weightx = wx; |
2 |
26 Feb 07 |
jari |
221 |
gbc.weighty = wy; |
2 |
26 Feb 07 |
jari |
222 |
} |
2 |
26 Feb 07 |
jari |
223 |
|
2 |
26 Feb 07 |
jari |
224 |
} |
2 |
26 Feb 07 |
jari |
225 |
private class CheckboxListener implements ItemListener{ |
2 |
26 Feb 07 |
jari |
//JCheckBox cbox; |
2 |
26 Feb 07 |
jari |
227 |
int tag; |
2 |
26 Feb 07 |
jari |
228 |
int count; |
2 |
26 Feb 07 |
jari |
229 |
CheckboxListener(int i,int j){ |
2 |
26 Feb 07 |
jari |
230 |
count=i; |
2 |
26 Feb 07 |
jari |
231 |
tag=j; |
2 |
26 Feb 07 |
jari |
232 |
} |
2 |
26 Feb 07 |
jari |
233 |
public void itemStateChanged(ItemEvent e){ |
2 |
26 Feb 07 |
jari |
234 |
if(e.getStateChange()==ItemEvent.SELECTED){ |
2 |
26 Feb 07 |
jari |
235 |
TMEV.setCustomerAnalysis(count,tag,1); |
2 |
26 Feb 07 |
jari |
236 |
} |
2 |
26 Feb 07 |
jari |
237 |
if(e.getStateChange()==ItemEvent.DESELECTED){ |
2 |
26 Feb 07 |
jari |
238 |
TMEV.setCustomerAnalysis(count,tag,0); |
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 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to the dialog events. |
2 |
26 Feb 07 |
jari |
245 |
*/ |
2 |
26 Feb 07 |
jari |
246 |
private class Listener extends DialogListener { |
2 |
26 Feb 07 |
jari |
247 |
|
2 |
26 Feb 07 |
jari |
248 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
249 |
Object source = e.getSource(); |
2 |
26 Feb 07 |
jari |
250 |
if (source == okButton) { |
2 |
26 Feb 07 |
jari |
251 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
252 |
dispose(); |
2 |
26 Feb 07 |
jari |
253 |
} else if (source == cancelButton) { |
2 |
26 Feb 07 |
jari |
254 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
255 |
dispose(); |
2 |
26 Feb 07 |
jari |
256 |
} |
2 |
26 Feb 07 |
jari |
257 |
else if (source == resetButton) { |
2 |
26 Feb 07 |
jari |
258 |
onReset(); |
2 |
26 Feb 07 |
jari |
259 |
} |
2 |
26 Feb 07 |
jari |
260 |
else if (source == infoButton){ |
2 |
26 Feb 07 |
jari |
261 |
HelpWindow hw = new HelpWindow(CustomToolbarInitDialog.this, "Script Algorithm Initialization Dialog"); |
2 |
26 Feb 07 |
jari |
262 |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
263 |
hw.setSize(450,650); |
2 |
26 Feb 07 |
jari |
264 |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
265 |
hw.show(); |
2 |
26 Feb 07 |
jari |
266 |
} |
2 |
26 Feb 07 |
jari |
267 |
else { |
2 |
26 Feb 07 |
jari |
268 |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
269 |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
270 |
} |
2 |
26 Feb 07 |
jari |
271 |
} |
2 |
26 Feb 07 |
jari |
272 |
} |
2 |
26 Feb 07 |
jari |
273 |
|
2 |
26 Feb 07 |
jari |
274 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
275 |
result = JOptionPane.CLOSED_OPTION; |
2 |
26 Feb 07 |
jari |
276 |
dispose(); |
2 |
26 Feb 07 |
jari |
277 |
} |
2 |
26 Feb 07 |
jari |
278 |
} |
2 |
26 Feb 07 |
jari |
279 |
|
2 |
26 Feb 07 |
jari |
280 |
} |