< prev index next >

test/jdk/java/awt/Window/ShapedAndTranslucentWindows/Common.java

Print this page


   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  */


 244 
 245         // foreground
 246         if (opacity < 1.0f){
 247             checkTranslucentShape();
 248         } else {
 249             points[0] = new Point(3 * blockSizeX, 3 * blockSizeY);
 250             points[1] = new Point(14 * blockSizeX, 14 * blockSizeY);
 251             points[2] = new Point(3 * blockSizeX, 14 * blockSizeY);
 252             points[3] = new Point(14 * blockSizeX, 3 * blockSizeY);
 253             checkShape(points, false);
 254         }
 255     }
 256 
 257     public void checkShape(Point[] points, boolean areBackgroundPoints) throws Exception {
 258 
 259         Point location = window.getLocationOnScreen();
 260 
 261         for (Point p : points) {
 262             p.translate(location.x, location.y);
 263             if (areBackgroundPoints) {
 264                 if (!robot.getPixelColor(p.x, p.y).equals(BG_COLOR))
 265                     throw new RuntimeException("Background point " + p + " color " + robot.getPixelColor(p.x, p.y) +
 266                             " does not equal to background color " + BG_COLOR);
 267                 else
 268                     System.out.println("OK with background point " + p);
 269             } else {
 270                 if (robot.getPixelColor(p.x, p.y).equals(BG_COLOR))
 271                     throw new RuntimeException("Foreground point " + p +
 272                             " equals to background color " + BG_COLOR);
 273                 else
 274                     System.out.println("OK with foreground point " + p);
 275             }
 276         }
 277     }
 278 











 279     public void initBackgroundFrame() {
 280         background = new Frame();
 281         background.setUndecorated(true);
 282         background.setBackground(BG_COLOR);
 283         background.setSize(500, 500);
 284         background.setLocation(dl, dl);
 285         background.setVisible(true);
 286     }
 287 
 288     public void initGUI() {
 289         if (windowClass.equals(Frame.class)) {
 290             window = new Frame();
 291             ((Frame) window).setUndecorated(true);
 292         } else  if (windowClass.equals(Dialog.class)) {
 293             window = new Dialog(background);
 294             ((Dialog) window).setUndecorated(true);
 295         } else {
 296             window = new Window(background);
 297         }
 298 
   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  */


 244 
 245         // foreground
 246         if (opacity < 1.0f){
 247             checkTranslucentShape();
 248         } else {
 249             points[0] = new Point(3 * blockSizeX, 3 * blockSizeY);
 250             points[1] = new Point(14 * blockSizeX, 14 * blockSizeY);
 251             points[2] = new Point(3 * blockSizeX, 14 * blockSizeY);
 252             points[3] = new Point(14 * blockSizeX, 3 * blockSizeY);
 253             checkShape(points, false);
 254         }
 255     }
 256 
 257     public void checkShape(Point[] points, boolean areBackgroundPoints) throws Exception {
 258 
 259         Point location = window.getLocationOnScreen();
 260 
 261         for (Point p : points) {
 262             p.translate(location.x, location.y);
 263             if (areBackgroundPoints) {
 264                 if (!similarColors(robot.getPixelColor(p.x, p.y), BG_COLOR))
 265                     throw new RuntimeException("Background point " + p + " color " + robot.getPixelColor(p.x, p.y) +
 266                             " does not equal to background color " + BG_COLOR);
 267                 else
 268                     System.out.println("OK with background point " + p);
 269             } else {
 270                 if (similarColors(robot.getPixelColor(p.x, p.y), BG_COLOR))
 271                     throw new RuntimeException("Foreground point " + p +
 272                             " equals to background color " + BG_COLOR);
 273                 else
 274                     System.out.println("OK with foreground point " + p);
 275             }
 276         }
 277     }
 278 
 279     public static boolean similarColors(final Color c1, final Color c2) {
 280         if((Math.abs(c1.getRed() - c2.getRed()) < 40) &&
 281            (Math.abs(c1.getBlue() - c2.getBlue()) < 40) &&
 282            (Math.abs(c1.getGreen() - c2.getGreen()) < 40)) {
 283                 return true;
 284         }
 285         else {
 286             return false;
 287         }
 288     }
 289 
 290     public void initBackgroundFrame() {
 291         background = new Frame();
 292         background.setUndecorated(true);
 293         background.setBackground(BG_COLOR);
 294         background.setSize(500, 500);
 295         background.setLocation(dl, dl);
 296         background.setVisible(true);
 297     }
 298 
 299     public void initGUI() {
 300         if (windowClass.equals(Frame.class)) {
 301             window = new Frame();
 302             ((Frame) window).setUndecorated(true);
 303         } else  if (windowClass.equals(Dialog.class)) {
 304             window = new Dialog(background);
 305             ((Dialog) window).setUndecorated(true);
 306         } else {
 307             window = new Window(background);
 308         }
 309 
< prev index next >