Example usage for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_DEFAULT

List of usage examples for java.awt RenderingHints VALUE_TEXT_ANTIALIAS_DEFAULT

Introduction

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

Prototype

Object VALUE_TEXT_ANTIALIAS_DEFAULT

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

Click Source Link

Document

Text antialiasing hint value -- text rendering is done according to the #KEY_ANTIALIASING hint or a default chosen by the implementation.

Usage

From source file:org.jfree.chart.demo.StackedXYBarChartDemo2.java

private static JFreeChart createChart(TableXYDataset tablexydataset) {
    DateAxis dateaxis = new DateAxis("Date");
    dateaxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    dateaxis.setLowerMargin(0.01D);//from   w  w  w  .  j a v a  2 s.c om
    dateaxis.setUpperMargin(0.01D);
    NumberAxis numberaxis = new NumberAxis("Count");
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    numberaxis.setUpperMargin(0.10000000000000001D);
    StackedXYBarRenderer stackedxybarrenderer = new StackedXYBarRenderer(0.14999999999999999D);
    stackedxybarrenderer.setDrawBarOutline(false);
    stackedxybarrenderer.setBaseItemLabelsVisible(true);
    stackedxybarrenderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    stackedxybarrenderer.setBasePositiveItemLabelPosition(
            new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER));
    stackedxybarrenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0} : {1} = {2}",
            new SimpleDateFormat("yyyy"), new DecimalFormat("0")));
    XYPlot xyplot = new XYPlot(tablexydataset, dateaxis, numberaxis, stackedxybarrenderer);
    JFreeChart jfreechart = new JFreeChart("Holes-In-One / Double Eagles", xyplot);
    jfreechart.removeLegend();
    jfreechart.addSubtitle(new TextTitle("PGA Tour, 1983 to 2003"));
    TextTitle texttitle = new TextTitle(
            "http://www.golfdigest.com/majors/masters/index.ssf?/majors/masters/gw20040402albatross.html",
            new Font("Dialog", 0, 8));
    jfreechart.addSubtitle(texttitle);
    jfreechart.setTextAntiAlias(RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT);
    LegendTitle legendtitle = new LegendTitle(xyplot);
    legendtitle.setBackgroundPaint(Color.white);
    legendtitle.setFrame(new BlockBorder());
    legendtitle.setPosition(RectangleEdge.BOTTOM);
    jfreechart.addSubtitle(legendtitle);
    return jfreechart;
}

From source file:RenderingUtils.java

private static Map desktopHints(Graphics2D g2) {
    if (isPrinting(g2)) {
        return null;
    }//from   w w  w .j ava2s . c om
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    GraphicsDevice device = g2.getDeviceConfiguration().getDevice();
    Map desktopHints = (Map) toolkit.getDesktopProperty(PROP_DESKTOPHINTS + '.' + device.getIDstring());
    if (desktopHints == null) {
        desktopHints = (Map) toolkit.getDesktopProperty(PROP_DESKTOPHINTS);
    }
    // It is possible to get a non-empty map but with disabled AA.
    if (desktopHints != null) {
        Object aaHint = desktopHints.get(RenderingHints.KEY_TEXT_ANTIALIASING);
        if ((aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
                || (aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT)) {
            desktopHints = null;
        }
    }
    return desktopHints;
}

From source file:com.igormaznitsa.jhexed.renders.svg.SVGImage.java

public void render(final Graphics2D g) throws IOException {
    final Object antialiasText = g.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
    final Object antialiasDraw = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Object antialiasAlpha = g.getRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION);
    try {//from  w ww .  j  a  v  a  2s. c o  m
        processAntialias(this.quality, g);
        this.svgGraphicsNode.primitivePaint(g);
    } finally {
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                antialiasText == null ? RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT : antialiasText);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                antialiasDraw == null ? RenderingHints.VALUE_ANTIALIAS_DEFAULT : antialiasDraw);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                antialiasAlpha == null ? RenderingHints.VALUE_ALPHA_INTERPOLATION_DEFAULT : antialiasAlpha);
    }
}

From source file:DefaultGraphics2D.java

/**
 * Get the rendering context of the <code>Font</code> within this
 * <code>Graphics2D</code> context. The {@link FontRenderContext}
 * encapsulates application hints such as anti-aliasing and fractional
 * metrics, as well as target device specific information such as
 * dots-per-inch. This information should be provided by the application when
 * using objects that perform typographical formatting, such as
 * <code>Font</code> and <code>TextLayout</code>. This information should
 * also be provided by applications that perform their own layout and need
 * accurate measurements of various characteristics of glyphs such as advance
 * and line height when various rendering hints have been applied to the text
 * rendering.// w  ww  .  j  a v a2  s  .  c om
 * 
 * @return a reference to an instance of FontRenderContext.
 * @see java.awt.font.FontRenderContext
 * @see java.awt.Font#createGlyphVector(FontRenderContext,char[])
 * @see java.awt.font.TextLayout
 * @since JDK1.2
 */
public FontRenderContext getFontRenderContext() {
    //
    // Find if antialiasing should be used.
    //
    Object antialiasingHint = hints.get(RenderingHints.KEY_TEXT_ANTIALIASING);
    boolean isAntialiased = true;
    if (antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_ON
            && antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT) {

        // If antialias was not turned off, then use the general rendering
        // hint.
        if (antialiasingHint != RenderingHints.VALUE_TEXT_ANTIALIAS_OFF) {
            antialiasingHint = hints.get(RenderingHints.KEY_ANTIALIASING);

            // Test general hint
            if (antialiasingHint != RenderingHints.VALUE_ANTIALIAS_ON
                    && antialiasingHint != RenderingHints.VALUE_ANTIALIAS_DEFAULT) {
                // Antialiasing was not requested. However, if it was not turned
                // off explicitly, use it.
                if (antialiasingHint == RenderingHints.VALUE_ANTIALIAS_OFF)
                    isAntialiased = false;
            }
        } else
            isAntialiased = false;

    }

    //
    // Find out whether fractional metrics should be used.
    //
    boolean useFractionalMetrics = true;
    if (hints.get(RenderingHints.KEY_FRACTIONALMETRICS) == RenderingHints.VALUE_FRACTIONALMETRICS_OFF)
        useFractionalMetrics = false;

    FontRenderContext frc = new FontRenderContext(defaultTransform, isAntialiased, useFractionalMetrics);
    return frc;
}

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// w ww  .  ja v a 2 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);

}