1 /*
2 * Copyright (c) 2014, 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 */
117 sourcePoint.translate(sign(targetPoint.x - sourcePoint.x),
118 sign(targetPoint.y - sourcePoint.y))) {
119 robot.mouseMove(sourcePoint.x, sourcePoint.y);
120 Thread.sleep(50);
121 }
122 robot.mouseRelease(InputEvent.BUTTON1_MASK);
123 robot.keyRelease(KeyEvent.VK_CONTROL);
124
125 Thread.sleep(FRAME_ACTIVATION_TIMEOUT);
126
127 if (process.isAlive()) {
128 process.destroy();
129 }
130 } catch (Throwable e) {
131 e.printStackTrace();
132 throw new RuntimeException(e);
133 }
134 } // run()
135
136 public void init() {
137 //Create instructions for the user here, as well as set up
138 // the environment -- set the layout manager, add buttons,
139 // etc.
140
141 String[] instructions =
142 {
143 "This is an AUTOMATIC test",
144 "simply wait until it is done"
145 };
146 Sysout.createDialog( );
147 Sysout.printInstructions( instructions );
148
149 frame.setTitle("Drop target frame");
150 frame.setLocation(200, 200);
151
152 } // init()
153
154 public void start() {
155 DropTargetPanel panel = new DropTargetPanel();
156 frame.add(panel);
157 frame.pack();
158 frame.setVisible(true);
159
160 try {
161 Thread.sleep(FRAME_ACTIVATION_TIMEOUT);
162
163 Point p = frame.getLocationOnScreen();
164 Dimension d = frame.getSize();
165
166 String javaPath = System.getProperty("java.home", "");
167 String command = javaPath + File.separator + "bin" +
168 File.separator + "java -cp " + System.getProperty("test.classes", ".") +
333 pres.exitValue = p.exitValue();
334 finished = true;
335 }
336 catch (IllegalThreadStateException e) {
337 // Process is not finished yet;
338 // Sleep a little to save on CPU cycles
339 Thread.currentThread().sleep(500);
340 }
341 }
342 if (in != null) in.close();
343 if (err != null) err.close();
344 }
345 catch (Throwable e) {
346 System.err.println("doWaitFor(): unexpected exception");
347 e.printStackTrace();
348 throw new RuntimeException(e);
349 }
350 return pres;
351 }
352 }
353
354 /****************************************************
355 Standard Test Machinery
356 DO NOT modify anything below -- it's a standard
357 chunk of code whose purpose is to make user
358 interaction uniform, and thereby make it simpler
359 to read and understand someone else's test.
360 ****************************************************/
361
362 /**
363 This is part of the standard test machinery.
364 It creates a dialog (with the instructions), and is the interface
365 for sending text messages to the user.
366 To print the instructions, send an array of strings to Sysout.createDialog
367 WithInstructions method. Put one line of instructions per array entry.
368 To display a message for the tester to see, simply call Sysout.println
369 with the string to be displayed.
370 This mimics System.out.println but works within the test harness as well
371 as standalone.
372 */
373
374 class Sysout
375 {
376 private static TestDialog dialog;
377
378 public static void createDialogWithInstructions( String[] instructions )
379 {
380 dialog = new TestDialog( new Frame(), "Instructions" );
381 dialog.printInstructions( instructions );
382 dialog.show();
383 println( "Any messages for the tester will display here." );
384 }
385
386 public static void createDialog( )
387 {
388 dialog = new TestDialog( new Frame(), "Instructions" );
389 String[] defInstr = { "Instructions will appear here. ", "" } ;
390 dialog.printInstructions( defInstr );
391 dialog.show();
392 println( "Any messages for the tester will display here." );
393 }
394
395
396 public static void printInstructions( String[] instructions )
397 {
398 dialog.printInstructions( instructions );
399 }
400
401
402 public static void println( String messageIn )
403 {
404 dialog.displayMessage( messageIn );
405 }
406
407 }// Sysout class
408
409 /**
410 This is part of the standard test machinery. It provides a place for the
411 test instructions to be displayed, and a place for interactive messages
412 to the user to be displayed.
413 To have the test instructions displayed, see Sysout.
414 To have a message to the user be displayed, see Sysout.
415 Do not call anything in this dialog directly.
416 */
417 class TestDialog extends Dialog
418 {
419
420 TextArea instructionsText;
421 TextArea messageText;
422 int maxStringLength = 80;
423
424 //DO NOT call this directly, go through Sysout
425 public TestDialog( Frame frame, String name )
426 {
427 super( frame, name );
428 int scrollBoth = TextArea.SCROLLBARS_BOTH;
429 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
430 add( "North", instructionsText );
431
432 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
433 add("South", messageText);
434
435 pack();
436
437 show();
438 }// TestDialog()
439
440 //DO NOT call this directly, go through Sysout
441 public void printInstructions( String[] instructions )
442 {
443 //Clear out any current instructions
444 instructionsText.setText( "" );
445
446 //Go down array of instruction strings
447
448 String printStr, remainingStr;
449 for( int i=0; i < instructions.length; i++ )
450 {
451 //chop up each into pieces maxSringLength long
452 remainingStr = instructions[ i ];
453 while( remainingStr.length() > 0 )
454 {
455 //if longer than max then chop off first max chars to print
456 if( remainingStr.length() >= maxStringLength )
457 {
458 //Try to chop on a word boundary
459 int posOfSpace = remainingStr.
460 lastIndexOf( ' ', maxStringLength - 1 );
461
462 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
463
464 printStr = remainingStr.substring( 0, posOfSpace + 1 );
465 remainingStr = remainingStr.substring( posOfSpace + 1 );
466 }
467 //else just print
468 else
469 {
470 printStr = remainingStr;
471 remainingStr = "";
472 }
473
474 instructionsText.append( printStr + "\n" );
475
476 }// while
477
478 }// for
479
480 }//printInstructions()
481
482 //DO NOT call this directly, go through Sysout
483 public void displayMessage( String messageIn )
484 {
485 messageText.append( messageIn + "\n" );
486 }
487
488 }// TestDialog class
|
1 /*
2 * Copyright (c) 2014, 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 */
117 sourcePoint.translate(sign(targetPoint.x - sourcePoint.x),
118 sign(targetPoint.y - sourcePoint.y))) {
119 robot.mouseMove(sourcePoint.x, sourcePoint.y);
120 Thread.sleep(50);
121 }
122 robot.mouseRelease(InputEvent.BUTTON1_MASK);
123 robot.keyRelease(KeyEvent.VK_CONTROL);
124
125 Thread.sleep(FRAME_ACTIVATION_TIMEOUT);
126
127 if (process.isAlive()) {
128 process.destroy();
129 }
130 } catch (Throwable e) {
131 e.printStackTrace();
132 throw new RuntimeException(e);
133 }
134 } // run()
135
136 public void init() {
137 frame.setTitle("Drop target frame");
138 frame.setLocation(200, 200);
139
140 } // init()
141
142 public void start() {
143 DropTargetPanel panel = new DropTargetPanel();
144 frame.add(panel);
145 frame.pack();
146 frame.setVisible(true);
147
148 try {
149 Thread.sleep(FRAME_ACTIVATION_TIMEOUT);
150
151 Point p = frame.getLocationOnScreen();
152 Dimension d = frame.getSize();
153
154 String javaPath = System.getProperty("java.home", "");
155 String command = javaPath + File.separator + "bin" +
156 File.separator + "java -cp " + System.getProperty("test.classes", ".") +
321 pres.exitValue = p.exitValue();
322 finished = true;
323 }
324 catch (IllegalThreadStateException e) {
325 // Process is not finished yet;
326 // Sleep a little to save on CPU cycles
327 Thread.currentThread().sleep(500);
328 }
329 }
330 if (in != null) in.close();
331 if (err != null) err.close();
332 }
333 catch (Throwable e) {
334 System.err.println("doWaitFor(): unexpected exception");
335 e.printStackTrace();
336 throw new RuntimeException(e);
337 }
338 return pres;
339 }
340 }
|