375
|
1 package alice.test.topology.aquarium.fx;
|
|
2
|
|
3 import java.io.IOException;
|
|
4
|
377
|
5 import alice.codesegment.OutputDataSegment;
|
375
|
6 import javafx.application.Application;
|
377
|
7 import javafx.event.EventHandler;
|
|
8 import javafx.scene.Group;
|
|
9 import javafx.scene.Parent;
|
|
10 import javafx.scene.PerspectiveCamera;
|
375
|
11 import javafx.scene.Scene;
|
377
|
12 import javafx.scene.SceneAntialiasing;
|
|
13 import javafx.scene.SubScene;
|
|
14 import javafx.scene.input.KeyEvent;
|
|
15 import javafx.scene.paint.Color;
|
|
16 import javafx.scene.transform.Rotate;
|
|
17 import javafx.scene.transform.Translate;
|
375
|
18 import javafx.stage.Stage;
|
381
|
19 import javafx.stage.WindowEvent;
|
375
|
20
|
|
21 public class Aquarium extends Application {
|
377
|
22
|
|
23 private OutputDataSegment ods = new OutputDataSegment();
|
375
|
24
|
|
25 @Override
|
|
26 public void start(Stage primaryStage) throws IOException {
|
387
|
27 String myName = getParameters().getRaw().get(0); // name
|
|
28 primaryStage.setTitle("Aquarium "+ myName);
|
375
|
29 primaryStage.setResizable(false);
|
381
|
30 primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
|
|
31 @Override
|
|
32 public void handle(WindowEvent event) {
|
384
|
33 // should send finish DataSegment
|
381
|
34 System.exit(0);
|
|
35 }
|
|
36 });
|
|
37
|
377
|
38 Scene scene = new Scene(createContent());
|
|
39 scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
|
|
40 public void handle(KeyEvent t) {
|
394
|
41 FishInfo info = null;
|
381
|
42 switch (t.getCode()) {
|
|
43 case RIGHT:
|
394
|
44 info = new FishInfo(0.1,0,0);
|
|
45 info.rolY = -1;
|
|
46 info.rotate = 90;
|
381
|
47 break;
|
|
48 case LEFT:
|
394
|
49 info = new FishInfo(-0.1,0,0);
|
|
50 info.rolY = 1;
|
|
51 info.rotate = 90;
|
381
|
52 break;
|
|
53 case UP:
|
394
|
54 info = new FishInfo(0,-0.1,0);
|
|
55 info.rolX = -1;
|
|
56 info.rotate = 90;
|
381
|
57 break;
|
|
58 case DOWN:
|
394
|
59 info = new FishInfo(0,0.1,0);
|
|
60 info.rolX = 1;
|
|
61 info.rotate = 90;
|
387
|
62 break;
|
|
63 case N:
|
394
|
64 info = new FishInfo(0,0,0.1);
|
|
65 info.rolX = -1;
|
387
|
66 break;
|
|
67 case M:
|
394
|
68 info = new FishInfo(0,0,-0.1);
|
|
69 info.rotate = 180;
|
381
|
70 break;
|
|
71 default: // do nothing
|
394
|
72 // reset. send median position. after implement
|
381
|
73 break;
|
|
74 }
|
394
|
75 ods.update(myName+"FishdiffP", info);
|
377
|
76 }
|
|
77 });
|
|
78 primaryStage.setScene(scene);
|
375
|
79 primaryStage.show();
|
|
80 }
|
|
81
|
377
|
82 private Parent createContent(){
|
|
83 Group root = new Group();
|
378
|
84 ods.put("root", root);
|
377
|
85
|
|
86 // Create and position camera
|
|
87 PerspectiveCamera camera = new PerspectiveCamera(true);
|
|
88 camera.getTransforms().addAll(
|
384
|
89 new Rotate(0, Rotate.Y_AXIS),
|
|
90 new Rotate(0, Rotate.X_AXIS),
|
377
|
91 new Translate(0, 0, -15));
|
379
|
92 camera.setId("camera");
|
377
|
93
|
379
|
94 root.getChildren().add(camera);
|
377
|
95
|
|
96 // Use a SubScene
|
|
97 SubScene subScene = new SubScene(root, 800, 700, true, SceneAntialiasing.BALANCED);
|
|
98 subScene.setFill(Color.TRANSPARENT);
|
|
99 subScene.setCamera(camera);
|
|
100 Group parent = new Group(subScene);
|
387
|
101
|
377
|
102 return parent;
|
|
103 }
|
|
104
|
|
105
|
375
|
106 public static void main(String[] args) {
|
|
107 launch(args);
|
|
108 }
|
377
|
109
|
375
|
110 }
|