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 Graphics create(int x, int y, int width, int height) 

Source Link

Document

Creates a new Graphics object based on this Graphics object, but with a new translation and clip area.

Usage

From source file:cpcc.ros.sim.osm.Camera.java

/**
 * Initialize the tile map./*  w w w.  jav  a  2s .c  om*/
 */
private void initMap() {
    map = new BufferedImage(mapWidth * cfg.getTileWidth(), mapHeight * cfg.getTileHeight(),
            BufferedImage.TYPE_INT_RGB);

    Graphics2D g2d = map.createGraphics();
    tiles = new Graphics[mapWidth][mapHeight];

    for (int w = 0; w < mapWidth; ++w) {
        for (int h = 0; h < mapHeight; ++h) {
            tiles[w][h] = g2d.create(w * cfg.getTileWidth(), h * cfg.getTileHeight(), cfg.getTileWidth(),
                    cfg.getTileHeight());
        }
    }
}

From source file:ca.sqlpower.wabit.report.ChartRenderer.java

public boolean renderReportContent(Graphics2D g, double width, double height, double scaleFactor, int pageIndex,
        boolean printing, SPVariableResolver variablesContext) {

    if (printing) {
        // If we're printing a streaming query, we have to
        // print whatever's displayed.
        if (this.chartCache == null || (this.chartCache != null && !this.chartCache.getQuery().isStreaming())) {
            refresh(false);// ww w.  ja v  a2s  .  c  o m
        }
    } else if (needsRefresh || this.chartCache == null) {
        // No chart loaded. Doing a refresh will trigger a new 
        // redraw later on.
        refresh();
        return false;
    }

    JFreeChart jFreeChart = null;
    try {
        jFreeChart = ChartSwingUtil.createChartFromQuery(chartCache);
        if (jFreeChart == null) {
            g.drawString("Loading...", 0, g.getFontMetrics().getHeight());
            return false;
        }

        Rectangle2D area = new Rectangle2D.Double(0, 0, width, height);

        // first pass establishes rendering info but draws nothing
        ChartRenderingInfo info = new ChartRenderingInfo();
        Graphics2D dummyGraphics = (Graphics2D) g.create(0, 0, 0, 0);
        jFreeChart.draw(dummyGraphics, area, info);
        dummyGraphics.dispose();

        // now for real
        Rectangle2D plotArea = info.getPlotInfo().getDataArea();
        ChartGradientPainter.paintChartGradient(g, area, (int) plotArea.getMaxY());
        jFreeChart.draw(g, area);

    } catch (Exception e) {
        logger.error("Error while rendering chart", e);
        g.drawString("Could not render chart: " + e.getMessage(), 0, g.getFontMetrics().getHeight());
    }
    return false;
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void drawTextByJTextArea(Graphics2D g2d, int x, int y, int width, int height, String text,
        String default_export_font, int style, int size, Color fontColor) throws Exception {

    //      g2d.setClip(x, y, width, height);
    //      g2d.setColor(Color.black);
    //      g2d.drawString(text, x, y+20);

    //Font font = new Font("Verdana", Font.PLAIN, 11);
    Font font = new Font(default_export_font, style, size);

    String[] stringsText = text.split("\r");
    //log.debug("TEXT: "+stringsText);
    //log.debug("TEXT: "+stringsText.length);

    String newText = "";

    for (int i = 0; i < stringsText.length; i++) {
        newText += stringsText[i];/*w ww  . ja va  2 s.co m*/
        if (i + 1 < stringsText.length) {
            newText += "\n";
        }
    }

    JTextArea n = new JTextArea(newText);
    n.setFont(font);
    n.setWrapStyleWord(true);
    n.setLineWrap(true);
    n.setForeground(fontColor);

    //log.debug("Text at: "+x+" "+y);
    //int x, int y, int width, int height
    n.setBounds(x, y, width, height);
    n.setOpaque(false);

    //Text
    SVGGraphics2D svgGenerator2 = (SVGGraphics2D) g2d.create(x, y, width, height);

    //svgGenerator2.create(x, y, width, height);
    //svgGenerator2.draw(.dra)
    n.paint(svgGenerator2);

}