181 imt.start(); |
168 imt.start(); |
182 } |
169 } |
183 |
170 |
184 |
171 |
185 }// class NonEDT_GUI_Deadlock |
172 }// class NonEDT_GUI_Deadlock |
186 |
|
187 |
|
188 /**************************************************** |
|
189 Standard Test Machinery |
|
190 DO NOT modify anything below -- it's a standard |
|
191 chunk of code whose purpose is to make user |
|
192 interaction uniform, and thereby make it simpler |
|
193 to read and understand someone else's test. |
|
194 ****************************************************/ |
|
195 |
|
196 /** |
|
197 This is part of the standard test machinery. |
|
198 It creates a dialog (with the instructions), and is the interface |
|
199 for sending text messages to the user. |
|
200 To print the instructions, send an array of strings to Sysout.createDialog |
|
201 WithInstructions method. Put one line of instructions per array entry. |
|
202 To display a message for the tester to see, simply call Sysout.println |
|
203 with the string to be displayed. |
|
204 This mimics System.out.println but works within the test harness as well |
|
205 as standalone. |
|
206 */ |
|
207 |
|
208 class Sysout |
|
209 { |
|
210 private static TestDialog dialog; |
|
211 |
|
212 public static void createDialogWithInstructions( String[] instructions ) |
|
213 { |
|
214 dialog = new TestDialog( new Frame(), "Instructions" ); |
|
215 dialog.printInstructions( instructions ); |
|
216 dialog.setVisible(true); |
|
217 println( "Any messages for the tester will display here." ); |
|
218 } |
|
219 |
|
220 public static void createDialog( ) |
|
221 { |
|
222 dialog = new TestDialog( new Frame(), "Instructions" ); |
|
223 String[] defInstr = { "Instructions will appear here. ", "" } ; |
|
224 dialog.printInstructions( defInstr ); |
|
225 dialog.setVisible(true); |
|
226 println( "Any messages for the tester will display here." ); |
|
227 } |
|
228 |
|
229 |
|
230 public static void printInstructions( String[] instructions ) |
|
231 { |
|
232 dialog.printInstructions( instructions ); |
|
233 } |
|
234 |
|
235 |
|
236 public static void println( String messageIn ) |
|
237 { |
|
238 dialog.displayMessage( messageIn ); |
|
239 } |
|
240 |
|
241 }// Sysout class |
|
242 |
|
243 /** |
|
244 This is part of the standard test machinery. It provides a place for the |
|
245 test instructions to be displayed, and a place for interactive messages |
|
246 to the user to be displayed. |
|
247 To have the test instructions displayed, see Sysout. |
|
248 To have a message to the user be displayed, see Sysout. |
|
249 Do not call anything in this dialog directly. |
|
250 */ |
|
251 class TestDialog extends Dialog |
|
252 { |
|
253 |
|
254 TextArea instructionsText; |
|
255 TextArea messageText; |
|
256 int maxStringLength = 80; |
|
257 |
|
258 //DO NOT call this directly, go through Sysout |
|
259 public TestDialog( Frame frame, String name ) |
|
260 { |
|
261 super( frame, name ); |
|
262 int scrollBoth = TextArea.SCROLLBARS_BOTH; |
|
263 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); |
|
264 add( "North", instructionsText ); |
|
265 |
|
266 messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); |
|
267 add("Center", messageText); |
|
268 |
|
269 pack(); |
|
270 |
|
271 show(); |
|
272 }// TestDialog() |
|
273 |
|
274 //DO NOT call this directly, go through Sysout |
|
275 public void printInstructions( String[] instructions ) |
|
276 { |
|
277 //Clear out any current instructions |
|
278 instructionsText.setText( "" ); |
|
279 |
|
280 //Go down array of instruction strings |
|
281 |
|
282 String printStr, remainingStr; |
|
283 for( int i=0; i < instructions.length; i++ ) |
|
284 { |
|
285 //chop up each into pieces maxSringLength long |
|
286 remainingStr = instructions[ i ]; |
|
287 while( remainingStr.length() > 0 ) |
|
288 { |
|
289 //if longer than max then chop off first max chars to print |
|
290 if( remainingStr.length() >= maxStringLength ) |
|
291 { |
|
292 //Try to chop on a word boundary |
|
293 int posOfSpace = remainingStr. |
|
294 lastIndexOf( ' ', maxStringLength - 1 ); |
|
295 |
|
296 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; |
|
297 |
|
298 printStr = remainingStr.substring( 0, posOfSpace + 1 ); |
|
299 remainingStr = remainingStr.substring( posOfSpace + 1 ); |
|
300 } |
|
301 //else just print |
|
302 else |
|
303 { |
|
304 printStr = remainingStr; |
|
305 remainingStr = ""; |
|
306 } |
|
307 |
|
308 instructionsText.append( printStr + "\n" ); |
|
309 |
|
310 }// while |
|
311 |
|
312 }// for |
|
313 |
|
314 }//printInstructions() |
|
315 |
|
316 //DO NOT call this directly, go through Sysout |
|
317 public void displayMessage( String messageIn ) |
|
318 { |
|
319 messageText.append( messageIn + "\n" ); |
|
320 System.out.println(messageIn); |
|
321 } |
|
322 |
|
323 }// TestDialog class |
|