1
1
/*
2
- * Copyright (c) 1999, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1999, 2023 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
68
68
* <p>
69
69
* Applications that use Robot for purposes other than self-testing should
70
70
* handle these error conditions gracefully.
71
+ * <p>
72
+ * Platforms and desktop environments may impose restrictions or limitations
73
+ * on the access required to implement all functionality in the Robot class.
74
+ * For example:
75
+ * <ul>
76
+ * <li> preventing access to the contents of any part of a desktop
77
+ * or Window on the desktop that is not owned by the running application.</li>
78
+ * <li> treating window decorations as non-owned content.</li>
79
+ * <li> ignoring or limiting specific requests to manipulate windows.</li>
80
+ * <li> ignoring or limiting specific requests for Robot generated (synthesized)
81
+ * events related to keyboard and mouse etc.</li>
82
+ * <li> requiring specific or global permissions to any access to window
83
+ * contents, even application owned content,or to perform even limited
84
+ * synthesizing of events.</li>
85
+ * </ul>
86
+ *
87
+ * The Robot API specification requires that approvals for these be granted
88
+ * for full operation.
89
+ * If they are not granted, the API will be degraded as discussed here.
90
+ * Relevant specific API methods may document more specific limitations
91
+ * and requirements.
92
+ * Depending on the policies of the desktop environment,
93
+ * the approvals mentioned above may:
94
+ * <ul>
95
+ * <li>be required every time</li>
96
+ * <li>or persistent for the lifetime of an application,</li>
97
+ * <li>or persistent across multiple user desktop sessions</li>
98
+ * <li>be fine-grained permissions</li>
99
+ * <li>be associated with a specific binary application,
100
+ * or a class of binary applications.</li>
101
+ * </ul>
102
+ *
103
+ * When such approvals need to given interactively, it may impede the normal
104
+ * operation of the application until approved, and if approval is denied
105
+ * or not possible, or cannot be made persistent then it will degrade
106
+ * the functionality of this class and in turn any part of the operation
107
+ * of the application which is dependent on it.
71
108
*
72
109
* @author Robi Khan
73
110
* @since 1.3
@@ -189,6 +226,11 @@ private static void checkIsScreenDevice(GraphicsDevice device) {
189
226
190
227
/**
191
228
* Moves mouse pointer to given screen coordinates.
229
+ * <p>
230
+ * The mouse pointer may not visually move on some platforms,
231
+ * while the subsequent mousePress and mouseRelease can be
232
+ * delivered to the correct location
233
+ *
192
234
* @param x X position
193
235
* @param y Y position
194
236
*/
@@ -383,8 +425,22 @@ private static void checkKeycodeArgument(int keycode) {
383
425
384
426
/**
385
427
* Returns the color of a pixel at the given screen coordinates.
428
+ * <p>
429
+ * If the desktop environment requires that permissions be granted
430
+ * to capture screen content, and the required permissions are not granted,
431
+ * then a {@code SecurityException} may be thrown,
432
+ * or the content of the returned {@code Color} is undefined.
433
+ * </p>
434
+ * @apiNote It is recommended to avoid calling this method on
435
+ * the AWT Event Dispatch Thread since screen capture may be a lengthy
436
+ * operation, particularly if acquiring permissions is needed and involves
437
+ * user interaction.
438
+ *
386
439
* @param x X position of pixel
387
440
* @param y Y position of pixel
441
+ * @throws SecurityException if {@code readDisplayPixels} permission
442
+ * is not granted, or access to the screen is denied
443
+ * by the desktop environment
388
444
* @return Color of the pixel
389
445
*/
390
446
public synchronized Color getPixelColor (int x , int y ) {
@@ -395,12 +451,25 @@ public synchronized Color getPixelColor(int x, int y) {
395
451
}
396
452
397
453
/**
398
- * Creates an image containing pixels read from the screen. This image does
399
- * not include the mouse cursor.
454
+ * Creates an image containing pixels read from the screen.
455
+ * <p>
456
+ * If the desktop environment requires that permissions be granted
457
+ * to capture screen content, and the required permissions are not granted,
458
+ * then a {@code SecurityException} may be thrown,
459
+ * or the contents of the returned {@code BufferedImage} are undefined.
460
+ * </p>
461
+ * @apiNote It is recommended to avoid calling this method on
462
+ * the AWT Event Dispatch Thread since screen capture may be a lengthy
463
+ * operation, particularly if acquiring permissions is needed and involves
464
+ * user interaction.
465
+ *
400
466
* @param screenRect Rect to capture in screen coordinates
401
467
* @return The captured image
402
- * @throws IllegalArgumentException if {@code screenRect} width and height are not greater than zero
403
- * @throws SecurityException if {@code readDisplayPixels} permission is not granted
468
+ * @throws IllegalArgumentException if {@code screenRect} width and height
469
+ * are not greater than zero
470
+ * @throws SecurityException if {@code readDisplayPixels} permission
471
+ * is not granted, or access to the screen is denied
472
+ * by the desktop environment
404
473
* @see SecurityManager#checkPermission
405
474
* @see AWTPermission
406
475
*/
@@ -410,7 +479,6 @@ public synchronized BufferedImage createScreenCapture(Rectangle screenRect) {
410
479
411
480
/**
412
481
* Creates an image containing pixels read from the screen.
413
- * This image does not include the mouse cursor.
414
482
* This method can be used in case there is a scaling transform
415
483
* from user space to screen (device) space.
416
484
* Typically this means that the display is a high resolution screen,
@@ -443,8 +511,11 @@ public synchronized BufferedImage createScreenCapture(Rectangle screenRect) {
443
511
* }</pre>
444
512
* @param screenRect Rect to capture in screen coordinates
445
513
* @return The captured image
446
- * @throws IllegalArgumentException if {@code screenRect} width and height are not greater than zero
447
- * @throws SecurityException if {@code readDisplayPixels} permission is not granted
514
+ * @throws IllegalArgumentException if {@code screenRect} width and height
515
+ * are not greater than zero
516
+ * @throws SecurityException if {@code readDisplayPixels} permission
517
+ * is not granted, or access to the screen is denied
518
+ * by the desktop environment
448
519
* @see SecurityManager#checkPermission
449
520
* @see AWTPermission
450
521
*
0 commit comments