version 1.1.9
[debian/openrocket] / src / net / sf / openrocket / gui / print / PrintableNoseCone.java
1 package net.sf.openrocket.gui.print;
2
3 import java.awt.Graphics2D;
4 import java.awt.Rectangle;
5 import java.awt.Shape;
6
7 import net.sf.openrocket.gui.rocketfigure.TransitionShapes;
8 import net.sf.openrocket.rocketcomponent.NoseCone;
9 import net.sf.openrocket.rocketcomponent.Transition;
10 import net.sf.openrocket.util.Transformation;
11
12 public class PrintableNoseCone extends AbstractPrintableTransition {
13         
14         /**
15          * If the component to be drawn is a nose cone, save a reference to it.
16          */
17         private NoseCone target;
18         
19         /**
20          * Construct a printable nose cone.
21          *
22          * @param noseCone the component to print
23          */
24         public PrintableNoseCone(Transition noseCone) {
25                 super(false, noseCone);
26         }
27         
28         @Override
29         protected void init(Transition component) {
30                 
31                 target = (NoseCone) component;
32                 double radius = target.getForeRadius();
33                 if (radius < target.getAftRadius()) {
34                         radius = target.getAftRadius();
35                 }
36                 setSize((int) PrintUnit.METERS.toPoints(2 * radius) + marginX,
37                                 (int) PrintUnit.METERS.toPoints(target.getLength() + target.getAftShoulderLength()) + marginY);
38         }
39         
40         /**
41          * Draw a nose cone.
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(marginX + r.getHeight() / 2, marginY);
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 }