2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
Copyright @ 1999-2005, 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 |
* COAAdditional3DAxesDialog.java |
2 |
26 Feb 07 |
jari |
7 |
* |
2 |
26 Feb 07 |
jari |
* Created on December 10, 2004, 11:00 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.coa; |
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.Toolkit; |
2 |
26 Feb 07 |
jari |
18 |
import java.awt.event.ActionEvent; |
2 |
26 Feb 07 |
jari |
19 |
import java.awt.event.ActionListener; |
2 |
26 Feb 07 |
jari |
20 |
import java.awt.event.WindowAdapter; |
2 |
26 Feb 07 |
jari |
21 |
|
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JComboBox; |
2 |
26 Feb 07 |
jari |
23 |
import javax.swing.JFrame; |
2 |
26 Feb 07 |
jari |
24 |
import javax.swing.JLabel; |
2 |
26 Feb 07 |
jari |
25 |
import javax.swing.JOptionPane; |
2 |
26 Feb 07 |
jari |
26 |
import javax.swing.JPanel; |
2 |
26 Feb 07 |
jari |
27 |
import javax.swing.border.EtchedBorder; |
2 |
26 Feb 07 |
jari |
28 |
|
2 |
26 Feb 07 |
jari |
29 |
import org.tigr.microarray.mev.cluster.gui.impl.dialogs.AlgorithmDialog; |
2 |
26 Feb 07 |
jari |
30 |
|
2 |
26 Feb 07 |
jari |
31 |
/** |
2 |
26 Feb 07 |
jari |
32 |
* |
2 |
26 Feb 07 |
jari |
* @author nbhagaba |
2 |
26 Feb 07 |
jari |
34 |
*/ |
2 |
26 Feb 07 |
jari |
35 |
public class COAAdditional3DAxesDialog extends AlgorithmDialog { |
2 |
26 Feb 07 |
jari |
36 |
boolean okPressed = false; |
2 |
26 Feb 07 |
jari |
37 |
private int numAxes; |
2 |
26 Feb 07 |
jari |
38 |
private JComboBox xAxisBox, yAxisBox, zAxisBox; |
2 |
26 Feb 07 |
jari |
39 |
|
2 |
26 Feb 07 |
jari |
/** Creates a new instance of PCAAdditional3DAxesDialog */ |
2 |
26 Feb 07 |
jari |
41 |
public COAAdditional3DAxesDialog(JFrame parentFrame, boolean modal, int numAxes) { |
2 |
26 Feb 07 |
jari |
42 |
super(parentFrame, "Select new projection axes", modal); |
2 |
26 Feb 07 |
jari |
43 |
this.numAxes = numAxes; |
2 |
26 Feb 07 |
jari |
44 |
setBounds(0, 0, 500, 200); |
2 |
26 Feb 07 |
jari |
45 |
setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
46 |
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); |
2 |
26 Feb 07 |
jari |
47 |
|
2 |
26 Feb 07 |
jari |
48 |
GridBagLayout gridbag = new GridBagLayout(); |
2 |
26 Feb 07 |
jari |
49 |
GridBagConstraints constraints = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
50 |
constraints.fill = GridBagConstraints.NONE; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
JPanel pane = new JPanel(); |
2 |
26 Feb 07 |
jari |
53 |
pane.setBackground(Color.white); |
2 |
26 Feb 07 |
jari |
54 |
pane.setBorder(new EtchedBorder()); |
2 |
26 Feb 07 |
jari |
55 |
pane.setLayout(gridbag); |
2 |
26 Feb 07 |
jari |
56 |
|
2 |
26 Feb 07 |
jari |
57 |
String[] axes = new String[numAxes]; |
2 |
26 Feb 07 |
jari |
58 |
for (int i = 0; i < axes.length; i++) { |
2 |
26 Feb 07 |
jari |
59 |
axes[i] = String.valueOf(i + 1); |
2 |
26 Feb 07 |
jari |
60 |
} |
2 |
26 Feb 07 |
jari |
61 |
xAxisBox = new JComboBox(axes); |
2 |
26 Feb 07 |
jari |
62 |
yAxisBox = new JComboBox(axes); |
2 |
26 Feb 07 |
jari |
63 |
zAxisBox = new JComboBox(axes); |
2 |
26 Feb 07 |
jari |
64 |
|
2 |
26 Feb 07 |
jari |
65 |
xAxisBox.setSelectedIndex(0); |
2 |
26 Feb 07 |
jari |
66 |
yAxisBox.setSelectedIndex(1); |
2 |
26 Feb 07 |
jari |
67 |
zAxisBox.setSelectedIndex(2); |
2 |
26 Feb 07 |
jari |
68 |
|
2 |
26 Feb 07 |
jari |
69 |
JLabel selectAxesLabel = new JLabel("Select components to plot: "); |
2 |
26 Feb 07 |
jari |
70 |
buildConstraints(constraints, 0, 0, 1, 1, 40, 100); |
2 |
26 Feb 07 |
jari |
71 |
gridbag.setConstraints(selectAxesLabel, constraints); |
2 |
26 Feb 07 |
jari |
72 |
pane.add(selectAxesLabel); |
2 |
26 Feb 07 |
jari |
73 |
|
2 |
26 Feb 07 |
jari |
74 |
buildConstraints(constraints, 1, 0, 1, 1, 20, 0); |
2 |
26 Feb 07 |
jari |
75 |
gridbag.setConstraints(xAxisBox, constraints); |
2 |
26 Feb 07 |
jari |
76 |
pane.add(xAxisBox); |
2 |
26 Feb 07 |
jari |
77 |
|
2 |
26 Feb 07 |
jari |
78 |
buildConstraints(constraints, 2, 0, 1, 1, 20, 0); |
2 |
26 Feb 07 |
jari |
79 |
gridbag.setConstraints(yAxisBox, constraints); |
2 |
26 Feb 07 |
jari |
80 |
pane.add(yAxisBox); |
2 |
26 Feb 07 |
jari |
81 |
|
2 |
26 Feb 07 |
jari |
82 |
buildConstraints(constraints, 3, 0, 1, 1, 20, 0); |
2 |
26 Feb 07 |
jari |
83 |
gridbag.setConstraints(zAxisBox, constraints); |
2 |
26 Feb 07 |
jari |
84 |
pane.add(zAxisBox); |
2 |
26 Feb 07 |
jari |
85 |
|
2 |
26 Feb 07 |
jari |
86 |
addContent(pane); |
2 |
26 Feb 07 |
jari |
//pack(); |
2 |
26 Feb 07 |
jari |
88 |
EventListener listener = new EventListener(); |
2 |
26 Feb 07 |
jari |
89 |
setActionListeners(listener); |
2 |
26 Feb 07 |
jari |
90 |
this.addWindowListener(listener); |
2 |
26 Feb 07 |
jari |
91 |
} |
2 |
26 Feb 07 |
jari |
92 |
|
2 |
26 Feb 07 |
jari |
93 |
public void setVisible(boolean visible) { |
2 |
26 Feb 07 |
jari |
94 |
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); |
2 |
26 Feb 07 |
jari |
95 |
setLocation((screenSize.width - getSize().width)/2, (screenSize.height - getSize().height)/2); |
2 |
26 Feb 07 |
jari |
96 |
|
2 |
26 Feb 07 |
jari |
97 |
super.setVisible(visible); |
2 |
26 Feb 07 |
jari |
98 |
} |
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
void buildConstraints(GridBagConstraints gbc, int gx, int gy, |
2 |
26 Feb 07 |
jari |
101 |
int gw, int gh, int wx, int wy) { |
2 |
26 Feb 07 |
jari |
102 |
|
2 |
26 Feb 07 |
jari |
103 |
gbc.gridx = gx; |
2 |
26 Feb 07 |
jari |
104 |
gbc.gridy = gy; |
2 |
26 Feb 07 |
jari |
105 |
gbc.gridwidth = gw; |
2 |
26 Feb 07 |
jari |
106 |
gbc.gridheight = gh; |
2 |
26 Feb 07 |
jari |
107 |
gbc.weightx = wx; |
2 |
26 Feb 07 |
jari |
108 |
gbc.weighty = wy; |
2 |
26 Feb 07 |
jari |
109 |
} |
2 |
26 Feb 07 |
jari |
110 |
|
2 |
26 Feb 07 |
jari |
111 |
public int getXAxis() { |
2 |
26 Feb 07 |
jari |
112 |
return xAxisBox.getSelectedIndex(); |
2 |
26 Feb 07 |
jari |
113 |
} |
2 |
26 Feb 07 |
jari |
114 |
|
2 |
26 Feb 07 |
jari |
115 |
public int getYAxis() { |
2 |
26 Feb 07 |
jari |
116 |
return yAxisBox.getSelectedIndex(); |
2 |
26 Feb 07 |
jari |
117 |
} |
2 |
26 Feb 07 |
jari |
118 |
|
2 |
26 Feb 07 |
jari |
119 |
public int getZAxis() { |
2 |
26 Feb 07 |
jari |
120 |
return zAxisBox.getSelectedIndex(); |
2 |
26 Feb 07 |
jari |
121 |
} |
2 |
26 Feb 07 |
jari |
122 |
|
2 |
26 Feb 07 |
jari |
123 |
public void setZBoxInvisible(boolean invis) { |
2 |
26 Feb 07 |
jari |
124 |
zAxisBox.setEnabled(!invis); |
2 |
26 Feb 07 |
jari |
125 |
zAxisBox.setVisible(!invis); |
2 |
26 Feb 07 |
jari |
126 |
} |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
128 |
public boolean isOkPressed() { |
2 |
26 Feb 07 |
jari |
129 |
return okPressed; |
2 |
26 Feb 07 |
jari |
130 |
} |
2 |
26 Feb 07 |
jari |
131 |
|
2 |
26 Feb 07 |
jari |
132 |
public static void main(String[] args) { |
2 |
26 Feb 07 |
jari |
133 |
COAAdditional3DAxesDialog pd = new COAAdditional3DAxesDialog(new JFrame(), true, 10); |
2 |
26 Feb 07 |
jari |
134 |
pd.setVisible(true); |
2 |
26 Feb 07 |
jari |
135 |
} |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
137 |
public class EventListener extends WindowAdapter implements ActionListener{ |
2 |
26 Feb 07 |
jari |
138 |
|
2 |
26 Feb 07 |
jari |
139 |
public void actionPerformed(ActionEvent ae) { |
2 |
26 Feb 07 |
jari |
140 |
String command = ae.getActionCommand(); |
2 |
26 Feb 07 |
jari |
141 |
if(command.equals("ok-command")){ |
2 |
26 Feb 07 |
jari |
142 |
int x = getXAxis(); |
2 |
26 Feb 07 |
jari |
143 |
int y = getYAxis(); |
2 |
26 Feb 07 |
jari |
144 |
int z = getZAxis(); |
2 |
26 Feb 07 |
jari |
145 |
if (!zAxisBox.isVisible()) { |
2 |
26 Feb 07 |
jari |
146 |
if (x==y) { |
2 |
26 Feb 07 |
jari |
147 |
JOptionPane.showMessageDialog(null, "Both axes cannot be the same", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
148 |
return; |
2 |
26 Feb 07 |
jari |
149 |
} |
2 |
26 Feb 07 |
jari |
150 |
} else { |
2 |
26 Feb 07 |
jari |
151 |
if ((x==y)||(y==z)||(x==z)) { |
2 |
26 Feb 07 |
jari |
152 |
JOptionPane.showMessageDialog(null, "No two axes can be the same", "Error", JOptionPane.ERROR_MESSAGE); |
2 |
26 Feb 07 |
jari |
153 |
return; |
2 |
26 Feb 07 |
jari |
154 |
} |
2 |
26 Feb 07 |
jari |
155 |
} |
2 |
26 Feb 07 |
jari |
156 |
|
2 |
26 Feb 07 |
jari |
157 |
okPressed = true; |
2 |
26 Feb 07 |
jari |
158 |
dispose(); |
2 |
26 Feb 07 |
jari |
159 |
|
2 |
26 Feb 07 |
jari |
160 |
} else if (command.equals("reset-command")) { |
2 |
26 Feb 07 |
jari |
161 |
xAxisBox.setSelectedIndex(0); |
2 |
26 Feb 07 |
jari |
162 |
yAxisBox.setSelectedIndex(1); |
2 |
26 Feb 07 |
jari |
163 |
zAxisBox.setSelectedIndex(2); |
2 |
26 Feb 07 |
jari |
164 |
} else if (command.equals("cancel-command")) { |
2 |
26 Feb 07 |
jari |
165 |
okPressed = false; |
2 |
26 Feb 07 |
jari |
166 |
dispose(); |
2 |
26 Feb 07 |
jari |
167 |
} else if (command.equals("info-command")){ |
2 |
26 Feb 07 |
jari |
168 |
} |
2 |
26 Feb 07 |
jari |
169 |
} |
2 |
26 Feb 07 |
jari |
170 |
} |
2 |
26 Feb 07 |
jari |
171 |
} |