DGP - 1st printing
[debian/openrocket] / src / net / sf / openrocket / gui / print / visitor / FinSetVisitorStrategy.java
1 /*
2  * FinSetVisitorStrategy.java
3  */
4 package net.sf.openrocket.gui.print.visitor;
5
6 import com.itextpdf.text.Document;
7 import com.itextpdf.text.pdf.PdfContentByte;
8 import com.itextpdf.text.pdf.PdfWriter;
9 import net.sf.openrocket.gui.print.PrintableFinSet;
10 import net.sf.openrocket.rocketcomponent.EllipticalFinSet;
11 import net.sf.openrocket.rocketcomponent.FinSet;
12 import net.sf.openrocket.rocketcomponent.FreeformFinSet;
13 import net.sf.openrocket.rocketcomponent.TrapezoidFinSet;
14
15 import java.awt.Graphics2D;
16 import java.util.Set;
17
18 /**
19  * A visitor strategy for drawing fin templates.
20  */
21 public class FinSetVisitorStrategy extends BaseVisitorStrategy {
22
23     /**
24      * Constructor.
25      * 
26      * @param doc              The iText document
27      * @param theWriter        The direct iText writer
28      * @param theStagesToVisit The stages to be visited by this strategy
29      */
30     public FinSetVisitorStrategy (Document doc, PdfWriter theWriter, Set<Integer> theStagesToVisit) {
31         super(doc, theWriter, theStagesToVisit);
32     }
33     
34     /**
35      * {@inheritDoc}
36      */
37     @Override
38     public void visit (final TrapezoidFinSet visitable) {
39         doVisit(visitable);
40     }
41
42     /**
43      * {@inheritDoc}
44      */
45     @Override
46     public void visit (final EllipticalFinSet visitable) {
47         doVisit(visitable);
48     }
49
50     /**
51      * {@inheritDoc}
52      */
53     @Override
54     public void visit (final FreeformFinSet visitable) {
55         doVisit(visitable);
56     }
57
58     /**
59      * The core behavior of this visitor.
60      * 
61      * @param visitable  the object to extract info about; a graphical image of the fin shape is drawn to the document
62      */
63     private void doVisit (final FinSet visitable) {
64         if (shouldVisitStage(visitable.getStageNumber())) {
65             PrintableFinSet pfs = new PrintableFinSet(visitable);
66
67             net.sf.openrocket.gui.print.visitor.Dimension d = getPageSize();
68             PdfContentByte cb = writer.getDirectContent();
69             Graphics2D g2 = cb.createGraphics(d.width, d.height);
70             pfs.print(g2);
71             g2.dispose();
72             document.newPage();
73         }
74     }
75 }
76