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 |
* PCASelectionDialog.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
* Created on February 27, 2003, 11:05 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.gui.impl.pca; |
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.Frame; |
2 |
26 Feb 07 |
jari |
16 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
17 |
import java.awt.GridBagLayout; |
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.ActionListener; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JTextField; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.UIManager; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.border.EtchedBorder; |
2 |
26 Feb 07 |
jari |
29 |
|
2 |
26 Feb 07 |
jari |
30 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.SampleSelectionPanel; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.dialogHelpUtil.HelpWindow; |
2 |
26 Feb 07 |
jari |
33 |
|
2 |
26 Feb 07 |
jari |
34 |
public class PCASelectionDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
35 |
|
2 |
26 Feb 07 |
jari |
36 |
private int result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
37 |
|
2 |
26 Feb 07 |
jari |
38 |
private SampleSelectionPanel sampleSelectionPanel; |
2 |
26 Feb 07 |
jari |
39 |
JTextField numNeighborsField; |
2 |
26 Feb 07 |
jari |
40 |
|
2 |
26 Feb 07 |
jari |
/** Creates new PCASelectionDialog */ |
2 |
26 Feb 07 |
jari |
42 |
public PCASelectionDialog(Frame frame) { |
2 |
26 Feb 07 |
jari |
43 |
super(frame, "PCA: Principal Components Analysis", true); |
2 |
26 Feb 07 |
jari |
//setSize(300, 110); |
2 |
26 Feb 07 |
jari |
45 |
setBounds(0, 0, 600, 200); |
2 |
26 Feb 07 |
jari |
//super.setResizable(false); |
2 |
26 Feb 07 |
jari |
47 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
48 |
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
2 |
26 Feb 07 |
jari |
49 |
|
2 |
26 Feb 07 |
jari |
50 |
GridBagLayout gridbag = new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
51 |
GridBagConstraints constraints = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
52 |
constraints.fill = GridBagConstraints.HORIZONTAL; |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
JPanel pane = new JPanel(); |
2 |
26 Feb 07 |
jari |
55 |
pane.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
56 |
pane.setBorder(new EtchedBorder()); |
2 |
26 Feb 07 |
jari |
57 |
pane.setLayout(gridbag); |
2 |
26 Feb 07 |
jari |
58 |
|
2 |
26 Feb 07 |
jari |
59 |
sampleSelectionPanel = new SampleSelectionPanel(Color.white, UIManager.getColor("Label.foreground"),true,"Sample Selection"); |
2 |
26 Feb 07 |
jari |
60 |
|
2 |
26 Feb 07 |
jari |
61 |
buildConstraints(constraints, 0, 0, 1, 1, 100, 50); |
2 |
26 Feb 07 |
jari |
62 |
gridbag.setConstraints(sampleSelectionPanel, constraints); |
2 |
26 Feb 07 |
jari |
63 |
pane.add(sampleSelectionPanel); |
2 |
26 Feb 07 |
jari |
64 |
|
2 |
26 Feb 07 |
jari |
65 |
JPanel numNeibsPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
66 |
numNeibsPanel.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
67 |
GridBagLayout grid2 = new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
JLabel numNeibsLabel= new JLabel("Number for neighbors for KNN imputation :"); |
2 |
26 Feb 07 |
jari |
70 |
buildConstraints(constraints, 0, 0, 1, 1, 50, 100); |
2 |
26 Feb 07 |
jari |
71 |
grid2.setConstraints(numNeibsLabel, constraints); |
2 |
26 Feb 07 |
jari |
72 |
numNeibsPanel.add(numNeibsLabel); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
numNeighborsField = new JTextField("10", 7); |
2 |
26 Feb 07 |
jari |
75 |
buildConstraints(constraints, 1, 0, 1, 1, 50, 100); |
2 |
26 Feb 07 |
jari |
76 |
grid2.setConstraints(numNeighborsField, constraints); |
2 |
26 Feb 07 |
jari |
77 |
numNeibsPanel.add(numNeighborsField); |
2 |
26 Feb 07 |
jari |
78 |
|
2 |
26 Feb 07 |
jari |
79 |
buildConstraints(constraints, 0, 1, 1, 1, 0, 50); |
2 |
26 Feb 07 |
jari |
80 |
gridbag.setConstraints(numNeibsPanel, constraints); |
2 |
26 Feb 07 |
jari |
81 |
pane.add(numNeibsPanel); |
2 |
26 Feb 07 |
jari |
82 |
|
2 |
26 Feb 07 |
jari |
83 |
setActionListeners(new EventListener()); |
2 |
26 Feb 07 |
jari |
//addContent(sampleSelectionPanel); |
2 |
26 Feb 07 |
jari |
85 |
addContent(pane); |
2 |
26 Feb 07 |
jari |
86 |
pack(); |
2 |
26 Feb 07 |
jari |
87 |
} |
2 |
26 Feb 07 |
jari |
88 |
|
2 |
26 Feb 07 |
jari |
89 |
void buildConstraints(GridBagConstraints gbc, int gx, int gy, |
2 |
26 Feb 07 |
jari |
90 |
int gw, int gh, int wx, int wy) { |
2 |
26 Feb 07 |
jari |
91 |
|
2 |
26 Feb 07 |
jari |
92 |
gbc.gridx = gx; |
2 |
26 Feb 07 |
jari |
93 |
gbc.gridy = gy; |
2 |
26 Feb 07 |
jari |
94 |
gbc.gridwidth = gw; |
2 |
26 Feb 07 |
jari |
95 |
gbc.gridheight = gh; |
2 |
26 Feb 07 |
jari |
96 |
gbc.weightx = wx; |
2 |
26 Feb 07 |
jari |
97 |
gbc.weighty = wy; |
2 |
26 Feb 07 |
jari |
98 |
} |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
public int showModal(){ |
2 |
26 Feb 07 |
jari |
101 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
102 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
103 |
show(); |
2 |
26 Feb 07 |
jari |
104 |
return result; |
2 |
26 Feb 07 |
jari |
105 |
} |
2 |
26 Feb 07 |
jari |
106 |
|
2 |
26 Feb 07 |
jari |
107 |
public boolean isClusterGenesSelected(){ |
2 |
26 Feb 07 |
jari |
108 |
return sampleSelectionPanel.isClusterGenesSelected(); |
2 |
26 Feb 07 |
jari |
109 |
} |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
public void resetControls(){ |
2 |
26 Feb 07 |
jari |
112 |
sampleSelectionPanel.setClusterGenesSelected(true); |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
public int getNumNeighbors() { |
2 |
26 Feb 07 |
jari |
116 |
return Integer.parseInt(numNeighborsField.getText()); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
protected class EventListener implements ActionListener { |
2 |
26 Feb 07 |
jari |
120 |
public void actionPerformed(ActionEvent event) { |
2 |
26 Feb 07 |
jari |
121 |
String command = event.getActionCommand(); |
2 |
26 Feb 07 |
jari |
// Object source = event.getSource(); |
2 |
26 Feb 07 |
jari |
123 |
if (command.equals("ok-command")) { |
2 |
26 Feb 07 |
jari |
124 |
try { |
2 |
26 Feb 07 |
jari |
125 |
int numNeibs = getNumNeighbors(); |
2 |
26 Feb 07 |
jari |
126 |
if (numNeibs <= 0) { |
2 |
26 Feb 07 |
jari |
127 |
JOptionPane.showMessageDialog(null, "Invalid number of neighbors", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
128 |
return; |
2 |
26 Feb 07 |
jari |
129 |
} else { |
2 |
26 Feb 07 |
jari |
130 |
result = JOptionPane.OK_OPTION; |
2 |
26 Feb 07 |
jari |
131 |
dispose(); |
2 |
26 Feb 07 |
jari |
132 |
} |
2 |
26 Feb 07 |
jari |
133 |
} catch (NumberFormatException nfe){ |
2 |
26 Feb 07 |
jari |
134 |
JOptionPane.showMessageDialog(null, "Invalid number of neighbors", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
135 |
return; |
2 |
26 Feb 07 |
jari |
136 |
} |
2 |
26 Feb 07 |
jari |
137 |
} else if (command.equals("cancel-command")){ |
2 |
26 Feb 07 |
jari |
138 |
result = JOptionPane.CANCEL_OPTION; |
2 |
26 Feb 07 |
jari |
139 |
dispose(); |
2 |
26 Feb 07 |
jari |
140 |
} else if (command.equals("reset-command")){ |
2 |
26 Feb 07 |
jari |
141 |
resetControls(); |
2 |
26 Feb 07 |
jari |
142 |
} else if (command.equals("info-command")){ |
2 |
26 Feb 07 |
jari |
143 |
HelpWindow helpWindow = new HelpWindow(PCASelectionDialog.this, "PCA Initialization Dialog"); |
2 |
26 Feb 07 |
jari |
144 |
if(helpWindow.getWindowContent()){ |
2 |
26 Feb 07 |
jari |
145 |
helpWindow.setSize(450, 350); |
2 |
26 Feb 07 |
jari |
146 |
helpWindow.setLocation(); |
2 |
26 Feb 07 |
jari |
147 |
helpWindow.show(); |
2 |
26 Feb 07 |
jari |
148 |
} |
2 |
26 Feb 07 |
jari |
149 |
else{ |
2 |
26 Feb 07 |
jari |
150 |
helpWindow.dispose(); |
2 |
26 Feb 07 |
jari |
151 |
} |
2 |
26 Feb 07 |
jari |
152 |
} |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
} |
2 |
26 Feb 07 |
jari |
155 |
|
2 |
26 Feb 07 |
jari |
156 |
public static void main(String [] args){ |
2 |
26 Feb 07 |
jari |
157 |
PCASelectionDialog dialog = new PCASelectionDialog(new Frame()); |
2 |
26 Feb 07 |
jari |
158 |
int result = dialog.showModal(); |
2 |
26 Feb 07 |
jari |
159 |
System.out.println("result = "+result); |
2 |
26 Feb 07 |
jari |
160 |
System.exit(0); |
2 |
26 Feb 07 |
jari |
161 |
} |
2 |
26 Feb 07 |
jari |
162 |
|
2 |
26 Feb 07 |
jari |
163 |
} |