Example usage for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON

List of usage examples for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON

Introduction

In this page you can find the example usage for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON.

Prototype

Object VALUE_TEXT_ANTIALIAS_ON

To view the source code for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_ON.

Click Source Link

Document

Text antialiasing hint value -- text rendering is done with some form of antialiasing.

Usage

From source file:org.forester.archaeopteryx.TreePanel.java

final void setTextAntialias() {
    if ((_phylogeny != null) && !_phylogeny.isEmpty()) {
        if (_phylogeny.getNumberOfExternalNodes() <= LIMIT_FOR_HQ_RENDERING) {
            _rendering_hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        } else {/* w  ww .j a va  2  s.  c o m*/
            _rendering_hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
        }
    }
    if (getMainPanel().getOptions().isAntialiasScreen()) {
        if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR) {
            _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        } else {
            _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        }
        try {
            _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
        } catch (final Throwable e) {
            _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        }
    } else {
        _rendering_hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
        _rendering_hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    }
}

From source file:org.apache.batchee.tools.maven.DiagramMojo.java

private void saveView(final Dimension currentSize, final Dimension desiredSize, final String name,
        final VisualizationViewer<Node, Edge> viewer) throws MojoExecutionException {
    BufferedImage bi = new BufferedImage(currentSize.width, currentSize.height, BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g = bi.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    final boolean db = viewer.isDoubleBuffered();
    viewer.setDoubleBuffered(false);/*from  w ww.  ja v a 2 s .co  m*/
    viewer.paint(g);
    viewer.setDoubleBuffered(db);
    if (!currentSize.equals(desiredSize)) {
        final double xFactor = desiredSize.width * 1. / currentSize.width;
        final double yFactor = desiredSize.height * 1. / currentSize.height;
        final double factor = Math.min(xFactor, yFactor);
        getLog().info("optimal size is (" + currentSize.width + ", " + currentSize.height + ")");
        getLog().info("scaling with a factor of " + factor);

        final AffineTransform tx = new AffineTransform();
        tx.scale(factor, factor);
        final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
        BufferedImage biNew = new BufferedImage((int) (bi.getWidth() * factor), (int) (bi.getHeight() * factor),
                bi.getType());
        bi = op.filter(bi, biNew);
    }
    g.dispose();

    OutputStream os = null;
    try {
        final File file = new File(output, (outputFileName != null ? outputFileName : name) + "." + format);
        os = new FileOutputStream(file);
        if (!ImageIO.write(bi, format, os)) {
            throw new MojoExecutionException("can't save picture " + name + "." + format);
        }
        getLog().info("Saved " + file.getAbsolutePath());
    } catch (final IOException e) {
        throw new MojoExecutionException("can't save the diagram", e);
    } finally {
        if (os != null) {
            try {
                os.flush();
                os.close();
            } catch (final IOException e) {
                // no-op
            }
        }
    }
}

From source file:org.apache.batchee.tools.maven.doc.DiagramGenerator.java

private void saveView(final Dimension currentSize, final Dimension desiredSize, final String name,
        final VisualizationViewer<Node, Edge> viewer) {
    BufferedImage bi = new BufferedImage(currentSize.width, currentSize.height, BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g = bi.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

    final boolean db = viewer.isDoubleBuffered();
    viewer.setDoubleBuffered(false);//from  w  w w  .  j  a  va  2  s.c  o  m
    viewer.paint(g);
    viewer.setDoubleBuffered(db);
    if (!currentSize.equals(desiredSize)) {
        final double xFactor = desiredSize.width * 1. / currentSize.width;
        final double yFactor = desiredSize.height * 1. / currentSize.height;
        final double factor = Math.min(xFactor, yFactor);
        info("optimal size is (" + currentSize.width + ", " + currentSize.height + ")");
        info("scaling with a factor of " + factor);

        final AffineTransform tx = new AffineTransform();
        tx.scale(factor, factor);
        final AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);
        BufferedImage biNew = new BufferedImage((int) (bi.getWidth() * factor), (int) (bi.getHeight() * factor),
                bi.getType());
        bi = op.filter(bi, biNew);
    }
    g.dispose();

    OutputStream os = null;
    try {
        final File file = new File(output, (outputFileName != null ? outputFileName : name) + "." + format);
        os = new FileOutputStream(file);
        if (!ImageIO.write(bi, format, os)) {
            throw new IllegalStateException("can't save picture " + name + "." + format);
        }
        info("Saved " + file.getAbsolutePath());
    } catch (final IOException e) {
        throw new IllegalStateException("can't save the diagram", e);
    } finally {
        if (os != null) {
            try {
                os.flush();
                os.close();
            } catch (final IOException e) {
                // no-op
            }
        }
    }
}

From source file:org.apache.fop.render.bitmap.AbstractBitmapDocumentHandler.java

/** {@inheritDoc} */
public IFPainter startPageContent() throws IFException {
    int bitmapWidth;
    int bitmapHeight;
    double scale;
    Point2D offset = null;// www . j  a  v a 2 s  .c o m
    if (targetBitmapSize != null) {
        //Fit the generated page proportionally into the given rectangle (in pixels)
        double scale2w = 1000 * targetBitmapSize.width / this.currentPageDimensions.getWidth();
        double scale2h = 1000 * targetBitmapSize.height / this.currentPageDimensions.getHeight();
        bitmapWidth = targetBitmapSize.width;
        bitmapHeight = targetBitmapSize.height;

        //Centering the page in the given bitmap
        offset = new Point2D.Double();
        if (scale2w < scale2h) {
            scale = scale2w;
            double h = this.currentPageDimensions.height * scale / 1000;
            offset.setLocation(0, (bitmapHeight - h) / 2.0);
        } else {
            scale = scale2h;
            double w = this.currentPageDimensions.width * scale / 1000;
            offset.setLocation((bitmapWidth - w) / 2.0, 0);
        }
    } else {
        //Normal case: just scale according to the target resolution
        scale = scaleFactor * getUserAgent().getTargetResolution()
                / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION;
        bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f);
        bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f);
    }

    //Set up bitmap to paint on
    this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight);
    Graphics2D graphics2D = this.currentImage.createGraphics();

    // draw page background
    if (!getSettings().hasTransparentPageBackground()) {
        graphics2D.setBackground(getSettings().getPageBackgroundColor());
        graphics2D.setPaint(getSettings().getPageBackgroundColor());
        graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight);
    }

    //Set rendering hints
    graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    if (getSettings().isAntiAliasingEnabled() && this.currentImage.getColorModel().getPixelSize() > 1) {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    }
    if (getSettings().isQualityRenderingEnabled()) {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    } else {
        graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    }
    graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

    //Set up initial coordinate system for the page
    if (offset != null) {
        graphics2D.translate(offset.getX(), offset.getY());
    }
    graphics2D.scale(scale / 1000f, scale / 1000f);

    return new Java2DPainter(graphics2D, getContext(), getFontInfo());
}

From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java

/**
 * Note:  assumption is that featureList is sorted by pStart position.
 *
 * @param featureList/*from  www . ja v  a 2s .  c  o  m*/
 * @param context
 * @param trackRectangle
 * @param track
 */
@Override
public void render(List<IGVFeature> featureList, RenderContext context, Rectangle trackRectangle, Track track) {

    double origin = context.getOrigin();
    double locScale = context.getScale();

    // TODO -- use enum instead of string "Color"
    if ((featureList != null) && !featureList.isEmpty()) {

        // Create a graphics object to draw font names.  Graphics are not cached
        // by font, only by color, so its neccessary to create a new one to prevent
        // affecting other tracks.
        Font font = FontManager.getFont(track.getFontSize());
        Graphics2D fontGraphics = (Graphics2D) context.getGraphic2DForColor(Color.BLACK).create();

        if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) {
            fontGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                    RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        }
        fontGraphics.setFont(font);

        //determine whether to show flanking regions
        PreferenceManager prefs = PreferenceManager.getInstance();
        boolean shouldShowFlankingRegions = prefs
                .getAsBoolean(PreferenceManager.SAM_SHOW_JUNCTION_FLANKINGREGIONS);

        // Track coordinates
        double trackRectangleX = trackRectangle.getX();
        double trackRectangleMaxX = trackRectangle.getMaxX();

        SpliceJunctionFeature selectedFeature = (SpliceJunctionFeature) ((FeatureTrack) track)
                .getSelectedFeature();

        // Start of Roche-Tessella modification
        if (track.getAutoScale()) {
            Frequency f = new Frequency();
            List<Integer> scores = new ArrayList<Integer>();

            for (IGVFeature feature : featureList) {
                SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
                f.addValue(junctionFeature.getScore());
                scores.add((int) junctionFeature.getScore());
            }

            Collections.sort(scores);
            Collections.reverse(scores);
            for (int s : scores) {
                if (f.getCumPct(s) < 0.99) {
                    maxDepth = s;
                    break;
                }
            }

        }
        // End of Roche-Tessella modification

        for (IGVFeature feature : featureList) {
            SpliceJunctionFeature junctionFeature = (SpliceJunctionFeature) feature;
            //if same junction as selected feature, highlight
            boolean shouldHighlight = false;
            if (selectedFeature != null && selectedFeature.isSameJunction(junctionFeature)) {
                setHighlightFeature(junctionFeature);
                shouldHighlight = true;
            }

            // Get the pStart and pEnd of the entire feature.  at extreme zoom levels the
            // virtual pixel value can be too large for an int, so the computation is
            // done in double precision and cast to an int only when its confirmed its
            // within the field of view.
            int flankingStart = junctionFeature.getStart();
            int flankingEnd = junctionFeature.getEnd();

            int junctionStart = junctionFeature.getJunctionStart();
            int junctionEnd = junctionFeature.getJunctionEnd();

            double virtualPixelStart = Math.round((flankingStart - origin) / locScale);
            double virtualPixelEnd = Math.round((flankingEnd - origin) / locScale);

            double virtualPixelJunctionStart = Math.round((junctionStart - origin) / locScale);
            double virtualPixelJunctionEnd = Math.round((junctionEnd - origin) / locScale);

            // If the any part of the feature fits in the
            // Track rectangle draw it
            if ((virtualPixelEnd >= trackRectangleX) && (virtualPixelStart <= trackRectangleMaxX)) {

                //
                int displayPixelEnd = (int) Math.min(trackRectangleMaxX, virtualPixelEnd);
                int displayPixelStart = (int) Math.max(trackRectangleX, virtualPixelStart);

                float depth = junctionFeature.getJunctionDepth();
                Color color = feature.getColor();

                drawFeature((int) virtualPixelStart, (int) virtualPixelEnd, (int) virtualPixelJunctionStart,
                        (int) virtualPixelJunctionEnd, depth, trackRectangle, context, feature.getStrand(),
                        junctionFeature, shouldHighlight, color, shouldShowFlankingRegions);
            }
        }

        //draw a central horizontal line
        Graphics2D g2D = context.getGraphic2DForColor(COLOR_CENTERLINE);
        g2D.drawLine((int) trackRectangleX, (int) trackRectangle.getCenterY(), (int) trackRectangleMaxX,
                (int) trackRectangle.getCenterY());

    }
}

From source file:org.broad.igv.renderer.SpliceJunctionRenderer.java

/**
 * Draw a filled arc representing a single feature. The thickness and height of the arc are proportional to the
 * depth of coverage.  Some of this gets a bit arcane -- the result of lots of visual tweaking.
 *
 * @param pixelFeatureStart  the starting position of the feature, whether on-screen or not
 * @param pixelFeatureEnd    the ending position of the feature, whether on-screen or not
 * @param pixelJunctionStart the starting position of the junction, whether on-screen or not
 * @param pixelJunctionEnd   the ending position of the junction, whether on-screen or not
 * @param depth              coverage depth
 * @param trackRectangle//from   w w w  .j ava2 s. c  o  m
 * @param context
 * @param strand
 * @param junctionFeature
 * @param shouldHighlight
 * @param featureColor       the color specified for this feature.  May be null.
 */
protected void drawFeature(int pixelFeatureStart, int pixelFeatureEnd, int pixelJunctionStart,
        int pixelJunctionEnd, float depth, Rectangle trackRectangle, RenderContext context, Strand strand,
        SpliceJunctionFeature junctionFeature, boolean shouldHighlight, Color featureColor,
        boolean shouldShowFlankingRegions) {

    boolean isPositiveStrand = true;
    // Get the feature's direction, color appropriately
    if (strand != null && strand.equals(Strand.NEGATIVE))
        isPositiveStrand = false;

    //If the feature color is specified, use it, except that we set our own alpha depending on whether
    //the feature is highlighted.  Otherwise default based on strand and highlight.
    Color color;
    if (featureColor != null) {
        int r = featureColor.getRed();
        int g = featureColor.getGreen();
        int b = featureColor.getBlue();
        int alpha = shouldHighlight ? 255 : 140;
        color = new Color(r, g, b, alpha);
    } else {
        if (isPositiveStrand)
            color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_POS : ARC_COLOR_POS;
        else
            color = shouldHighlight ? ARC_COLOR_HIGHLIGHT_NEG : ARC_COLOR_NEG;
    }

    Graphics2D g2D = context.getGraphic2DForColor(color);
    if (PreferenceManager.getInstance().getAsBoolean(PreferenceManager.ENABLE_ANTIALISING)) {
        g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }
    //Height of top of an arc of maximum depth
    int maxPossibleArcHeight = (trackRectangle.height - 1) / 2;

    if (shouldShowFlankingRegions) {
        if (junctionFeature.hasFlankingRegionDepthArrays()) {
            //draw a wigglegram of the splice junction flanking region depth of coverage

            int startFlankingRegionPixelLength = pixelJunctionStart - pixelFeatureStart;
            int endFlankingRegionPixelLength = pixelFeatureEnd - pixelJunctionEnd;

            drawFlankingRegion(g2D, pixelFeatureStart, startFlankingRegionPixelLength,
                    junctionFeature.getStartFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle,
                    isPositiveStrand);
            drawFlankingRegion(g2D, pixelJunctionEnd + 1, endFlankingRegionPixelLength,
                    junctionFeature.getEndFlankingRegionDepthArray(), maxPossibleArcHeight, trackRectangle,
                    isPositiveStrand);
        } else {
            //Draw rectangles indicating the overlap on each side of the junction
            int overlapRectHeight = 3;
            int overlapRectTopX = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -2 : 0);
            if (pixelFeatureStart < pixelJunctionStart) {
                g2D.fillRect(pixelFeatureStart, overlapRectTopX, pixelJunctionStart - pixelFeatureStart,
                        overlapRectHeight);
            }
            if (pixelJunctionEnd < pixelFeatureEnd) {
                g2D.fillRect(pixelJunctionEnd, overlapRectTopX, pixelFeatureEnd - pixelJunctionEnd,
                        overlapRectHeight);
            }
        }
    }

    //Create a path describing the arc, using Bezier curves. The Bezier control points for the top and
    //bottom arcs are based on the boundary points of the rectangles containing the arcs

    //proportion of the maximum arc height used by a minimum-height arc
    double minArcHeightProportion = 0.33;

    int innerArcHeight = (int) (maxPossibleArcHeight * minArcHeightProportion);
    float depthProportionOfMax = Math.min(1, depth / maxDepth);
    int arcWidth = Math.max(1,
            (int) ((1 - minArcHeightProportion) * maxPossibleArcHeight * depthProportionOfMax));
    int outerArcHeight = innerArcHeight + arcWidth;

    //Height of bottom of the arc
    int arcBeginY = (int) trackRectangle.getCenterY() + (isPositiveStrand ? -1 : 1);
    int outerArcPeakY = isPositiveStrand ? arcBeginY - outerArcHeight : arcBeginY + outerArcHeight;
    int innerArcPeakY = isPositiveStrand ? arcBeginY - innerArcHeight : arcBeginY + innerArcHeight;
    //dhmay: I don't really understand Bezier curves.  For some reason I have to put the Bezier control
    //points farther up or down than I want the arcs to extend.  This multiplier seems about right
    int outerBezierY = arcBeginY + (int) (1.3 * (outerArcPeakY - arcBeginY));
    int innerBezierY = arcBeginY + (int) (1.3 * (innerArcPeakY - arcBeginY));

    //Putting the Bezier control points slightly off to the sides of the arc 
    int bezierXPad = Math.max(1, (pixelJunctionEnd - pixelJunctionStart) / 30);

    GeneralPath arcPath = new GeneralPath();
    arcPath.moveTo(pixelJunctionStart, arcBeginY);
    arcPath.curveTo(pixelJunctionStart - bezierXPad, outerBezierY, //Bezier 1
            pixelJunctionEnd + bezierXPad, outerBezierY, //Bezier 2
            pixelJunctionEnd, arcBeginY); //Arc end
    arcPath.curveTo(pixelJunctionEnd + bezierXPad, innerBezierY, //Bezier 1
            pixelJunctionStart - bezierXPad, innerBezierY, //Bezier 2
            pixelJunctionStart, arcBeginY); //Arc end

    //Draw the arc, to ensure outline is drawn completely (fill won't do it, necessarily). This will also
    //give the arc a darker outline
    g2D.draw(arcPath);
    //Fill the arc
    g2D.fill(arcPath);

    g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
    g2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);

}

From source file:org.colombbus.tangara.AboutWindow.java

private BufferedImage createBackgroundImage(Image baseBackgroundImg) {
    BufferedImage newImg = new BufferedImage(baseBackgroundImg.getWidth(null),
            baseBackgroundImg.getHeight(null), BufferedImage.TYPE_INT_RGB);
    newImg.getGraphics().drawImage(baseBackgroundImg, 0, 0, null);
    Graphics2D drawingGraphics = (Graphics2D) newImg.getGraphics();
    Color titleColor = Configuration.instance().getColor("tangara.title.color");
    String titleText = Configuration.instance().getString("tangara.title");
    Font titleFont = Configuration.instance().getFont("tangara.title.font");
    drawingGraphics.setFont(titleFont);//from  w w  w . j  av  a2 s  . c o  m
    drawingGraphics.setColor(titleColor);
    drawingGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
            RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    drawingGraphics.drawString(titleText, marginLeft, windowHeight / 2 - marginText);
    return newImg;
}

From source file:org.cruk.mga.CreateReport.java

/**
 * Creates a summary plot for the given set of multi-genome alignment summaries.
 *
 * @param multiGenomeAlignmentSummaries/*from w  ww. j  av a2 s  .co m*/
 * @param the name of the image file
 * @throws IOException
 */
private void createSummaryPlot(Collection<MultiGenomeAlignmentSummary> multiGenomeAlignmentSummaries,
        String imageFilename) throws IOException {
    if (imageFilename == null)
        return;

    int n = multiGenomeAlignmentSummaries.size();
    log.debug("Number of summaries = " + n);

    scaleForPlotWidth();

    int fontHeight = getFontHeight();
    int rowHeight = (int) (fontHeight * ROW_HEIGHT_SCALING_FACTOR);
    int labelOffset = (rowHeight - fontHeight) / 2;
    int rowGap = (int) (fontHeight * ROW_GAP_SCALING_FACTOR);
    int height = (rowHeight + rowGap) * (n + 3);
    int rowSeparation = rowHeight + rowGap;

    BufferedImage image = new BufferedImage(plotWidth, height, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g2 = image.createGraphics();

    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    g2.setStroke(new BasicStroke(Math.max(1.0f, 0.65f * scaleFactor)));

    g2.setFont(font);

    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, plotWidth, height);
    g2.setColor(Color.BLACK);

    int offset = rowGap + rowHeight - labelOffset;
    int x0 = drawLabels(g2, offset, rowSeparation, multiGenomeAlignmentSummaries);

    long maxSequenceCount = getMaximumSequenceCount(multiGenomeAlignmentSummaries);
    log.debug("Maximum sequence count: " + maxSequenceCount);

    maxSequenceCount = Math.max(maxSequenceCount, minimumSequenceCount);

    long tickInterval = (int) getTickInterval(maxSequenceCount);
    log.debug("Tick interval: " + tickInterval);
    int tickIntervals = (int) (Math.max(1, maxSequenceCount) / tickInterval);
    if (maxSequenceCount % tickInterval != 0)
        tickIntervals += 1;
    maxSequenceCount = tickIntervals * tickInterval;
    log.debug("No. tick intervals: " + tickIntervals);
    log.debug("Maximum sequence count: " + maxSequenceCount);

    int y = rowGap + n * rowSeparation;
    int x1 = drawAxisAndLegend(g2, x0, y, tickIntervals, maxSequenceCount);

    offset = rowGap;
    drawAlignmentBars(g2, offset, rowHeight, rowSeparation, x0, x1, maxSequenceCount,
            multiGenomeAlignmentSummaries);

    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(imageFilename));
    ImageIO.write(image, "png", out);
    out.close();
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

protected void prepareGraphicsContext() {
    _g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    _g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    getDisplayServer().setGraphicsContext(_g2d);
}

From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java

public BufferedImage createTilePicture(int width) {

    Color[] colors = new Color[] { Color.GREEN, Color.RED, Color.BLUE, Color.YELLOW };

    double scale = width / sceneRectangle.getWidth();
    int height = (int) Math.round(sceneRectangle.getHeight() * scale);

    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D graphics = image.createGraphics();
    graphics.scale(scale, scale);//ww w.ja va  2s. co  m
    graphics.translate(-sceneRectangle.getX(), -sceneRectangle.getY());
    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphics.setPaint(Color.WHITE);
    graphics.fill(sceneRectangle);
    graphics.setStroke(new BasicStroke(100F));
    graphics.setFont(new Font("Arial", Font.PLAIN, 800));

    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].brighter(), 100));
        graphics.fill(rect);
    }
    for (int i = 0; i < tileInfos.length; i++) {
        Rectangle rect = tileInfos[i].rectangle;
        graphics.setPaint(addAlpha(colors[i % colors.length].darker(), 100));
        graphics.draw(rect);
        graphics.setPaint(colors[i % colors.length].darker().darker());
        graphics.drawString("Tile " + (i + 1) + ": " + tileInfos[i].id, rect.x + 1200F, rect.y + 2200F);
    }
    return image;
}