2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2004, 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 |
* GeneListImportDialog.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
* Created on June 17, 2004, 10:52 AM |
2 |
26 Feb 07 |
jari |
9 |
*/ |
2 |
26 Feb 07 |
jari |
10 |
|
2 |
26 Feb 07 |
jari |
11 |
package org.tigr.microarray.mev.cluster.clusterUtil; |
2 |
26 Feb 07 |
jari |
12 |
|
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.event.WindowEvent; |
2 |
26 Feb 07 |
jari |
21 |
import java.util.StringTokenizer; |
2 |
26 Feb 07 |
jari |
22 |
import java.util.Vector; |
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.JComboBox; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.JScrollPane; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JTextPane; |
2 |
26 Feb 07 |
jari |
31 |
|
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener; |
2 |
26 Feb 07 |
jari |
34 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.ParameterPanel; |
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
/** |
2 |
26 Feb 07 |
jari |
38 |
* |
2 |
26 Feb 07 |
jari |
* @author braisted |
2 |
26 Feb 07 |
jari |
40 |
*/ |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
public class ListImportDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
44 |
|
2 |
26 Feb 07 |
jari |
45 |
private Vector annFields; |
2 |
26 Feb 07 |
jari |
46 |
private JComboBox listBox; |
2 |
26 Feb 07 |
jari |
47 |
private JTextPane pane; |
2 |
26 Feb 07 |
jari |
48 |
private int result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of GeneListImportDialog */ |
2 |
26 Feb 07 |
jari |
51 |
public ListImportDialog(String [] fieldNames, boolean geneList) { |
2 |
26 Feb 07 |
jari |
52 |
super(new JFrame(), geneList ? "Gene List Import Dialog" : "Sample List Import Dialog", true); |
2 |
26 Feb 07 |
jari |
53 |
annFields = new Vector(); |
2 |
26 Feb 07 |
jari |
54 |
for(int i = 0; i < fieldNames.length; i++){ |
2 |
26 Feb 07 |
jari |
55 |
annFields.addElement(fieldNames[i]); |
2 |
26 Feb 07 |
jari |
56 |
} |
2 |
26 Feb 07 |
jari |
57 |
|
2 |
26 Feb 07 |
jari |
58 |
ParameterPanel paramPanel; |
2 |
26 Feb 07 |
jari |
59 |
if(geneList) |
2 |
26 Feb 07 |
jari |
60 |
paramPanel = new ParameterPanel("Gene List Import Parameters"); |
2 |
26 Feb 07 |
jari |
61 |
else |
2 |
26 Feb 07 |
jari |
62 |
paramPanel = new ParameterPanel("Sample List Import Parameters"); |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
paramPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
65 |
|
2 |
26 Feb 07 |
jari |
66 |
JLabel listLabel; |
2 |
26 Feb 07 |
jari |
67 |
if(geneList) |
2 |
26 Feb 07 |
jari |
68 |
listLabel = new JLabel("Gene ID Type:"); |
2 |
26 Feb 07 |
jari |
69 |
else |
2 |
26 Feb 07 |
jari |
70 |
listLabel = new JLabel("Sample ID Type:"); |
2 |
26 Feb 07 |
jari |
71 |
|
2 |
26 Feb 07 |
jari |
72 |
listBox = new JComboBox(annFields); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
if(annFields.size() > 0) |
2 |
26 Feb 07 |
jari |
76 |
listBox.setSelectedIndex(0); |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
JLabel textLabel; |
2 |
26 Feb 07 |
jari |
79 |
textLabel = new JLabel("Paste List (ctrl-v):"); |
2 |
26 Feb 07 |
jari |
80 |
pane = new JTextPane(); |
2 |
26 Feb 07 |
jari |
81 |
pane.setPreferredSize(new Dimension(125, 200)); |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
JScrollPane scroll = new JScrollPane(pane); |
2 |
26 Feb 07 |
jari |
84 |
scroll.getViewport().setViewSize(new Dimension(125, 200)); |
2 |
26 Feb 07 |
jari |
85 |
scroll.setBorder(BorderFactory.createLineBorder(Color.black, 2)); |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
paramPanel.add(listLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(10,0,0,20), 0,0)); |
2 |
26 Feb 07 |
jari |
88 |
paramPanel.add(listBox, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,0,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
89 |
paramPanel.add(textLabel, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(20,0,0,20), 0,0)); |
2 |
26 Feb 07 |
jari |
90 |
paramPanel.add(scroll, new GridBagConstraints(1,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
92 |
addContent(paramPanel); |
2 |
26 Feb 07 |
jari |
93 |
setActionListeners(new Listener()); |
2 |
26 Feb 07 |
jari |
94 |
pack(); |
2 |
26 Feb 07 |
jari |
95 |
} |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of GeneListImportDialog */ |
2 |
26 Feb 07 |
jari |
98 |
public ListImportDialog(java.awt.Frame parent, String [] fieldNames, boolean geneList) { |
2 |
26 Feb 07 |
jari |
99 |
super(parent, geneList ? "Gene List Import Dialog" : "Sample List Import Dialog", true); |
2 |
26 Feb 07 |
jari |
100 |
annFields = new Vector(); |
2 |
26 Feb 07 |
jari |
101 |
for(int i = 0; i < fieldNames.length; i++){ |
2 |
26 Feb 07 |
jari |
102 |
annFields.addElement(fieldNames[i]); |
2 |
26 Feb 07 |
jari |
103 |
} |
2 |
26 Feb 07 |
jari |
104 |
|
2 |
26 Feb 07 |
jari |
105 |
ParameterPanel paramPanel; |
2 |
26 Feb 07 |
jari |
106 |
if(geneList) |
2 |
26 Feb 07 |
jari |
107 |
paramPanel = new ParameterPanel("Gene List Import Parameters"); |
2 |
26 Feb 07 |
jari |
108 |
else |
2 |
26 Feb 07 |
jari |
109 |
paramPanel = new ParameterPanel("Sample List Import Parameters"); |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
paramPanel.setLayout(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
112 |
|
2 |
26 Feb 07 |
jari |
113 |
JLabel listLabel; |
2 |
26 Feb 07 |
jari |
114 |
if(geneList) |
2 |
26 Feb 07 |
jari |
115 |
listLabel = new JLabel("Gene ID Type:"); |
2 |
26 Feb 07 |
jari |
116 |
else |
2 |
26 Feb 07 |
jari |
117 |
listLabel = new JLabel("Sample ID Type:"); |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
listBox = new JComboBox(annFields); |
2 |
26 Feb 07 |
jari |
120 |
|
2 |
26 Feb 07 |
jari |
121 |
|
2 |
26 Feb 07 |
jari |
122 |
if(annFields.size() > 0) |
2 |
26 Feb 07 |
jari |
123 |
listBox.setSelectedIndex(0); |
2 |
26 Feb 07 |
jari |
124 |
|
2 |
26 Feb 07 |
jari |
125 |
JLabel textLabel; |
2 |
26 Feb 07 |
jari |
126 |
textLabel = new JLabel("Paste List (ctrl-v):"); |
2 |
26 Feb 07 |
jari |
127 |
pane = new JTextPane(); |
2 |
26 Feb 07 |
jari |
128 |
pane.setPreferredSize(new Dimension(125, 200)); |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
JScrollPane scroll = new JScrollPane(pane); |
2 |
26 Feb 07 |
jari |
131 |
scroll.getViewport().setViewSize(new Dimension(125, 200)); |
2 |
26 Feb 07 |
jari |
132 |
scroll.setBorder(BorderFactory.createLineBorder(Color.black, 2)); |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
paramPanel.add(listLabel, new GridBagConstraints(0,0,1,1,0,0,GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(10,0,0,20), 0,0)); |
2 |
26 Feb 07 |
jari |
135 |
paramPanel.add(listBox, new GridBagConstraints(1,0,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(10,0,0,0), 0,0)); |
2 |
26 Feb 07 |
jari |
136 |
paramPanel.add(textLabel, new GridBagConstraints(0,1,1,1,0,0,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(20,0,0,20), 0,0)); |
2 |
26 Feb 07 |
jari |
137 |
paramPanel.add(scroll, new GridBagConstraints(1,1,1,1,0,0,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(20,0,10,0), 0,0)); |
2 |
26 Feb 07 |
jari |
138 |
|
2 |
26 Feb 07 |
jari |
139 |
addContent(paramPanel); |
2 |
26 Feb 07 |
jari |
140 |
setActionListeners(new Listener()); |
2 |
26 Feb 07 |
jari |
141 |
pack(); |
2 |
26 Feb 07 |
jari |
142 |
} |
2 |
26 Feb 07 |
jari |
143 |
|
2 |
26 Feb 07 |
jari |
144 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
146 |
*/ |
2 |
26 Feb 07 |
jari |
147 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
148 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
149 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
150 |
show(); |
2 |
26 Feb 07 |
jari |
151 |
return result; |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
|
2 |
26 Feb 07 |
jari |
154 |
/** |
2 |
26 Feb 07 |
jari |
* Resets controls to default initial settings |
2 |
26 Feb 07 |
jari |
156 |
*/ |
2 |
26 Feb 07 |
jari |
157 |
private void resetControls(){ |
2 |
26 Feb 07 |
jari |
158 |
listBox.setSelectedIndex(0); |
2 |
26 Feb 07 |
jari |
159 |
pane.setText(""); |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
161 |
|
2 |
26 Feb 07 |
jari |
162 |
public String getFieldName() { |
2 |
26 Feb 07 |
jari |
163 |
return (String)(listBox.getSelectedItem()); |
2 |
26 Feb 07 |
jari |
164 |
} |
2 |
26 Feb 07 |
jari |
165 |
|
2 |
26 Feb 07 |
jari |
166 |
public String [] getList() { |
2 |
26 Feb 07 |
jari |
167 |
String text = pane.getText(); |
2 |
26 Feb 07 |
jari |
168 |
StringTokenizer stok = new StringTokenizer(text, "\n"); |
2 |
26 Feb 07 |
jari |
169 |
String [] outputList = new String[stok.countTokens()]; |
2 |
26 Feb 07 |
jari |
170 |
int cnt = 0; |
2 |
26 Feb 07 |
jari |
171 |
while(stok.hasMoreTokens()) { |
2 |
26 Feb 07 |
jari |
172 |
outputList[cnt] = stok.nextToken().trim(); |
2 |
26 Feb 07 |
jari |
173 |
cnt++; |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
return outputList; |
2 |
26 Feb 07 |
jari |
176 |
} |
2 |
26 Feb 07 |
jari |
177 |
|
2 |
26 Feb 07 |
jari |
178 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to the dialog and check boxes items events. |
2 |
26 Feb 07 |
jari |
180 |
*/ |
2 |
26 Feb 07 |
jari |
181 |
private class Listener extends DialogListener { |
2 |
26 Feb 07 |
jari |
182 |
|
2 |
26 Feb 07 |
jari |
183 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
184 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
185 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
186 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
187 |
dispose(); |
2 |
26 Feb 07 |
jari |
188 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
189 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
190 |
dispose(); |
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
else if (command.equals("reset-command")){ |
2 |
26 Feb 07 |
jari |
193 |
resetControls(); |
2 |
26 Feb 07 |
jari |
194 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
195 |
return; |
2 |
26 Feb 07 |
jari |
196 |
} |
2 |
26 Feb 07 |
jari |
197 |
else if (command.equals("info-command")){ |
2 |
26 Feb 07 |
jari |
198 |
HelpWindow hw = new HelpWindow(ListImportDialog.this, "List Import Dialog"); |
2 |
26 Feb 07 |
jari |
199 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
200 |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
201 |
hw.setSize(450,600); |
2 |
26 Feb 07 |
jari |
202 |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
203 |
hw.show(); |
2 |
26 Feb 07 |
jari |
204 |
return; |
2 |
26 Feb 07 |
jari |
205 |
} |
2 |
26 Feb 07 |
jari |
206 |
else { |
2 |
26 Feb 07 |
jari |
207 |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
208 |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
209 |
return; |
2 |
26 Feb 07 |
jari |
210 |
} } |
2 |
26 Feb 07 |
jari |
211 |
dispose(); |
2 |
26 Feb 07 |
jari |
212 |
} |
2 |
26 Feb 07 |
jari |
213 |
|
2 |
26 Feb 07 |
jari |
214 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
215 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
216 |
dispose(); |
2 |
26 Feb 07 |
jari |
217 |
} |
2 |
26 Feb 07 |
jari |
218 |
} |
2 |
26 Feb 07 |
jari |
219 |
|
2 |
26 Feb 07 |
jari |
220 |
} |