import java.awt.*;

public class ResistorView extends ComponentView {
    private String value;
    private Polygon shape;
    private Point textPosition;
    public ResistorView (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 = {10,0,0,5,5,-5,-5,0,0,-10,-10,0,0,-5,-5,5,5,0,0,10};
	int[] y = {-25,-25,-45,-45,-55,-55,-45,-45,-25,-25,25,25,
		   45,45,55,55,45,45,25,25};
	for (int i=0; i<x.length ; i++) {
	    x[i]*=h; x[i]/=100;
	    y[i]*=h; y[i]/=100;
	}
	shape = new Polygon(x,y,x.length);
	value= Integer.toString(v);	
	textPosition = new Point(3*x[19], y[19]);
	body=shape.getBounds();
    }
    public void rotate() {
	int t;
	for (int i=0; i<shape.npoints; i++) {
	    t=shape.ypoints[i];
	    shape.ypoints[i] = shape.xpoints[i];
	    shape.xpoints[i] =-t;
	}
	shape.invalidate();
	t= textPosition.y;
	textPosition.y = textPosition.x;
	textPosition.x = -t;
	body=shape.getBounds();
    }
    public void paintComponent (Graphics2D g) {
	g.setColor(color);
	g.translate(center.x, center.y);
	g.draw(shape);
	g.fill(shape);
	g.drawString(value,textPosition.x, textPosition.y);
	g.translate(-center.x, -center.y);
    }
}