/*******************************************************************************
* Copyright 2014 Miami-Dade County
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package cirmlive;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.CacheHint;
import javafx.scene.DepthTest;
import javafx.scene.Parent;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.SubScene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.transform.Rotate;
import javafx.scene.transform.Translate;
import javafx.stage.Stage;
/**
* An experimental 3d version of CirmLive.
* Navigate by using the buttons on the bottom of the window.
* The purpose of this experiment
*
* @author Thomas Hilpold
*/
public class CiRMLive3d extends Application{
public final static String TITLE = "3D Miami-Dade County CiRM Live ! - Experimental JavaFX Prototype v 2014.07.07 (hilpold)";
CiRMLive cirmLive;
Button leftBt = new Button("LEFT");
Button forwardBt = new Button("FORWARD");
Button rightBt = new Button("RIGHT");
Button backBt = new Button("BACK");
Button upBt = new Button("UP");
Button downBt = new Button("DOWN");
Button lookLeftBt = new Button("LOOK_LEFT");
Button lookRightBt = new Button("LOOK_RIGHT");
Translate cameraTranslate = new Translate(700,400,-800);
Rotate cameraRotate = new Rotate(0);
public Parent createContent() {
BorderPane p = new BorderPane();
HBox btBox = new HBox(50, leftBt, lookLeftBt, forwardBt, upBt, downBt, backBt, lookRightBt, rightBt);
btBox.alignmentProperty().set(Pos.CENTER);
p.setBottom(btBox);
setUpButtons();
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.getTransforms().add(cameraTranslate);
camera.getTransforms().add(cameraRotate);
camera.setFieldOfView(50);
camera.setFarClip(10000);
camera.setNearClip(1);
p.setDepthTest(DepthTest.ENABLE);
BorderPane cirmLiveUI = cirmLive.createSceneContent();
cirmLiveUI.setCache(true);
cirmLiveUI.setCacheShape(true);
cirmLiveUI.setCacheHint(CacheHint.QUALITY);
//cirmLiveUI.setSsetAlignment(camera, Pos.CENTER);
//cirmLiveUI.setTranslateZ(500);
//TODO root.getChildren().addAll(c, c2, c3);
SubScene subScene = new SubScene(cirmLiveUI, 1600, 900, true, SceneAntialiasing.BALANCED);
subScene.setFill(Color.CORAL);
subScene.setCamera(camera);
p.setCenter(subScene);
return p;
}
public void setUpButtons() {
int speed = 100;
leftBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
cameraTranslate.setX(cameraTranslate.getX() - speed);
}
});
rightBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
cameraTranslate.setX(cameraTranslate.getX() + speed);
}
});
upBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
cameraTranslate.setY(cameraTranslate.getY() - speed);
}
});
downBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
cameraTranslate.setY(cameraTranslate.getY() + speed);
}
});
forwardBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
cameraTranslate.setZ(cameraTranslate.getZ() + speed);
}
});
backBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
cameraTranslate.setZ(cameraTranslate.getZ() - speed);
}
});
lookLeftBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
double angle = cameraRotate.getAngle();
cameraRotate.setAxis(Rotate.Y_AXIS);
cameraRotate.setPivotX(0);
cameraRotate.setPivotY(0);
cameraRotate.setPivotZ(0);
cameraRotate.setAngle(angle - 10);
}
});
lookRightBt.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
double angle = cameraRotate.getAngle();
cameraRotate.setAxis(Rotate.Y_AXIS);
cameraRotate.setPivotX(0);
cameraRotate.setPivotY(0);
cameraRotate.setPivotZ(0);
cameraRotate.setAngle(angle + 10);
}
});
}
@Override
public void start(Stage primaryStage) throws Exception {
setUserAgentStylesheet(STYLESHEET_CASPIAN);
cirmLive = new CiRMLive();
cirmLive.initClusterStats();
Parent content = createContent();
Scene topScene = new Scene(content, 1600, 900, true, SceneAntialiasing.BALANCED);
topScene.setFill(Color.gray(0.1));
primaryStage.setScene(topScene);
primaryStage.setTitle(TITLE);
primaryStage.setWidth(1600);
primaryStage.setHeight(950);
primaryStage.show();
if (cirmLive.dateList.size() > 0) cirmLive.updateCurrentPieChart();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}