< prev index next >

test/java/awt/FileDialog/FileDialogIconTest/FileDialogIconTest.java

Print this page
rev 17561 : 8185500: [TESTBUG] Add keywords headful/printer in java/awt and javax tests.
Summary: Add new keyword 'printer'. Some minor test fixes to show headless exception. Add some @requires windows.
   1 /*
   2  * Copyright (c) 2016, 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  */
  23 
  24 /* @test


  25  * @bug 8157163 8159132
  26  * @summary AWT FileDialog does not inherit icon image from parent Frame
  27  * @requires os.family=="windows"
  28  * @run main FileDialogIconTest
  29  */
  30 
  31 import java.awt.Color;
  32 import java.awt.Dialog;
  33 import java.awt.FileDialog;
  34 import java.awt.Frame;
  35 import java.awt.Graphics;
  36 import java.awt.Point;
  37 import java.awt.Robot;
  38 import java.awt.Image;
  39 import java.awt.image.BufferedImage;
  40 import javax.swing.SwingUtilities;
  41 
  42 public class FileDialogIconTest {
  43     private static Frame frame;
  44     private static Dialog dialog;


  51             frame.setIconImage(createImage());
  52             frame.setVisible(true);
  53             robot = new Robot();
  54             robot.waitForIdle();
  55             robot.delay(200);
  56 
  57             dialog = new FileDialog(frame, "Dialog");
  58             dialog.setModal(false);
  59             dialog.setVisible(true);
  60             robot.waitForIdle();
  61             robot.delay(1000);
  62 
  63             p = new Point(20, 20);
  64             SwingUtilities.convertPointToScreen(p, dialog);
  65             Color color = robot.getPixelColor(p.x, p.y);
  66             if (!Color.RED.equals(color)) {
  67                 throw new RuntimeException("Dialog icon was not inherited from " +
  68                         "owning window. Wrong color: " + color);
  69             }
  70         } finally {
  71             dialog.dispose();
  72             frame.dispose();
  73         }
  74     }
  75 
  76     private static Image createImage() {
  77         BufferedImage image = new BufferedImage(64, 64,
  78                                                   BufferedImage.TYPE_INT_ARGB);
  79         Graphics g = image.getGraphics();
  80         g.setColor(Color.RED);
  81         g.fillRect(0, 0, image.getWidth(), image.getHeight());
  82         g.dispose();
  83         return image;
  84     }
  85 
  86 }
   1 /*
   2  * Copyright (c) 2016, 2017, 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  */
  23 
  24 /**
  25  * @test
  26  * @key headful
  27  * @bug 8157163 8159132
  28  * @summary AWT FileDialog does not inherit icon image from parent Frame
  29  * @requires os.family=="windows"
  30  * @run main FileDialogIconTest
  31  */
  32 
  33 import java.awt.Color;
  34 import java.awt.Dialog;
  35 import java.awt.FileDialog;
  36 import java.awt.Frame;
  37 import java.awt.Graphics;
  38 import java.awt.Point;
  39 import java.awt.Robot;
  40 import java.awt.Image;
  41 import java.awt.image.BufferedImage;
  42 import javax.swing.SwingUtilities;
  43 
  44 public class FileDialogIconTest {
  45     private static Frame frame;
  46     private static Dialog dialog;


  53             frame.setIconImage(createImage());
  54             frame.setVisible(true);
  55             robot = new Robot();
  56             robot.waitForIdle();
  57             robot.delay(200);
  58 
  59             dialog = new FileDialog(frame, "Dialog");
  60             dialog.setModal(false);
  61             dialog.setVisible(true);
  62             robot.waitForIdle();
  63             robot.delay(1000);
  64 
  65             p = new Point(20, 20);
  66             SwingUtilities.convertPointToScreen(p, dialog);
  67             Color color = robot.getPixelColor(p.x, p.y);
  68             if (!Color.RED.equals(color)) {
  69                 throw new RuntimeException("Dialog icon was not inherited from " +
  70                         "owning window. Wrong color: " + color);
  71             }
  72         } finally {
  73             if (dialog != null) { dialog.dispose(); }
  74             if (frame  != null) { frame.dispose();  }
  75         }
  76     }
  77 
  78     private static Image createImage() {
  79         BufferedImage image = new BufferedImage(64, 64,
  80                                                   BufferedImage.TYPE_INT_ARGB);
  81         Graphics g = image.getGraphics();
  82         g.setColor(Color.RED);
  83         g.fillRect(0, 0, image.getWidth(), image.getHeight());
  84         g.dispose();
  85         return image;
  86     }
  87 
  88 }
< prev index next >