Example usage for java.awt Graphics2D create

List of usage examples for java.awt Graphics2D create

Introduction

In this page you can find the example usage for java.awt Graphics2D create.

Prototype

public abstract Graphics create();

Source Link

Document

Creates a new Graphics object that is a copy of this Graphics object.

Usage

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

protected void paintPage(Graphics2D grx) {
    if (pageError) {
        paintPageError(grx);//from www.j  av  a 2  s  . c o m
        return;
    }

    try {
        if (exporter == null) {
            exporter = getGraphics2DExporter();
        } else {
            exporter.reset();
        }

        exporter.setParameter(JRExporterParameter.JASPER_PRINT, viewerContext.getJasperPrint());
        exporter.setParameter(JRGraphics2DExporterParameter.GRAPHICS_2D, grx.create());
        exporter.setParameter(JRExporterParameter.PAGE_INDEX, Integer.valueOf(viewerContext.getPageIndex()));
        exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom));
        exporter.setParameter(JRExporterParameter.OFFSET_X, Integer.valueOf(1)); //lblPage border
        exporter.setParameter(JRExporterParameter.OFFSET_Y, Integer.valueOf(1));
        //exporter.setParameter(JRExporterParameter.FILE_RESOLVER, viewerContext.getFileResolver());
        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(JRViewerPanel.this,
                        viewerContext.getBundleString("error.displaying"));
            }
        });
    }

}

From source file:net.sf.jasperreports.swing.JRViewerPanel.java

protected void paintPage(Graphics2D grx) {
    if (pageError) {
        paintPageError(grx);//  ww  w .  j ava  2 s  .c  o m
        return;
    }

    try {
        if (exporter == null) {
            exporter = getGraphics2DExporter();
        } else {
            exporter.reset();
        }

        exporter.setExporterInput(new SimpleExporterInput(viewerContext.getJasperPrint()));

        SimpleGraphics2DReportConfiguration configuration = new SimpleGraphics2DReportConfiguration();
        configuration.setPageIndex(viewerContext.getPageIndex());
        configuration.setZoomRatio(realZoom);
        configuration.setOffsetX(1); //lblPage border
        configuration.setOffsetY(1);
        exporter.setConfiguration(configuration);

        SimpleGraphics2DExporterOutput output = new SimpleGraphics2DExporterOutput();
        Graphics2D g = (Graphics2D) grx.create();
        output.setGraphics2D(g);
        exporter.setExporterOutput(output);

        try {
            exporter.exportReport();
        } finally {
            g.dispose();
        }
    } catch (Exception e) {
        if (log.isErrorEnabled()) {
            log.error("Page paint error.", e);
        }

        pageError = true;

        paintPageError(grx);
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(JRViewerPanel.this,
                        viewerContext.getBundleString("error.displaying"));
            }
        });
    }

}

From source file:org.geomajas.plugin.rasterizing.layer.RasterDirectLayer.java

protected void addImage(Graphics2D graphics, ImageResult imageResult, MapViewport viewport) throws IOException {
    Rectangle screenArea = viewport.getScreenArea();
    ReferencedEnvelope worldBounds = viewport.getBounds();
    // convert map bounds to application bounds
    double printScale = screenArea.getWidth() / worldBounds.getWidth();
    if (tileScale < 0) {
        tileScale = printScale;/*  w  w  w  .  j  ava  2  s  . co  m*/
    }
    Envelope applicationBounds = new Envelope((worldBounds.getMinX()) * printScale,
            (worldBounds.getMaxX()) * printScale, -(worldBounds.getMinY()) * printScale,
            -(worldBounds.getMaxY()) * printScale);
    Bbox imageBounds = imageResult.getRasterImage().getBounds();
    // find transform between image bounds and application bounds
    double tx = (imageBounds.getX() * printScale / tileScale - applicationBounds.getMinX());
    double ty = (imageBounds.getY() * printScale / tileScale - applicationBounds.getMinY());
    BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageResult.getImage()));
    double scaleX = imageBounds.getWidth() / image.getWidth() * printScale / tileScale;
    double scaleY = imageBounds.getHeight() / image.getHeight() * printScale / tileScale;
    AffineTransform transform = new AffineTransform();
    transform.translate(tx, ty);
    transform.scale(scaleX, scaleY);
    if (log.isDebugEnabled()) {
        log.debug("adding image, width=" + image.getWidth() + ",height=" + image.getHeight() + ",x=" + tx
                + ",y=" + ty);
    }
    // opacity
    log.debug("before drawImage");
    // create a copy to apply transform
    Graphics2D g = (Graphics2D) graphics.create();
    // apply opacity to image off-graphics to avoid interference with whatever opacity model is used by graphics
    BufferedImage opaqueCopy = makeOpaque(image);
    g.drawImage(opaqueCopy, transform, null);
    log.debug("after drawImage");
}

From source file:com.openbravo.pos.util.JRViewer411.java

/**
 * // w ww .ja  v  a  2  s.  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, Integer.valueOf(pageIndex));
        exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom));
        exporter.setParameter(JRExporterParameter.OFFSET_X, Integer.valueOf(1)); //lblPage border
        exporter.setParameter(JRExporterParameter.OFFSET_Y, Integer.valueOf(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(JRViewer411.this, getBundleString("error.displaying"));
            }
        });
    }

}

From source file:neg.JRViewerSin.java

/**
 * //from w  w w  .  j a  va  2s .  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(JRViewerSin.this, getBundleString("error.displaying"));
            }
        });
    }

}

From source file:neg.JRViewer.java

/**
 * //from   w  w  w.  j  a va 2s .  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(JRViewer.this, getBundleString("error.displaying"));
            }
        });
    }

}

From source file:neg.JRViewerDet1.java

/**
 * //from  ww w  .j a v  a2s  .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(JRViewerDet1.this, getBundleString("error.displaying"));
            }
        });
    }

}

From source file:neg.JRViewerDet2.java

/**
 * //from w  ww.  j  a v 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(JRViewerDet2.this, getBundleString("error.displaying"));
            }
        });
    }

}

From source file:cn.pholance.datamanager.common.components.JRViewer.java

/**
 * /*  ww w . j  a  va  2s  .  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, Integer.valueOf(pageIndex));
        exporter.setParameter(JRGraphics2DExporterParameter.ZOOM_RATIO, new Float(realZoom));
        exporter.setParameter(JRExporterParameter.OFFSET_X, Integer.valueOf(1)); //lblPage border
        exporter.setParameter(JRExporterParameter.OFFSET_Y, Integer.valueOf(1));
        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:ireport_5_6_0.view.JRViewer.java

/**
 * /*w w w  .  jav a  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() {
            @Override
            public void run() {
                JOptionPane.showMessageDialog(JRViewer.this, getBundleString("error.displaying"));
            }
        });
    }
}