Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/awt/Mixing/AWT_Mixing/JSplitPaneOverlapping.java
48795 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 creates puts heavyweight and lightweight components into different panels and test if splitter image and components itself are drawn correctly.43* <p>See base class for test info.44*/45/*46@test47@bug 698610948@summary Overlapping test for javax.swing.JSplitPane49@author [email protected]: area=awt.mixing50@library ../../regtesthelpers51@build Util52@run main JSplitPaneOverlapping53*/54public class JSplitPaneOverlapping extends OverlappingTestBase {5556private boolean clicked = false;57private Point splitterLoc;58private JScrollPane sp1;59private JScrollPane sp2;6061protected void prepareControls() {62JFrame frame = new JFrame("SplitPane Mixing");63JPanel p = new JPanel(new GridLayout());64p.setPreferredSize(new Dimension(500, 500));65propagateAWTControls(p);66sp1 = new JScrollPane(p);6768JButton button = new JButton("JButton");69button.setBackground(Color.RED);70button.addActionListener(new ActionListener() {7172public void actionPerformed(ActionEvent e) {73clicked = true;74}75});76sp2 = new JScrollPane(button);7778JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sp1, sp2);79splitPane.setOneTouchExpandable(false);80splitPane.setDividerLocation(150);8182splitPane.setPreferredSize(new Dimension(400, 200));8384frame.getContentPane().add(splitPane);85frame.pack();86frame.setVisible(true);87}8889private static final boolean ignoreFail = false;9091@Override92protected boolean performTest() {93try {94SwingUtilities.invokeAndWait(new Runnable() {95public void run() {96splitterLoc = sp2.getLocationOnScreen();97Point leftLoc = sp1.getLocationOnScreen();98leftLoc.translate(sp1.getWidth(), 0);99splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);100}101});102} catch (Exception e) {103e.printStackTrace();104throw new RuntimeException("Where is splitter?");105}106// run robot107Robot robot = Util.createRobot();108robot.setAutoDelay(ROBOT_DELAY);109110robot.mouseMove(splitterLoc.x, splitterLoc.y);111Util.waitForIdle(robot);112113robot.mousePress(InputEvent.BUTTON1_MASK);114robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);115Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);116System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);117if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {118fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");119}120robot.mouseRelease(InputEvent.BUTTON1_MASK);121122clickAndBlink(robot, splitterLoc);123124return clicked;125}126127// this strange plumbing stuff is required due to "Standard Test Machinery" in base class128public static void main(String args[]) throws InterruptedException {129instance = new JSplitPaneOverlapping();130OverlappingTestBase.doMain(args);131}132}133134135