/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package diamondbenchmark; import com.sun.javafx.perf.PerformanceTracker; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; import javafx.application.Application; import javafx.beans.binding.StringBinding; import javafx.beans.property.DoubleProperty; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.layout.Region; import javafx.scene.shape.LineTo; import javafx.scene.shape.MoveTo; import javafx.scene.shape.Path; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.util.Duration; /** * * @author jp202575 */ public class DiamondBenchmarkBug extends Application { private Scene scene; private Group root; private static final int TRACKS = 200; private static final int OFFSET_X = 20; private static final int OFFSET_Y = 20; private static boolean START_AT_ZERO = false; static final boolean HAS_TEXT = true; @Override public void start(Stage primaryStage) { root = new Group(); scene = new Scene(root, 500, 500); //Screen.getMainScreen().getVisibleWidth(), Screen.getMainScreen().getVisibleHeight()); for (int i=0; i < TRACKS; i++) { createDiamond(); } primaryStage.setTitle("Diamond Benchmark"); primaryStage.setScene(scene); primaryStage.show(); final PerformanceTracker tracker = PerformanceTracker.getSceneTracker(scene); final Timeline timeline = new Timeline( new KeyFrame(Duration.seconds(1), new EventHandler() { public void handle(ActionEvent t) { System.out.println("::FPS = " + tracker.getAverageFPS()); //System.out.println("::PLS = " + tracker.getAveragePulses()); tracker.resetAverageFPS(); } })); timeline.setCycleCount(Timeline.INDEFINITE); timeline.play(); } public void createDiamond() { Diamond diamond = new Diamond(100+(int)(Math.random()*400)); root.getChildren().add(diamond); Timeline timeline = new Timeline(); timeline.setCycleCount(Timeline.INDEFINITE); double startX, startY, endX, endY; double diamondWidth = START_AT_ZERO ? 0 : 120; double diamondHeight = START_AT_ZERO ? 0 : 40; double width = scene.getWidth() - diamondWidth; double height = scene.getHeight() - diamondHeight; if (Math.random() > 0.5) { // start top or bottom if (Math.random() > 0.5) { // start top startY = OFFSET_Y * (START_AT_ZERO ? 0 : 2); } else { // start bottom startY = height; } startX = Math.max(diamondWidth, Math.random() * width); } else { // start left or right if (Math.random() > 0.5) { // start left startX = START_AT_ZERO ? 0 : OFFSET_X; } else { // start right startX = width; } startY = Math.max(diamondHeight, Math.random() * height); } if (Math.random() > 0.5) { // end top or bottom if (Math.random() > 0.5) { // end top endY = OFFSET_Y * (START_AT_ZERO ? 0 : 2); } else { // end bottom endY = height; } endX = Math.max(diamondWidth, Math.random() * width); } else { // end left or right if (Math.random() > 0.5) { // end left endX = START_AT_ZERO ? 0 : OFFSET_X; } else { // end right endX = width; } endY = Math.max(diamondHeight, Math.random() * height); } double angle = Math.toDegrees(Math.atan((endY-startY) / (endX-startX))) -90; diamond.angle.set(angle); diamond.setTranslateX(startX); diamond.setTranslateY(startY); diamond.altatude.setValue(1000+(int)(32*Math.random())); timeline.getKeyFrames().addAll( new KeyFrame(Duration.seconds(11+(Math.random()*100d)), new KeyValue(diamond.translateXProperty(), endX), new KeyValue(diamond.translateYProperty(), endY), new KeyValue(diamond.altatude, 1000+(int)(32*Math.random())) ) ); timeline.play(); } /** * The main() method is ignored in correctly deployed JavaFX application. * main() serves only as fallback in case the application can not be * launched through deployment artifacts, e.g., in IDEs with limited FX * support. NetBeans ignores main(). * * @param args the command line arguments */ public static void main(String[] args) { launch(args); } private static Font font = Font.getDefault(); //Font.loadFont("System", 8); private class Diamond extends Region { private Text text = HAS_TEXT ? new Text() : null; private Path diamond = new Path(); public final StringProperty textProperty = HAS_TEXT ? text.textProperty() : new SimpleStringProperty(); public final DoubleProperty angle = new SimpleDoubleProperty(); public final IntegerProperty altatude = new SimpleIntegerProperty(); public Diamond(final int id) { if (HAS_TEXT) { text.setFont(font); text.setX(OFFSET_X); text.setY(-OFFSET_Y); getChildren().add(text); } getChildren().add(diamond); diamond.rotateProperty().bind(angle); diamond.getElements().addAll( new MoveTo(0,18), new LineTo(0,10), new LineTo(3,0), new LineTo(0,-10), new LineTo(-3,0), new LineTo(0,10) ); textProperty.bind(new StringBinding() { { bind(altatude,translateXProperty(),translateYProperty()); } @Override protected String computeValue() { return String.format("BA%d\n%.4flat\n%.4flon\n%dft\n", id,getTranslateX(),getTranslateY(),altatude.get()); } }); } } }