import java.awt.*; public class FuenteCC extends Component { private int v; private Point b; // the other terminal of this component private FuenteCCView fuenteCCView; public FuenteCC (int v){ a = new Point(COMPONENT_SIZE, COMPONENT_SIZE); b = new Point(COMPONENT_SIZE, 2*COMPONENT_SIZE); this.v=v; fuenteCCView = new FuenteCCView(a,b,v); } public void paintComponent (Graphics2D g) { fuenteCCView.paintComponent(g); } public Boolean isUnderPoint(Point p) { return (fuenteCCView.isUnderPoint(p)); } public void rotate(){ Point c=new Point((a.x+b.x)/2,(a.y+b.y)/2); int tem = a.y; a.y=c.y+(a.x-c.x); a.x=c.x-(tem-c.y); tem = b.y; b.y=c.y+(b.x-c.x); b.x=c.x-(tem-c.y); fuenteCCView.rotate(); } public void setRed(){ fuenteCCView.setRed(); } public void unsetRed(){ fuenteCCView.unsetRed(); } public void translate(int dx, int dy){ a.translate(dx,dy); b.translate(dx,dy); fuenteCCView.translate(dx,dy); } public Point distance(Component c) { // here Point is a used as a vector double d,min=20000000; // min big enough to ensure change Point t, minVector = new Point(); final Point[] terminals = c.getTerminals(); for (int i = terminals.length-1; i>=0; i--) { t = terminals[i]; d = t.distanceSq(a); if (d < min) { min=d; minVector.setLocation(a.x-t.x,a.y-t.y); } d = t.distanceSq(b); if (d < min) { min=d; minVector.setLocation(b.x-t.x,b.y-t.y); } } return minVector; } public Point[] getTerminals () { Point[] t = new Point[2]; t[0]=a; t[1]=b; return t; } }