package de.prob2.ui.formula;

import java.util.ArrayList;
import java.util.List;

import de.prob.animator.domainobjects.ExpandedFormula;
import javafx.scene.layout.Region;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Ellipse;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;


public class FormulaNode extends Region {
		
	//private Ellipse ellipse;
	private Rectangle rectangle;
	private Text text;
	private Color color;
	public List<FormulaNode> next;
	
	public FormulaNode(ExpandedFormula data) {
		next = new ArrayList<FormulaNode>();
		text = new Text(data.getLabel());
		double width = text.getLayoutBounds().getWidth();
		double height = text.getLayoutBounds().getHeight();
		rectangle = new Rectangle(width + 10, height * 2);
		color = calculateColor(data);
		if(data.getChildren() == null || data.getChildren().isEmpty()) {
			return;
		}
		for(int i = 0; i < data.getChildren().size(); i++) {
			next.add(new FormulaNode(data.getChildren().get(i)));
		}
		
	}
		
	public FormulaNode(double centerX, double centerY, ExpandedFormula data) {
		this(data);
		setPosition(centerX, centerY);
	}
	

	
	public void setPosition(double x, double y) {
		double width = text.getLayoutBounds().getWidth();
		double height = text.getLayoutBounds().getHeight();
		text.setX(x + 5);
		text.setY(y);
		rectangle.setX(x);
		rectangle.setY(y - height);
		
		draw();
	}
	
	public double getLeft() {
		return rectangle.getX();
	}
	
	public double getRight() {
		return rectangle.getX() + rectangle.getWidth();
	}
	
	public double getX() {
		return getLeft();
	}

	public double getY() {
		return rectangle.getY() + 0.5 * rectangle.getHeight();
	}
	
	
	private void draw() {
		text.setFill(Color.BLACK);
		rectangle.setStroke(Color.BLACK);
		setFill(color);
		this.getChildren().add(rectangle);
		this.getChildren().add(text);
	}
	
	private Color calculateColor(ExpandedFormula data) {
		if(data.getValue() instanceof Boolean && (Boolean) data.getValue() == false) {
			return Color.ORANGERED;
		}
		return Color.LIME;
	}
	
	
	private void setFill(Paint value) {
		rectangle.setFill(value);
	}
	
	public String toString() {
		return text.getText();
	}
	

}

@@ -634,16 +634,123 @@
 bel());%0A
+%09%09if(data.getValue() instanceof String) %7B%0A%09%09%09text.setText(text.getText() + %22 = %22 + data.getValue());%09%09%0A%09%09%7D%0A
 %09%09double
@@ -1858,16 +1858,78 @@
 BLACK);%0A
+%09%09if(color == Color.GRAY) %7B%0A%09%09%09text.setFill(Color.WHITE);%0A%09%09%7D%0A
 %09%09rectan
@@ -2138,19 +2138,52 @@
 eof 
-Boolean && 
+String) %7B%0A%09%09%09return Color.GRAY;%0A%09%09%7D else if(
 (Boo

Improve FormulaNode