1 package net.sf.openrocket.gui.print;
3 import net.sf.openrocket.rocketcomponent.Transition;
7 import java.awt.image.BufferedImage;
9 public abstract class AbstractPrintableTransition extends JPanel {
11 * The stroke of the transition arc.
13 private final static BasicStroke thinStroke = new BasicStroke(1.0f);
18 protected int marginX = (int) PrintUnit.INCHES.toPoints(0.25f);
23 protected int marginY = (int) PrintUnit.INCHES.toPoints(0.25f);
26 * Constructor. Initialize this printable with the component to be printed.
28 * @param isDoubleBuffered a boolean, true for double-buffering
29 * @param transition the component to be printed
31 public AbstractPrintableTransition(boolean isDoubleBuffered, Transition transition) {
32 super(isDoubleBuffered);
33 setBackground(Color.white);
38 * Compute the basic values of each arc of the transition/shroud. This is adapted from
39 * <a href="http://www.rocketshoppe.com/info/Transitions.pdf">The Properties of
40 * Model Rocket Body Tube Transitions, by J.R. Brohm</a>
42 * @param component the transition component
44 protected abstract void init(Transition component);
47 * Draw the component onto the graphics context.
49 * @param g2 the graphics context
51 protected abstract void draw(Graphics2D g2);
54 * Returns a generated image of the transition. May then be used wherever AWT images can be used, or converted to
55 * another image/picture format and used accordingly.
57 * @return an awt image of the fin set
59 public Image createImage() {
60 int width = getWidth() + marginX;
61 int height = getHeight() + marginY;
62 // Create a buffered image in which to draw
63 BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
64 // Create a graphics contents on the buffered image
65 Graphics2D g2d = bufferedImage.createGraphics();
67 g2d.setBackground(Color.white);
68 g2d.clearRect(0, 0, width, height);
70 // Graphics context no longer needed so dispose it
76 public void paintComponent(Graphics g) {
77 Graphics2D g2 = (Graphics2D) g;
78 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
79 RenderingHints.VALUE_ANTIALIAS_ON);
81 g2.setColor(Color.BLACK);
82 g2.setStroke(thinStroke);