1 /*
2 * Copyright (c) 2006, 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 */
26 @bug 6322625
27 @summary REG:Choice does not trigger MouseReleased when dragging and releasing the mouse outside choice, XAWT
28 @author andrei.dmitriev area=awt.choice
29 @run main DragMouseOutAndRelease
30 */
31
32 import java.awt.*;
33 import java.awt.event.*;
34
35 public class DragMouseOutAndRelease
36 {
37 static Frame frame = new Frame("Test Frame");
38 static Choice choice1 = new Choice();
39 static Robot robot;
40 static Point pt;
41 static volatile boolean mousePressed = false;
42 static volatile boolean mouseReleased = false;
43
44 private static void init()
45 {
46 String[] instructions =
47 {
48 "This is an AUTOMATIC test, simply wait until it is done.",
49 "The result (passed or failed) will be shown in the",
50 "message window below."
51 };
52 Sysout.createDialog( );
53 Sysout.printInstructions( instructions );
54
55 frame.setLayout (new FlowLayout ());
56 for (int i = 1; i<10;i++){
57 choice1.add("item "+i);
58 }
59 frame.add(choice1);
60
61 choice1.addMouseListener(new MouseAdapter() {
62 public void mousePressed(MouseEvent me) {
63 mousePressed = true;
64 System.out.println(me);
65 }
66 public void mouseReleased(MouseEvent me) {
67 mouseReleased = true;
68 System.out.println(me);
69 }
70 });
71
72 frame.pack();
73 frame.setVisible(true);
74 frame.validate();
176 if( ! testGeneratedInterrupt ) throw e;
177
178 //reset flag in case hit this code more than once for some reason (just safety)
179 testGeneratedInterrupt = false;
180
181 if ( theTestPassed == false )
182 {
183 throw new RuntimeException( failureMessage );
184 }
185 }
186
187 }//main
188
189 public static synchronized void setTimeoutTo( int seconds )
190 {
191 sleepTime = seconds * 1000;
192 }
193
194 public static synchronized void pass()
195 {
196 Sysout.println( "The test passed." );
197 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
198 //first check if this is executing in main thread
199 if ( mainThread == Thread.currentThread() )
200 {
201 //Still in the main thread, so set the flag just for kicks,
202 // and throw a test passed exception which will be caught
203 // and end the test.
204 theTestPassed = true;
205 throw new TestPassedException();
206 }
207 theTestPassed = true;
208 testGeneratedInterrupt = true;
209 mainThread.interrupt();
210 }//pass()
211
212 public static synchronized void fail()
213 {
214 //test writer didn't specify why test failed, so give generic
215 fail( "it just plain failed! :-)" );
216 }
217
218 public static synchronized void fail( String whyFailed )
219 {
220 Sysout.println( "The test failed: " + whyFailed );
221 Sysout.println( "The test is over, hit Ctl-C to stop Java VM" );
222 //check if this called from main thread
223 if ( mainThread == Thread.currentThread() )
224 {
225 //If main thread, fail now 'cause not sleeping
226 throw new RuntimeException( whyFailed );
227 }
228 theTestPassed = false;
229 testGeneratedInterrupt = true;
230 failureMessage = whyFailed;
231 mainThread.interrupt();
232 }//fail()
233
234 }// class DragMouseOutAndRelease
235
236 //This exception is used to exit from any level of call nesting
237 // when it's determined that the test has passed, and immediately
238 // end the test.
239 class TestPassedException extends RuntimeException
240 {
241 }
242
243 //*********** End Standard Test Machinery Section **********
244
245
246 //************ Begin classes defined for the test ****************
247
248 // if want to make listeners, here is the recommended place for them, then instantiate
249 // them in init()
250
251 /* Example of a class which may be written as part of a test
252 class NewClass implements anInterface
253 {
254 static int newVar = 0;
255
256 public void eventDispatched(AWTEvent e)
257 {
258 //Counting events to see if we get enough
259 eventCount++;
260
261 if( eventCount == 20 )
262 {
263 //got enough events, so pass
264
265 DragMouseOutAndRelease.pass();
266 }
267 else if( tries == 20 )
268 {
269 //tried too many times without getting enough events so fail
270
271 DragMouseOutAndRelease.fail();
272 }
273
274 }// eventDispatched()
275
276 }// NewClass class
277
278 */
279
280
281 //************** End classes defined for the test *******************
282
283
284
285
286 /****************************************************
287 Standard Test Machinery
288 DO NOT modify anything below -- it's a standard
289 chunk of code whose purpose is to make user
290 interaction uniform, and thereby make it simpler
291 to read and understand someone else's test.
292 ****************************************************/
293
294 /**
295 This is part of the standard test machinery.
296 It creates a dialog (with the instructions), and is the interface
297 for sending text messages to the user.
298 To print the instructions, send an array of strings to Sysout.createDialog
299 WithInstructions method. Put one line of instructions per array entry.
300 To display a message for the tester to see, simply call Sysout.println
301 with the string to be displayed.
302 This mimics System.out.println but works within the test harness as well
303 as standalone.
304 */
305
306 class Sysout
307 {
308 private static TestDialog dialog;
309
310 public static void createDialogWithInstructions( String[] instructions )
311 {
312 dialog = new TestDialog( new Frame(), "Instructions" );
313 dialog.printInstructions( instructions );
314 dialog.setVisible(true);
315 println( "Any messages for the tester will display here." );
316 }
317
318 public static void createDialog( )
319 {
320 dialog = new TestDialog( new Frame(), "Instructions" );
321 String[] defInstr = { "Instructions will appear here. ", "" } ;
322 dialog.printInstructions( defInstr );
323 dialog.setVisible(true);
324 println( "Any messages for the tester will display here." );
325 }
326
327
328 public static void printInstructions( String[] instructions )
329 {
330 dialog.printInstructions( instructions );
331 }
332
333
334 public static void println( String messageIn )
335 {
336 dialog.displayMessage( messageIn );
337 System.out.println(messageIn);
338 }
339
340 }// Sysout class
341
342 /**
343 This is part of the standard test machinery. It provides a place for the
344 test instructions to be displayed, and a place for interactive messages
345 to the user to be displayed.
346 To have the test instructions displayed, see Sysout.
347 To have a message to the user be displayed, see Sysout.
348 Do not call anything in this dialog directly.
349 */
350 class TestDialog extends Dialog
351 {
352
353 TextArea instructionsText;
354 TextArea messageText;
355 int maxStringLength = 80;
356
357 //DO NOT call this directly, go through Sysout
358 public TestDialog( Frame frame, String name )
359 {
360 super( frame, name );
361 int scrollBoth = TextArea.SCROLLBARS_BOTH;
362 instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
363 add( "North", instructionsText );
364
365 messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
366 add("Center", messageText);
367
368 pack();
369
370 setVisible(true);
371 }// TestDialog()
372
373 //DO NOT call this directly, go through Sysout
374 public void printInstructions( String[] instructions )
375 {
376 //Clear out any current instructions
377 instructionsText.setText( "" );
378
379 //Go down array of instruction strings
380
381 String printStr, remainingStr;
382 for( int i=0; i < instructions.length; i++ )
383 {
384 //chop up each into pieces maxSringLength long
385 remainingStr = instructions[ i ];
386 while( remainingStr.length() > 0 )
387 {
388 //if longer than max then chop off first max chars to print
389 if( remainingStr.length() >= maxStringLength )
390 {
391 //Try to chop on a word boundary
392 int posOfSpace = remainingStr.
393 lastIndexOf( ' ', maxStringLength - 1 );
394
395 if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1;
396
397 printStr = remainingStr.substring( 0, posOfSpace + 1 );
398 remainingStr = remainingStr.substring( posOfSpace + 1 );
399 }
400 //else just print
401 else
402 {
403 printStr = remainingStr;
404 remainingStr = "";
405 }
406
407 instructionsText.append( printStr + "\n" );
408
409 }// while
410
411 }// for
412
413 }//printInstructions()
414
415 //DO NOT call this directly, go through Sysout
416 public void displayMessage( String messageIn )
417 {
418 messageText.append( messageIn + "\n" );
419 System.out.println(messageIn);
420 }
421
422 }// TestDialog class
|
1 /*
2 * Copyright (c) 2006, 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 */
26 @bug 6322625
27 @summary REG:Choice does not trigger MouseReleased when dragging and releasing the mouse outside choice, XAWT
28 @author andrei.dmitriev area=awt.choice
29 @run main DragMouseOutAndRelease
30 */
31
32 import java.awt.*;
33 import java.awt.event.*;
34
35 public class DragMouseOutAndRelease
36 {
37 static Frame frame = new Frame("Test Frame");
38 static Choice choice1 = new Choice();
39 static Robot robot;
40 static Point pt;
41 static volatile boolean mousePressed = false;
42 static volatile boolean mouseReleased = false;
43
44 private static void init()
45 {
46 frame.setLayout (new FlowLayout ());
47 for (int i = 1; i<10;i++){
48 choice1.add("item "+i);
49 }
50 frame.add(choice1);
51
52 choice1.addMouseListener(new MouseAdapter() {
53 public void mousePressed(MouseEvent me) {
54 mousePressed = true;
55 System.out.println(me);
56 }
57 public void mouseReleased(MouseEvent me) {
58 mouseReleased = true;
59 System.out.println(me);
60 }
61 });
62
63 frame.pack();
64 frame.setVisible(true);
65 frame.validate();
167 if( ! testGeneratedInterrupt ) throw e;
168
169 //reset flag in case hit this code more than once for some reason (just safety)
170 testGeneratedInterrupt = false;
171
172 if ( theTestPassed == false )
173 {
174 throw new RuntimeException( failureMessage );
175 }
176 }
177
178 }//main
179
180 public static synchronized void setTimeoutTo( int seconds )
181 {
182 sleepTime = seconds * 1000;
183 }
184
185 public static synchronized void pass()
186 {
187 System.out.println( "The test passed." );
188 System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
189 //first check if this is executing in main thread
190 if ( mainThread == Thread.currentThread() )
191 {
192 //Still in the main thread, so set the flag just for kicks,
193 // and throw a test passed exception which will be caught
194 // and end the test.
195 theTestPassed = true;
196 throw new TestPassedException();
197 }
198 theTestPassed = true;
199 testGeneratedInterrupt = true;
200 mainThread.interrupt();
201 }//pass()
202
203 public static synchronized void fail()
204 {
205 //test writer didn't specify why test failed, so give generic
206 fail( "it just plain failed! :-)" );
207 }
208
209 public static synchronized void fail( String whyFailed )
210 {
211 System.out.println( "The test failed: " + whyFailed );
212 System.out.println( "The test is over, hit Ctl-C to stop Java VM" );
213 //check if this called from main thread
214 if ( mainThread == Thread.currentThread() )
215 {
216 //If main thread, fail now 'cause not sleeping
217 throw new RuntimeException( whyFailed );
218 }
219 theTestPassed = false;
220 testGeneratedInterrupt = true;
221 failureMessage = whyFailed;
222 mainThread.interrupt();
223 }//fail()
224
225 }// class DragMouseOutAndRelease
226
227 //This exception is used to exit from any level of call nesting
228 // when it's determined that the test has passed, and immediately
229 // end the test.
230 class TestPassedException extends RuntimeException
231 {
232 }
|