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: TerrainInitDialog.java,v $ |
2 |
26 Feb 07 |
jari |
* $Revision: 1.5 $ |
2 |
26 Feb 07 |
jari |
* $Date: 2006/04/20 18:53:39 $ |
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 |
package org.tigr.microarray.mev.cluster.gui.impl.terrain; |
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.Frame; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.GridBagLayout; |
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.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.JPanel; |
2 |
26 Feb 07 |
jari |
30 |
import javax.swing.JRadioButton; |
2 |
26 Feb 07 |
jari |
31 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
32 |
import javax.swing.UIManager; |
2 |
26 Feb 07 |
jari |
33 |
import javax.swing.border.EmptyBorder; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
import org.tigr.microarray.mev.cluster.gui.impl.GUIFactory; |
2 |
26 Feb 07 |
jari |
36 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
37 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.DialogListener; |
2 |
26 Feb 07 |
jari |
38 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
40 |
public class TerrainInitDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
41 |
private int result; |
2 |
26 Feb 07 |
jari |
42 |
|
2 |
26 Feb 07 |
jari |
43 |
private JRadioButton genRadio; |
2 |
26 Feb 07 |
jari |
44 |
private JRadioButton expRadio; |
2 |
26 Feb 07 |
jari |
45 |
private JTextField neighboursField; |
2 |
26 Feb 07 |
jari |
46 |
|
2 |
26 Feb 07 |
jari |
// private static final String text1 = "Cluster Analysis Software Package "; |
2 |
26 Feb 07 |
jari |
// private static final String text2 = "The Institute for Genomic Research "; |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
/** |
2 |
26 Feb 07 |
jari |
* Constructs a <code>TerrainInitDialog</code> with default |
2 |
26 Feb 07 |
jari |
* initial parameters. |
2 |
26 Feb 07 |
jari |
53 |
*/ |
2 |
26 Feb 07 |
jari |
54 |
public TerrainInitDialog(Frame parent) { |
2 |
26 Feb 07 |
jari |
55 |
super((JFrame)parent, "Terrain Initialization", true); |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
58 |
addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
59 |
|
2 |
26 Feb 07 |
jari |
60 |
JPanel parameters = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
61 |
parameters.setBorder(new EmptyBorder(20, 10, 20, 10)); |
2 |
26 Feb 07 |
jari |
62 |
parameters.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
63 |
|
2 |
26 Feb 07 |
jari |
64 |
GridBagConstraints gbc = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
65 |
gbc.anchor = GridBagConstraints.WEST; |
2 |
26 Feb 07 |
jari |
66 |
|
2 |
26 Feb 07 |
jari |
67 |
genRadio = new JRadioButton("Genes"); |
2 |
26 Feb 07 |
jari |
68 |
genRadio.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
69 |
genRadio.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
70 |
genRadio.setForeground(UIManager.getColor("Label.foreground")); |
2 |
26 Feb 07 |
jari |
71 |
gbc.gridx = 0; gbc.gridy = 0; |
2 |
26 Feb 07 |
jari |
72 |
parameters.add(genRadio, gbc); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
expRadio = new JRadioButton("Samples"); |
2 |
26 Feb 07 |
jari |
75 |
expRadio.setForeground(UIManager.getColor("Label.foreground")); |
2 |
26 Feb 07 |
jari |
76 |
expRadio.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
77 |
expRadio.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
78 |
gbc.gridx = 1; gbc.gridy = 0; gbc.insets.left = 25; |
2 |
26 Feb 07 |
jari |
79 |
parameters.add(expRadio, gbc); |
2 |
26 Feb 07 |
jari |
80 |
gbc.insets.left = 0; |
2 |
26 Feb 07 |
jari |
81 |
gbc.gridx = 0; gbc.gridy = 1; gbc.insets.top = 20; |
2 |
26 Feb 07 |
jari |
82 |
parameters.add(new JLabel("Neighbors:"), gbc); |
2 |
26 Feb 07 |
jari |
83 |
gbc.gridx = 1; gbc.insets.left = 25; |
2 |
26 Feb 07 |
jari |
84 |
neighboursField = new JTextField(String.valueOf(20), 5); |
2 |
26 Feb 07 |
jari |
85 |
parameters.add(neighboursField, gbc); |
2 |
26 Feb 07 |
jari |
86 |
|
2 |
26 Feb 07 |
jari |
87 |
ButtonGroup bg = new ButtonGroup(); |
2 |
26 Feb 07 |
jari |
88 |
bg.add(genRadio); |
2 |
26 Feb 07 |
jari |
89 |
bg.add(expRadio); |
2 |
26 Feb 07 |
jari |
90 |
genRadio.setSelected(true); |
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
// JButton button1 = new JButton("OK"); |
2 |
26 Feb 07 |
jari |
// button1.setActionCommand("ok-command"); |
2 |
26 Feb 07 |
jari |
// button1.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
// button1.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
// JButton button2 = new JButton("Cancel"); |
2 |
26 Feb 07 |
jari |
// button2.setActionCommand("cancel-command"); |
2 |
26 Feb 07 |
jari |
// button2.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
// button2.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
101 |
|
2 |
26 Feb 07 |
jari |
// JPanel insetsPanel = new JPanel(new GridLayout(2, 1)); |
2 |
26 Feb 07 |
jari |
// insetsPanel.add(new JLabel(text1)); |
2 |
26 Feb 07 |
jari |
// insetsPanel.add(new JLabel(text2)); |
2 |
26 Feb 07 |
jari |
105 |
|
2 |
26 Feb 07 |
jari |
// JPanel buttons = new JPanel(new GridLayout(1, 2, 10, 10)); |
2 |
26 Feb 07 |
jari |
// buttons.add(button1); |
2 |
26 Feb 07 |
jari |
// buttons.add(button2); |
2 |
26 Feb 07 |
jari |
109 |
|
2 |
26 Feb 07 |
jari |
// JPanel panel2 = new JPanel(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
// panel2.setBorder(new EmptyBorder(10, 0, 0, 0)); |
2 |
26 Feb 07 |
jari |
// panel2.add(insetsPanel, BorderLayout.WEST); |
2 |
26 Feb 07 |
jari |
// panel2.add(buttons, BorderLayout.EAST); |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
JPanel panel3 = new JPanel(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
116 |
panel3.setForeground(Color.white); |
2 |
26 Feb 07 |
jari |
117 |
panel3.setBorder(BorderFactory.createLineBorder(Color.gray)); |
2 |
26 Feb 07 |
jari |
// panel3.add(new JLabel(GUIFactory.getIcon("genebar.gif")), BorderLayout.NORTH); |
2 |
26 Feb 07 |
jari |
119 |
panel3.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
120 |
panel3.add(parameters, BorderLayout.WEST); |
2 |
26 Feb 07 |
jari |
121 |
panel3.add(new JLabel(GUIFactory.getIcon("dialog_button_bar.gif")), BorderLayout.EAST); |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
// JPanel panel1 = new JPanel(new BorderLayout()); |
2 |
26 Feb 07 |
jari |
// panel1.setBorder(new EmptyBorder(10, 10, 10, 10)); |
2 |
26 Feb 07 |
jari |
// panel1.add(panel2, BorderLayout.SOUTH); |
2 |
26 Feb 07 |
jari |
// panel1.add(panel3, BorderLayout.NORTH); |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
setActionListeners(listener); |
2 |
26 Feb 07 |
jari |
129 |
addContent(panel3); |
2 |
26 Feb 07 |
jari |
// getContentPane().add(panel1, BorderLayout.CENTER); |
2 |
26 Feb 07 |
jari |
131 |
pack(); |
2 |
26 Feb 07 |
jari |
132 |
} |
2 |
26 Feb 07 |
jari |
133 |
|
2 |
26 Feb 07 |
jari |
134 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
136 |
*/ |
2 |
26 Feb 07 |
jari |
137 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
138 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
139 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
140 |
show(); |
2 |
26 Feb 07 |
jari |
141 |
return result; |
2 |
26 Feb 07 |
jari |
142 |
} |
2 |
26 Feb 07 |
jari |
143 |
|
2 |
26 Feb 07 |
jari |
144 |
/** |
2 |
26 Feb 07 |
jari |
* Returns true if genes radio button was selected. |
2 |
26 Feb 07 |
jari |
146 |
*/ |
2 |
26 Feb 07 |
jari |
147 |
public boolean isGenes() { |
2 |
26 Feb 07 |
jari |
148 |
return genRadio.isSelected(); |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
|
2 |
26 Feb 07 |
jari |
151 |
/** |
2 |
26 Feb 07 |
jari |
* Returns neighbours value. |
2 |
26 Feb 07 |
jari |
153 |
*/ |
2 |
26 Feb 07 |
jari |
154 |
public int getNeighbours() { |
2 |
26 Feb 07 |
jari |
155 |
return Integer.parseInt(neighboursField.getText()); |
2 |
26 Feb 07 |
jari |
156 |
} |
2 |
26 Feb 07 |
jari |
157 |
|
2 |
26 Feb 07 |
jari |
158 |
/** |
2 |
26 Feb 07 |
jari |
* The class to listen to the dialog events. |
2 |
26 Feb 07 |
jari |
160 |
*/ |
2 |
26 Feb 07 |
jari |
161 |
private class Listener extends DialogListener { |
2 |
26 Feb 07 |
jari |
162 |
|
2 |
26 Feb 07 |
jari |
163 |
public void actionPerformed(ActionEvent e) { |
2 |
26 Feb 07 |
jari |
164 |
String command = e.getActionCommand(); |
2 |
26 Feb 07 |
jari |
165 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
166 |
try { |
2 |
26 Feb 07 |
jari |
167 |
int value = Integer.parseInt(neighboursField.getText()); |
2 |
26 Feb 07 |
jari |
168 |
if (value < 1) |
2 |
26 Feb 07 |
jari |
169 |
throw new NumberFormatException("value must be more than 0."); |
2 |
26 Feb 07 |
jari |
170 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
171 |
dispose(); |
2 |
26 Feb 07 |
jari |
172 |
} catch (NumberFormatException nfe) { |
2 |
26 Feb 07 |
jari |
173 |
JOptionPane.showMessageDialog(TerrainInitDialog.this, "Error number: " + nfe.getMessage(), "Input Error!", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
176 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
177 |
dispose(); |
2 |
26 Feb 07 |
jari |
178 |
} else if (command.equals("reset-command")){ |
2 |
26 Feb 07 |
jari |
179 |
genRadio.setSelected(true); |
2 |
26 Feb 07 |
jari |
180 |
neighboursField.setText("20"); |
2 |
26 Feb 07 |
jari |
181 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
182 |
return; |
2 |
26 Feb 07 |
jari |
183 |
} else if (command.equals("info-command")){ |
2 |
26 Feb 07 |
jari |
184 |
HelpWindow hw = new HelpWindow(TerrainInitDialog.this, "Terrain Map Initialization Dialog"); |
2 |
26 Feb 07 |
jari |
185 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
186 |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
187 |
hw.setSize(450,600); |
2 |
26 Feb 07 |
jari |
188 |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
189 |
hw.show(); |
2 |
26 Feb 07 |
jari |
190 |
return; |
2 |
26 Feb 07 |
jari |
191 |
} |
2 |
26 Feb 07 |
jari |
192 |
else { |
2 |
26 Feb 07 |
jari |
193 |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
194 |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
195 |
return; |
2 |
26 Feb 07 |
jari |
196 |
} |
2 |
26 Feb 07 |
jari |
197 |
} |
2 |
26 Feb 07 |
jari |
198 |
} |
2 |
26 Feb 07 |
jari |
199 |
|
2 |
26 Feb 07 |
jari |
200 |
public void windowClosing(WindowEvent e) { |
2 |
26 Feb 07 |
jari |
201 |
result = JOptionPane.CLOSED_OPTION; |
2 |
26 Feb 07 |
jari |
202 |
dispose(); |
2 |
26 Feb 07 |
jari |
203 |
} |
2 |
26 Feb 07 |
jari |
204 |
} |
2 |
26 Feb 07 |
jari |
205 |
|
2 |
26 Feb 07 |
jari |
206 |
public static void main(String[] args) { |
2 |
26 Feb 07 |
jari |
207 |
TerrainInitDialog dlg = new TerrainInitDialog(new javax.swing.JFrame()); |
2 |
26 Feb 07 |
jari |
208 |
if (dlg.showModal() == JOptionPane.OK_OPTION) { |
2 |
26 Feb 07 |
jari |
209 |
System.out.println("ok"); |
2 |
26 Feb 07 |
jari |
210 |
} |
2 |
26 Feb 07 |
jari |
211 |
System.exit(0); |
2 |
26 Feb 07 |
jari |
212 |
} |
2 |
26 Feb 07 |
jari |
213 |
} |