view src/main/java/alice/test/topology/aquarium/fx/AddObject.java @ 547:e91a574b69de dispose

remove index
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Tue, 18 Aug 2015 16:15:17 +0900
parents 15eeb439830c
children
line wrap: on
line source

package alice.test.topology.aquarium.fx;

import javafx.application.Platform;
import javafx.scene.Group;
import javafx.scene.Node;
import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class AddObject extends CodeSegment {
    // add Object on javaFx Scene
    private Receiver info = ids.create(CommandType.TAKE);  // objectList
    private Receiver info1 = ids.create(CommandType.TAKE); // fish Object made from CreateObject CS
    private Receiver info2 = ids.create(CommandType.PEEK); // node name
    private boolean executed = false;

    public AddObject(){
        info.setKey("root", this);
        info1.setKey("addOffer", this);
        info2.setKey("host", this);
    }

    @Override
    public void run() {


        if (!executed) {
            executed = true;
            // javafx's Scene can be accessed only FX application thread.
            Platform.runLater(this);
        } else {
            boolean duplication = false;
            Group root = info.asClass(Group.class);
            Group obj = info1.asClass(Group.class);
            String myName = info2.asString();

            for (Node n : root.getChildren()){
                if (n.getId().equals(obj.getId()))
                    duplication = true;
            }

            if (!duplication) {
                root.getChildren().add(obj);
                System.out.println(obj.getId()+" add");
                ods.put(obj.getId()+"Fish", obj);

                // controlled own fish
                if (myName.equals(obj.getId())){
                    new CalculatePosition(obj.getId()+"FishdiffP");
                }
                new SetTranslate(obj.getId()+"Fish");

                FishInfo fishInfo = new FishInfo();
                fishInfo.name = obj.getId();
                fishInfo.size = obj.getScaleX();
                ods.put("register", fishInfo);
            }
            ods.flip(info);
            new AddObject();
        }
    }


}