Example usage for java.awt RenderingHints KEY_ANTIALIASING

List of usage examples for java.awt RenderingHints KEY_ANTIALIASING

Introduction

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

Prototype

Key KEY_ANTIALIASING

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

Click Source Link

Document

Antialiasing hint key.

Usage

From source file:org.kalypso.contribs.eclipse.jobs.BufferPaintJob.java

/**
 * Configures the graphics-context before actual painting is started (i.e. {@link IPaintable#paint(Graphics2D, IProgressMonitor)} is called).<br>
 * Default behaviour is to set activate anti-aliasing (normal and text).<br>
 * Overwrite to change./*w w  w. ja  v a 2s.  c  om*/
 */
private void configureGraphics(final Graphics2D gr) {
    gr.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    gr.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
}

From source file:domainhealth.frontend.graphics.JFreeChartGraphImpl.java

/**
 * Gets handle on the 2D graphics image object for the graph ready to 
 * change (eg. add text to).// www  . j  a v a 2 s  .co  m
 * 
 * @param graphImage The current graph image
 * @return The 2D object handle
 */
private Graphics2D get2DGraphics(BufferedImage graphImage) {
    Graphics2D graphics2D = (Graphics2D) graphImage.getGraphics();
    graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphics2D.setColor(Color.BLACK);
    return graphics2D;
}

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

/**
 * Initializes the icons//  ww w  .  ja v  a  2s.  co  m
 *
 */
private void initializeIcons() {
    BufferedImage imageSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = (Graphics2D) imageSelected.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(selectedBackgroundColor);
    g.fillRect(0, 0, iconSize, iconSize);
    g.setColor(Color.green);
    g.fillOval(0, 0, iconSize - 1, iconSize - 1);
    iconSelected = new ImageIcon(imageSelected);
    BufferedImage imageNotSelected = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_RGB);
    g = (Graphics2D) imageNotSelected.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g.setColor(Color.white);
    g.fillRect(0, 0, iconSize, iconSize);
    g.setColor(Color.lightGray);
    g.fillOval(0, 0, iconSize - 1, iconSize - 1);
    iconNotSelected = new ImageIcon(imageNotSelected);
}

From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java

/**
 *  Paint this Component using the Tree2DPainter with TimeBars
 *
 *  @param g the graphics device/*from w  w w  .  ja  v  a2  s  .  c  om*/
 */
@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g.create();

    /**
     * Enable antialiased graphics.
     */
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    Dimension currentSize = this.getSize();

    /**
     * Check to see if this component has changed size or if this
     * is our first time drawing.
     */
    if (this.fDimension == null || !this.fDimension.equals(currentSize) || this.fTreeArea == null
            || this.fLeftTreeArea == null || this.fEstMaxDateWidth == null) {
        this.fDimension = currentSize;

        this.fTreeArea = new Rectangle2D.Double(0, 0, currentSize.getWidth(), currentSize.getHeight());

        /** Adjust the width ratio using the maximum date width. */
        this.refreshLeafNodes();
        this.estimateMaximumDateWidth(g2);
        if ((this.fEstMaxDateWidth * 2) > (this.fTreeArea.getWidth() * this.fTreeWidthRatio)
                - this.fTreeArea.getWidth()) {
            this.fTreeWidthRatio = (this.fTreeArea.getWidth() - (this.fEstMaxDateWidth * 2))
                    / this.fTreeArea.getWidth();
        }

        /** Make left tree area for tree. */
        this.fLeftTreeArea = new Rectangle2D.Double(0, 0, this.fTreeArea.getWidth() * this.fTreeWidthRatio,
                this.fTreeArea.getHeight());

        /** Now, clear the right tree area so that it will be recalculated. */
        this.fRightTreeArea = null;
    }

    /** Paint the tree. */
    this.fTreePainter.drawTree(g2, this.fLeftTreeArea);

    /**
     * Check to see if we have calculated the date data.
     * The order of this is very important. We need to have
     * called the painter before we can get the coordinates.
     */
    if (this.fLeafNodes.isEmpty() || this.fLeafDates.isEmpty())
        /** Just calculate the Leaf data. */
        this.refreshLeafNodes();

    /**
     *  Draw the date axis and lines to the leaf nodes.
     */
    if (fTopLeafDate != null || fBottomLeafDate != null) {

        if (this.fRightTreeArea == null) {
            calculateDateMargins();
            this.fRightTreeArea = new Rectangle2D.Double(this.fTreeArea.getWidth() * this.fTreeWidthRatio,
                    this.fTopLeafPt.getY(), this.fTreeArea.getWidth(), this.fBottomLeafPt.getY());
        }

        double cursor = this.fRightTreeArea.getX()
                + ((this.fRightTreeArea.getWidth() - this.fRightTreeArea.getX()) / 2);
        drawDateAxis(g2, cursor, this.fRightTreeArea);
        drawDatesToLeafs(g2, cursor, this.fRightTreeArea);
    } else {
        // g2."No TIME INFORMATION AVAILABLE
        // g2.drawString("NO TIME INFORMATION AVAILABLE", x, y);
        System.out.println("TimeBarPanel: No time information available!");
    }

    if (this.fMousePressed && this.fMouseSelectionRect != null) {
        /** Color of line varies depending on image colors. */
        g2.setXORMode(Color.white);
        g2.drawRect(this.fMouseSelectionRect.x, this.fMouseSelectionRect.y, this.fMouseSelectionRect.width - 1,
                this.fMouseSelectionRect.height - 1);
    }

}

From source file:TextBouncer.java

protected void setAntialiasing(Graphics2D g2) {
    if (mAntialiasing == false)
        return;/*from w  w  w .  j  av a 2  s  .c  o  m*/
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}

From source file:org.tros.logo.swing.LogoPanel.java

@Override
public void forward(final double distance) {
    Drawable command = new Drawable() {

        @Override/*from w w w  .j  av  a 2 s. c  o  m*/
        public void draw(Graphics2D g2, TurtleState turtleState) {
            double newx = turtleState.penX + (distance * Math.cos(turtleState.angle));
            double newy = turtleState.penY + (distance * Math.sin(turtleState.angle));

            if (!turtleState.penup) {
                g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                g2.draw(new Line2D.Double(turtleState.penX, turtleState.penY, newx, newy));
            }

            turtleState.penX = newx;
            turtleState.penY = newy;
        }

        @Override
        public void addListener(DrawListener listener) {
        }

        @Override
        public void removeListener(DrawListener listener) {
        }

        @Override
        public Drawable cloneDrawable() {
            return this;
        }
    };
    submitCommand(command);
}

From source file:org.geowebcache.georss.GeometryRasterMaskBuilder.java

/**
 * @param geom a geometry to mask the affected tiles for, in this matrix's gridSubSet coordinate
 *     reference system//from   w  ww. j av a  2  s. c  om
 */
public void setMasksForGeometry(final Geometry geom) {
    if (geom == null || geom.isEmpty()) {
        return;
    }

    final int startLevel = getStartLevel();
    final int maxLevel = startLevel + getNumLevels() - 1;

    // loop over only up to the configured max masking level
    final int endLevel = Math.min(maxLevel, this.maxMaskLevel);

    if (logger.isDebugEnabled()) {
        logger.debug("Geom: " + geom);
    }

    if (aggregatedGeomBounds == null) {
        aggregatedGeomBounds = new Envelope(geom.getEnvelopeInternal());
    } else {
        aggregatedGeomBounds.expandToInclude(geom.getEnvelopeInternal());
    }

    for (int level = startLevel; level <= endLevel; level++) {
        final Geometry geometryInGridCrs = transformToGridCrs(geom, level);
        if (logger.isDebugEnabled()) {
            logger.debug("Geom in grid CRS: " + geometryInGridCrs);
        }

        final Geometry bufferedGeomInGridCrs = geometryInGridCrs.buffer(TILE_BUFFER_RATIO);

        if (logger.isDebugEnabled()) {
            logger.debug("Buffered Geom in grid CRS: " + bufferedGeomInGridCrs);
        }

        // do not generalize in LiteShape, it affects the expected masked pixels
        boolean generalize = false;
        // shape used identity transform, as the geometry is already projected
        Shape shape = new LiteShape(bufferedGeomInGridCrs, IDENTITY, generalize);

        Graphics2D graphics = getGraphics(level);
        /*
         * Disable antialiasing explicitly, otherwise the rendering will pick the platform's
         * default potentially producing missing pixels
         */
        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        graphics.setColor(Color.WHITE);
        graphics.fill(shape);
    }
}

From source file:net.technicpack.launcher.lang.ResourceLoader.java

public BufferedImage getCircleClippedImage(String imageName) {
    BufferedImage contentImage = getImage(imageName);

    // copy the picture to an image with transparency capabilities
    BufferedImage outputImage = new BufferedImage(contentImage.getWidth(), contentImage.getHeight(),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2 = (Graphics2D) outputImage.getGraphics();
    g2.drawImage(contentImage, 0, 0, null);

    // Create the area around the circle to cut out
    Area cutOutArea = new Area(new Rectangle(0, 0, outputImage.getWidth(), outputImage.getHeight()));

    int diameter = (outputImage.getWidth() < outputImage.getHeight()) ? outputImage.getWidth()
            : outputImage.getHeight();/*w ww  . j ava  2  s  .  c o m*/
    cutOutArea.subtract(new Area(new Ellipse2D.Float((outputImage.getWidth() - diameter) / 2,
            (outputImage.getHeight() - diameter) / 2, diameter, diameter)));

    // Set the fill color to an opaque color
    g2.setColor(Color.WHITE);
    // Set the composite to clear pixels
    g2.setComposite(AlphaComposite.Clear);
    // Turn on antialiasing
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Clear the cut out area
    g2.fill(cutOutArea);

    // dispose of the graphics object
    g2.dispose();

    return outputImage;
}

From source file:edu.ku.brc.ui.GraphicsUtils.java

/**
 * Modifes the given {@link Graphics} object to enable anti-aliased
 * drawing.//from  w w  w  .j a v  a 2s .co m
 *
 * @param g a {@link Graphics} object
 */
public static void turnOnAntialiasedDrawing(Graphics g) {
    if (g instanceof Graphics2D) {
        ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
}

From source file:com.qumasoft.guitools.compare.ContentRow.java

@Override
public void paint(Graphics g) {
    if ((getRowType() == ROWTYPE_REPLACE) && rowHadAnnotations) {
        Graphics2D g2 = (Graphics2D) g;

        String s = getText();/*from   w  w w  .  jav a  2  s  . co m*/

        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        if (s.length() > 0) {
            int index = 0;
            AttributedString attributedString = new AttributedString(s, getFont().getAttributes());
            try {
                for (byte rType : fileACharacterTypeArray) {
                    switch (rType) {
                    case ContentRow.ROWTYPE_DELETE:
                        attributedString.addAttribute(TextAttribute.STRIKETHROUGH, null, index, index + 1);
                        break;
                    case ContentRow.ROWTYPE_REPLACE:
                        attributedString.addAttribute(TextAttribute.BACKGROUND,
                                ColorManager.getReplaceCompareHiliteBackgroundColor(), index, index + 1);
                        break;
                    default:
                        break;
                    }
                    index++;
                }
                g2.drawString(attributedString.getIterator(), 0, getFont().getSize());
            } catch (java.lang.IllegalArgumentException e) {
                LOGGER.log(Level.WARNING, "bad replace indexes. begin index: [" + index + "] end index: ["
                        + index + "]. String length: [" + s.length() + "]");
            }
        } else {
            super.paint(g);
        }
    } else {
        super.paint(g);
    }
}