2 |
26 Feb 07 |
jari |
1 |
/* |
2 |
26 Feb 07 |
jari |
* Created on May 25, 2006 |
2 |
26 Feb 07 |
jari |
3 |
*/ |
2 |
26 Feb 07 |
jari |
4 |
package org.tigr.microarray.mev.r; |
2 |
26 Feb 07 |
jari |
5 |
|
2 |
26 Feb 07 |
jari |
6 |
import java.awt.Color; |
2 |
26 Feb 07 |
jari |
7 |
import java.awt.Dimension; |
2 |
26 Feb 07 |
jari |
8 |
import java.awt.Font; |
2 |
26 Feb 07 |
jari |
9 |
import java.awt.Frame; |
2 |
26 Feb 07 |
jari |
10 |
import java.awt.GridBagConstraints; |
2 |
26 Feb 07 |
jari |
11 |
import java.awt.GridBagLayout; |
2 |
26 Feb 07 |
jari |
12 |
import java.awt.Insets; |
2 |
26 Feb 07 |
jari |
13 |
import java.io.File; |
2 |
26 Feb 07 |
jari |
14 |
import java.io.FileWriter; |
2 |
26 Feb 07 |
jari |
15 |
import java.io.IOException; |
2 |
26 Feb 07 |
jari |
16 |
import java.util.Vector; |
2 |
26 Feb 07 |
jari |
17 |
|
2 |
26 Feb 07 |
jari |
18 |
import javax.swing.BorderFactory; |
2 |
26 Feb 07 |
jari |
19 |
import javax.swing.Box; |
2 |
26 Feb 07 |
jari |
20 |
import javax.swing.BoxLayout; |
2 |
26 Feb 07 |
jari |
21 |
import javax.swing.JComboBox; |
2 |
26 Feb 07 |
jari |
22 |
import javax.swing.JFileChooser; |
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.JScrollPane; |
2 |
26 Feb 07 |
jari |
28 |
import javax.swing.border.Border; |
2 |
26 Feb 07 |
jari |
29 |
import javax.swing.border.TitledBorder; |
2 |
26 Feb 07 |
jari |
30 |
|
2 |
26 Feb 07 |
jari |
31 |
import org.tigr.microarray.mev.TMEV; |
2 |
26 Feb 07 |
jari |
32 |
import org.tigr.microarray.mev.cluster.gui.impl.usc.Reader; |
2 |
26 Feb 07 |
jari |
33 |
import org.tigr.microarray.mev.cluster.gui.impl.usc.USCTextFileFilter; |
2 |
26 Feb 07 |
jari |
34 |
|
2 |
26 Feb 07 |
jari |
35 |
/** |
2 |
26 Feb 07 |
jari |
* @author iVu |
2 |
26 Feb 07 |
jari |
37 |
*/ |
2 |
26 Feb 07 |
jari |
38 |
public class ClassAssigner { |
2 |
26 Feb 07 |
jari |
39 |
private boolean requireAllLabelsAssigned = true; |
2 |
26 Feb 07 |
jari |
40 |
private int minNumAssignsPerLabel = 3; |
2 |
26 Feb 07 |
jari |
41 |
|
2 |
26 Feb 07 |
jari |
42 |
private String[] rowNames; |
2 |
26 Feb 07 |
jari |
43 |
private String[] comboNames; |
2 |
26 Feb 07 |
jari |
44 |
private Vector vComboBox; |
2 |
26 Feb 07 |
jari |
45 |
|
2 |
26 Feb 07 |
jari |
46 |
private String borderTitle; |
2 |
26 Feb 07 |
jari |
47 |
private String message; |
2 |
26 Feb 07 |
jari |
48 |
|
2 |
26 Feb 07 |
jari |
49 |
private JPanel mainPanel; |
2 |
26 Feb 07 |
jari |
50 |
private JScrollPane jsp; |
2 |
26 Feb 07 |
jari |
51 |
|
2 |
26 Feb 07 |
jari |
52 |
public static String TEST_CLASS_STRING = "Unknown (Test)"; |
2 |
26 Feb 07 |
jari |
53 |
|
2 |
26 Feb 07 |
jari |
54 |
|
2 |
26 Feb 07 |
jari |
55 |
/** |
2 |
26 Feb 07 |
jari |
* Constructor |
2 |
26 Feb 07 |
jari |
* @param rowNamesP |
2 |
26 Feb 07 |
jari |
* @param comboNamesP |
2 |
26 Feb 07 |
jari |
59 |
*/ |
2 |
26 Feb 07 |
jari |
60 |
public ClassAssigner( String[] rowNamesP, String[] comboNamesP ) { |
2 |
26 Feb 07 |
jari |
61 |
this.rowNames = rowNamesP; |
2 |
26 Feb 07 |
jari |
62 |
this.comboNames = comboNamesP; |
2 |
26 Feb 07 |
jari |
63 |
this.createAssigner(); |
2 |
26 Feb 07 |
jari |
64 |
}//constructor |
2 |
26 Feb 07 |
jari |
65 |
public ClassAssigner( String[] rowNamesP, String[] comboNamesP, String borderTitleP, |
2 |
26 Feb 07 |
jari |
66 |
String messageP ) { |
2 |
26 Feb 07 |
jari |
67 |
this.rowNames = rowNamesP; |
2 |
26 Feb 07 |
jari |
68 |
this.comboNames = comboNamesP; |
2 |
26 Feb 07 |
jari |
69 |
this.borderTitle = borderTitleP; |
2 |
26 Feb 07 |
jari |
70 |
this.message = messageP; |
2 |
26 Feb 07 |
jari |
71 |
this.createAssigner(); |
2 |
26 Feb 07 |
jari |
72 |
}//constructor |
2 |
26 Feb 07 |
jari |
73 |
public ClassAssigner( String[] rowNamesP, String[] comboNamesP, |
2 |
26 Feb 07 |
jari |
74 |
boolean requireAllLabelsAssignedP ) { |
2 |
26 Feb 07 |
jari |
75 |
this.rowNames = rowNamesP; |
2 |
26 Feb 07 |
jari |
76 |
this.comboNames = comboNamesP; |
2 |
26 Feb 07 |
jari |
77 |
this.requireAllLabelsAssigned = requireAllLabelsAssignedP; |
2 |
26 Feb 07 |
jari |
78 |
this.createAssigner(); |
2 |
26 Feb 07 |
jari |
79 |
}//constructor |
2 |
26 Feb 07 |
jari |
80 |
public ClassAssigner( String[] rowNamesP, String[] comboNamesP, |
2 |
26 Feb 07 |
jari |
81 |
boolean requireAllLabelsAssignedP, int minNumAssignsPerLabelP ) { |
2 |
26 Feb 07 |
jari |
82 |
this.rowNames = rowNamesP; |
2 |
26 Feb 07 |
jari |
83 |
this.comboNames = comboNamesP; |
2 |
26 Feb 07 |
jari |
84 |
this.requireAllLabelsAssigned = requireAllLabelsAssignedP; |
2 |
26 Feb 07 |
jari |
85 |
this.minNumAssignsPerLabel = minNumAssignsPerLabelP; |
2 |
26 Feb 07 |
jari |
86 |
this.createAssigner(); |
2 |
26 Feb 07 |
jari |
87 |
}//constructor |
2 |
26 Feb 07 |
jari |
88 |
public ClassAssigner( String[] rowNamesP, String[] comboNamesP, String borderTitleP, |
2 |
26 Feb 07 |
jari |
89 |
String messageP, boolean requireAllLabelsAssignedP, int minNumAssignsPerLabelP ) { |
2 |
26 Feb 07 |
jari |
90 |
this.rowNames = rowNamesP; |
2 |
26 Feb 07 |
jari |
91 |
this.comboNames = comboNamesP; |
2 |
26 Feb 07 |
jari |
92 |
this.borderTitle = borderTitleP; |
2 |
26 Feb 07 |
jari |
93 |
this.message = messageP; |
2 |
26 Feb 07 |
jari |
94 |
this.requireAllLabelsAssigned = requireAllLabelsAssignedP; |
2 |
26 Feb 07 |
jari |
95 |
this.minNumAssignsPerLabel = minNumAssignsPerLabelP; |
2 |
26 Feb 07 |
jari |
96 |
this.createAssigner(); |
2 |
26 Feb 07 |
jari |
97 |
}//constructor |
2 |
26 Feb 07 |
jari |
98 |
|
2 |
26 Feb 07 |
jari |
99 |
|
2 |
26 Feb 07 |
jari |
100 |
/** |
2 |
26 Feb 07 |
jari |
* Creates the GUI |
2 |
26 Feb 07 |
jari |
102 |
*/ |
2 |
26 Feb 07 |
jari |
103 |
private void createAssigner() { |
2 |
26 Feb 07 |
jari |
104 |
this.mainPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
//this.mainPanel.setPreferredSize( new Dimension( 300, 300 ) ); |
2 |
26 Feb 07 |
jari |
106 |
this.vComboBox = new Vector(); |
2 |
26 Feb 07 |
jari |
107 |
|
2 |
26 Feb 07 |
jari |
//some variables that will be used to construct the gui |
2 |
26 Feb 07 |
jari |
109 |
int rowKount = this.rowNames.length; |
2 |
26 Feb 07 |
jari |
110 |
int colKount = this.comboNames.length; |
2 |
26 Feb 07 |
jari |
111 |
Dimension dRowNameLabel = new Dimension( 250, 24 ); |
2 |
26 Feb 07 |
jari |
112 |
Dimension dCombo = new Dimension( 150, 24 ); |
2 |
26 Feb 07 |
jari |
113 |
Dimension dGap = new Dimension( 5, 24 ); |
2 |
26 Feb 07 |
jari |
//Dimension dHorPadding = new Dimension( 20, 24 ); |
2 |
26 Feb 07 |
jari |
115 |
|
2 |
26 Feb 07 |
jari |
//set panel attributes |
2 |
26 Feb 07 |
jari |
117 |
this.mainPanel.setLayout( new GridBagLayout() ); |
2 |
26 Feb 07 |
jari |
118 |
GridBagConstraints c = new GridBagConstraints(); |
2 |
26 Feb 07 |
jari |
119 |
|
2 |
26 Feb 07 |
jari |
//set some text as a message (instruction) if text supplied |
2 |
26 Feb 07 |
jari |
121 |
if( this.message != null ) { |
2 |
26 Feb 07 |
jari |
122 |
JLabel label = new JLabel( this.message ); |
2 |
26 Feb 07 |
jari |
123 |
c.insets = new Insets( 25, 25, 25, 25 ); |
2 |
26 Feb 07 |
jari |
124 |
c.gridy = 0; |
2 |
26 Feb 07 |
jari |
125 |
this.mainPanel.add( label, c ); |
2 |
26 Feb 07 |
jari |
126 |
}//message |
2 |
26 Feb 07 |
jari |
127 |
|
2 |
26 Feb 07 |
jari |
//reset the insets for the rows |
2 |
26 Feb 07 |
jari |
129 |
c.insets = new Insets( 0, 0, 0, 4 ); |
2 |
26 Feb 07 |
jari |
//loop through the rows |
2 |
26 Feb 07 |
jari |
131 |
for( int r = 0; r < rowKount; r ++ ) { |
2 |
26 Feb 07 |
jari |
//create a Label for this row |
2 |
26 Feb 07 |
jari |
133 |
JLabel rowLabel = new JLabel( this.rowNames[ r ] ); |
2 |
26 Feb 07 |
jari |
134 |
rowLabel.setPreferredSize( dRowNameLabel ); |
2 |
26 Feb 07 |
jari |
135 |
rowLabel.setHorizontalAlignment( JLabel.RIGHT ); |
2 |
26 Feb 07 |
jari |
136 |
|
2 |
26 Feb 07 |
jari |
//now create the comboBox for this row |
2 |
26 Feb 07 |
jari |
138 |
JComboBox rowCombo = new JComboBox( this.comboNames ); |
2 |
26 Feb 07 |
jari |
139 |
rowCombo.setPreferredSize( dCombo ); |
2 |
26 Feb 07 |
jari |
140 |
|
2 |
26 Feb 07 |
jari |
//put this on its own JPanel |
2 |
26 Feb 07 |
jari |
142 |
JPanel rowPanel = new JPanel(); |
2 |
26 Feb 07 |
jari |
143 |
rowPanel.setLayout( new BoxLayout( rowPanel, BoxLayout.X_AXIS ) ); |
2 |
26 Feb 07 |
jari |
//rowPanel.add( Box.createHorizontalGlue() ); |
2 |
26 Feb 07 |
jari |
145 |
rowPanel.add( rowLabel ); |
2 |
26 Feb 07 |
jari |
146 |
rowPanel.add( Box.createRigidArea( dGap ) ); |
2 |
26 Feb 07 |
jari |
147 |
rowPanel.add( rowCombo ); |
2 |
26 Feb 07 |
jari |
//rowPanel.add( Box.createHorizontalGlue() ); |
2 |
26 Feb 07 |
jari |
149 |
|
2 |
26 Feb 07 |
jari |
//shade every other row for readability |
2 |
26 Feb 07 |
jari |
151 |
if( r % 2 == 0 ) { |
2 |
26 Feb 07 |
jari |
152 |
rowPanel.setBackground( Color.LIGHT_GRAY ); |
2 |
26 Feb 07 |
jari |
153 |
} |
2 |
26 Feb 07 |
jari |
154 |
|
2 |
26 Feb 07 |
jari |
//add row to main |
2 |
26 Feb 07 |
jari |
156 |
c.gridy = r + 1; |
2 |
26 Feb 07 |
jari |
157 |
this.mainPanel.add( rowPanel, c ); |
2 |
26 Feb 07 |
jari |
158 |
|
2 |
26 Feb 07 |
jari |
//add the box to the Vector |
2 |
26 Feb 07 |
jari |
160 |
this.vComboBox.add( rowCombo ); |
2 |
26 Feb 07 |
jari |
161 |
}//r |
2 |
26 Feb 07 |
jari |
162 |
|
2 |
26 Feb 07 |
jari |
//create a border if calling class supplied a title |
2 |
26 Feb 07 |
jari |
164 |
if( this.borderTitle != null ) { |
2 |
26 Feb 07 |
jari |
165 |
Border greyLine = BorderFactory.createLineBorder( Color.LIGHT_GRAY, 1 ); |
2 |
26 Feb 07 |
jari |
166 |
Font font11 = new Font( "Arial", Font.PLAIN, 11 ); |
2 |
26 Feb 07 |
jari |
167 |
TitledBorder border = BorderFactory.createTitledBorder( greyLine, |
2 |
26 Feb 07 |
jari |
168 |
this.borderTitle, TitledBorder.LEADING, TitledBorder.TOP, font11 ); |
2 |
26 Feb 07 |
jari |
169 |
this.mainPanel.setBorder( border ); |
2 |
26 Feb 07 |
jari |
170 |
}//border |
2 |
26 Feb 07 |
jari |
171 |
|
2 |
26 Feb 07 |
jari |
172 |
this.jsp = new JScrollPane( this.mainPanel ); |
2 |
26 Feb 07 |
jari |
173 |
this.jsp.setPreferredSize( new Dimension( 450, 350 ) ); |
2 |
26 Feb 07 |
jari |
174 |
}//createAssigner() |
2 |
26 Feb 07 |
jari |
175 |
|
2 |
26 Feb 07 |
jari |
176 |
|
2 |
26 Feb 07 |
jari |
177 |
/** |
2 |
26 Feb 07 |
jari |
178 |
* |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
180 |
*/ |
2 |
26 Feb 07 |
jari |
181 |
public boolean verifyLabeling() { |
2 |
26 Feb 07 |
jari |
182 |
boolean toReturn = true; |
2 |
26 Feb 07 |
jari |
183 |
|
2 |
26 Feb 07 |
jari |
//just to make sure that we really want to verify labelling |
2 |
26 Feb 07 |
jari |
185 |
if( this.requireAllLabelsAssigned ) { |
2 |
26 Feb 07 |
jari |
//loop through the labels |
2 |
26 Feb 07 |
jari |
187 |
for( int i = 0; i < this.comboNames.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
//disregard if this is the test label |
2 |
26 Feb 07 |
jari |
189 |
if( this.comboNames[ i ].equalsIgnoreCase( ClassAssigner.TEST_CLASS_STRING ) ) { |
2 |
26 Feb 07 |
jari |
//ignore |
2 |
26 Feb 07 |
jari |
191 |
} else { |
2 |
26 Feb 07 |
jari |
//now kount # of times it is selected in combos |
2 |
26 Feb 07 |
jari |
193 |
int occurKount = 0; |
2 |
26 Feb 07 |
jari |
194 |
for( int j = 0; j < this.vComboBox.size(); j ++ ) { |
2 |
26 Feb 07 |
jari |
195 |
JComboBox box = ( JComboBox ) this.vComboBox.elementAt( j ); |
2 |
26 Feb 07 |
jari |
196 |
int iSelected = box.getSelectedIndex(); |
2 |
26 Feb 07 |
jari |
197 |
if( iSelected == i ) { |
2 |
26 Feb 07 |
jari |
198 |
occurKount ++; |
2 |
26 Feb 07 |
jari |
199 |
} |
2 |
26 Feb 07 |
jari |
200 |
}//j |
2 |
26 Feb 07 |
jari |
201 |
|
2 |
26 Feb 07 |
jari |
//is this at least minimum # of occurences |
2 |
26 Feb 07 |
jari |
203 |
if( occurKount < this.minNumAssignsPerLabel ) { |
2 |
26 Feb 07 |
jari |
//not enough |
2 |
26 Feb 07 |
jari |
205 |
String sErr = "Class " + this.comboNames[ i ] + " has been assigned " |
2 |
26 Feb 07 |
jari |
206 |
+ occurKount + " times.\r\nIt must be assigned at least " |
2 |
26 Feb 07 |
jari |
207 |
+ this.minNumAssignsPerLabel + " times"; |
2 |
26 Feb 07 |
jari |
208 |
this.error( sErr ); |
2 |
26 Feb 07 |
jari |
209 |
toReturn = false; |
2 |
26 Feb 07 |
jari |
210 |
break; |
2 |
26 Feb 07 |
jari |
211 |
} |
2 |
26 Feb 07 |
jari |
212 |
} |
2 |
26 Feb 07 |
jari |
213 |
}//i |
2 |
26 Feb 07 |
jari |
214 |
} else { |
2 |
26 Feb 07 |
jari |
215 |
toReturn = true; |
2 |
26 Feb 07 |
jari |
216 |
} |
2 |
26 Feb 07 |
jari |
217 |
|
2 |
26 Feb 07 |
jari |
218 |
return toReturn; |
2 |
26 Feb 07 |
jari |
219 |
}//verifyLabeling() |
2 |
26 Feb 07 |
jari |
220 |
|
2 |
26 Feb 07 |
jari |
221 |
|
2 |
26 Feb 07 |
jari |
222 |
/** |
2 |
26 Feb 07 |
jari |
223 |
* |
2 |
26 Feb 07 |
jari |
224 |
*/ |
2 |
26 Feb 07 |
jari |
225 |
public void onSaveAssignments() { |
2 |
26 Feb 07 |
jari |
226 |
StringBuffer sb = new StringBuffer(); |
2 |
26 Feb 07 |
jari |
227 |
String newLine = "\r\n"; |
2 |
26 Feb 07 |
jari |
228 |
for( int i = 0; i < this.vComboBox.size(); i ++ ) { |
2 |
26 Feb 07 |
jari |
229 |
JComboBox box = ( JComboBox ) this.vComboBox.elementAt( i ); |
2 |
26 Feb 07 |
jari |
230 |
sb.append( box.getSelectedIndex() ); |
2 |
26 Feb 07 |
jari |
231 |
sb.append( newLine ); |
2 |
26 Feb 07 |
jari |
232 |
}//i |
2 |
26 Feb 07 |
jari |
233 |
|
2 |
26 Feb 07 |
jari |
//show a dialog so user can set save path |
2 |
26 Feb 07 |
jari |
//load the current path |
2 |
26 Feb 07 |
jari |
236 |
String dataPath = "/" + TMEV.getDataPath(); |
2 |
26 Feb 07 |
jari |
237 |
if( dataPath == null ) { |
2 |
26 Feb 07 |
jari |
238 |
dataPath = ""; |
2 |
26 Feb 07 |
jari |
239 |
} |
2 |
26 Feb 07 |
jari |
240 |
|
2 |
26 Feb 07 |
jari |
//pop up dialog for save |
2 |
26 Feb 07 |
jari |
242 |
JFileChooser chooser = new JFileChooser( dataPath ); |
2 |
26 Feb 07 |
jari |
243 |
USCTextFileFilter textFilter = new USCTextFileFilter(); |
2 |
26 Feb 07 |
jari |
244 |
chooser.addChoosableFileFilter( textFilter ); |
2 |
26 Feb 07 |
jari |
245 |
int returnVal = chooser.showSaveDialog( new Frame() ); |
2 |
26 Feb 07 |
jari |
246 |
if( returnVal == JFileChooser.APPROVE_OPTION ) { |
2 |
26 Feb 07 |
jari |
247 |
File saveFile; |
2 |
26 Feb 07 |
jari |
248 |
|
2 |
26 Feb 07 |
jari |
249 |
if( chooser.getFileFilter() == textFilter ) { |
2 |
26 Feb 07 |
jari |
//make sure to add .txt |
2 |
26 Feb 07 |
jari |
251 |
String path = chooser.getSelectedFile().getPath(); |
2 |
26 Feb 07 |
jari |
252 |
if( path.toLowerCase().endsWith( "txt" ) ) { |
2 |
26 Feb 07 |
jari |
//great, already ok |
2 |
26 Feb 07 |
jari |
254 |
saveFile = new File( path ); |
2 |
26 Feb 07 |
jari |
255 |
} else { |
2 |
26 Feb 07 |
jari |
//add it |
2 |
26 Feb 07 |
jari |
257 |
String subPath; |
2 |
26 Feb 07 |
jari |
258 |
int period = path.lastIndexOf( "." ); |
2 |
26 Feb 07 |
jari |
259 |
if( period != -1 ) { |
2 |
26 Feb 07 |
jari |
260 |
System.out.println( "period = -1" ); |
2 |
26 Feb 07 |
jari |
261 |
subPath = path.substring( 0, period ); |
2 |
26 Feb 07 |
jari |
262 |
} else { |
2 |
26 Feb 07 |
jari |
263 |
subPath = path; |
2 |
26 Feb 07 |
jari |
264 |
} |
2 |
26 Feb 07 |
jari |
265 |
String newPath = subPath + ".txt"; |
2 |
26 Feb 07 |
jari |
266 |
saveFile = new File( newPath ); |
2 |
26 Feb 07 |
jari |
267 |
} |
2 |
26 Feb 07 |
jari |
268 |
} else { |
2 |
26 Feb 07 |
jari |
269 |
saveFile = chooser.getSelectedFile(); |
2 |
26 Feb 07 |
jari |
270 |
} |
2 |
26 Feb 07 |
jari |
271 |
|
2 |
26 Feb 07 |
jari |
272 |
this.writeFile( saveFile, sb.toString() ); |
2 |
26 Feb 07 |
jari |
273 |
} else { |
2 |
26 Feb 07 |
jari |
//user cancelled |
2 |
26 Feb 07 |
jari |
275 |
} |
2 |
26 Feb 07 |
jari |
276 |
}//onSaveAssignments() |
2 |
26 Feb 07 |
jari |
277 |
|
2 |
26 Feb 07 |
jari |
278 |
|
2 |
26 Feb 07 |
jari |
279 |
/** |
2 |
26 Feb 07 |
jari |
* Write the String s to File f |
2 |
26 Feb 07 |
jari |
* @param f |
2 |
26 Feb 07 |
jari |
* @param s |
2 |
26 Feb 07 |
jari |
283 |
*/ |
2 |
26 Feb 07 |
jari |
284 |
private void writeFile( File f, String s ) { |
2 |
26 Feb 07 |
jari |
285 |
try { |
2 |
26 Feb 07 |
jari |
286 |
FileWriter fw = new FileWriter( f ); |
2 |
26 Feb 07 |
jari |
287 |
fw.write( s ); |
2 |
26 Feb 07 |
jari |
288 |
fw.flush(); |
2 |
26 Feb 07 |
jari |
289 |
fw.close(); |
2 |
26 Feb 07 |
jari |
290 |
} catch (IOException e) { |
2 |
26 Feb 07 |
jari |
291 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
292 |
this.error( e.getMessage() ); |
2 |
26 Feb 07 |
jari |
293 |
} |
2 |
26 Feb 07 |
jari |
294 |
}//writeFile() |
2 |
26 Feb 07 |
jari |
295 |
|
2 |
26 Feb 07 |
jari |
296 |
|
2 |
26 Feb 07 |
jari |
297 |
/** |
2 |
26 Feb 07 |
jari |
298 |
* |
2 |
26 Feb 07 |
jari |
299 |
*/ |
2 |
26 Feb 07 |
jari |
300 |
public void onLoadAssignments() { |
2 |
26 Feb 07 |
jari |
//show a file dialog |
2 |
26 Feb 07 |
jari |
302 |
GenericFileDialog gfd = new GenericFileDialog( new Frame(), "Load the Class File" ); |
2 |
26 Feb 07 |
jari |
303 |
if( gfd.showModal() == JOptionPane.OK_OPTION ) { |
2 |
26 Feb 07 |
jari |
304 |
File fLoaded = gfd.getSelectedFile(); |
2 |
26 Feb 07 |
jari |
//File testFile = new File( "/Users/iVu/Documents/Dev/MeV/TMEV3.1_RAMA1.0/data/AML/smallClassFile.txt" ); |
2 |
26 Feb 07 |
jari |
306 |
try { |
2 |
26 Feb 07 |
jari |
307 |
this.readClassFile( fLoaded ); |
2 |
26 Feb 07 |
jari |
308 |
} catch (Exception e) { |
2 |
26 Feb 07 |
jari |
309 |
e.printStackTrace(); |
2 |
26 Feb 07 |
jari |
310 |
this.error( e.getMessage() ); |
2 |
26 Feb 07 |
jari |
311 |
} |
2 |
26 Feb 07 |
jari |
312 |
} else { |
2 |
26 Feb 07 |
jari |
//user cancelled, do nothing |
2 |
26 Feb 07 |
jari |
314 |
} |
2 |
26 Feb 07 |
jari |
315 |
}//onLoadSelection() |
2 |
26 Feb 07 |
jari |
316 |
|
2 |
26 Feb 07 |
jari |
317 |
|
2 |
26 Feb 07 |
jari |
318 |
/** |
2 |
26 Feb 07 |
jari |
319 |
* |
2 |
26 Feb 07 |
jari |
* @param fLoaded |
2 |
26 Feb 07 |
jari |
* @throws Exception |
2 |
26 Feb 07 |
jari |
322 |
*/ |
2 |
26 Feb 07 |
jari |
323 |
private void readClassFile( File fLoaded ) throws Exception { |
2 |
26 Feb 07 |
jari |
324 |
Reader r = new Reader(); |
2 |
26 Feb 07 |
jari |
325 |
r.readFile( fLoaded ); |
2 |
26 Feb 07 |
jari |
326 |
Vector vLine = r.getVNullLine( "MOTHRA" ); |
2 |
26 Feb 07 |
jari |
327 |
|
2 |
26 Feb 07 |
jari |
//first check to see if there are the same number of slides |
2 |
26 Feb 07 |
jari |
329 |
if( vLine.size() == this.rowNames.length ) { |
2 |
26 Feb 07 |
jari |
//loop through the lines and alter the JComboBoxes accordingly |
2 |
26 Feb 07 |
jari |
331 |
for( int l = 0; l < vLine.size(); l ++ ) { |
2 |
26 Feb 07 |
jari |
332 |
String line = ( String ) vLine.elementAt( l ); |
2 |
26 Feb 07 |
jari |
333 |
if( line.equals( ClassAssigner.TEST_CLASS_STRING ) ) { |
2 |
26 Feb 07 |
jari |
//select the test case |
2 |
26 Feb 07 |
jari |
335 |
this.setClassAsTest( l ); |
2 |
26 Feb 07 |
jari |
336 |
} else { |
2 |
26 Feb 07 |
jari |
//select the appropriate class |
2 |
26 Feb 07 |
jari |
338 |
int i = Integer.parseInt( line ); |
2 |
26 Feb 07 |
jari |
339 |
this.setSelectedClass( l, i ); |
2 |
26 Feb 07 |
jari |
340 |
} |
2 |
26 Feb 07 |
jari |
341 |
}//l |
2 |
26 Feb 07 |
jari |
342 |
} else { |
2 |
26 Feb 07 |
jari |
343 |
throw new Exception( "Your Assignments File and loaded data don't appear to match" ); |
2 |
26 Feb 07 |
jari |
344 |
} |
2 |
26 Feb 07 |
jari |
345 |
}//readClassFile() |
2 |
26 Feb 07 |
jari |
346 |
|
2 |
26 Feb 07 |
jari |
347 |
|
2 |
26 Feb 07 |
jari |
348 |
|
2 |
26 Feb 07 |
jari |
//--------------------------------------Getters & Setters---------------------------------- |
2 |
26 Feb 07 |
jari |
350 |
public void setSelectedClass( int iHyb, int iSelectedIndex ) { |
2 |
26 Feb 07 |
jari |
351 |
JComboBox box = ( JComboBox ) this.vComboBox.elementAt( iHyb ); |
2 |
26 Feb 07 |
jari |
352 |
box.setSelectedIndex( iSelectedIndex ); |
2 |
26 Feb 07 |
jari |
353 |
this.mainPanel.repaint(); |
2 |
26 Feb 07 |
jari |
354 |
} |
2 |
26 Feb 07 |
jari |
355 |
public void setClassAsTest( int iHyb ) { |
2 |
26 Feb 07 |
jari |
356 |
JComboBox box = ( JComboBox ) this.vComboBox.elementAt( iHyb ); |
2 |
26 Feb 07 |
jari |
357 |
int iTest = this.comboNames.length - 1; |
2 |
26 Feb 07 |
jari |
358 |
box.setSelectedIndex( iTest ); |
2 |
26 Feb 07 |
jari |
359 |
this.mainPanel.repaint(); |
2 |
26 Feb 07 |
jari |
360 |
} |
2 |
26 Feb 07 |
jari |
361 |
public void setRequireAllLabelsAssigned( boolean b ) { |
2 |
26 Feb 07 |
jari |
362 |
this.requireAllLabelsAssigned = b; |
2 |
26 Feb 07 |
jari |
363 |
} |
2 |
26 Feb 07 |
jari |
364 |
public boolean getRequireAllLabelsAssigned() { |
2 |
26 Feb 07 |
jari |
365 |
return this.requireAllLabelsAssigned; |
2 |
26 Feb 07 |
jari |
366 |
} |
2 |
26 Feb 07 |
jari |
367 |
public void setMinAssignsPerLabel( int i ) { |
2 |
26 Feb 07 |
jari |
368 |
this.minNumAssignsPerLabel = i; |
2 |
26 Feb 07 |
jari |
369 |
} |
2 |
26 Feb 07 |
jari |
370 |
public int getMinNumAssignsPerLabel() { |
2 |
26 Feb 07 |
jari |
371 |
return this.minNumAssignsPerLabel; |
2 |
26 Feb 07 |
jari |
372 |
} |
2 |
26 Feb 07 |
jari |
373 |
/** |
2 |
26 Feb 07 |
jari |
* Returns a Vector containing all the JComboBoxes in order |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
376 |
*/ |
2 |
26 Feb 07 |
jari |
377 |
public Vector getVComboBox() { |
2 |
26 Feb 07 |
jari |
378 |
return this.vComboBox; |
2 |
26 Feb 07 |
jari |
379 |
} |
2 |
26 Feb 07 |
jari |
380 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the index of the selected item in the JComboBox specified by |
2 |
26 Feb 07 |
jari |
* rowIndex |
2 |
26 Feb 07 |
jari |
* @param rowIndex |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
385 |
*/ |
2 |
26 Feb 07 |
jari |
386 |
public int getSelectedIndex( int rowIndex ) { |
2 |
26 Feb 07 |
jari |
387 |
int toReturn = -1; |
2 |
26 Feb 07 |
jari |
388 |
|
2 |
26 Feb 07 |
jari |
389 |
JComboBox box = ( JComboBox ) this.vComboBox.elementAt( rowIndex ); |
2 |
26 Feb 07 |
jari |
390 |
toReturn = box.getSelectedIndex(); |
2 |
26 Feb 07 |
jari |
391 |
|
2 |
26 Feb 07 |
jari |
392 |
return toReturn; |
2 |
26 Feb 07 |
jari |
393 |
} |
2 |
26 Feb 07 |
jari |
394 |
/** |
2 |
26 Feb 07 |
jari |
* Returns the String displayed in the JComboBox specified by rowIndex |
2 |
26 Feb 07 |
jari |
* @param rowIndex |
2 |
26 Feb 07 |
jari |
* @return |
2 |
26 Feb 07 |
jari |
398 |
*/ |
2 |
26 Feb 07 |
jari |
399 |
public String getSelectedString( int rowIndex ) { |
2 |
26 Feb 07 |
jari |
400 |
String toReturn = null; |
2 |
26 Feb 07 |
jari |
401 |
|
2 |
26 Feb 07 |
jari |
402 |
JComboBox box = ( JComboBox ) this.vComboBox.elementAt( rowIndex ); |
2 |
26 Feb 07 |
jari |
403 |
toReturn = ( String ) box.getSelectedItem(); |
2 |
26 Feb 07 |
jari |
404 |
|
2 |
26 Feb 07 |
jari |
405 |
return toReturn; |
2 |
26 Feb 07 |
jari |
406 |
} |
2 |
26 Feb 07 |
jari |
407 |
public boolean hasTest() { |
2 |
26 Feb 07 |
jari |
408 |
boolean toReturn = false; |
2 |
26 Feb 07 |
jari |
409 |
|
2 |
26 Feb 07 |
jari |
410 |
for( int i = 0; i < this.vComboBox.size(); i ++ ) { |
2 |
26 Feb 07 |
jari |
411 |
JComboBox box = ( JComboBox ) this.vComboBox.elementAt( i ); |
2 |
26 Feb 07 |
jari |
412 |
if( box.getSelectedIndex() != this.comboNames.length ) { |
2 |
26 Feb 07 |
jari |
413 |
toReturn = true; |
2 |
26 Feb 07 |
jari |
414 |
break; |
2 |
26 Feb 07 |
jari |
415 |
} |
2 |
26 Feb 07 |
jari |
416 |
} |
2 |
26 Feb 07 |
jari |
417 |
|
2 |
26 Feb 07 |
jari |
418 |
return toReturn; |
2 |
26 Feb 07 |
jari |
419 |
} |
2 |
26 Feb 07 |
jari |
420 |
/* |
2 |
26 Feb 07 |
jari |
public JPanel getMainPanel() { |
2 |
26 Feb 07 |
jari |
return this.mainPanel; |
2 |
26 Feb 07 |
jari |
423 |
} |
2 |
26 Feb 07 |
jari |
424 |
*/ |
2 |
26 Feb 07 |
jari |
425 |
public JScrollPane getScrollPane() { |
2 |
26 Feb 07 |
jari |
426 |
return this.jsp; |
2 |
26 Feb 07 |
jari |
427 |
} |
2 |
26 Feb 07 |
jari |
//-------------------------------------- End Getters & Setters---------------------------------- |
2 |
26 Feb 07 |
jari |
429 |
|
2 |
26 Feb 07 |
jari |
430 |
/** |
2 |
26 Feb 07 |
jari |
* Displays an error dialog |
2 |
26 Feb 07 |
jari |
* @param message |
2 |
26 Feb 07 |
jari |
433 |
*/ |
2 |
26 Feb 07 |
jari |
434 |
public void error( String message ) { |
2 |
26 Feb 07 |
jari |
435 |
JOptionPane.showMessageDialog( new JFrame(), |
2 |
26 Feb 07 |
jari |
436 |
message, "Input Error", JOptionPane.ERROR_MESSAGE ); |
2 |
26 Feb 07 |
jari |
437 |
}//end error() |
2 |
26 Feb 07 |
jari |
438 |
|
2 |
26 Feb 07 |
jari |
439 |
|
2 |
26 Feb 07 |
jari |
440 |
/** |
2 |
26 Feb 07 |
jari |
* Test Harness |
2 |
26 Feb 07 |
jari |
* @param args |
2 |
26 Feb 07 |
jari |
443 |
*/ |
2 |
26 Feb 07 |
jari |
444 |
public static void main( String[] args ) { |
2 |
26 Feb 07 |
jari |
445 |
String[] rows = new String[ 25 ]; |
2 |
26 Feb 07 |
jari |
446 |
for( int i = 0; i < rows.length; i ++ ) { |
2 |
26 Feb 07 |
jari |
447 |
rows[ i ] = "Slide:" + Integer.toString( i ); |
2 |
26 Feb 07 |
jari |
448 |
} |
2 |
26 Feb 07 |
jari |
449 |
String[] combos = new String[ 3 ]; |
2 |
26 Feb 07 |
jari |
450 |
combos[ 0 ] = "Test"; |
2 |
26 Feb 07 |
jari |
451 |
combos[ 1 ] = "Tumor"; |
2 |
26 Feb 07 |
jari |
452 |
combos[ 2 ] = "Normal"; |
2 |
26 Feb 07 |
jari |
453 |
|
2 |
26 Feb 07 |
jari |
454 |
|
2 |
26 Feb 07 |
jari |
455 |
JFrame jf = new JFrame(); |
2 |
26 Feb 07 |
jari |
456 |
jf.setSize( 400, 600 ); |
2 |
26 Feb 07 |
jari |
457 |
ClassAssigner ca = new ClassAssigner( rows, combos ); |
2 |
26 Feb 07 |
jari |
458 |
System.out.println( ca.getSelectedString( 0 ) ); |
2 |
26 Feb 07 |
jari |
459 |
jf.setContentPane( ca.getScrollPane() ); |
2 |
26 Feb 07 |
jari |
460 |
jf.show(); |
2 |
26 Feb 07 |
jari |
461 |
} |
2 |
26 Feb 07 |
jari |
462 |
} |