1
1
/*
2
- * Copyright (c) 1999, 2019 , 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
@@ -180,6 +217,11 @@ private void checkIsScreenDevice(GraphicsDevice device) {
180
217
181
218
/**
182
219
* Moves mouse pointer to given screen coordinates.
220
+ * <p>
221
+ * The mouse pointer may not visually move on some platforms,
222
+ * while the subsequent mousePress and mouseRelease can be
223
+ * delivered to the correct location
224
+ *
183
225
* @param x X position
184
226
* @param y Y position
185
227
*/
@@ -374,8 +416,22 @@ private void checkKeycodeArgument(int keycode) {
374
416
375
417
/**
376
418
* Returns the color of a pixel at the given screen coordinates.
419
+ * <p>
420
+ * If the desktop environment requires that permissions be granted
421
+ * to capture screen content, and the required permissions are not granted,
422
+ * then a {@code SecurityException} may be thrown,
423
+ * or the content of the returned {@code Color} is undefined.
424
+ * </p>
425
+ * @apiNote It is recommended to avoid calling this method on
426
+ * the AWT Event Dispatch Thread since screen capture may be a lengthy
427
+ * operation, particularly if acquiring permissions is needed and involves
428
+ * user interaction.
429
+ *
377
430
* @param x X position of pixel
378
431
* @param y Y position of pixel
432
+ * @throws SecurityException if {@code readDisplayPixels} permission
433
+ * is not granted, or access to the screen is denied
434
+ * by the desktop environment
379
435
* @return Color of the pixel
380
436
*/
381
437
public synchronized Color getPixelColor (int x , int y ) {
@@ -386,12 +442,25 @@ public synchronized Color getPixelColor(int x, int y) {
386
442
}
387
443
388
444
/**
389
- * Creates an image containing pixels read from the screen. This image does
390
- * not include the mouse cursor.
445
+ * Creates an image containing pixels read from the screen.
446
+ * <p>
447
+ * If the desktop environment requires that permissions be granted
448
+ * to capture screen content, and the required permissions are not granted,
449
+ * then a {@code SecurityException} may be thrown,
450
+ * or the contents of the returned {@code BufferedImage} are undefined.
451
+ * </p>
452
+ * @apiNote It is recommended to avoid calling this method on
453
+ * the AWT Event Dispatch Thread since screen capture may be a lengthy
454
+ * operation, particularly if acquiring permissions is needed and involves
455
+ * user interaction.
456
+ *
391
457
* @param screenRect Rect to capture in screen coordinates
392
458
* @return The captured image
393
- * @throws IllegalArgumentException if {@code screenRect} width and height are not greater than zero
394
- * @throws SecurityException if {@code readDisplayPixels} permission is not granted
459
+ * @throws IllegalArgumentException if {@code screenRect} width and height
460
+ * are not greater than zero
461
+ * @throws SecurityException if {@code readDisplayPixels} permission
462
+ * is not granted, or access to the screen is denied
463
+ * by the desktop environment
395
464
* @see SecurityManager#checkPermission
396
465
* @see AWTPermission
397
466
*/
@@ -401,7 +470,6 @@ public synchronized BufferedImage createScreenCapture(Rectangle screenRect) {
401
470
402
471
/**
403
472
* Creates an image containing pixels read from the screen.
404
- * This image does not include the mouse cursor.
405
473
* This method can be used in case there is a scaling transform
406
474
* from user space to screen (device) space.
407
475
* Typically this means that the display is a high resolution screen,
@@ -434,8 +502,11 @@ public synchronized BufferedImage createScreenCapture(Rectangle screenRect) {
434
502
* }</pre>
435
503
* @param screenRect Rect to capture in screen coordinates
436
504
* @return The captured image
437
- * @throws IllegalArgumentException if {@code screenRect} width and height are not greater than zero
438
- * @throws SecurityException if {@code readDisplayPixels} permission is not granted
505
+ * @throws IllegalArgumentException if {@code screenRect} width and height
506
+ * are not greater than zero
507
+ * @throws SecurityException if {@code readDisplayPixels} permission
508
+ * is not granted, or access to the screen is denied
509
+ * by the desktop environment
439
510
* @see SecurityManager#checkPermission
440
511
* @see AWTPermission
441
512
*
1 commit comments
openjdk-notifier[bot] commentedon Jul 18, 2024
Review
Issues