11/*
2- * Copyright (c) 2003, 2019 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2003, 2020 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
@@ -63,7 +63,7 @@ public class CycleDMImage extends Component implements Runnable, KeyListener {
6363 boolean earlyExit = false ;
6464 Image rImage = null , wImage = null , bImage = null ;
6565 int imgSize = 10 ;
66- Robot robot = null ;
66+ static Robot robot = null ;
6767 volatile static boolean done = false ;
6868 static String errorMessage = null ;
6969
@@ -106,15 +106,6 @@ static void delay(long ms) {
106106 }
107107
108108 public boolean checkResult (DisplayMode dm ) {
109- if (robot == null ) {
110- try {
111- robot = new Robot ();
112- }
113- catch (Exception e ) {
114- errorMessage = "Problems creating Robot" ;
115- return false ;
116- }
117- }
118109 Rectangle bounds = getGraphicsConfiguration ().getBounds ();
119110 int pixels [] = new int [imgSize * 4 ];
120111 BufferedImage clientPixels =
@@ -175,6 +166,7 @@ public void run() {
175166 gd .setFullScreenWindow ((Window ) getParent ());
176167 // First, delay a bit just to let the fullscreen window
177168 // settle down before switching display modes
169+ robot .waitForIdle ();
178170 delay (1000 );
179171
180172 if (!gd .isDisplayChangeSupported ()) {
@@ -197,10 +189,12 @@ public void run() {
197189 boolean skip = false ;
198190 for (final DisplayMode dmUnique : dmSubset ) {
199191 int bitDepth = dm .getBitDepth ();
200- if (bitDepth == 24 ||
201- (dmUnique .getWidth () == dm .getWidth () &&
202- dmUnique .getHeight () == dm .getHeight () &&
203- dmUnique .getBitDepth () == dm .getBitDepth ())) {
192+ int width = dm .getWidth ();
193+ int height = dm .getHeight ();
194+ if (bitDepth == 24 || width <= 800 || height <= 600 ||
195+ (dmUnique .getWidth () == width &&
196+ dmUnique .getHeight () == height &&
197+ dmUnique .getBitDepth () == bitDepth )) {
204198 skip = true ;
205199 break ;
206200 }
@@ -265,7 +259,8 @@ public void keyPressed(KeyEvent e) {
265259 public void keyReleased (KeyEvent e ) {
266260 }
267261
268- public static void main (String args []) {
262+ public static void main (String args []) throws Exception {
263+ robot = new Robot ();
269264 GraphicsEnvironment ge = GraphicsEnvironment .getLocalGraphicsEnvironment ();
270265 for (final GraphicsDevice gd : ge .getScreenDevices ()) {
271266 if (!gd .isFullScreenSupported ()) {
@@ -274,6 +269,7 @@ public static void main(String args[]) {
274269 continue ;
275270 }
276271 done = false ;
272+ DisplayMode currentDM = gd .getDisplayMode ();
277273 Frame frame = new Frame (gd .getDefaultConfiguration ());
278274 try {
279275 frame .setSize (400 , 400 );
@@ -292,14 +288,16 @@ public static void main(String args[]) {
292288 }
293289 }
294290 } finally {
291+ gd .setDisplayMode (currentDM );
292+ gd .setFullScreenWindow (null );
295293 frame .dispose ();
296294 }
297295 if (errorMessage != null ) {
298296 throw new RuntimeException (errorMessage );
299297 }
300298 // delay a bit just to let the fullscreen window disposing complete
301299 // before switching to next display
302- delay (4000 );
300+ delay (10000 );
303301 }
304302 }
305303}
0 commit comments