Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java
47626 views
/*1* Copyright (c) 2014, 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*/222324import java.awt.Color;25import java.awt.Dimension;26import java.awt.GridLayout;27import java.awt.Point;28import java.awt.Robot;29import java.awt.event.ActionEvent;30import java.awt.event.ActionListener;31import java.awt.event.InputEvent;32import javax.swing.JButton;33import javax.swing.JFrame;34import javax.swing.JPanel;35import javax.swing.JScrollPane;36import javax.swing.JSplitPane;37import javax.swing.SwingUtilities;38import test.java.awt.regtesthelpers.Util;3940/**41* AWT/Swing overlapping test for {@link javax.swing.JSplitPane } component.42* <p>This test puts heavyweight and lightweight components into different43* panels and test if splitter image and components itself are drawn correctly.44* <p>See base class for test info.45*/46/*47@test48@bug 698610949@summary Overlapping test for javax.swing.JSplitPane50@author [email protected]: area=awt.mixing51@library ../../regtesthelpers52@build Util53@run main JSplitPaneOverlapping54*/55public class JSplitPaneOverlapping extends OverlappingTestBase {5657private boolean clicked = false;58private Point splitterLoc;59private JScrollPane sp1;60private JScrollPane sp2;6162protected void prepareControls() {63JFrame frame = new JFrame("SplitPane Mixing");64JPanel p = new JPanel(new GridLayout());65p.setPreferredSize(new Dimension(500, 500));66propagateAWTControls(p);67sp1 = new JScrollPane(p);6869JButton button = new JButton("JButton");70button.setBackground(Color.RED);71button.addActionListener(new ActionListener() {7273public void actionPerformed(ActionEvent e) {74clicked = true;75}76});77sp2 = new JScrollPane(button);7879JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp1, sp2);80splitPane.setOneTouchExpandable(false);81splitPane.setDividerLocation(150);8283splitPane.setPreferredSize(new Dimension(400, 200));8485frame.getContentPane().add(splitPane);86frame.pack();87frame.setVisible(true);88}8990private static final boolean ignoreFail = false;9192@Override93protected boolean performTest() {94try {95SwingUtilities.invokeAndWait(new Runnable() {96public void run() {97splitterLoc = sp2.getLocationOnScreen();98Point leftLoc = sp1.getLocationOnScreen();99leftLoc.translate(sp1.getWidth(), 0);100splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);101}102});103} catch (Exception e) {104e.printStackTrace();105throw new RuntimeException("Where is splitter?");106}107// run robot108Robot robot = Util.createRobot();109robot.setAutoDelay(ROBOT_DELAY);110111robot.mouseMove(splitterLoc.x, splitterLoc.y);112Util.waitForIdle(robot);113114robot.mousePress(InputEvent.BUTTON1_MASK);115robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);116Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);117System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);118if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {119fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");120}121robot.mouseRelease(InputEvent.BUTTON1_MASK);122123clickAndBlink(robot, splitterLoc);124125return clicked;126}127128// this strange plumbing stuff is required due to "Standard Test Machinery" in base class129public static void main(String args[]) throws InterruptedException {130instance = new JSplitPaneOverlapping();131OverlappingTestBase.doMain(args);132}133}134135136