Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java
41152 views
/*1* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.Container;24import java.awt.Point;25import java.awt.event.MouseAdapter;26import java.awt.event.MouseEvent;27import java.awt.event.InputEvent;28import java.lang.reflect.InvocationTargetException;29import javax.swing.JFrame;30import javax.swing.SpringLayout;31import javax.swing.SwingUtilities;32import test.java.awt.regtesthelpers.Util;3334/**35* Base class for testing overlapping of Swing and AWT component put into GlassPane.36* Validates drawing and event delivery at the components intersection.37* <p> See {@link OverlappingTestBase} for usage38*39* @author Sergey Grinev40*/41public abstract class GlassPaneOverlappingTestBase extends SimpleOverlappingTestBase {4243/**44* If true components is additionally tested to be correctly drawn after resize.45*/46protected boolean testResize = true;47private JFrame f = null;48private volatile Point ancestorLoc;4950/**51* Setups GlassPane with lightweight component returned by {@link SimpleOverlappingTestBase#getSwingComponent() }52* Called by base class.53*/54@Override55protected void prepareControls() {56wasLWClicked = false;5758if(f != null) {59f.setVisible(false);60}61f = new JFrame("Mixing : GlassPane Overlapping test");62f.setLayout(new SpringLayout());63f.setSize(200, 200);6465propagateAWTControls(f);6667f.getGlassPane().setVisible(true);68Container glassPane = (Container) f.getGlassPane();69glassPane.setLayout(null);7071testedComponent = getSwingComponent();72if (useDefaultClickValidation) {73testedComponent.addMouseListener(new MouseAdapter() {7475@Override76public void mouseClicked(MouseEvent e) {77//System.err.println("lw mouse clicked");78wasLWClicked = true;79}80});81}82testedComponent.setBounds(0, 0, testedComponent.getPreferredSize().width, testedComponent.getPreferredSize().height);83glassPane.add(testedComponent);8485f.setVisible(true);86}8788public GlassPaneOverlappingTestBase() {89super();90}9192public GlassPaneOverlappingTestBase(boolean defaultClickValidation) {93super(defaultClickValidation);94}9596/**97* Run test by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) } validation for current lightweight component.98* <p>Also resize component and repeat validation in the resized area.99* <p>Called by base class.100* @return true if test passed101* @see GlassPaneOverlappingTestBase#testResize102*/103@Override104protected boolean performTest() {105if (!super.performTest()) {106return false;107}108if (testResize) {109wasLWClicked = false;110try {111SwingUtilities.invokeAndWait(new Runnable() {112113public void run() {114testedComponent.setBounds(0, 0, testedComponent.getPreferredSize().width, testedComponent.getPreferredSize().height + 20);115ancestorLoc = f.getLocationOnScreen();116}117});118} catch (InterruptedException ex) {119fail(ex.getMessage());120} catch (InvocationTargetException ex) {121fail(ex.getMessage());122}123Point lLoc = testedComponent.getLocationOnScreen();124lLoc.translate(1, testedComponent.getPreferredSize().height + 1);125126/* this is a workaround for certain jtreg(?) focus issue:127tests fail starting after failing mixing tests but always pass alone.128*/129Util.waitForIdle(robot);130ancestorLoc.translate(isOel7() ? 5 : f.getWidth() / 2 - 15, 2);131robot.mouseMove(ancestorLoc.x, ancestorLoc.y);132Util.waitForIdle(robot);133robot.mousePress(InputEvent.BUTTON1_MASK);134robot.delay(50);135robot.mouseRelease(InputEvent.BUTTON1_MASK);136Util.waitForIdle(robot);137138clickAndBlink(robot, lLoc);139return wasLWClicked;140} else {141return true;142}143}144}145146147