import java.awt.*;

public class FuenteCCView extends ComponentView {
    private String value;
    private Point textPosition;
    private Polygon shape1, shape2;

    public FuenteCCView (Point a, Point b, int v){
	center = new Point((a.x+b.x)/2, (a.y+b.y)/2);
	int h = (Math.abs(a.x-b.x)+Math.abs(a.y-b.y));
	int[] x = {0, 5, 5, -5, -5, 0, 0, -25, 25, 0};
	int[] y = {-45, -45,-55, -55, -45, -45, -10, -10, -10, -10};
	for (int i=0; i<x.length ; i++) {
	    x[i]*=h; x[i]/=100;
	    y[i]*=h; y[i]/=100;
	}
	shape1 = new Polygon(x,y,x.length);
	x = new int[] {0, -5, -5, 5, 5, 0, 0, -10, 10, 0};
	y = new int[] {45, 45, 55, 55, 45, 45, 10, 10, 10, 10};
	for (int i=0; i<x.length ; i++) {
	    x[i]*=h; x[i]/=100;
	    y[i]*=h; y[i]/=100;
	}
	shape2 = new Polygon(x,y,x.length);
	value= Integer.toString(v);	
	textPosition = new Point(3*x[8], y[8]);
	body = shape1.getBounds(); 
	body = shape2.getBounds().union(body);
    }
    public void rotate() {
	int t;
	for (int i=0; i<shape1.npoints; i++) {
	    t=shape1.ypoints[i];
	    shape1.ypoints[i] = shape1.xpoints[i];
	    shape1.xpoints[i] =-t;
	    t=shape2.ypoints[i];
	    shape2.ypoints[i] = shape2.xpoints[i];
	    shape2.xpoints[i] =-t;
	}
	shape1.invalidate();
	shape2.invalidate();
	t= textPosition.y;
	textPosition.y = textPosition.x;
	textPosition.x = -t;
	body = shape1.getBounds(); 
	body = shape2.getBounds().union(body);
    }
    public void paintComponent (Graphics2D g) {
	g.setColor(color);
	g.translate(center.x, center.y);
	g.draw(shape1);
	g.draw(shape2);
	g.fill(shape1);
	g.fill(shape2);
	g.drawString(value,textPosition.x, textPosition.y);
	g.translate(-center.x, -center.y);
    }
}