changeset 6:ae0a39622a58

add Position controller
author e095732
date Mon, 28 Jan 2013 16:29:47 +0900
parents 1245abe6625f
children 75f7a75bec83
files src/alice/test/topology/aquarium/fx/AddObject.java src/alice/test/topology/aquarium/fx/Aquarium.java src/alice/test/topology/aquarium/fx/AquariumController.java src/alice/test/topology/aquarium/fx/FishData.java src/alice/test/topology/aquarium/fx/PositionController.java src/alice/test/topology/aquarium/fx/SetTranslation.java
diffstat 6 files changed, 71 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/test/topology/aquarium/fx/AddObject.java	Mon Jan 28 00:25:01 2013 +0900
+++ b/src/alice/test/topology/aquarium/fx/AddObject.java	Mon Jan 28 16:29:47 2013 +0900
@@ -9,6 +9,7 @@
 import javafx.collections.ObservableList;
 import javafx.scene.Node;
 import javafx.scene.paint.Color;
+import javafx.scene.shape.Rectangle;
 import javafx.scene.shape.RectangleBuilder;
 
 public class AddObject extends CodeSegment{
@@ -29,20 +30,18 @@
 				double size = 75;
 				Color color = Color.RED;
 				Random rnd = new Random();
-				ObjectList obj = new ObjectList();
 				for (int i = 0;i < num; i++){
-					obj.list.add(RectangleBuilder.create()
+					Rectangle rect = RectangleBuilder.create()
 							.width(size).height(size)
 							.fill(color.deriveColor(0.0, 1.0, 1.0, 1.0))
 							.translateX(rnd.nextInt(600))
 							.translateY(rnd.nextInt(600))
 							.translateZ(0)
 							.id("FISH"+i)
-							.build());
-				}
-				for (int i = 0;i < num; i++){
-					new SetTranslation(obj.list.get(i), "FISH"+i);
-					list.add(obj.list.get(i));
+							.build();
+					new SetTranslation(rect ,rect.getId());
+					list.add(rect);
+					new PositionController(rect.getId());
 				}
 				System.out.println("Create OBJ " + num);
 				System.out.println(list);
--- a/src/alice/test/topology/aquarium/fx/Aquarium.java	Mon Jan 28 00:25:01 2013 +0900
+++ b/src/alice/test/topology/aquarium/fx/Aquarium.java	Mon Jan 28 16:29:47 2013 +0900
@@ -24,7 +24,7 @@
 	public void start(Stage primaryStage) throws IOException {
 		root = FXMLLoader.load(getClass().getResource("aquarium.fxml"));
 		// AquariumController cont = (AquariumController) loader.getController(); get Controller instance
-		ImageView iv = (ImageView) root.getChildren().get(3);
+		ImageView iv = (ImageView) root.getChildren().get(1);
 		Image img = new Image("fish.jpg");
 		iv.setImage(img);
 		list = root.getChildren();
--- a/src/alice/test/topology/aquarium/fx/AquariumController.java	Mon Jan 28 00:25:01 2013 +0900
+++ b/src/alice/test/topology/aquarium/fx/AquariumController.java	Mon Jan 28 16:29:47 2013 +0900
@@ -4,14 +4,13 @@
 import javafx.scene.control.TextField;
 import javafx.scene.image.ImageView;
 import javafx.scene.input.KeyEvent;
-import javafx.scene.shape.Rectangle;
 
 public class AquariumController {
 	
-	@FXML private Rectangle rect1;
-	@FXML private Rectangle rect2;
-	@FXML private TextField text;
-	@FXML private ImageView image;
+	@FXML 
+	private TextField text;
+	@FXML 
+	private ImageView image;
 	
 	public AquariumController(){
 		System.out.println("run JavaFX");	
--- a/src/alice/test/topology/aquarium/fx/FishData.java	Mon Jan 28 00:25:01 2013 +0900
+++ b/src/alice/test/topology/aquarium/fx/FishData.java	Mon Jan 28 16:29:47 2013 +0900
@@ -22,5 +22,15 @@
 		y = _y;
 		z = _z;
 	}
+	
+	public void SetXYZ(double _x, double _y, double _z){
+		x = _x;
+		y = _y;
+		z = _z;
+	}
+	
+	public double getX(){ return x;}
+	public double getY(){ return y;}
+	public double getZ(){ return z;}
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/alice/test/topology/aquarium/fx/PositionController.java	Mon Jan 28 16:29:47 2013 +0900
@@ -0,0 +1,49 @@
+package alice.test.topology.aquarium.fx;
+
+import alice.codesegment.CodeSegment;
+import alice.datasegment.CommandType;
+import alice.datasegment.Receiver;
+
+public class PositionController extends CodeSegment{
+	
+	private Receiver data = ids.create(CommandType.PEEK);
+	double max = 600;
+	
+	public PositionController(String key){
+		this.data.setKey(key);
+	}
+	
+	public PositionController(String key ,int index){
+		this.data.setKey(key, index);
+	}
+
+	@Override
+	public void run() {
+		//System.out.println(data.val);
+		synchronized(this){
+			try {
+				// TODO
+				// Waiting should be done in Alice kernel
+				// ids.create(CommandType.WAIT);
+			 
+				wait(20);
+		
+		FishData fd = data.asClass(FishData.class);
+		if(fd.getX()+2.0>max){
+			System.out.println("over");
+			fd.SetXYZ(50, fd.getY(), fd.getZ());
+			
+		} else {
+			
+			fd.SetXYZ(fd.getX()+3.0, fd.getY(), fd.getZ());
+		}
+
+		new PositionController(data.key, data.index);
+		ods.update("local", data.key, fd);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+
+}
--- a/src/alice/test/topology/aquarium/fx/SetTranslation.java	Mon Jan 28 00:25:01 2013 +0900
+++ b/src/alice/test/topology/aquarium/fx/SetTranslation.java	Mon Jan 28 16:29:47 2013 +0900
@@ -23,6 +23,7 @@
 	}
 
 	public SetTranslation(Rectangle rect, String key){
+		ods.put("local", key, new FishData(rect.getTranslateX(),rect.getTranslateY(),rect.getTranslateZ()));
 		this.rect = rect;
 		data.setKey(key);
 	}