List of usage examples for java.awt Graphics2D create
public abstract Graphics create();
From source file:com.openbravo.pos.util.JRViewer400.java
/** * /*from www . j ava 2s . c o m*/ */ protected void paintPage(Graphics2D grx) { if (pageError) { paintPageError(grx); return; } try { if (exporter == null) { exporter = getGraphics2DExporter(); } else { exporter.reset(); } exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput(); output.setGraphics2D((Graphics2D) grx.create()); exporter.setExporterOutput(output); SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration(); configuration.setPageIndex(pageIndex); configuration.setZoomRatio(realZoom); configuration.setOffsetX(1); //lblPage border configuration.setOffsetY(1); exporter.setConfiguration(configuration); exporter.exportReport(); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Page paint error.", e); } pageError = true; paintPageError(grx); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(JRViewer400.this, getBundleString("error.displaying")); } }); } }
From source file:net.sf.jasperreports.view.JRViewer.java
/** * //w w w . j av a 2 s . c o m */ protected void paintPage(Graphics2D grx) { if (pageError) { paintPageError(grx); return; } try { if (exporter == null) { exporter = getGraphics2DExporter(); } else { exporter.reset(); } exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput(); output.setGraphics2D((Graphics2D) grx.create()); exporter.setExporterOutput(output); SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration(); configuration.setPageIndex(pageIndex); configuration.setZoomRatio(realZoom); configuration.setOffsetX(1); //lblPage border configuration.setOffsetY(1); exporter.setConfiguration(configuration); exporter.exportReport(); } catch (Exception e) { if (log.isErrorEnabled()) { log.error("Page paint error.", e); } pageError = true; paintPageError(grx); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(JRViewer.this, getBundleString("error.displaying")); } }); } }
From source file:neg.JRViewerComercial.java
/** * /* w w w. j ava2s. co m*/ */ protected void paintPage(Graphics2D grx) { if (pageError) { paintPageError(grx); return; } try { if (exporter == null) { exporter = getGraphics2DExporter(); } else { exporter.reset(); } exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, grx.create()); exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex)); exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom)); exporter.setParameter(JRExporterParameter.OFFSET_X, new Integer(1)); //lblPage border exporter.setParameter(JRExporterParameter.OFFSET_Y, new Integer(1)); if (type == TYPE_FILE_NAME) { exporter.setParameter(JRExporterParameter.FILE_RESOLVER, fileResolver); } exporter.exportReport(); } catch (Exception e) { if (log.isErrorEnabled()) log.error("Page paint error.", e); pageError = true; paintPageError(grx); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(JRViewerComercial.this, getBundleString("error.displaying")); } }); } }
From source file:neg.JRViewerComercialProveedor.java
/** * //from w w w. j a v a 2s . c om */ protected void paintPage(Graphics2D grx) { if (pageError) { paintPageError(grx); return; } try { if (exporter == null) { exporter = getGraphics2DExporter(); } else { exporter.reset(); } exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, grx.create()); exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex)); exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom)); exporter.setParameter(JRExporterParameter.OFFSET_X, new Integer(1)); //lblPage border exporter.setParameter(JRExporterParameter.OFFSET_Y, new Integer(1)); if (type == TYPE_FILE_NAME) { exporter.setParameter(JRExporterParameter.FILE_RESOLVER, fileResolver); } exporter.exportReport(); } catch (Exception e) { if (log.isErrorEnabled()) log.error("Page paint error.", e); pageError = true; paintPageError(grx); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(JRViewerComercialProveedor.this, getBundleString("error.displaying")); } }); } }
From source file:neg.JRViewerFactura.java
/** * //from ww w .jav a 2 s . c o m */ protected void paintPage(Graphics2D grx) { if (pageError) { paintPageError(grx); return; } try { if (exporter == null) { exporter = getGraphics2DExporter(); } else { exporter.reset(); } exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, grx.create()); exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex)); exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom)); exporter.setParameter(JRExporterParameter.OFFSET_X, new Integer(1)); //lblPage border exporter.setParameter(JRExporterParameter.OFFSET_Y, new Integer(1)); if (type == TYPE_FILE_NAME) { exporter.setParameter(JRExporterParameter.FILE_RESOLVER, fileResolver); } exporter.exportReport(); } catch (Exception e) { if (log.isErrorEnabled()) log.error("Page paint error.", e); pageError = true; paintPageError(grx); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(JRViewerFactura.this, getBundleString("error.displaying")); } }); } }
From source file:neg.JRViewerInformeUnitario.java
/** * //from www.j a va 2 s.c o m */ protected void paintPage(Graphics2D grx) { if (pageError) { paintPageError(grx); return; } try { if (exporter == null) { exporter = getGraphics2DExporter(); } else { exporter.reset(); } exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, grx.create()); exporter.setParameter(JRExporterParameter.PAGE_INDEX, new Integer(pageIndex)); exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom)); exporter.setParameter(JRExporterParameter.OFFSET_X, new Integer(1)); //lblPage border exporter.setParameter(JRExporterParameter.OFFSET_Y, new Integer(1)); if (type == TYPE_FILE_NAME) { exporter.setParameter(JRExporterParameter.FILE_RESOLVER, fileResolver); } exporter.exportReport(); } catch (Exception e) { if (log.isErrorEnabled()) log.error("Page paint error.", e); pageError = true; paintPageError(grx); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(JRViewerInformeUnitario.this, getBundleString("error.displaying")); } }); } }
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * Draws borders. Borders are drawn in-memory and painted as a bitmap. * @param borderRect the border rectangle * @param bpsBefore the border specification on the before side * @param bpsAfter the border specification on the after side * @param bpsStart the border specification on the start side * @param bpsEnd the border specification on the end side */// ww w.java 2 s.co m protected void drawQualityBorders(Rectangle2D.Float borderRect, final BorderProps bpsBefore, final BorderProps bpsAfter, final BorderProps bpsStart, final BorderProps bpsEnd) { Graphics2DAdapter g2a = getGraphics2DAdapter(); final Rectangle.Float effBorderRect = new Rectangle2D.Float(0, 0, borderRect.width, borderRect.height); final Rectangle paintRect = new Rectangle(Math.round(borderRect.x * 1000f), Math.round(borderRect.y * 1000f), (int) Math.floor(borderRect.width * 1000f) + 1, (int) Math.floor(borderRect.height * 1000f) + 1); //Add one pixel wide safety margin around the paint area int pixelWidth = (int) Math.round(UnitConv.in2mpt(1) / userAgent.getTargetResolution()); final int xoffset = Math.round(-effBorderRect.x * 1000f) + pixelWidth; final int yoffset = pixelWidth; paintRect.x += xoffset; paintRect.y += yoffset; paintRect.width += 2 * pixelWidth; paintRect.height += 2 * pixelWidth; RendererContext rc = createRendererContext(paintRect.x, paintRect.y, paintRect.width, paintRect.height, null); Map atts = new java.util.HashMap(); atts.put(ImageHandlerUtil.CONVERSION_MODE, ImageHandlerUtil.CONVERSION_MODE_BITMAP); atts.put(SRC_TRANSPARENCY, "true"); rc.setProperty(RendererContextConstants.FOREIGN_ATTRIBUTES, atts); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.translate(xoffset, yoffset); g2d.scale(1000, 1000); float startx = effBorderRect.x; float starty = effBorderRect.y; float width = effBorderRect.width; float height = effBorderRect.height; boolean[] b = new boolean[] { (bpsBefore != null), (bpsEnd != null), (bpsAfter != null), (bpsStart != null) }; if (!b[0] && !b[1] && !b[2] && !b[3]) { return; } float[] bw = new float[] { (b[0] ? bpsBefore.width / 1000f : 0.0f), (b[1] ? bpsEnd.width / 1000f : 0.0f), (b[2] ? bpsAfter.width / 1000f : 0.0f), (b[3] ? bpsStart.width / 1000f : 0.0f) }; float[] clipw = new float[] { BorderProps.getClippedWidth(bpsBefore) / 1000f, BorderProps.getClippedWidth(bpsEnd) / 1000f, BorderProps.getClippedWidth(bpsAfter) / 1000f, BorderProps.getClippedWidth(bpsStart) / 1000f }; starty += clipw[0]; height -= clipw[0]; height -= clipw[2]; startx += clipw[3]; width -= clipw[3]; width -= clipw[1]; boolean[] slant = new boolean[] { (b[3] && b[0]), (b[0] && b[1]), (b[1] && b[2]), (b[2] && b[3]) }; if (bpsBefore != null) { //endTextObject(); float sx1 = startx; float sx2 = (slant[0] ? sx1 + bw[3] - clipw[3] : sx1); float ex1 = startx + width; float ex2 = (slant[1] ? ex1 - bw[1] + clipw[1] : ex1); float outery = starty - clipw[0]; float clipy = outery + clipw[0]; float innery = outery + bw[0]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(sx1, clipy); float sx1a = sx1; float ex1a = ex1; if (bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) { sx1a -= clipw[3]; } if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { ex1a += clipw[1]; } lineTo(sx1a, outery); lineTo(ex1a, outery); } lineTo(ex1, clipy); lineTo(ex2, innery); lineTo(sx2, innery); closePath(); //clip(); g.clip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, outery, ex1a - sx1a, innery - outery); Java2DRenderer.drawBorderLine(lineRect, true, true, bpsBefore.style, bpsBefore.color, g); //restoreGraphicsState(); } if (bpsEnd != null) { //endTextObject(); float sy1 = starty; float sy2 = (slant[1] ? sy1 + bw[0] - clipw[0] : sy1); float ey1 = starty + height; float ey2 = (slant[2] ? ey1 - bw[2] + clipw[2] : ey1); float outerx = startx + width + clipw[1]; float clipx = outerx - clipw[1]; float innerx = outerx - bw[1]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(clipx, sy1); float sy1a = sy1; float ey1a = ey1; if (bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { sy1a -= clipw[0]; } if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { ey1a += clipw[2]; } lineTo(outerx, sy1a); lineTo(outerx, ey1a); } lineTo(clipx, ey1); lineTo(innerx, ey2); lineTo(innerx, sy2); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(innerx, sy1a, outerx - innerx, ey1a - sy1a); Java2DRenderer.drawBorderLine(lineRect, false, false, bpsEnd.style, bpsEnd.color, g); //restoreGraphicsState(); } if (bpsAfter != null) { //endTextObject(); float sx1 = startx; float sx2 = (slant[3] ? sx1 + bw[3] - clipw[3] : sx1); float ex1 = startx + width; float ex2 = (slant[2] ? ex1 - bw[1] + clipw[1] : ex1); float outery = starty + height + clipw[2]; float clipy = outery - clipw[2]; float innery = outery - bw[2]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(ex1, clipy); float sx1a = sx1; float ex1a = ex1; if (bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { if (bpsStart != null && bpsStart.mode == BorderProps.COLLAPSE_OUTER) { sx1a -= clipw[3]; } if (bpsEnd != null && bpsEnd.mode == BorderProps.COLLAPSE_OUTER) { ex1a += clipw[1]; } lineTo(ex1a, outery); lineTo(sx1a, outery); } lineTo(sx1, clipy); lineTo(sx2, innery); lineTo(ex2, innery); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(sx1a, innery, ex1a - sx1a, outery - innery); Java2DRenderer.drawBorderLine(lineRect, true, false, bpsAfter.style, bpsAfter.color, g); //restoreGraphicsState(); } if (bpsStart != null) { //endTextObject(); float sy1 = starty; float sy2 = (slant[0] ? sy1 + bw[0] - clipw[0] : sy1); float ey1 = sy1 + height; float ey2 = (slant[3] ? ey1 - bw[2] + clipw[2] : ey1); float outerx = startx - clipw[3]; float clipx = outerx + clipw[3]; float innerx = outerx + bw[3]; //saveGraphicsState(); Graphics2D g = (Graphics2D) g2d.create(); moveTo(clipx, ey1); float sy1a = sy1; float ey1a = ey1; if (bpsStart.mode == BorderProps.COLLAPSE_OUTER) { if (bpsBefore != null && bpsBefore.mode == BorderProps.COLLAPSE_OUTER) { sy1a -= clipw[0]; } if (bpsAfter != null && bpsAfter.mode == BorderProps.COLLAPSE_OUTER) { ey1a += clipw[2]; } lineTo(outerx, ey1a); lineTo(outerx, sy1a); } lineTo(clipx, sy1); lineTo(innerx, sy2); lineTo(innerx, ey2); closePath(); //clip(); g.setClip(currentPath); currentPath = null; Rectangle2D.Float lineRect = new Rectangle2D.Float(outerx, sy1a, innerx - outerx, ey1a - sy1a); Java2DRenderer.drawBorderLine(lineRect, false, false, bpsStart.style, bpsStart.color, g); //restoreGraphicsState(); } } public Dimension getImageSize() { return paintRect.getSize(); } }; try { g2a.paintImage(painter, rc, paintRect.x - xoffset, paintRect.y, paintRect.width, paintRect.height); } catch (IOException ioe) { handleIOTrouble(ioe); } }
From source file:org.apache.fop.util.BitmapImageUtilTestCase.java
private BufferedImage createTestImage() { BufferedImage buf = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = buf.createGraphics(); g2d.setBackground(Color.WHITE); g2d.clearRect(0, 0, buf.getWidth(), buf.getHeight()); //A few rectangles rotated and with different color Graphics2D copy = (Graphics2D) g2d.create(); copy.translate(170, 170);// w w w .j a va 2s. c o m int c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(0.0f, 1 - f, 0.0f); copy.setColor(col); copy.fillRect(0, 0, 120, 120); copy.rotate(-2 * Math.PI / c); } copy.dispose(); //the same in gray scales copy = (Graphics2D) g2d.create(); copy.translate(470, 310); c = 12; for (int i = 0; i < c; i++) { float f = ((i + 1) / (float) c); Color col = new Color(f, f, f); copy.setColor(col); copy.fillRect(0, 0, 120, 120); copy.rotate(-2 * Math.PI / c); } copy.dispose(); return buf; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
/** * Draws the object./*w w w .j ava2s . co m*/ * * @param graphics * the graphics device. * @param area * the area inside which the object should be drawn. */ public void draw(final Graphics2D graphics, final Rectangle2D area) { final Graphics2D g2 = (Graphics2D) graphics.create(); if (isDrawPageBackground()) { g2.setPaint(Color.white); g2.fill(area); } g2.translate(-area.getX(), -area.getY()); try { final StrictBounds pageBounds = StrictGeomUtility.createBounds(area.getX(), area.getY(), area.getWidth(), area.getHeight()); this.pageArea = pageBounds; this.drawArea = pageBounds; this.graphics = g2; if (startBlockBox(rootBox)) { processRootBand(pageBounds); } finishBlockBox(rootBox); } finally { this.graphics = null; this.drawArea = null; g2.dispose(); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.graphics.internal.LogicalPageDrawable.java
protected boolean drawDrawable(final RenderableReplacedContentBox content, final Graphics2D g2, final DrawableWrapper d) { final double x = StrictGeomUtility.toExternalValue(content.getX()); final double y = StrictGeomUtility.toExternalValue(content.getY()); final double width = StrictGeomUtility.toExternalValue(content.getWidth()); final double height = StrictGeomUtility.toExternalValue(content.getHeight()); if ((width < 0 || height < 0) || (width == 0 && height == 0)) { return false; }/*from w w w . j a va2 s . c o m*/ final Graphics2D clone = (Graphics2D) g2.create(); final StyleSheet styleSheet = content.getStyleSheet(); final Object attribute = styleSheet.getStyleProperty(ElementStyleKeys.ANTI_ALIASING); if (attribute != null) { if (Boolean.TRUE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } else if (Boolean.FALSE.equals(attribute)) { clone.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } } if (RenderUtility.isFontSmooth(styleSheet, metaData)) { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { clone.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } if (strictClipping == false) { final double extraPadding; final Object o = styleSheet.getStyleProperty(ElementStyleKeys.STROKE); if (o instanceof BasicStroke) { final BasicStroke stroke = (BasicStroke) o; extraPadding = stroke.getLineWidth() / 2.0; } else { extraPadding = 0.5; } final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x - extraPadding, y - extraPadding, width + 2 * extraPadding, height + 2 * extraPadding); clone.clip(clipBounds); clone.translate(x, y); } else { final Rectangle2D.Double clipBounds = new Rectangle2D.Double(x, y, width + 1, height + 1); clone.clip(clipBounds); clone.translate(x, y); } configureGraphics(styleSheet, clone); configureStroke(styleSheet, clone); final Rectangle2D.Double bounds = new Rectangle2D.Double(0, 0, width, height); d.draw(clone, bounds); clone.dispose(); return true; }