2 * PrintableComponent.java
4 package net.sf.openrocket.gui.print;
6 import java.awt.Graphics;
7 import java.awt.Graphics2D;
8 import java.awt.print.PageFormat;
9 import java.awt.print.Printable;
10 import java.awt.print.PrinterException;
12 import javax.swing.JPanel;
15 * Common interface for components we want to print. Used by PageFitPrintStrategy
17 * @author Jason Blood <dyster2000@gmail.com>
19 public class PrintableComponent extends JPanel implements Printable {
22 * The printing offsets
24 private int offsetX = 0;
25 private int offsetY = 0;
30 public PrintableComponent() {
35 * From the java.awt.print.Printable interface.
37 * Prints the page at the specified index into the specified {@link java.awt.Graphics} context in the specified
38 * format. A <code>PrinterJob</code> calls the <code>Printable</code> interface to request that a page be rendered
39 * into the context specified by <code>graphics</code>. The format of the page to be drawn is specified by
40 * <code>pageFormat</code>. The zero based index of the requested page is specified by <code>pageIndex</code>. If
41 * the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. The
42 * <code>Graphics</code> class or subclass implements the {@link java.awt.print.PrinterGraphics} interface to
43 * provide additional information. If the <code>Printable</code> object aborts the print job then it throws a
44 * {@link java.awt.print.PrinterException}.
46 * Note: This is not currently used in OpenRocket. It's only here for reference.
48 * @param graphics the context into which the page is drawn
49 * @param pageFormat the size and orientation of the page being drawn
50 * @param pageIndex the zero based index of the page to be drawn
52 * @return PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if <code>pageIndex</code> specifies a
55 * @throws java.awt.print.PrinterException
56 * thrown when the print job is terminated.
59 public int print (final Graphics graphics, final PageFormat pageFormat, final int pageIndex)
60 throws PrinterException {
62 Graphics2D g2d = (Graphics2D) graphics;
63 PrintUtilities.translateToJavaOrigin(g2d, pageFormat);
64 PrintUtilities.disableDoubleBuffering(this);
66 PrintUtilities.enableDoubleBuffering(this);
67 return Printable.PAGE_EXISTS;
71 * Set the offset this component will be printed to the page
72 * @param x X offset to print at.
73 * @param y Y offset to print at.
75 public void setPrintOffset(int x, int y) {
81 * Get the X offset this component will be printed to the page
82 * @return X offset to print at.
84 public int getOffsetX() {
89 * Get the Y offset this component will be printed to the page
90 * @return Y offset to print at.
92 public int getOffsetY() {