17f072308e9890215dd392adca4548c872b934ae
[debian/openrocket] / core / src / net / sf / openrocket / gui / print / PrintableNoseCone.java
1 package net.sf.openrocket.gui.print;
2
3 import net.sf.openrocket.gui.rocketfigure.TransitionShapes;
4 import net.sf.openrocket.rocketcomponent.NoseCone;
5 import net.sf.openrocket.util.Transformation;
6
7 import java.awt.Graphics2D;
8 import java.awt.Rectangle;
9 import java.awt.Shape;
10
11 public class PrintableNoseCone extends AbstractPrintable<NoseCone> {
12
13         /**
14          * If the component to be drawn is a nose cone, save a reference to it.
15          */
16         private NoseCone target;
17
18         /**
19          * Construct a printable nose cone.
20          *
21          * @param noseCone the component to print
22          */
23         public PrintableNoseCone(NoseCone noseCone) {
24                 super(false, noseCone);
25         }
26
27         @Override
28         protected void init(NoseCone component) {
29
30                 target = component;
31                 double radius = target.getForeRadius();
32                 if (radius < target.getAftRadius()) {
33                         radius = target.getAftRadius();
34                 }
35                 setSize((int) PrintUnit.METERS.toPoints(2 * radius) + marginX,
36                                 (int) PrintUnit.METERS.toPoints(target.getLength() + target.getAftShoulderLength()) + marginY);
37         }
38
39         /**
40          * Draw a nose cone.
41          *
42          * @param g2 the graphics context
43          */
44         @Override
45         protected void draw(Graphics2D g2) {
46                 Shape[] shapes = TransitionShapes.getShapesSide(target, Transformation.rotate_x(0d), PrintUnit.METERS.toPoints(1));
47
48                 if (shapes != null && shapes.length > 0) {
49                         Rectangle r = shapes[0].getBounds();
50                         g2.translate(marginX + r.getHeight() / 2 + getOffsetX(), marginY + getOffsetY());
51                         g2.rotate(Math.PI / 2);
52                         for (Shape shape : shapes) {
53                                 g2.draw(shape);
54                         }
55                         g2.rotate(-Math.PI / 2);
56                 }
57         }
58 }