378
|
1 package alice.test.topology.aquarium.fx;
|
|
2
|
|
3 import javafx.application.Platform;
|
|
4 import javafx.scene.Group;
|
|
5 import javafx.scene.Node;
|
|
6 import alice.codesegment.CodeSegment;
|
|
7 import alice.datasegment.CommandType;
|
|
8 import alice.datasegment.Receiver;
|
|
9
|
|
10 public class AddObject extends CodeSegment {
|
419
|
11 // add Object on javaFx Scene
|
467
|
12 private Receiver info = ids.create(CommandType.TAKE); // objectList
|
|
13 private Receiver info1 = ids.create(CommandType.TAKE); // fish Object made from CreateObject CS
|
419
|
14 private Receiver info2 = ids.create(CommandType.PEEK); // node name
|
|
15 private boolean executed = false;
|
|
16
|
|
17 public AddObject(){
|
547
|
18 info.setKey("root", this);
|
|
19 info1.setKey("addOffer", this);
|
|
20 info2.setKey("host", this);
|
419
|
21 }
|
|
22
|
|
23 @Override
|
|
24 public void run() {
|
|
25
|
|
26
|
|
27 if (!executed) {
|
|
28 executed = true;
|
|
29 // javafx's Scene can be accessed only FX application thread.
|
|
30 Platform.runLater(this);
|
|
31 } else {
|
|
32 boolean duplication = false;
|
|
33 Group root = info.asClass(Group.class);
|
|
34 Group obj = info1.asClass(Group.class);
|
|
35 String myName = info2.asString();
|
405
|
36
|
419
|
37 for (Node n : root.getChildren()){
|
|
38 if (n.getId().equals(obj.getId()))
|
|
39 duplication = true;
|
|
40 }
|
|
41
|
|
42 if (!duplication) {
|
|
43 root.getChildren().add(obj);
|
|
44 System.out.println(obj.getId()+" add");
|
|
45 ods.put(obj.getId()+"Fish", obj);
|
|
46
|
467
|
47 // controlled own fish
|
419
|
48 if (myName.equals(obj.getId())){
|
|
49 new CalculatePosition(obj.getId()+"FishdiffP");
|
|
50 }
|
|
51 new SetTranslate(obj.getId()+"Fish");
|
|
52
|
|
53 FishInfo fishInfo = new FishInfo();
|
|
54 fishInfo.name = obj.getId();
|
|
55 fishInfo.size = obj.getScaleX();
|
|
56 ods.put("register", fishInfo);
|
|
57 }
|
|
58 ods.flip(info);
|
|
59 new AddObject();
|
|
60 }
|
|
61 }
|
|
62
|
378
|
63
|
|
64 }
|