1 package net.sf.openrocket.gui.print;
3 import net.sf.openrocket.rocketcomponent.CenteringRing;
6 import java.awt.Graphics;
7 import java.awt.Graphics2D;
9 import java.awt.geom.Ellipse2D;
12 * This class creates a renderable centering ring. It depends only on AWT/Swing and can be called from other
13 * actors (like iText handlers) to render the centering ring on different graphics contexts.
15 public class PrintableCenteringRing extends AbstractPrintable<CenteringRing> {
17 * If the component to be drawn is a centering ring, save a reference to it.
19 private CenteringRing target;
24 protected int marginX = (int) PrintUnit.INCHES.toPoints(0.25f);
29 protected int marginY = (int) PrintUnit.INCHES.toPoints(0.25f);
32 * The line length of the cross hairs.
34 private final int lineLength = 10;
37 * Construct a printable nose cone.
39 * @param theRing the component to print
41 public PrintableCenteringRing(CenteringRing theRing) {
42 super(false, theRing);
46 * @param component the centering ring component
49 protected void init(final CenteringRing component) {
53 double radius = target.getOuterRadius();
54 setSize((int) PrintUnit.METERS.toPoints(2 * radius) + marginX,
55 (int) PrintUnit.METERS.toPoints(2 * radius) + marginY);
59 * Draw a centering ring.
61 * @param g2 the graphics context
64 protected void draw(Graphics2D g2) {
65 double radius = PrintUnit.METERS.toPoints(target.getOuterRadius());
67 Color original = g2.getBackground();
70 Shape outerCircle = new Ellipse2D.Double(x, y, radius * 2, radius * 2);
71 g2.setColor(Color.lightGray);
73 g2.setColor(Color.black);
78 double innerRadius = PrintUnit.METERS.toPoints(target.getInnerRadius());
79 Shape innerCircle = new Ellipse2D.Double(x - innerRadius, y - innerRadius, innerRadius * 2, innerRadius * 2);
80 g2.setColor(original);
82 g2.setColor(Color.black);
85 drawCross(g2, (int) x, (int) y, lineLength, lineLength);
89 * Draw the center cross-hair.
91 * @param g the graphics context
92 * @param x the x coordinate of the center point
93 * @param y the y coordinate of the center point
94 * @param width the width in pixels of the horizontal hair
95 * @param height the width in pixels of the vertical hair
97 private void drawCross(Graphics g, int x, int y, int width, int height) {
98 g.setColor(Color.black);
99 ((Graphics2D) g).setStroke(thinStroke);
100 g.drawLine(x - width / 2, y, x + width / 2, y);
101 g.drawLine(x, y - height / 2, x, y + height / 2);