package visualization;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.Area;

import background.systemVariables.SimpleVariable;

public class Design {	
	
	public Font valueFont = new Font("Arial", Font.PLAIN, 20);
	public Font nameFont = new Font("Arial", Font.ITALIC, 19);

	public int offsetWidth = 10;
	public int offsetHeight = 6;
	public int vizArc = 3;
	public int vizWidth;
	public int vizHeight;
	public int defWidth = 30;
	public int defHeight = 30;
	public int multipleValueOffset = 0;
	
	public DesignColorSet colors;
	
	public Design(String s) {
		colors = DesignColorSet.getColorByName(s);
		recalculateMultiplicator(1);
	}
	
	
	public void recalculateMultiplicator(int i ) { recalculateMultiplicator(i, 1); }
	public void recalculateMultiplicator(int i, int j) {		
		vizWidth = i*defWidth;
		vizHeight = j*defHeight;
	}
	
	public void drawIt(Graphics2D g, Area shape, Color basicColor, Boolean fill, Color fillColor, Color activeFillColor) { drawIt(g, shape, basicColor, false, Color.BLACK, fill, fillColor, activeFillColor); 	}
	public void drawIt(Graphics2D g, Area shape, Color basicColor) { drawIt(g, shape, basicColor, false, Color.BLACK, false, Color.BLACK, Color.BLACK); }
	public void drawIt(Graphics2D g, Area shape, Color basicColor, Boolean isActive, Color activeColor) { drawIt(g, shape, basicColor, isActive, activeColor, false, Color.BLACK, Color.BLACK); }
	
	public void drawIt(Graphics2D g, Area shape, Color basicColor, Boolean isActive, Color activeColor, Boolean fill, Color fillColor, Color activeFillColor) {			
		if (fill) { g.setColor(fillColor);
       		if (isActive) g.setColor(activeFillColor);        		
       		g.fill(shape); 
       	}
       	       	
       	g.setColor(basicColor);
		if (isActive) g.setColor(activeColor);        	
       	g.draw(shape);
	}
		
	public void drawIt(Graphics2D g, String s, Font f, Color basicColor, Boolean isActive, Color activeColor, int x, int y) {
		g.setFont(f);
		g.setColor(basicColor);
		if (isActive) g.setColor(activeColor); 
        g.drawString(s, x, y);	                		
	}

	
	public Area getAreaFromString(Graphics2D g, String s, Font f) {
		GlyphVector v = f.createGlyphVector(g.getFontMetrics(f).getFontRenderContext(), s);
        Shape value = v.getOutline();
        return new Area(value);                		
	}

	public void moveAreaTo(Area a, int x, int y) {
        AffineTransform at = new AffineTransform();        
        at.translate(x, y);
        a.transform(at);
	}	
	
	public int[] getDimensions(Graphics2D g, SimpleVariable var) {
		int[] dim = new int[2];
		Rectangle bounds = getAreaFromString(g,var.getValue("string"),valueFont).getBounds();
		dim[0] = bounds.width + 2*offsetWidth;
		dim[1] = bounds.height + 2*offsetHeight;
		return dim;
	}
	
	public Area getMultipleValueDesignBorder(Graphics2D g, Boolean draw, int x, int y, int width, int height, int values) {		
		return getMultipleValueDesignBorder(g, draw, x, y, width, height, values, 1);
	}
	
	public Area getMultipleValueDesignBorder(Graphics2D g, Boolean draw, int x, int y, int width, int height, int valuesX, int valuesY) {		
		return new Area();
	}

	
	public Area getDesignBorder(Graphics2D g, Boolean draw, Boolean active, int x, int y, int width, int height) {
		return getDesignBorder(g, draw, active, x, y, width, height, 1, 1);
	}
	
	public Area getDesignBorder(Graphics2D g, Boolean draw, Boolean active, int x, int y, int width, int height, int valueNumberX) {
		return getDesignBorder(g, draw, active, x, y, width, height, valueNumberX, 1);
	}
	
	public Area getDesignBorder(Graphics2D g, Boolean draw, Boolean active, int x, int y, int width, int height, int valueNumberX, int valueNumberY) {
		return new Area();
	}
		
	public Area getDesignValueShape(Graphics2D g,Boolean draw, SimpleVariable var, int x, int y) {       					
		return getDesignValueShape(g, draw, var, x, y, 1, 1);
	}

	public Area getDesignValueShape(Graphics2D g,Boolean draw, SimpleVariable var, int x, int y, int valueNumber) {
		return getDesignValueShape(g, draw, var, x, y, valueNumber, 1);
	}

	public Area getDesignValueShape(Graphics2D g,Boolean draw, SimpleVariable var, int x, int y, int valueNumberX, int valueNumberY) {
		return new Area();
	}

	
	public Area getDesignNameShape(Graphics2D g, Boolean draw, String name, int x, int y, int width, int height) {
		return getDesignNameShape(g, draw, name, x, y, width, height, 1, 1);
	}

	public Area getDesignNameShape(Graphics2D g, Boolean draw, String name, int x, int y, int width, int height, int values) {
		return getDesignNameShape(g, draw, name, x, y, width, height, values, 1);
	}
	
	public Area getDesignNameShape(Graphics2D g, Boolean draw, String name, int x, int y, int width, int height, int valuesX, int valuesY) {
		return new Area();
	}

}
