/
githubmirror
/
panama-vector
Обзор
Документация
Войти
/
githubmirror
/
panama-vector
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/jdk/java/awt/Mixing/AWT_Mixing/GlassPaneOverlappingTestBase.java
176 строк
6 KB
Khalid Boulanouare
8360498: [TEST_BUG] Some Mixing test continue to fail
23 апр 2026, 20:05
23 апр 2026, 20:05
8256d13
Код
Авторство
О чём код?
/* * Copyright (c) 2014, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ import java.awt.Component; import java.awt.Container; import java.awt.KeyboardFocusManager; import java.awt.Point; import java.awt.event.FocusAdapter; import java.awt.event.FocusEvent; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.lang.reflect.InvocationTargetException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import javax.swing.JFrame; import javax.swing.SpringLayout; import javax.swing.SwingUtilities; /** * Base class for testing overlapping of Swing and AWT component put into GlassPane. * Validates drawing and event delivery at the components intersection. * <p> See {@link OverlappingTestBase} for usage * * @author Sergey Grinev */ public abstract class GlassPaneOverlappingTestBase extends SimpleOverlappingTestBase { /** * If true components is additionally tested to be correctly drawn after resize. */ protected boolean testResize = true; private JFrame f = null; /** * Setups GlassPane with lightweight component returned by {@link SimpleOverlappingTestBase#getSwingComponent() } * Called by base class. */ @Override protected void prepareControls() { wasLWClicked = false; if (f != null) { f.setVisible(false); } f = new JFrame("Mixing : GlassPane Overlapping test"); f.setLayout(new SpringLayout()); f.setSize(200, 200); propagateAWTControls(f); f.getGlassPane() .setVisible(true); Container glassPane = (Container) f.getGlassPane(); glassPane.setLayout(null); testedComponent = getSwingComponent(); if (useDefaultClickValidation) { testedComponent.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { //System.err.println("lw mouse clicked"); wasLWClicked = true; } }); } testedComponent.setBounds(0, 0, testedComponent.getPreferredSize().width, testedComponent.getPreferredSize().height); glassPane.add(testedComponent); f.setLocationRelativeTo(null); f.setVisible(true); } public GlassPaneOverlappingTestBase() { super(); } public GlassPaneOverlappingTestBase(boolean defaultClickValidation) { super(defaultClickValidation); } @Override protected final boolean isMultiFramesTest() { return false; } /** * Run test by {@link OverlappingTestBase#clickAndBlink(java.awt.Robot, java.awt.Point) } validation for current lightweight component. * <p>Also resize component and repeat validation in the resized area. * <p>Called by base class. * * @return true if test passed * @see GlassPaneOverlappingTestBase#testResize */ @Override protected boolean performTest() { if (!super.performTest()) { return false; } if (!testResize) { return true; } final CountDownLatch latch = new CountDownLatch(1); f.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { latch.countDown(); } }); wasLWClicked = false; try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { testedComponent.setBounds(0, 0, testedComponent.getPreferredSize().width, testedComponent.getPreferredSize().height + 20); Component focusOwner = KeyboardFocusManager .getCurrentKeyboardFocusManager() .getFocusOwner(); if (focusOwner == f) { // frame already has focus latch.countDown(); } else { f.requestFocusInWindow(); } } }); } catch (InterruptedException | InvocationTargetException ex) { fail(ex.getMessage()); } try { if (!latch.await(1, TimeUnit.SECONDS)) { throw new RuntimeException("Ancestor frame didn't receive focus"); } final Point[] points = new Point[1]; SwingUtilities.invokeAndWait(() -> { Point lLoc = testedComponent.getLocationOnScreen(); lLoc.translate(1, testedComponent.getPreferredSize().height + 1); points[0] = lLoc; }); clickAndBlink(robot, points[0]); } catch (InterruptedException | InvocationTargetException e) { throw new RuntimeException(e); } return wasLWClicked; } @Override protected void cleanup() { f.dispose(); } }