5243N/A/*
5243N/A * Copyright (c) 2012 Oracle and/or its affiliates. All rights reserved.
5243N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5243N/A *
5243N/A * This code is free software; you can redistribute it and/or modify it
5243N/A * under the terms of the GNU General Public License version 2 only, as
5243N/A * published by the Free Software Foundation.
5243N/A *
5243N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5243N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5243N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5243N/A * version 2 for more details (a copy is included in the LICENSE file that
5243N/A * accompanied this code).
5243N/A *
5243N/A * You should have received a copy of the GNU General Public License version
5243N/A * 2 along with this work; if not, write to the Free Software Foundation,
5243N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5243N/A *
5243N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5243N/A * or visit www.oracle.com if you need additional information or have any
5243N/A * questions.
5243N/A */
5243N/A
5243N/A/*
5243N/A * Portions Copyright (c) 2012 IBM Corporation
5243N/A */
5243N/A
5243N/Aimport javax.swing.JButton;
5243N/Aimport javax.swing.JDesktopPane;
5243N/Aimport javax.swing.JFrame;
5243N/Aimport javax.swing.SwingUtilities;
5243N/Aimport sun.awt.SunToolkit;
5243N/A
5243N/Aimport java.awt.AWTException;
5243N/Aimport java.awt.AlphaComposite;
5243N/Aimport java.awt.Color;
5243N/Aimport java.awt.Graphics;
5243N/Aimport java.awt.Graphics2D;
5243N/Aimport java.awt.Rectangle;
5243N/Aimport java.awt.Robot;
5243N/Aimport java.awt.Toolkit;
5243N/Aimport java.awt.image.BufferedImage;
5243N/A
5243N/A/* @test 1.1 2012/04/12
5243N/A * @bug 7154030
5243N/A * @summary Swing components fail to hide after calling hide()
5243N/A * @author Jonathan Lu
5243N/A * @library ../../regtesthelpers/
5243N/A * @build Util
5243N/A * @run main bug7154030
5243N/A */
5243N/A
5243N/Apublic class bug7154030 {
5243N/A
5243N/A private static JButton button = null;
5243N/A
5243N/A public static void main(String[] args) throws Exception {
5243N/A BufferedImage imageInit = null;
5243N/A
5243N/A BufferedImage imageShow = null;
5243N/A
5243N/A BufferedImage imageHide = null;
5243N/A
5243N/A SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
5243N/A
5243N/A Robot robot = new Robot();
5243N/A
5243N/A SwingUtilities.invokeAndWait(new Runnable() {
5243N/A
5243N/A @Override
5243N/A public void run() {
5243N/A JDesktopPane desktop = new JDesktopPane();
5243N/A button = new JButton("button");
5243N/A JFrame frame = new JFrame();
5243N/A
5243N/A button.setSize(200, 200);
5243N/A button.setLocation(100, 100);
5243N/A button.setForeground(Color.RED);
5243N/A button.setBackground(Color.RED);
5243N/A button.setOpaque(true);
5243N/A button.setVisible(false);
5243N/A desktop.add(button);
5243N/A
5243N/A frame.setContentPane(desktop);
5243N/A frame.setSize(300, 300);
5243N/A frame.setLocation(0, 0);
5243N/A frame.setVisible(true);
5243N/A frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
5243N/A }
5243N/A });
5243N/A
5243N/A toolkit.realSync();
5243N/A imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
5243N/A
5243N/A SwingUtilities.invokeAndWait(new Runnable() {
5243N/A
5243N/A @Override
5243N/A public void run() {
5243N/A button.show();
5243N/A }
5243N/A });
5243N/A
5243N/A toolkit.realSync();
5243N/A imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
5243N/A if (Util.compareBufferedImages(imageInit, imageShow)) {
5243N/A throw new Exception("Failed to show opaque button");
5243N/A }
5243N/A
5243N/A toolkit.realSync();
5243N/A
5243N/A SwingUtilities.invokeAndWait(new Runnable() {
5243N/A
5243N/A @Override
5243N/A public void run() {
5243N/A button.hide();
5243N/A }
5243N/A });
5243N/A
5243N/A toolkit.realSync();
5243N/A imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
5243N/A
5243N/A if (!Util.compareBufferedImages(imageInit, imageHide)) {
5243N/A throw new Exception("Failed to hide opaque button");
5243N/A }
5243N/A
5243N/A SwingUtilities.invokeAndWait(new Runnable() {
5243N/A
5243N/A @Override
5243N/A public void run() {
5243N/A button.setOpaque(false);
5243N/A button.setBackground(new Color(128, 128, 0));
5243N/A button.setVisible(false);
5243N/A }
5243N/A });
5243N/A
5243N/A toolkit.realSync();
5243N/A imageInit = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
5243N/A
5243N/A SwingUtilities.invokeAndWait(new Runnable() {
5243N/A
5243N/A @Override
5243N/A public void run() {
5243N/A button.show();
5243N/A }
5243N/A });
5243N/A
5243N/A toolkit.realSync();
5243N/A imageShow = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
5243N/A
5243N/A SwingUtilities.invokeAndWait(new Runnable() {
5243N/A
5243N/A @Override
5243N/A public void run() {
5243N/A button.hide();
5243N/A }
5243N/A });
5243N/A
5243N/A if (Util.compareBufferedImages(imageInit, imageShow)) {
5243N/A throw new Exception("Failed to show non-opaque button");
5243N/A }
5243N/A
5243N/A toolkit.realSync();
5243N/A imageHide = robot.createScreenCapture(new Rectangle(0, 0, 300, 300));
5243N/A
5243N/A if (!Util.compareBufferedImages(imageInit, imageHide)) {
5243N/A throw new Exception("Failed to hide non-opaque button");
5243N/A }
5243N/A }
5243N/A}