/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. */ package test.rendering.app.shapes; import javafx.application.Application; import javafx.beans.InvalidationListener; import javafx.beans.Observable; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.input.MouseEvent; import javafx.scene.layout.FlowPane; import javafx.scene.layout.Pane; import javafx.scene.layout.VBox; import javafx.scene.paint.Color; import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class CircleApp1 extends Application { public static void main(String[] a) { //for debug Application.launch(a); } class GiantCircle implements Runnable{ public void run() { System.out.println("--B"); Rectangle rectangle = new Rectangle(300, 300, Color.BLUE); System.out.println("--E"); pageContent.getChildren().addAll(rectangle, new Circle(0,0,77000)); } } protected void setup() { addPage("Clickme", new GiantCircle()); } protected final int width = 400; protected final int height = 600; protected final String title = ""; protected static Scene scene; private Pane buttons; private Pane subButtons; private Pane pageContent; protected boolean mouseTransparent = true; private static final int TABS_SPACE = 70; private static final int SUB_TABS_SPACE = 400; @Override public void start(Stage stage) { System.err.println("start"); // create scene stage.setX(100); stage.setY(100); scene = new Scene(new Group()); stage.setScene(scene); fillScene(); stage.show(); stage.toFront(); stage.setFocused(true); } protected void fillScene() { VBox vBox = new VBox(); FlowPane hflow = new FlowPane(); hflow.setMaxWidth(width); vBox.getChildren().add(buttons = hflow); FlowPane subflow = new FlowPane(); subflow.setMaxWidth(width); vBox.getChildren().add(subButtons = subflow); pageContent = new Pane(); pageContent.setMinSize(width, height); pageContent.setMaxSize(width, height); pageContent.setPrefSize(width, width); pageContent.setMouseTransparent(mouseTransparent); vBox.getChildren().add(pageContent); pageContent.setTranslateX(10); pageContent.setTranslateY(10); ((Group) scene.getRoot()).getChildren().add(vBox); buttons.layoutBoundsProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable ov) { if (buttons.getBoundsInLocal().getHeight() > TABS_SPACE) { throw new IndexOutOfBoundsException("Too many tabs, they shouldn't exceed 2 rows."); } } }); subButtons.layoutBoundsProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable ov) { if (subButtons.getBoundsInLocal().getHeight() > SUB_TABS_SPACE) { throw new IndexOutOfBoundsException("Too many sub tabs, they shouldn't exceed 2 rows."); } } }); setup(); } protected void addPage(final String name, final Runnable pageSetupAction) { /*Utils.deferAction*/javafx.application.Platform.runLater(new Runnable() { public void run() { // add content to the scene class ButtonRunnable implements Runnable { TextButton button = null; public ButtonRunnable() { } public void setButton(TextButton button) { this.button = button; } public void run() { System.err.println("opening page " + name); //currentPage = name; subButtons.getChildren().clear(); scene.getWindow().sizeToScene(); resetPage(); if (pageSetupAction != null) { pageSetupAction.run(); } } } ButtonRunnable runnable = new ButtonRunnable(); TextButton button = new TextButton(name, runnable); runnable.setButton(button); buttons.getChildren().add(button); scene.getWindow().sizeToScene(); } }); } protected void resetPage() { pageContent.getChildren().clear(); } public static class TextButton extends Button { protected final String name; private final static Color activeColor = Color.RED; private final static Color passiveColor = Color.LIGHTGREEN; private final Runnable textAction; public String getName() { return name; } public void setTextHandler(EventHandler handler) { this.setOnMousePressed(handler); } public TextButton(String name, final Runnable action) { this(name, action, passiveColor); } public TextButton(String name, final Runnable action, final Color color) { super(name); this.name = name; this.textAction = action; this.setId(name); EventHandler handler = new EventHandler() { public void handle(MouseEvent t) { if (null != textAction) { textAction.run(); } } }; this.setOnMousePressed(handler); this.setStyle("-fx-base: rgb(" + Math.round(color.getRed()*100) + "%," + Math.round(color.getGreen()*100) + "%," + Math.round(color.getBlue()*100) + "%);" + "-fx-pressed-base: rgb(" + Math.round(activeColor.getRed()*100) + "%," + Math.round(activeColor.getGreen()*100) + "%," + Math.round(activeColor.getBlue()*100) + "%);" + " -fx-background-radius: 1; " + "-fx-background-insets: 1"); } public void setFillWithActiveColor() { } public void setFillWithPassiveColor() { } } }