1 /*
2 * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
274 }
275 }
276 public synchronized boolean getState() {
277 return state;
278 }
279 }
280
281 class TestKFM extends DefaultKeyboardFocusManager {
282 protected synchronized void enqueueKeyEvents(long after,
283 Component untilFocused)
284 {
285 super.enqueueKeyEvents(after, untilFocused);
286
287 if (untilFocused == TestDialogTypeAhead.this.ok) {
288 TestDialogTypeAhead.this.robotSema.raise();
289 }
290 }
291 }
292 }// class TestDialogTypeAhead
293
294
295 /****************************************************
296 Standard Test Machinery
297 DO NOT modify anything below -- it's a standard
298 chunk of code whose purpose is to make user
299 interaction uniform, and thereby make it simpler
300 to read and understand someone else's test.
301 ****************************************************/
302
303 /**
304 This is part of the standard test machinery.
305 It creates a dialog (with the instructions), and is the interface
306 for sending text messages to the user.
307 To print the instructions, send an array of strings to Sysout.createDialog
308 WithInstructions method. Put one line of instructions per array entry.
309 To display a message for the tester to see, simply call Sysout.println
310 with the string to be displayed.
311 This mimics System.out.println but works within the test harness as well
312 as standalone.
313 */
314
315 class Sysout
316 {
317 private static TestDialog dialog;
318
319 public static void createDialogWithInstructions( String[] instructions )
320 {
321 dialog = new TestDialog( new Frame(), "Instructions" );
322 dialog.printInstructions( instructions );
323 dialog.setVisible(true);
324 println( "Any messages for the tester will display here." );
325 }
326
327 public static void createDialog( )
328 {
329 dialog = new TestDialog( new Frame(), "Instructions" );
330 String[] defInstr = { "Instructions will appear here. ", "" } ;
331 dialog.printInstructions( defInstr );
332 dialog.setVisible(true);
333 println( "Any messages for the tester will display here." );
334 }
335
336
337 public static void printInstructions( String[] instructions )
338 {
339 dialog.printInstructions( instructions );
340 }
341
342
343 public static void println( String messageIn )
344 {
345 dialog.displayMessage( messageIn );
346 }
347
348 }// Sysout class
349
350 /**
351 This is part of the standard test machinery. It provides a place for the
352 test instructions to be displayed, and a place for interactive messages
353 to the user to be displayed.
354 To have the test instructions displayed, see Sysout.
355 To have a message to the user be displayed, see Sysout.
356 Do not call anything in this dialog directly.
357 */
358 class TestDialog extends Dialog
359 {
360
361 TextArea instructionsText;
362 TextArea messageText;
363 int maxStringLength = 80;
364
365 //DO NOT call this directly, go through Sysout
366 public TestDialog( Frame frame, String name )
367 {
368 super( frame, name );
369 int scrollBoth = TextArea.SCROLLBARS_BOTH;
370 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
371 add( "North", instructionsText );
372
373 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
374 add("Center", messageText);
375
376 pack();
377
378 show();
379 }// TestDialog()
380
381 //DO NOT call this directly, go through Sysout
382 public void printInstructions( String[] instructions )
383 {
384 //Clear out any current instructions
385 instructionsText.setText( "" );
386
387 //Go down array of instruction strings
388
389 String printStr, remainingStr;
390 for( int i=0; i < instructions.length; i++ )
391 {
392 //chop up each into pieces maxSringLength long
393 remainingStr = instructions[ i ];
394 while( remainingStr.length() > 0 )
395 {
396 //if longer than max then chop off first max chars to print
397 if( remainingStr.length() >= maxStringLength )
398 {
399 //Try to chop on a word boundary
400 int posOfSpace = remainingStr.
401 lastIndexOf( ' ', maxStringLength - 1 );
402
403 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
404
405 printStr = remainingStr.substring( 0, posOfSpace + 1 );
406 remainingStr = remainingStr.substring( posOfSpace + 1 );
407 }
408 //else just print
409 else
410 {
411 printStr = remainingStr;
412 remainingStr = "";
413 }
414
415 instructionsText.append( printStr + "\n" );
416
417 }// while
418
419 }// for
420
421 }//printInstructions()
422
423 //DO NOT call this directly, go through Sysout
424 public void displayMessage( String messageIn )
425 {
426 messageText.append( messageIn + "\n" );
427 System.out.println(messageIn);
428 }
429
430 }// TestDialog class
|
1 /*
2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
274 }
275 }
276 public synchronized boolean getState() {
277 return state;
278 }
279 }
280
281 class TestKFM extends DefaultKeyboardFocusManager {
282 protected synchronized void enqueueKeyEvents(long after,
283 Component untilFocused)
284 {
285 super.enqueueKeyEvents(after, untilFocused);
286
287 if (untilFocused == TestDialogTypeAhead.this.ok) {
288 TestDialogTypeAhead.this.robotSema.raise();
289 }
290 }
291 }
292 }// class TestDialogTypeAhead
293
|