375
|
1 package alice.test.topology.aquarium.fx;
|
|
2
|
522
|
3 import java.awt.image.BufferedImage;
|
375
|
4 import java.io.IOException;
|
522
|
5 import java.net.URL;
|
|
6
|
|
7 import javax.imageio.ImageIO;
|
375
|
8
|
377
|
9 import alice.codesegment.OutputDataSegment;
|
375
|
10 import javafx.application.Application;
|
522
|
11 import javafx.embed.swing.SwingFXUtils;
|
377
|
12 import javafx.event.EventHandler;
|
|
13 import javafx.scene.Group;
|
|
14 import javafx.scene.Parent;
|
|
15 import javafx.scene.PerspectiveCamera;
|
375
|
16 import javafx.scene.Scene;
|
377
|
17 import javafx.scene.SceneAntialiasing;
|
|
18 import javafx.scene.SubScene;
|
522
|
19 import javafx.scene.image.ImageView;
|
|
20 import javafx.scene.image.WritableImage;
|
377
|
21 import javafx.scene.input.KeyEvent;
|
|
22 import javafx.scene.paint.Color;
|
|
23 import javafx.scene.transform.Rotate;
|
|
24 import javafx.scene.transform.Translate;
|
375
|
25 import javafx.stage.Stage;
|
381
|
26 import javafx.stage.WindowEvent;
|
375
|
27
|
|
28 public class Aquarium extends Application {
|
377
|
29
|
419
|
30 private OutputDataSegment ods = new OutputDataSegment();
|
|
31
|
|
32 @Override
|
|
33 public void start(Stage primaryStage) throws IOException {
|
618
|
34 String myName = getParameters().getRaw().get(0); // name
|
467
|
35 primaryStage.setTitle("Aquarium "+ myName);
|
419
|
36 primaryStage.setResizable(false);
|
|
37 primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
|
|
38 @Override
|
|
39 public void handle(WindowEvent event) {
|
|
40 // should send finish DataSegment
|
|
41 System.exit(0);
|
467
|
42 }
|
419
|
43 });
|
375
|
44
|
419
|
45 Scene scene = new Scene(createContent());
|
522
|
46 scene.setFill(Color.color(0.2, 0.5, 1.0));
|
419
|
47 scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
|
|
48 public void handle(KeyEvent t) {
|
|
49 FishInfo info = null;
|
|
50 switch (t.getCode()) {
|
|
51 case RIGHT:
|
|
52 info = new FishInfo(0.1,0,0);
|
|
53 info.rolY = -1;
|
|
54 info.rotate = 90;
|
|
55 break;
|
|
56 case LEFT:
|
|
57 info = new FishInfo(-0.1,0,0);
|
|
58 info.rolY = 1;
|
|
59 info.rotate = 90;
|
|
60 break;
|
|
61 case UP:
|
|
62 info = new FishInfo(0,-0.1,0);
|
|
63 info.rolX = -1;
|
|
64 info.rotate = 90;
|
|
65 break;
|
|
66 case DOWN:
|
|
67 info = new FishInfo(0,0.1,0);
|
|
68 info.rolX = 1;
|
|
69 info.rotate = 90;
|
|
70 break;
|
|
71 case N:
|
|
72 info = new FishInfo(0,0,0.1);
|
|
73 break;
|
|
74 case M:
|
|
75 info = new FishInfo(0,0,-0.1);
|
|
76 info.rotate = 180;
|
|
77 break;
|
|
78 default: // do nothing
|
|
79 // reset. send median position. after implement
|
|
80 info = new FishInfo(0,0,0);
|
|
81 break;
|
|
82 }
|
|
83 ods.update(myName+"FishdiffP", info);
|
|
84 }
|
|
85 });
|
|
86 primaryStage.setScene(scene);
|
|
87 primaryStage.show();
|
|
88 }
|
377
|
89
|
419
|
90 private Parent createContent(){
|
|
91 Group root = new Group();
|
|
92 ods.put("root", root);
|
377
|
93
|
419
|
94 // Create and position camera
|
|
95 PerspectiveCamera camera = new PerspectiveCamera(true);
|
|
96 camera.getTransforms().addAll(
|
|
97 new Rotate(0, Rotate.Y_AXIS),
|
|
98 new Rotate(0, Rotate.X_AXIS),
|
|
99 new Translate(0, 0, -15));
|
|
100 camera.setId("camera");
|
522
|
101 root.getChildren().add(camera);
|
377
|
102
|
522
|
103 BufferedImage img = null;
|
|
104 try {
|
|
105 URL url = getClass().getClassLoader().getResource("images/IKAMUSUME.jpg");
|
|
106 img = ImageIO.read(url);
|
|
107 } catch (IOException e) {
|
|
108 e.printStackTrace();
|
|
109 }
|
|
110 WritableImage wimg = SwingFXUtils.toFXImage(img, null);
|
|
111 ImageView iview = new ImageView(wimg);
|
|
112 iview.setFitWidth(11);
|
|
113 iview.setFitHeight(11);
|
|
114 iview.setTranslateX(-5.5);
|
|
115 iview.setTranslateY(-5.5);
|
|
116 iview.setTranslateZ(6.0);
|
|
117 iview.setId("IKAMUSUME");
|
|
118 root.getChildren().add(iview);
|
387
|
119
|
419
|
120 // Use a SubScene
|
|
121 SubScene subScene = new SubScene(root, 800, 700, true, SceneAntialiasing.BALANCED);
|
|
122 subScene.setFill(Color.TRANSPARENT);
|
|
123 subScene.setCamera(camera);
|
|
124 Group parent = new Group(subScene);
|
|
125
|
|
126 return parent;
|
|
127 }
|
377
|
128
|
419
|
129 public static void main(String[] args) {
|
|
130 launch(args);
|
|
131 }
|
377
|
132
|
375
|
133 }
|