create changelog entry
[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) + 4,
36                                 (int) PrintUnit.METERS.toPoints(target.getLength() + target.getAftShoulderLength()) + 4);
37         }
38
39         /**
40          * Draw a nose cone.  Presumes that the graphics context has already had the x/y position translated based on
41      * where it should be drawn.
42          *
43          * @param g2 the graphics context
44          */
45         @Override
46         protected void draw(Graphics2D g2) {
47                 Shape[] shapes = TransitionShapes.getShapesSide(target, Transformation.rotate_x(0d), PrintUnit.METERS.toPoints(1));
48
49                 if (shapes != null && shapes.length > 0) {
50                         Rectangle r = shapes[0].getBounds();
51                         g2.translate(r.getHeight() / 2, 0);
52                         g2.rotate(Math.PI / 2);
53                         for (Shape shape : shapes) {
54                                 g2.draw(shape);
55                         }
56                         g2.rotate(-Math.PI / 2);
57                 }
58         }
59 }