Path: blob/master/test/jdk/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java
41152 views
/*1* Copyright (c) 2014, 2020, 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* @key headful49* @bug 698610950* @summary Overlapping test for javax.swing.JSplitPane51* @author [email protected]: area=awt.mixing52* @library /java/awt/patchlib ../../regtesthelpers53* @modules java.desktop/sun.awt54* java.desktop/java.awt.peer55* @build java.desktop/java.awt.Helper56* @build Util57* @run main JSplitPaneOverlapping58*/59public class JSplitPaneOverlapping extends OverlappingTestBase {6061private boolean clicked = false;62private Point splitterLoc;63private JScrollPane sp1;64private JScrollPane sp2;6566protected void prepareControls() {67JFrame frame = new JFrame("SplitPane Mixing");68JPanel p = new JPanel(new GridLayout());69p.setPreferredSize(new Dimension(500, 500));70propagateAWTControls(p);71sp1 = new JScrollPane(p);7273JButton button = new JButton("JButton");74button.setBackground(Color.RED);75button.addActionListener(new ActionListener() {7677public void actionPerformed(ActionEvent e) {78clicked = true;79}80});81sp2 = new JScrollPane(button);8283JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp1, sp2);84splitPane.setOneTouchExpandable(false);85splitPane.setDividerLocation(150);8687splitPane.setPreferredSize(new Dimension(400, 200));8889frame.getContentPane().add(splitPane);90frame.pack();91frame.setVisible(true);92}9394private static final boolean ignoreFail = false;9596@Override97protected boolean performTest() {98try {99SwingUtilities.invokeAndWait(new Runnable() {100public void run() {101splitterLoc = sp2.getLocationOnScreen();102Point leftLoc = sp1.getLocationOnScreen();103leftLoc.translate(sp1.getWidth(), 0);104splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);105}106});107} catch (Exception e) {108e.printStackTrace();109throw new RuntimeException("Where is splitter?");110}111// run robot112Robot robot = Util.createRobot();113robot.setAutoDelay(ROBOT_DELAY);114115robot.mouseMove(splitterLoc.x, splitterLoc.y);116Util.waitForIdle(robot);117118robot.mousePress(InputEvent.BUTTON1_MASK);119robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);120Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);121robot.mouseRelease(InputEvent.BUTTON1_MASK);122123System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);124if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {125fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");126}127clickAndBlink(robot, splitterLoc);128129return clicked;130}131132// this strange plumbing stuff is required due to "Standard Test Machinery" in base class133public static void main(String args[]) throws InterruptedException {134instance = new JSplitPaneOverlapping();135OverlappingTestBase.doMain(args);136}137}138139140