Skip to content

Instantly share code, notes, and snippets.

@gilleain
Created August 23, 2010 11:00
Show Gist options
  • Save gilleain/545250 to your computer and use it in GitHub Desktop.
Save gilleain/545250 to your computer and use it in GitHub Desktop.
public class ArcDrawer extends AWTDrawVisitor {
private Graphics2D g2;
public ArcDrawer(Graphics2D g) {
super(g);
this.g2 = g;
}
@Override
public void visit(IRenderingElement element) {
if (element instanceof ArcElement) {
visit((ArcElement) element);
} else {
super.visit(element);
}
}
public void visit(ArcElement arc) {
// transform the arc endpoints into the diagonal corners of a rect
double fudge = (arc.orientation == ArcElement.Orientation.N)?
0.75 : -0.75;
int[] p1 = this.transformPoint(arc.x1, arc.y1 + arc.h + fudge);
int[] p2 = this.transformPoint(arc.x2, arc.y2 - arc.h + fudge);
Color savedColor = g2.getColor();
this.g2.setColor(arc.color);
int x = p1[0];
int y = p1[1];
int w = Math.abs(p2[0] - p1[0]);
int h = Math.abs(p2[1] - p1[1]);
// System.out.println(
// String.format("Arc %d %d %d %d %d %d %d %d %f",
// x, y, w, h, p1[0], p1[1], p2[0], p2[1], arc.h));
if (arc.orientation == ArcElement.Orientation.N) {
this.g2.drawArc(x, y, w, h, 0, 180);
} else {
this.g2.drawArc(x, y, w, h, 0, -180);
}
g2.setColor(savedColor);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment