/* * $Id$ * * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ import java.io.PrintStream; import javafx.application.Application; import javafx.collections.ObservableList; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ListView; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Ellipse; import javafx.scene.text.Text; import javafx.stage.Popup; import javafx.stage.Screen; import javafx.stage.Stage; /** * @test @run graphics.api.control.popup.PopupTest_9 @manual PopupTest_9.html * @keywords desktop @source PopupTest_9.java Constants.java @profile desktop */ /* * Test to check that changing parent of a popup to a node, group, control or * scene from another stage or another stage, or popup using keyword bind works * correctly */ public class PopupTest_9 extends Application { private Popup p1; private Popup p2; private Stage stage1; private Stage stage2; public final double X1 = Screen.getPrimary().getBounds().getWidth() - 180; public static final int Y1 = 100; public static void main(String[] args) { launch(args); } public void start(Stage primaryStage) { int h = 320; int w = 250; p1 = new Popup(); p2 = new Popup(); stage1 = new Stage(); stage2 = new Stage(); final Button button1 = new Button("Show Popup 1 - parent button"); final Button button2 = new Button("Hide Popup 1"); final Button button3 = new Button("Show Popup 2 - parent listView"); final Button button4 = new Button("Hide Popup 2"); button1.setOnAction(new EventHandler() { public void handle(Event t) { p1.show(stage1, X1, Y1); } }); button2.setOnAction(new EventHandler() { public void handle(Event t) { p1.hide(); } }); button3.setOnAction(new EventHandler() { public void handle(Event t) { p2.show(stage2, X1, Y1 + 200); } }); button4.setOnAction(new EventHandler() { public void handle(Event t) { p2.hide(); } }); ListView listView = new ListView(); ObservableList lvi = javafx.collections.FXCollections.observableArrayList(); lvi.addAll("1", "2", "3"); listView.setItems(lvi); listView.setPrefHeight(80.0F); p1.setAutoFix(true); //p1.setParent(listView);//TODO: Fix Me. p1.setAutoHide(false); StackPane stack = new StackPane(); Ellipse ellipse = new Ellipse(70.0F, 50.0F); ellipse.setFill(Color.AQUAMARINE); Text text = new Text("Popup 1"); text.setTranslateX(-10.0F); stack.getChildren().clear(); stack.getChildren().addAll(ellipse, text); p1.getContent().clear(); p1.getContent().addAll(stack); //End of StackPane here //End of Popup Creation p2.setAutoFix(true); //p2.setParent(button1);//TODO: Fix Me. p2.setAutoHide(false); StackPane stack2 = new StackPane(); Ellipse ellipse2 = new Ellipse(70.0F, 50.0F); ellipse2.setFill(Color.AQUAMARINE); Text text2 = new Text("Popup 2"); text2.setTranslateX(-10.0F); stack2.getChildren().clear(); stack2.getChildren().addAll(ellipse2, text2); p2.getContent().clear(); p2.getContent().addAll(stack2); //End of StackPane here //End of Popup Creation Scene scene1 = new Scene(new Group(), w, h); VBox vbox = new VBox(2.0F); vbox.getChildren().clear(); vbox.getChildren().addAll(button1, button2, button3, button4); vbox.setTranslateX(10.0F); vbox.setTranslateY(10.0F); ((Group) scene1.getRoot()).getChildren().clear(); ((Group) scene1.getRoot()).getChildren().addAll(vbox); Scene scene2 = new Scene(new Group(), w, h); ((Group) scene2.getRoot()).getChildren().clear(); ((Group) scene2.getRoot()).getChildren().addAll(listView); stage1.setTitle("First Stage"); stage1.setScene(scene1); stage2.setTitle("Second Stage"); stage2.setScene(scene2); System.out.println("Passed"); stage1.show(); stage2.show(); } }