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