2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* GDMMemberSelectionDialog.java |
2 |
26 Feb 07 |
jari |
3 |
* |
2 |
26 Feb 07 |
jari |
* Created on October 6, 2003, 3:57 PM |
2 |
26 Feb 07 |
jari |
5 |
*/ |
2 |
26 Feb 07 |
jari |
6 |
|
2 |
26 Feb 07 |
jari |
7 |
package org.tigr.microarray.mev.cluster.gui.impl.gdm; |
2 |
26 Feb 07 |
jari |
8 |
|
2 |
26 Feb 07 |
jari |
9 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
10 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
11 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
12 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
13 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
14 |
import java.awt.Toolkit; |
2 |
26 Feb 07 |
jari |
15 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
16 |
|
2 |
26 Feb 07 |
jari |
17 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
18 |
import javax.swing.JCheckBox; |
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
24 |
|
2 |
26 Feb 07 |
jari |
25 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
26 |
|
2 |
26 Feb 07 |
jari |
27 |
public class GDMMemberSelectionDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
JTextField kField; |
2 |
26 Feb 07 |
jari |
30 |
JCheckBox allBox; |
2 |
26 Feb 07 |
jari |
31 |
JPanel selectPanel; |
2 |
26 Feb 07 |
jari |
32 |
JLabel label1; |
2 |
26 Feb 07 |
jari |
33 |
JLabel label2; |
2 |
26 Feb 07 |
jari |
34 |
JLabel label3; |
2 |
26 Feb 07 |
jari |
35 |
int k; |
2 |
26 Feb 07 |
jari |
36 |
|
2 |
26 Feb 07 |
jari |
37 |
int result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
38 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of GDMMemberSelectionDialog */ |
2 |
26 Feb 07 |
jari |
40 |
public GDMMemberSelectionDialog(JFrame parent, int num_elements) { |
2 |
26 Feb 07 |
jari |
41 |
super(parent, "Select number of neighbors",true); |
2 |
26 Feb 07 |
jari |
42 |
k = num_elements; |
2 |
26 Feb 07 |
jari |
43 |
|
2 |
26 Feb 07 |
jari |
44 |
Listener listener = new Listener(); |
2 |
26 Feb 07 |
jari |
45 |
|
2 |
26 Feb 07 |
jari |
46 |
allBox = new JCheckBox("Save all neighbors", true); |
2 |
26 Feb 07 |
jari |
47 |
allBox.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
48 |
allBox.setFocusPainted(false); |
2 |
26 Feb 07 |
jari |
49 |
allBox.setActionCommand("save-all-command"); |
2 |
26 Feb 07 |
jari |
50 |
allBox.setHorizontalAlignment(JCheckBox.CENTER); |
2 |
26 Feb 07 |
jari |
51 |
allBox.addActionListener(listener); |
2 |
26 Feb 07 |
jari |
52 |
|
2 |
26 Feb 07 |
jari |
53 |
kField = new JTextField("20", 6); |
2 |
26 Feb 07 |
jari |
54 |
kField.setEnabled(false); |
2 |
26 Feb 07 |
jari |
55 |
label1 = new JLabel("Save the nearest "); |
2 |
26 Feb 07 |
jari |
56 |
label1.setEnabled(false); |
2 |
26 Feb 07 |
jari |
57 |
label2 = new JLabel(" neighbors"); |
2 |
26 Feb 07 |
jari |
58 |
label2.setEnabled(false); |
2 |
26 Feb 07 |
jari |
59 |
label3 = new JLabel("( There are "+num_elements+" elements in the matrix. )"); |
2 |
26 Feb 07 |
jari |
60 |
label3.setEnabled(false); |
2 |
26 Feb 07 |
jari |
61 |
|
2 |
26 Feb 07 |
jari |
62 |
selectPanel = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
63 |
selectPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
64 |
selectPanel.add(label1, new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
65 |
selectPanel.add(kField, new GridBagConstraints(1,0,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
66 |
selectPanel.add(label2, new GridBagConstraints(2,0,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
67 |
selectPanel.add(label3, new GridBagConstraints(0,1,3,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(5,0,0,0),0,0)); |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
JPanel parameters = new JPanel(new GridBagLayout()); |
2 |
26 Feb 07 |
jari |
70 |
parameters.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
71 |
parameters.setBorder(BorderFactory.createLineBorder(Color.black)); |
2 |
26 Feb 07 |
jari |
72 |
parameters.add(allBox, new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(10,0,15,0),0,0)); |
2 |
26 Feb 07 |
jari |
73 |
parameters.add(selectPanel, new GridBagConstraints(0,1,1,1,0.0,0.0,GridBagConstraints.CENTER,GridBagConstraints.BOTH,new Insets(0,0,10,0),0,0)); |
2 |
26 Feb 07 |
jari |
74 |
|
2 |
26 Feb 07 |
jari |
75 |
addContent(parameters); |
2 |
26 Feb 07 |
jari |
76 |
setActionListeners(listener); |
2 |
26 Feb 07 |
jari |
77 |
pack(); |
2 |
26 Feb 07 |
jari |
78 |
} |
2 |
26 Feb 07 |
jari |
79 |
|
2 |
26 Feb 07 |
jari |
80 |
private void resetControls(){ |
2 |
26 Feb 07 |
jari |
81 |
label1.setEnabled(false); |
2 |
26 Feb 07 |
jari |
82 |
label2.setEnabled(false); |
2 |
26 Feb 07 |
jari |
83 |
label3.setEnabled(false); |
2 |
26 Feb 07 |
jari |
84 |
kField.setText("20"); |
2 |
26 Feb 07 |
jari |
85 |
allBox.setSelected(true); |
2 |
26 Feb 07 |
jari |
86 |
} |
2 |
26 Feb 07 |
jari |
87 |
|
2 |
26 Feb 07 |
jari |
88 |
private void setControls(boolean setting){ |
2 |
26 Feb 07 |
jari |
89 |
label1.setEnabled(setting); |
2 |
26 Feb 07 |
jari |
90 |
label2.setEnabled(setting); |
2 |
26 Feb 07 |
jari |
91 |
label3.setEnabled(setting); |
2 |
26 Feb 07 |
jari |
92 |
kField.setEnabled(setting); |
2 |
26 Feb 07 |
jari |
93 |
} |
2 |
26 Feb 07 |
jari |
94 |
|
2 |
26 Feb 07 |
jari |
95 |
public int getK(){ |
2 |
26 Feb 07 |
jari |
96 |
if(allBox.isSelected()) |
2 |
26 Feb 07 |
jari |
97 |
return k; |
2 |
26 Feb 07 |
jari |
98 |
return Integer.parseInt(kField.getText()); |
2 |
26 Feb 07 |
jari |
99 |
} |
2 |
26 Feb 07 |
jari |
100 |
|
2 |
26 Feb 07 |
jari |
101 |
private boolean validateInput(){ |
2 |
26 Feb 07 |
jari |
102 |
int n; |
2 |
26 Feb 07 |
jari |
103 |
try{ |
2 |
26 Feb 07 |
jari |
104 |
n = Integer.parseInt(kField.getText()); |
2 |
26 Feb 07 |
jari |
105 |
if(n < 0){ |
2 |
26 Feb 07 |
jari |
106 |
JOptionPane.showMessageDialog(this, "Input must be > 0", "Input Warning", JOptionPane.WARNING_MESSAGE); |
2 |
26 Feb 07 |
jari |
107 |
return false; |
2 |
26 Feb 07 |
jari |
108 |
} |
2 |
26 Feb 07 |
jari |
109 |
if(n > k){ |
2 |
26 Feb 07 |
jari |
110 |
JOptionPane.showMessageDialog(this, "Input must be <= the number of matrix elements ("+k+")", "Input Warning", JOptionPane.WARNING_MESSAGE); |
2 |
26 Feb 07 |
jari |
111 |
return false; |
2 |
26 Feb 07 |
jari |
112 |
} |
2 |
26 Feb 07 |
jari |
113 |
} catch (NumberFormatException nfe) { |
2 |
26 Feb 07 |
jari |
114 |
JOptionPane.showMessageDialog(this, "Invalid number format.", "Input Warning", JOptionPane.WARNING_MESSAGE); |
2 |
26 Feb 07 |
jari |
115 |
return false; |
2 |
26 Feb 07 |
jari |
116 |
} |
2 |
26 Feb 07 |
jari |
117 |
return true; |
2 |
26 Feb 07 |
jari |
118 |
} |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
120 |
/** |
2 |
26 Feb 07 |
jari |
* Shows the dialog. |
2 |
26 Feb 07 |
jari |
122 |
*/ |
2 |
26 Feb 07 |
jari |
123 |
public int showModal() { |
2 |
26 Feb 07 |
jari |
124 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
125 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
126 |
show(); |
2 |
26 Feb 07 |
jari |
127 |
return result; |
2 |
26 Feb 07 |
jari |
128 |
} |
2 |
26 Feb 07 |
jari |
129 |
|
2 |
26 Feb 07 |
jari |
130 |
private class Listener implements ActionListener{ |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
public void actionPerformed(java.awt.event.ActionEvent evt) { |
2 |
26 Feb 07 |
jari |
133 |
String command = evt.getActionCommand(); |
2 |
26 Feb 07 |
jari |
134 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
135 |
if(!allBox.isSelected()){ |
2 |
26 Feb 07 |
jari |
136 |
if(validateInput()){ |
2 |
26 Feb 07 |
jari |
137 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
138 |
} else { |
2 |
26 Feb 07 |
jari |
139 |
return; |
2 |
26 Feb 07 |
jari |
140 |
} |
2 |
26 Feb 07 |
jari |
141 |
} else { |
2 |
26 Feb 07 |
jari |
142 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
143 |
} |
2 |
26 Feb 07 |
jari |
144 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
145 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
146 |
dispose(); |
2 |
26 Feb 07 |
jari |
147 |
} else if (command.equals("reset-command")){ |
2 |
26 Feb 07 |
jari |
148 |
resetControls(); |
2 |
26 Feb 07 |
jari |
149 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
150 |
return; |
2 |
26 Feb 07 |
jari |
151 |
} |
2 |
26 Feb 07 |
jari |
152 |
else if (command.equals("info-command")){ |
2 |
26 Feb 07 |
jari |
/* HelpWindow hw = new HelpWindow(HCLInitDialog.this, "HCL Initialization Dialog"); |
2 |
26 Feb 07 |
jari |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
if(hw.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
hw.setSize(450,600); |
2 |
26 Feb 07 |
jari |
hw.setLocation(); |
2 |
26 Feb 07 |
jari |
hw.show(); |
2 |
26 Feb 07 |
jari |
return; |
2 |
26 Feb 07 |
jari |
160 |
} |
2 |
26 Feb 07 |
jari |
else { |
2 |
26 Feb 07 |
jari |
hw.setVisible(false); |
2 |
26 Feb 07 |
jari |
hw.dispose(); |
2 |
26 Feb 07 |
jari |
return; |
2 |
26 Feb 07 |
jari |
165 |
} |
2 |
26 Feb 07 |
jari |
166 |
*/ |
2 |
26 Feb 07 |
jari |
167 |
} else if(command.equals("save-all-command")){ |
2 |
26 Feb 07 |
jari |
168 |
setControls(!allBox.isSelected()); |
2 |
26 Feb 07 |
jari |
169 |
return; |
2 |
26 Feb 07 |
jari |
170 |
} |
2 |
26 Feb 07 |
jari |
171 |
dispose(); |
2 |
26 Feb 07 |
jari |
172 |
} |
2 |
26 Feb 07 |
jari |
173 |
|
2 |
26 Feb 07 |
jari |
174 |
} |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
177 |
GDMMemberSelectionDialog d = new GDMMemberSelectionDialog(new JFrame(), 1080); |
2 |
26 Feb 07 |
jari |
178 |
d.showModal(); |
2 |
26 Feb 07 |
jari |
179 |
System.out.println("save "+d.getK()+" neighbors"); |
2 |
26 Feb 07 |
jari |
180 |
} |
2 |
26 Feb 07 |
jari |
181 |
|
2 |
26 Feb 07 |
jari |
182 |
} |