view src/main/java/alice/test/topology/aquarium/fx/AddObject.java @ 405:c817721af5ec dispose

change timing create addObject code segment
author sugi
date Tue, 24 Jun 2014 13:38:34 +0900
parents ca92da166f1a
children d28b1216d615
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");
		info1.setKey("addOffer");
		info2.setKey("host");
	}
	
	@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);
				ods.put(obj.getId()+"Fish", obj);

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

}