1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package scenegraph; 27 28 import javafx.collections.FXCollections; 29 import javafx.collections.ObservableList; 30 import javafx.geometry.Orientation; 31 import javafx.scene.Group; 32 import javafx.scene.PerspectiveCamera; 33 import javafx.scene.Scene; 34 import javafx.scene.control.ListView; 35 import javafx.scene.layout.GridPane; 36 import javafx.scene.layout.Priority; 37 import javafx.scene.paint.Color; 38 import javafx.scene.shape.Rectangle; 39 import javafx.stage.Stage; 40 import org.junit.Test; 41 import testharness.VisualTestBase; 42 43 /** 44 * Test bounds update of invisible node in the scene graph. 45 */ 46 public class JDK8130122Test extends VisualTestBase { 47 48 private Stage testStage; 49 private Scene testScene; 50 51 private static final double TOLERANCE = 0.07; 52 53 @Test(timeout=5000) 54 public void testEmptyShapes() { 55 final int WIDTH = 800; 56 final int HEIGHT = 400; 57 final ObservableList<Rectangle> data = FXCollections.<Rectangle>observableArrayList(); 58 59 data.addAll(new Rectangle(100, 100, Color.RED), new Rectangle(100, 100, Color.BLUE), 60 new Rectangle(100, 100, Color.RED), new Rectangle(100, 100, Color.BLUE), 61 new Rectangle(100, 100, Color.RED), new Rectangle(100, 100, Color.BLUE), 62 new Rectangle(100, 100, Color.RED), new Rectangle(100, 100, Color.BLUE)); 63 64 final ListView<Rectangle> horizontalListView = new ListView<Rectangle>(); 65 66 runAndWait(() -> { 67 final GridPane gridPane = new GridPane(); 68 gridPane.setPrefWidth(WIDTH); 69 gridPane.setPrefHeight(HEIGHT); 70 71 horizontalListView.setOrientation(Orientation.HORIZONTAL); 72 horizontalListView.setItems(data); 73 74 gridPane.add(horizontalListView, 0, 0); 75 horizontalListView.setVisible(false); 76 GridPane.setVgrow(horizontalListView, Priority.ALWAYS); 77 GridPane.setHgrow(horizontalListView, Priority.ALWAYS); 78 79 Group root = new Group(gridPane); 80 81 testStage = getStage(); 82 testStage.setTitle("Test bounds update of invisible node"); 83 testScene = new Scene(root, WIDTH, HEIGHT); 84 testScene.setCamera(new PerspectiveCamera()); 85 testScene.setFill(Color.WHITE); 86 testStage.setScene(testScene); 87 testStage.show(); 88 }); 89 waitFirstFrame(); 90 runAndWait(() -> { 91 Color color = getColor(testScene, 200, 250); 92 assertColorEquals(Color.WHITE, color, TOLERANCE); 93 data.add(0, new Rectangle(250, 150, Color.GREEN)); 94 }); 95 waitNextFrame(); 96 runAndWait(() -> { 97 Color color = getColor(testScene, 200, 250); 98 assertColorEquals(Color.WHITE, color, TOLERANCE); 99 horizontalListView.setVisible(true); 100 }); 101 waitNextFrame(); 102 runAndWait(() -> { 103 Color color = getColor(testScene, 200, 250); 104 assertColorEquals(Color.GREEN, color, TOLERANCE); 105 }); 106 107 } 108 109 }