package com.xmunch.atomspace.visualization;

import com.xmunch.atomspace.aux.GlobalValues;
import com.xmunch.atomspace.aux.VertexType;
import com.xmunch.atomspace.aux.VisualizationParams;

public class VisualizationSpace {
	private UbigraphClient graph;

	public VisualizationSpace() {
		graph = new UbigraphClient();
		graph.clear();
		setEdgeStyle();
	}
	
	public void removeEdge(String id) {
		graph.removeEdge(Integer.valueOf(id));
	}

	public void createEdge(String edgeLabel, String from, String to) {
		Integer identifier = graph.newEdge(Integer.valueOf(from), Integer.valueOf(to));
		graph.setEdgeAttribute(
				identifier, 
				VisualizationParams.LABEL.get(),
				edgeLabel);
	}

	public void removeVertex(String id) {
		graph.removeVertex(Integer.valueOf(id));
	}
	
	public void createVertex(String id, String vertexType, String label) {
		Integer identifier = Integer.valueOf(id);
		graph.newVertex(identifier);
		
		graph.setVertexAttribute(
				identifier, 
				VisualizationParams.SHAPE.get(),
				VisualizationParams.SPHERE.get());
		
		graph.setVertexAttribute(
				identifier,
				VisualizationParams.SIZE.get(),
				GlobalValues.ONE.get());
		
		graph.setVertexAttribute(
				identifier,
				VisualizationParams.LABEL.get(),
				label);
		
		graph.setVertexAttribute(
				identifier,
				VisualizationParams.COLOR.get(),
				getTypeColor(vertexType));
		
		graph.setVertexAttribute(
				identifier,
				VisualizationParams.FONT_COLOR.get(),
				getTypeColor(vertexType));
	
	}

	private String getTypeColor(String vertexType) {
		String color = new String();
		
		switch (VertexType.valueOf(vertexType)){
		case A:
			color = GlobalValues.BLUE.get();
			break;
		case B:
			color = GlobalValues.GREEN.get();
			break;
		case C:
			color = GlobalValues.YELLOW.get();
			break;
		case D:
			color = GlobalValues.WHITE.get();
			break;
		case E:
			color = GlobalValues.PINK.get();
			break;
		case F:
			color = GlobalValues.RED.get();
			break;
		}
		
		return color;
	}

	private void setEdgeStyle() {
		graph.setEdgeStyleAttribute(0, VisualizationParams.WIDTH.get(), GlobalValues.ONE.get());
		graph.setEdgeStyleAttribute(0, VisualizationParams.COLOR.get(), GlobalValues.YELLOW.get());
		graph.setEdgeStyleAttribute(0, VisualizationParams.ARROW.get(), GlobalValues.TRUE.get());
	}

}

@@ -579,24 +579,112 @@
 lueOf(to));%0A
+%09%09String label = new String();%0A%09%09%0A%09%09if(edgeLabel != null)%7B%0A%09%09%09label = edgeLabel;%0A%09%09%7D%0A%09%09%0A
 %09%09graph.setE
@@ -689,32 +689,32 @@
 tEdgeAttribute(%0A
-
 %09%09%09%09identifier, 
@@ -755,21 +755,17 @@
 (),%0A%09%09%09%09
-edgeL
+l
 abel);%0A%09
@@ -1541,39 +1541,39 @@
 (),%0A%09%09%09%09
-getTypeColor(vertexType
+GlobalValues.WHITE.get(
 ));%0A%09%0A%09%7D
@@ -1795,13 +1795,11 @@
 ues.
-G
 RE
-EN
+D
 .get
@@ -1987,63 +1987,8 @@
 ak;%0A
-%09%09case F:%0A%09%09%09color = GlobalValues.RED.get();%0A%09%09%09break;%0A
 %09%09%7D%0A
@@ -2112,34 +2112,36 @@
 ), GlobalValues.
-ON
+THRE
 E.get());%0A%09%09grap
@@ -2209,30 +2209,121 @@
 lobalValues.
-YELLOW
+GREEN.get());%0A%09%09graph.setEdgeStyleAttribute(0, VisualizationParams.ARROW.get(), GlobalValues.TRUE
 .get());%0A%09%09g
@@ -2369,32 +2369,41 @@
 tionParams.ARROW
+_POSITION
 .get(), GlobalVa
@@ -2407,27 +2407,323 @@
 lValues.
-TRUE.get());
+ONE.get());%0A%09%09graph.setEdgeStyleAttribute(0, VisualizationParams.STROKE.get(), VisualizationParams.DASHED.get());%0A%09%09graph.setEdgeStyleAttribute(0, VisualizationParams.FONT_COLOR.get(),GlobalValues.YELLOW.get());%0A%09%09graph.setEdgeStyleAttribute(0, VisualizationParams.STRENGTH.get(),GlobalValues.HALF.get());%0A%09%09
 %0A%09%7D%0A%0A%7D%0A

Solve bugs in VisualizationSpace