Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/swing/JTree/8072676/TreeClipTest.java
38853 views
/*1* Copyright (c) 2015, 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.*;24import java.awt.image.BufferedImage;25import java.io.File;26import java.io.IOException;27import javax.imageio.ImageIO;28import javax.swing.*;29import javax.swing.tree.DefaultMutableTreeNode;30import javax.swing.tree.DefaultTreeModel;3132/*33* @test34* @bug 807267635* @summary Checks if the tree painter doesn't expand existing clip36* @author Anton Nashatyrev37*/38public class TreeClipTest {3940static boolean passed = true;4142static boolean checkImage(BufferedImage img, int clipY) {43for (int y = clipY; y < img.getHeight(); y++) {44for (int x = 0; x < img.getWidth(); x++) {45if ((img.getRGB(x,y) & 0xFFFFFF) != 0xFFFFFF) {46return false;47}48}49}50return true;51}5253public static void main(String[] args) throws Exception {54SwingUtilities.invokeAndWait(new Runnable() {55@Override56public void run() {57DefaultMutableTreeNode root = new DefaultMutableTreeNode("JTree");58DefaultMutableTreeNode parent;5960parent = new DefaultMutableTreeNode("colors");61root.add(parent);62parent.add(new DefaultMutableTreeNode("blue"));63DefaultTreeModel model = new DefaultTreeModel(root);64JTree tree = new JTree(model);6566BufferedImage img = new BufferedImage(50, 50, BufferedImage.TYPE_INT_ARGB);67for (int clipY = 1; clipY < 50; clipY++) {68Graphics2D ig = img.createGraphics();69ig.setColor(Color.WHITE);70ig.fillRect(0,0,1000, 1000);71tree.setSize(200,200);72ig.setClip(0,0,1000,clipY);73tree.paint(ig);74ig.dispose();7576if (!checkImage(img, clipY)) {77System.err.println("Failed with clipY=" + clipY);78passed = false;79try {80ImageIO.write(img, "PNG", new File("failedResult.png"));81} catch (IOException e) {82e.printStackTrace();83}84return;85}86}87}88});8990if (!passed) {91throw new RuntimeException("Test failed.");92} else {93System.out.println("Passed.");94}95}96}9798