/* * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. */ package helloworld; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.Ellipse; import javafx.scene.shape.Line; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; import javafx.util.Duration; import java.util.LinkedList; import java.util.List; import java.util.Random; import javafx.application.Platform; public class HelloCache extends Application { @Override public void start(final Stage stage) { stage.setTitle("Hellocache"); int winWidth = 1024; int winHeight = 768; final Scene scene = new Scene(new Group(), winWidth, winHeight); scene.setFill(Color.LIGHTGREEN); final Timeline timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); timeline.setAutoReverse(true); List kvs = new LinkedList(); final int hCount = 2 * 4; final int vCount = hCount * 3 / 4; final double tileWidth = winWidth / (2 * hCount); final double tileHeight = winHeight / (2 * vCount); final Random rand = new Random(); System.out.println("Total: " + hCount * vCount); for (int i = 0; i < vCount; i++) { for (int j = 0; j < hCount; j++) { Ellipse ellipse = new Ellipse(tileWidth, tileHeight); ellipse.setFill(Color.rgb((int)(255.0f / vCount * i), (int)(255.0f * rand.nextFloat()), (int)(255.0f / hCount * j))); Line line = new Line(0,0, tileWidth, tileHeight); line.setStrokeWidth(1); line.setStroke(Color.BLACK); Group grp = new Group(ellipse, line); grp.setTranslateX(j*2*tileWidth + tileWidth); grp.setTranslateY(i*2*tileHeight + tileHeight); grp.setCache(true); ((Group) scene.getRoot()).getChildren().add(grp); final KeyValue kv; if (j % 2 == 0) { if (i % 2 == 0) { kv = new KeyValue(grp.translateXProperty(), j*2*tileWidth + tileWidth + 2*tileWidth); } else { kv = new KeyValue(grp.translateYProperty(), i*2*tileHeight + tileHeight - 2*tileHeight); } } else { if (i % 2 == 0) { kv = new KeyValue(grp.translateYProperty(), i*2*tileHeight + tileHeight + 2*tileHeight); } else { kv = new KeyValue(grp.translateXProperty(), j*2*tileWidth + tileWidth - 2*tileWidth); } } kvs.add(kv); } } stage.setScene(scene); stage.show(); final KeyFrame kf = new KeyFrame(Duration.millis(500), kvs.toArray(new KeyValue[0])); timeline.getKeyFrames().add(kf); timeline.play(); } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } }