view src/main/java/alice/test/topology/aquarium/fx/AddObject.java @ 397:ca92da166f1a multicast

check All fish object in own scene om CheckAllFishInfoExist code segment
author sugi
date Sun, 22 Jun 2014 21:06:40 +0900
parents 878d397904da
children c817721af5ec
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.PEEK);  // objectList 
	private Receiver info1 = ids.create(CommandType.TAKE); // fish Object made from CreateObject CS 
	private boolean executed = false;
	
	public AddObject(){
		info.setKey("root");
		info1.setKey("addOffer");
	}
	
	@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);
			
			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);
			new AddObject();
		}	
	}
	

}