X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fprint%2FPrintableFinSet.java;fp=core%2Fsrc%2Fnet%2Fsf%2Fopenrocket%2Fgui%2Fprint%2FPrintableFinSet.java;h=8e5389b2bd3cf7072efc339414dcf92c56db6716;hb=9349577cdfdff682b2aabd6daa24fdc3a7449b58;hp=cf07cb13e02f96519f249efdccd5e231dc10b996;hpb=30ba0a882f0c061176ba14dbf86d3d6fad096c02;p=debian%2Fopenrocket diff --git a/core/src/net/sf/openrocket/gui/print/PrintableFinSet.java b/core/src/net/sf/openrocket/gui/print/PrintableFinSet.java index cf07cb13..8e5389b2 100644 --- a/core/src/net/sf/openrocket/gui/print/PrintableFinSet.java +++ b/core/src/net/sf/openrocket/gui/print/PrintableFinSet.java @@ -6,34 +6,25 @@ package net.sf.openrocket.gui.print; import net.sf.openrocket.rocketcomponent.FinSet; import net.sf.openrocket.util.Coordinate; -import javax.swing.*; -import java.awt.*; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; import java.awt.geom.GeneralPath; import java.awt.image.BufferedImage; -import java.awt.print.PageFormat; -import java.awt.print.Printable; -import java.awt.print.PrinterException; /** * This class allows for a FinSet to be printable. It does so by decorating an existing finset (which will not be * modified) and rendering it within a JPanel. The JPanel is not actually visualized on a display, but instead renders * it to a print device. */ -public class PrintableFinSet extends JPanel implements Printable { +public class PrintableFinSet extends PrintableComponent { /** * The object that represents the shape (outline) of the fin. This gets drawn onto the Swing component. */ protected GeneralPath polygon = null; - /** - * The X margin. - */ - private final int marginX = (int)(PrintUnit.POINTS_PER_INCH * 0.3f); - /** - * The Y margin. - */ - private final int marginY = (int)(PrintUnit.POINTS_PER_INCH * 0.3f); /** * The minimum X coordinate. */ @@ -58,9 +49,7 @@ public class PrintableFinSet extends JPanel implements Printable { * @param points an array of points. */ public PrintableFinSet (Coordinate[] points) { - super(false); init(points); - setBackground(Color.white); } /** @@ -77,8 +66,8 @@ public class PrintableFinSet extends JPanel implements Printable { int maxY = 0; for (Coordinate point : points) { - final long x = PrintUnit.METERS.toPoints(point.x); - final long y = PrintUnit.METERS.toPoints(point.y); + final long x = (long)PrintUnit.METERS.toPoints(point.x); + final long y = (long)PrintUnit.METERS.toPoints(point.y); minX = (int) Math.min(x, minX); minY = (int) Math.min(y, minY); maxX = (int) Math.max(x, maxX); @@ -90,60 +79,6 @@ public class PrintableFinSet extends JPanel implements Printable { setSize(maxX - minX, maxY - minY); } - /** - * Get the X-axis margin value. - * - * @return margin, in points - */ - protected double getMarginX () { - return marginX; - } - - /** - * Get the Y-axis margin value. - * - * @return margin, in points - */ - protected double getMarginY () { - return marginY; - } - - /** - * From the java.awt.print.Printable interface. - *

- * Prints the page at the specified index into the specified {@link java.awt.Graphics} context in the specified - * format. A PrinterJob calls the Printable interface to request that a page be rendered - * into the context specified by graphics. The format of the page to be drawn is specified by - * pageFormat. The zero based index of the requested page is specified by pageIndex. If - * the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. The - * Graphics class or subclass implements the {@link java.awt.print.PrinterGraphics} interface to - * provide additional information. If the Printable object aborts the print job then it throws a - * {@link java.awt.print.PrinterException}. - *

- * Note: This is not currently used in OpenRocket. It's only here for reference. - * - * @param graphics the context into which the page is drawn - * @param pageFormat the size and orientation of the page being drawn - * @param pageIndex the zero based index of the page to be drawn - * - * @return PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if pageIndex specifies a - * non-existent page. - * - * @throws java.awt.print.PrinterException - * thrown when the print job is terminated. - */ - @Override - public int print (final Graphics graphics, final PageFormat pageFormat, final int pageIndex) - throws PrinterException { - - Graphics2D g2d = (Graphics2D) graphics; - PrintUtilities.translateToJavaOrigin(g2d, pageFormat); - PrintUtilities.disableDoubleBuffering(this); - paint(g2d); - PrintUtilities.enableDoubleBuffering(this); - return Printable.PAGE_EXISTS; - } - /** * Returns a generated image of the fin set. May then be used wherever AWT images can be used, or converted to * another image/picture format and used accordingly. @@ -151,17 +86,17 @@ public class PrintableFinSet extends JPanel implements Printable { * @return an awt image of the fin set */ public Image createImage () { - int width = getWidth() + marginX; - int height = getHeight() + marginY; - // Create a buffered image in which to draw + int width = getWidth(); + int height = getHeight(); + // Create a buffered image in which to draw BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - // Create a graphics contents on the buffered image + // Create a graphics contents on the buffered image Graphics2D g2d = bufferedImage.createGraphics(); - // Draw graphics + // Draw graphics g2d.setBackground(Color.white); g2d.clearRect(0, 0, width, height); paintComponent(g2d); - // Graphics context no longer needed so dispose it + // Graphics context no longer needed so dispose it g2d.dispose(); return bufferedImage; } @@ -174,13 +109,15 @@ public class PrintableFinSet extends JPanel implements Printable { * @param g the Java2D graphics context */ @Override - public void paintComponent (Graphics g) { - super.paintComponent(g); + public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; int x = 0; int y = 0; + int marginX = this.getOffsetX(); + int marginY = this.getOffsetY(); + // The minimum X/Y can be negative (primarily only Y due to fin tabs; rarely (never) X, but protect both anyway). if (minX < marginX) { x = marginX + Math.abs(minX); @@ -195,5 +132,4 @@ public class PrintableFinSet extends JPanel implements Printable { g2d.setPaint(TemplateProperties.getLineColor()); g2d.draw(polygon); } - }