import com.sun.javafx.perf.PerformanceTracker; import java.util.List; import javafx.animation.AnimationTimer; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeView; import javafx.stage.Stage; import javafx.util.Duration; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author ekaterina.pavlova@oracle.com */ public class TreeViewExpandPerfTest extends Application { enum TreeViewType {WIDE, DEPTH}; static double SCENE_WEIGHT = 300.0; static double SCENE_HEIGHT = 600.0; static int TABLEVIEW_SIZE = 100; static TreeViewType treeViewType = TreeViewType.WIDE; TreeView treeView; TreeView createTreeView() { TreeItem treeRoot = new TreeItem("Root"); TreeView treeView = new TreeView(); treeView.setShowRoot(true); treeView.setRoot(treeRoot); treeView.setMinSize(SCENE_WEIGHT-10, SCENE_WEIGHT-10); treeView.setMinSize(SCENE_WEIGHT-10, SCENE_WEIGHT-10); treeRoot.setExpanded(false); for (int i=0; i obj = new TreeItem("text tree item " + i); treeRoot.getChildren().add(obj); if (treeViewType == TreeViewType.WIDE) treeRoot = obj; } treeView.setMaxSize(SCENE_WEIGHT-10, SCENE_WEIGHT-10); return treeView; } void expandTreeItemRecur(TreeItem item, boolean flag) { item.setExpanded(flag); List items = item.getChildren(); for (int i=0; i 0) item = (TreeItem)item.getChildren().get(0); else item = null; } } void expandTreeView(TreeView treeView, boolean flag) { TreeItem treeItem = treeView.getRoot(); if (treeViewType == treeViewType.DEPTH) treeItem.setExpanded(flag); else expandTreeItem(treeItem, flag); } Stage stage; PerformanceTracker perfTracker; Group rootGroup; int iters=1; @Override public void start(Stage primaryStage) { stage = new Stage(); rootGroup = new Group(); Scene scene = new Scene(rootGroup, SCENE_WEIGHT, SCENE_HEIGHT); stage.setScene(scene); stage.sizeToScene(); stage.setVisible(true); perfTracker = PerformanceTracker.getSceneTracker(scene); Timeline autoTL = new Timeline(); KeyFrame endWarmupKF = new KeyFrame(Duration.valueOf(5000), new EventHandler() { @Override public void handle(ActionEvent e) { String fpsText = String.format("WARMUP DONE: fps %.2f", perfTracker.getInstantFPS()); System.out.println(fpsText); perfTracker.resetAverageFPS(); } }); KeyFrame endTestKF = new KeyFrame(Duration.valueOf(60000), new EventHandler() { @Override public void handle(ActionEvent e) { String fpsText = String.format("TEST DONE: fps %.2f", perfTracker.getInstantFPS()); System.out.println(fpsText); Platform.exit(); } }); autoTL.getKeyFrames().add(endWarmupKF); autoTL.getKeyFrames().add(endTestKF); Timeline fpsTimeline = new Timeline(); fpsTimeline.setCycleCount(Timeline.INDEFINITE); KeyFrame fpsKeyFrame = new KeyFrame(Duration.valueOf(1000), new EventHandler() { @Override public void handle(ActionEvent e) { String fpsText = String.format("FPS: %.2f", perfTracker.getInstantFPS()); System.out.println(fpsText); } }); fpsTimeline.getKeyFrames().add(fpsKeyFrame); treeView = createTreeView(); rootGroup.getChildren().add(treeView); AnimationTimer PerfRunner = new AnimationTimer() { boolean stop = false; @Override public void handle(long l) { stage.setTitle("Iters " + iters); expandTreeView(treeView, (iters %2 == 0) ); iters++; } }; autoTL.play(); fpsTimeline.play(); PerfRunner.start(); } public static void main(String[] args) { for (int index = 0; index < args.length; index++) { String arg = args[index]; if ("-size".equals(arg)) { if (index+1 >= args.length) { System.err.println("-size option requires an integer argument"); System.exit(1); } try { TABLEVIEW_SIZE = Integer.parseInt(args[index+1]); } catch (IllegalArgumentException e) { System.err.println("-allocCnt option must be integer]"); System.exit(1); } index++; } else if ("-type".equals(arg)) { if (index+1 >= args.length) { System.err.println("-type option requires an argument"); System.exit(1); } try { treeViewType = treeViewType.valueOf(args[index+1].toUpperCase()); } catch (IllegalArgumentException e) { System.err.println("-type option must be from {wide, depth}"); System.exit(1); } index++; } } System.out.println("TableView size: " + TABLEVIEW_SIZE); System.out.println("TableView type: " + treeViewType); Application.launch(TreeViewExpandPerfTest.class, args); } }