Example usage for java.awt.image BufferedImage getGraphics

List of usage examples for java.awt.image BufferedImage getGraphics

Introduction

In this page you can find the example usage for java.awt.image BufferedImage getGraphics.

Prototype

public java.awt.Graphics getGraphics() 

Source Link

Document

This method returns a Graphics2D , but is here for backwards compatibility.

Usage

From source file:org.csml.tommo.sugar.modules.QualityHeatMapsPerTileAndBase.java

@Deprecated
private void writeTable2HTML(HTMLReportArchive report, LaneCoordinates laneCoordinates,
        TileNumeration tileNumeration) throws IOException {
    final ResultsTableModel model = new ResultsTableModel(this, laneCoordinates, tileNumeration);

    String flowCell = laneCoordinates.getFlowCell();
    Integer lane = laneCoordinates.getLane();

    ZipOutputStream zip = report.zipFile();
    StringBuffer b = report.htmlDocument();
    StringBuffer d = report.dataDocument();

    b.append("<table>\n");
    // Do the headers
    b.append("<tr>\n");
    d.append("#Tiles: ");

    // "row header" for base position number
    b.append("<th></th>\n");
    d.append("\t");
    for (int c = 0; c < model.getColumnCount(); c++) {
        b.append("<th>");
        b.append(model.getColumnName(c));
        d.append(model.getColumnName(c));
        b.append("</th>\n");
        d.append("\t");

        if (c == model.getTopBottomSeparatorColumn()) {
            b.append("<th>");
            b.append("Top-Bottom");
            d.append("Top-Bottom");
            b.append("</th>\n");
            d.append("\t");
        }/*  www  . ja  v  a2 s .co  m*/
    }
    b.append("</tr>\n");
    d.append("\n");

    long before = System.currentTimeMillis();

    // Do the rows
    d.append("#Base Positions: 1-" + maxSequenceLength);
    d.append("\n");
    for (int r = 0; r < model.getRowCount(); r++) {
        b.append("<tr>\n");

        // "header" for base position number
        b.append("<th>");
        int bp = model.getBasePosition(r);
        b.append(model.getCycleID(r) == 0 ? bp : "");
        b.append("</th>\n");

        for (int c = 0; c < model.getColumnCount(); c++) {
            TileBPCoordinates tileBPCoordinate = model.getCoordinateAt(r, c);
            TileCoordinates tileCoordinates = tileBPCoordinate.getTileCoordinate();
            b.append("<td>");
            MeanQualityMatrix matrix = getMeanQualityMatrix(tileBPCoordinate);

            if (matrix != null) {
                String imgFileName = "matrix_" + flowCell + "_" + lane + "_" + tileCoordinates.getTile() + "_"
                        + tileBPCoordinate.getBasePosition() + ".png";
                zip.putNextEntry(new ZipEntry(report.folderName() + "/Images/" + imgFileName));
                BufferedImage image = (BufferedImage) matrix.createBufferedImage(LinearPaintScale.PAINT_SCALE);
                int imgSize = Options.getHeatmapImageSize();
                BufferedImage scaledImage = new BufferedImage(imgSize, imgSize, BufferedImage.TYPE_INT_RGB);
                Graphics g = scaledImage.getGraphics();
                g.drawImage(image, 0, 0, imgSize, imgSize, null);
                g.dispose();
                ImageIO.write(scaledImage, "png", zip);

                b.append("<img src=\"Images/" + imgFileName + "\" alt=\"M[" + tileBPCoordinate.toString()
                        + "]\">\n");
            } else {
                b.append("");
                d.append("Missing matrix for: " + tileBPCoordinate + "\n");
            }
            b.append("</td>\n");

            if (c == model.getTopBottomSeparatorColumn()) {
                b.append("<td></td>\n");
            }
        }
        b.append("</tr>\n");
    }
    long after = System.currentTimeMillis();
    d.append("Creating report time: " + (after - before));

    b.append("</table>\n");
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

public String graphPerRrdDb(String rrdDb, GraphDefInfo graphDefInfo) {
    logger.info("start draw main graph rrdDb:" + rrdDb);
    String fileName = null;/*from  w  w  w. j a v a2 s  .  co m*/
    RrdGraphDef rrdGraphDef = null;
    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + ".png";

        rrdGraphDef = tetradRrdGraphDef.createGraphPerRrdDb(rrdDb, graphDefInfo);
        rrdGraphDef.setFilename(imagePath + fileName);

        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());
    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw main graph rrdDb:" + rrdDb);
    return fileName;
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

public String multiDeviceGraphPerRrd(String rrdDb, GraphDefInfo graphDefInfo) {
    logger.info("start draw main graph rrdDb:" + rrdDb);
    String fileName = null;/*from  w ww . j  av a2s .  c om*/
    RrdGraphDef rrdGraphDef = null;
    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + ".png";

        rrdGraphDef = tetradRrdGraphDef.createMultiDeviceGraphPerRrd(rrdDb, graphDefInfo);
        rrdGraphDef.setFilename(imagePath + fileName);

        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());
    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw main graph rrdDb:" + rrdDb);
    return fileName;
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

public String detailedGraphPerRrdDb(GraphDefInfo graphDefInfo) {
    logger.info("start draw main graph rrdDb:" + graphDefInfo.getFileName());
    String fileName = null;//from  w ww . j a va  2s  . com
    RrdGraphDef rrdGraphDef = null;
    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + "_detailed.png";

        rrdGraphDef = tetradRrdGraphDef.detailedCreateGraphPerRrdDb(graphDefInfo);
        rrdGraphDef.setFilename(imagePath + fileName);

        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());
    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw main graph rrdDb:" + graphDefInfo.getFileName());
    return fileName;
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

public String detailedMultiDeviceGraphPerRrd(String rrdDb, GraphDefInfo graphDefInfo, String title) {
    logger.info("start draw main graph rrdDb:" + rrdDb);
    String fileName = null;/*  w  w w . j a v  a2s.  c  o m*/
    RrdGraphDef rrdGraphDef = null;
    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + ".png";

        rrdGraphDef = tetradRrdGraphDef.detailedCreateMultiDeviceGraphPerRrd(rrdDb, graphDefInfo, title);
        rrdGraphDef.setFilename(imagePath + fileName);

        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());
    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw main graph rrdDb:" + rrdDb);
    return fileName;
}

From source file:org.csml.tommo.sugar.modules.QualityHeatMapsPerTileAndBase.java

private void writeImage2HTML(HTMLReportArchive report, LaneCoordinates laneCoordinates,
        TileNumeration tileNumeration) throws IOException {
    final ResultsTableModel model = new ResultsTableModel(this, laneCoordinates, tileNumeration);

    ZipOutputStream zip = report.zipFile();
    StringBuffer b = report.htmlDocument();
    StringBuffer d = report.dataDocument();

    int imgSize = Options.getHeatmapImageSize() + 1; // add one pixel for internal grid
    int width = imgSize * model.getColumnCount() + 1; // add one pixel for left border
    int topBottomSeparator = 50;
    if (model.getTopBottomSeparatorColumn() > 0) {
        width += topBottomSeparator; // add top bottom separator
    }//from   w ww.  j ava2  s  .c om
    int height = imgSize * model.getRowCount() + 1; // add one pixel for top border
    int yOffset = 10 * model.getTileNumeration().getCycleSize(); // space for column header
    int xOffset = 20; // space for row header
    BufferedImage fullImage = new BufferedImage(width + xOffset, height + yOffset, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) fullImage.getGraphics();
    Color headerBackground = new Color(0x00, 0x00, 0x80);
    Color headerForeground = Color.WHITE;

    // Do the headers
    d.append("#Tiles: ");

    d.append("\t");
    g2.setColor(headerBackground);
    g2.fillRect(0, height, width + xOffset, yOffset);
    g2.fillRect(width, 0, xOffset, height + yOffset);
    g2.setColor(headerForeground);
    g2.setFont(g2.getFont().deriveFont(7f).deriveFont(Font.BOLD));
    drawColumnHeader(g2, model, imgSize, topBottomSeparator, height, d);

    g2.setFont(g2.getFont().deriveFont(9f).deriveFont(Font.BOLD));
    drawRowHeader(g2, model, imgSize, width, xOffset);

    long before = System.currentTimeMillis();

    for (int r = 0; r < model.getRowCount(); r++) {

        int separator = 0;
        // "header" for base position number
        for (int c = 0; c < model.getColumnCount(); c++) {
            TileBPCoordinates tileBPCoordinate = model.getCoordinateAt(r, c);
            MeanQualityMatrix matrix = getMeanQualityMatrix(tileBPCoordinate);

            if (matrix != null) {
                BufferedImage image = (BufferedImage) matrix.createBufferedImage(LinearPaintScale.PAINT_SCALE);
                g2.drawImage(image, 1 + imgSize * c + separator, 1 + imgSize * r, imgSize * (c + 1) + separator,
                        imgSize * (r + 1), 0, 0, image.getWidth(), image.getHeight(), null);
            } else {
                d.append("Missing matrix for: " + tileBPCoordinate + "\n");
            }
            if (c == model.getTopBottomSeparatorColumn()) {
                separator = topBottomSeparator;
            }
        }
    }

    g2.dispose();

    String imgFileName = "matrix_" + laneCoordinates.getFlowCell() + "_" + laneCoordinates.getLane() + ".png";
    zip.putNextEntry(new ZipEntry(report.folderName() + "/Images/" + imgFileName));
    ImageIO.write(fullImage, "png", zip);
    b.append("<img src=\"Images/" + imgFileName + "\" alt=\"full image\">\n");

    // #38: Save each mean value of tile as a matrix file e.g. CSV file format
    writeCSVFile(report, laneCoordinates, tileNumeration, model);

    long after = System.currentTimeMillis();
    d.append("Creating report time: " + (after - before));

}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

public String graphSubRrdDb(GraphDefInfo graphDefInfo, String sortItem) {
    logger.info("start draw sub graph");
    String fileName = null;//from ww w .jav  a2s  .  c o  m
    RrdGraphDef rrdGraphDef = null;

    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + ".png";

        //rrd  
        rrdGraphDef = tetradRrdGraphDef.createSubMultiDeviceGraphPerRrd(graphDefInfo, sortItem);
        rrdGraphDef.setFilename(imagePath + fileName);

        // ? ? ?
        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());

    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw sub graph");
    return fileName;
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

public String lockGraphRrdDb(GraphDefInfo graphDefInfo, String sortItem) {
    logger.info("start draw lockGraph");
    String fileName = null;/*from w w w .  j  av  a 2 s .c  om*/
    RrdGraphDef rrdGraphDef = null;

    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + ".png";

        //rrd  
        rrdGraphDef = tetradRrdGraphDef.createLockMultiGraphPerRrd(graphDefInfo, sortItem);
        rrdGraphDef.setFilename(imagePath + fileName);

        // ? ? ?
        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());

    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw lockGraph");
    return fileName;
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

public String soloLockGraphRrdDb(GraphDefInfo graphDefInfo, String sortItem) {
    logger.info("start draw lockGraph");
    String fileName = null;/*w w  w. ja  v  a 2  s . c o  m*/
    RrdGraphDef rrdGraphDef = null;

    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + ".png";

        //rrd  
        rrdGraphDef = tetradRrdGraphDef.createSoloLockMultiGraphPerRrd(graphDefInfo, sortItem);
        rrdGraphDef.setFilename(imagePath + fileName);

        // ? ? ?
        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());

    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw lockGraph");
    return fileName;
}

From source file:net.cit.tetrad.rrd.service.TetradRrdDbServiceImpl.java

/**
 * ??? ?   ?//from   w  w  w. ja  v  a2s .  c om
 * @param device
 * @param filters
 * @param startTime
 * @param endTime
 * @return
 */
public String graphTetradRrdDb(GraphDefInfo graphDefInfo, String databaseName, String sortItem) {
    logger.info("start draw sub graph");
    String fileName = null;
    RrdGraphDef rrdGraphDef = null;

    try {
        String imagePath = CommonUtils.getDefaultRrdImgPath();
        fileName = graphDefInfo.getFileName() + "_" + databaseName + ".png";

        //rrd  
        rrdGraphDef = tetradRrdGraphDef.createRrdDbGraphDef(graphDefInfo, databaseName, sortItem);
        rrdGraphDef.setFilename(imagePath + fileName);

        // ? ? ?
        RrdGraph rrdGraph = new RrdGraph(rrdGraphDef);
        BufferedImage bim = new BufferedImage(graphDefInfo.getWidth(), graphDefInfo.getHeight(),
                BufferedImage.TYPE_INT_RGB);
        rrdGraph.render(bim.getGraphics());

    } catch (Exception e) {
        logger.error(e, e);
        fileName = "";
    }
    logger.info("end draw sub graph");
    return fileName;
}