Java Code Examples for java.awt.Graphics2D#addRenderingHints()

The following examples show how to use java.awt.Graphics2D#addRenderingHints() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: netbeans   File: VectorIcon.java    License: Apache License 2.0 6 votes vote down vote up
private static Graphics2D createGraphicsWithRenderingHintsConfigured(Graphics basedOn) {
    Graphics2D ret = (Graphics2D) basedOn.create();
    Object desktopHints =
            Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints");
    Map<Object, Object> hints = new LinkedHashMap<Object, Object>();
    if (desktopHints != null && desktopHints instanceof Map<?, ?>)
        hints.putAll((Map<?, ?>) desktopHints);
    /* Enable antialiasing by default. Adding this is required in order to get non-text
    antialiasing on Windows. */
    hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    /* In case a subclass decides to render text inside an icon, standardize the text
    antialiasing setting as well. Don't try to follow the editor's anti-aliasing setting, or
    to do subpixel rendering. It's more important that icons render in a predictable fashion, so
    the icon designer can get can review the appearance at design time. */
    hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    // Make stroke behavior as predictable as possible.
    hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    ret.addRenderingHints(hints);
    return ret;
}
 
Example 2
Source Project: netbeans   File: SVGIcon.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected Image createAndPaintImage(
        Component c, ColorModel colorModel, int deviceWidth, int deviceHeight, double scale)
{
    BufferedImage img = createBufferedImage(colorModel, deviceWidth, deviceHeight);
    /* Use Batik's createGraphics method to improve performance and avoid the
    "Graphics2D from BufferedImage lacks BUFFERED_IMAGE hint" warning. */
    final Graphics2D g = GraphicsUtil.createGraphics(img);
    try {
        g.scale(scale, scale);
        try {
            GraphicsNode graphicsNode = getGraphicsNode();
            g.addRenderingHints(createHints());
            graphicsNode.paint(g);
        } catch (IOException e) {
            LOG.log(Level.WARNING,
                    "Unexpected exception while re-loading an SVG file that previously loaded successfully", e);
        }
    } finally {
        g.dispose();
    }
    return img;
}
 
Example 3
Source Project: brModelo   File: MasterCli.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;
    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    g2d.addRenderingHints(renderHints);

    g2d.setPaint(Color.BLACK);
    Stroke stroke = new BasicStroke(2.f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
    g2d.setStroke(stroke);

    PintarTextos(g2d);
}
 
Example 4
Source Project: ChatRoom   File: ScrollBarUI.java    License: MIT License 6 votes vote down vote up
@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
	// ���һ��Ҫ���ϰ�����Ȼ�϶���ʧЧ��
	g.translate(thumbBounds.x, thumbBounds.y); 
	g.setColor(new Color( 0x303030 ));// ���ñ߿���ɫ
	g.drawRoundRect(5, 0, 6, thumbBounds.height-1, 5, 5); // ��һ��Բ�Ǿ���
	// �������
	Graphics2D g2 = (Graphics2D) g;
	RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	g2.addRenderingHints(rh);
	// ��͸��
	//g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
	// ���������ɫ�����������˽��䣬��������
	g2.setPaint(new GradientPaint(c.getWidth() / 2, 1, new Color( 0x303030 ), c.getWidth() / 2, c.getHeight(), new Color( 0x303030 )));
	// ���Բ�Ǿ���
	g2.fillRoundRect(5, 0, 6, thumbBounds.height-1, 5, 5);
}
 
Example 5
Source Project: pumpernickel   File: RenderableImageOperation.java    License: MIT License 6 votes vote down vote up
@Override
public RenderedImage createRendering(RenderContext renderContext) {
	Rectangle bounds = new Rectangle(0, 0, img.getWidth(),
			img.getHeight());
	Rectangle newBounds = renderContext.getTransform()
			.createTransformedShape(bounds).getBounds();

	BufferedImage bi = new BufferedImage(newBounds.width,
			newBounds.height, BufferedImage.TYPE_INT_ARGB);
	Graphics2D g = bi.createGraphics();
	g.translate(-newBounds.x, -newBounds.y);
	if (renderContext.getRenderingHints() != null)
		g.addRenderingHints(renderContext.getRenderingHints());
	g.drawRenderedImage(img, renderContext.getTransform());
	g.dispose();
	return bi;
}
 
Example 6
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background
    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    //renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
    Graphics2D Canvas = (Graphics2D) g;

    Canvas.addRenderingHints(renderHints);

    Canvas.setStroke(new BasicStroke(
            1f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND));

    Canvas.setPaint(Color.BLACK);
    ProcessPaint(Canvas);
}
 
Example 7
Source Project: visualvm   File: Utils.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static Graphics2D prepareGraphics(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Map rhints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
    if( rhints == null && Boolean.getBoolean("swing.aatext") ) { //NOI18N
         g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
    } else if( rhints != null ) {
        g2.addRenderingHints( rhints );
    }
    return g2;
}
 
Example 8
Source Project: netbeans   File: VectorIconTester.java    License: Apache License 2.0 5 votes vote down vote up
private static Graphics2D createGraphicsWithRenderingHintsConfigured(Graphics basedOn) {
    Graphics2D ret = (Graphics2D) basedOn.create();
    Object desktopHints
            = Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints");
    Map<Object, Object> hints = new LinkedHashMap<Object, Object>();
    if (desktopHints != null && desktopHints instanceof Map<?, ?>) {
        hints.putAll((Map<?, ?>) desktopHints);
    }
    hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    ret.addRenderingHints(hints);
    return ret;
}
 
Example 9
Source Project: netbeans   File: HtmlRenderer.java    License: Apache License 2.0 5 votes vote down vote up
private static void configureRenderingHints(Graphics graphics) {
    Graphics2D g = (Graphics2D) graphics;
    Object desktopHints
            = Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints");
    if (desktopHints instanceof Map<?, ?>) {
        g.addRenderingHints((Map<?, ?>) desktopHints);
    } else if (HtmlLabelUI.antialias) {
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }

}
 
Example 10
private void drawArrow(Graphics2D g, int x1, int y1, int x2, int y2) {

        RenderingHints renderHints
                = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
        renderHints.put(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);

        renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

        g.addRenderingHints(renderHints);

        g.setStroke(new BasicStroke(
                getSetaLargura(),
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND));

        //g.setPaint(Color.BLACK);
        int ARR_SIZE = 3 + getSetaLargura();
        double dx = x2 - x1, dy = y2 - y1;
        double angle = Math.atan2(dy, dx);
        int len = (int) Math.sqrt(dx * dx + dy * dy);
        AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
        at.concatenate(AffineTransform.getRotateInstance(angle));
        //AffineTransform bkp = g.getTransform();
        g.setTransform(at);

        // Draw horizontal arrow starting in (0, 0)
        g.drawLine(ARR_SIZE, 0, len - ARR_SIZE, 0);

        if (isSetaPontaEsquerda()) {
            g.fillPolygon(new int[]{len, len - ARR_SIZE, len - ARR_SIZE, len},
                    new int[]{0, -ARR_SIZE, ARR_SIZE, 0}, 4);
        }
        if (isSetaPontaDireita()) {
            g.fillPolygon(new int[]{0, ARR_SIZE, ARR_SIZE, 0},
                    new int[]{0, -ARR_SIZE, ARR_SIZE, 0}, 4);
        }
    }
 
Example 11
Source Project: netbeans   File: LinkButton.java    License: Apache License 2.0 5 votes vote down vote up
private static Graphics2D prepareGraphics(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Map rhints = (Map)(Toolkit.getDefaultToolkit().getDesktopProperty("awt.font.desktophints")); //NOI18N
    if( rhints == null && Boolean.getBoolean("swing.aatext") ) { //NOI18N
         g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
    } else if( rhints != null ) {
        g2.addRenderingHints( rhints );
    }
    return g2;
}
 
Example 12
Source Project: netbeans   File: DocumentViewOp.java    License: Apache License 2.0 5 votes vote down vote up
void updateFontRenderContext(Graphics2D g, boolean paint) {
    if (g != null) {
        if (!paint && ViewHierarchyImpl.SETTINGS_LOG.isLoggable(Level.FINE)) {
            ViewHierarchyImpl.SETTINGS_LOG.fine(
                    "DocumentView.updateFontColorSettings() Antialiasing Rendering Hints:\n    Graphics: " + // NOI18N
                            g.getRenderingHints() + 
                            "\n    Desktop Hints: " + renderingHints + // NOI18N
                            "\n    Extra Hints: " + extraRenderingHints + '\n'); // NOI18N
        }

        // Use rendering hints (antialiasing etc.)
        if (renderingHints != null) {
            g.addRenderingHints(renderingHints);
        }
        if (extraRenderingHints.size() > 0) {
            g.addRenderingHints(extraRenderingHints);
        }
        if (paint) {
            if (!fontRenderContextFromPaint) {
                fontRenderContextFromPaint = true;
                fontRenderContext = g.getFontRenderContext();
                // Release children since the original non-painting graphics does not have
                // proper AA set.
                releaseChildrenNeedsLock(); // Already locked in DV.paint()
            }
        } else {
            fontRenderContext = g.getFontRenderContext();
        }
    }
}
 
Example 13
protected void paintLabel(Graphics2D g2d) {
    g2d.setColor(Color.DARK_GRAY);
    Toolkit tk = Toolkit.getDefaultToolkit();
    Map antialiasedTextHints = (Map) (tk.getDesktopProperty("awt.font.desktophints"));
    g2d.addRenderingHints(antialiasedTextHints);
    Dimension size = this.getSize();
    CenteredStringRenderer.drawCentered(g2d, this.label,
            size.width / 2, (int) (size.height * 0.4),
            CenteredStringRenderer.NOFLIP);
}
 
Example 14
Source Project: brModelo   File: Diagrama.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void ExternalPaint(Graphics g) {
    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    renderHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

    Graphics2D Canvas = (Graphics2D) g;

    Canvas.addRenderingHints(renderHints);

    Canvas.setStroke(new BasicStroke(
            1f,
            BasicStroke.CAP_ROUND,
            BasicStroke.JOIN_ROUND));

    Canvas.setPaint(Color.BLACK);

    for (int i = subItens.size() - 1; i > -1; i--) {
        Elementar e = subItens.get(i);
        if (e.CanPaint()) {
            e.DoPaint(Canvas);
        }
    }
}
 
Example 15
@Override
public Component getListCellRendererComponent(JList list, Object value,
        int index, boolean isSelected, boolean cellHasFocus) {
    Legenda.ItemDeLegenda entry = (Legenda.ItemDeLegenda) value;
    setText(entry.getTexto());

    BufferedImage off_Image = new BufferedImage(ehLina ? 32 : 16, 16, BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = off_Image.createGraphics();
    
    RenderingHints renderHints =
            new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    
    g.addRenderingHints(renderHints);
    g.setColor(entry.getCor());
    if (ehLina) {
        g.fillRect(1, 6, 30, 4);
    } else {
        g.fillRect(1, 1, 14, 14);
    }
    ImageIcon img = new ImageIcon(off_Image);

    setIcon(img);

    if (isSelected) {
        setBackground(HIGHLIGHT_COLOR);
        setForeground(Color.white);
    } else {
        setBackground(Color.white);
        setForeground(Color.black);
    }
    
    return this;
}
 
Example 16
Source Project: brModelo   File: Editor.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
    super.paintComponent(g); //paint background

    if (diagramaAtual == null) {
        return;
    }

    RenderingHints renderHints
            = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);

    Graphics2D Canvas = (Graphics2D) g;
    Canvas.addRenderingHints(renderHints);

    Canvas.setPaint(Color.BLACK);
    Stroke stroke = new BasicStroke(2.f,
            BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
    Canvas.setStroke(stroke);

    Canvas.drawRect(box.getLocation().x, box.getLocation().y, box.getWidth(), box.getHeight());
    Canvas.setPaint(Color.GRAY);
    Canvas.drawRect(box.getLocation().x + 1, box.getLocation().y + 1, box.getWidth(), box.getHeight());
    //Canvas.setPaint(Color.BLACK);
}
 
Example 17
@Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g); //paint background
        RenderingHints renderHints
                = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
        renderHints.put(RenderingHints.KEY_RENDERING,
                RenderingHints.VALUE_RENDER_QUALITY);

        Graphics2D Canvas = (Graphics2D) g;
        Canvas.addRenderingHints(renderHints);

//        Canvas.setPaint(Color.BLACK);
//        Canvas.draw3DRect(0, 0, getWidth() - 4, getHeight() - 4, true);
        Canvas.setPaint(Color.BLACK);
        Stroke stroke = new BasicStroke(1.f,
                BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER);
        Canvas.setStroke(stroke);

        Canvas.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
        Canvas.setPaint(Color.GRAY);
        Canvas.drawRect(0, 0, getWidth() - 2, getHeight() - 2);

        if (pgatual == 0) {
            return;
        }
        float[] dash4 = {2f, 2f, 2f};

        BasicStroke bs4 = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 1.0f, dash4,
                2f);
        Canvas.setStroke(bs4);

        Canvas.drawLine(l - 1, 1, l - 1, getHeight() - 1);
        Canvas.drawLine(l + w + 1, 1, l + w + 1, getHeight() - 1);
        Canvas.drawLine(1, t - 1, getWidth() - 1, t - 1);
        Canvas.drawLine(1, t + h + 1, getWidth() - 1, t + h + 1);

        Canvas.setStroke(new BasicStroke(
                1f,
                BasicStroke.CAP_ROUND,
                BasicStroke.JOIN_ROUND));
        Canvas.setPaint(Color.BLACK);
        DrawPagina(Canvas);
    }
 
Example 18
/**
 * Draw this plot onto the specified image at the position of the
 * specified rectangle with the size of the specified rectangle.
 * The plot is rendered using anti-aliasing.
 * This can be used to paint a number of different
 * plots onto a single buffered image.  This method can be used, for
 * example, by a servlet to produce an image, rather than
 * requiring an applet to instantiate a PlotBox.
 *
 * @param bufferedImage Image onto which the plot is drawn.
 * @param rectangle The size and position of the plot in the image.
 * @param hints Rendering hints for this plot.
 * @param transparent Indicator that the background of the plot
 * should not be painted.
 * @return The modified bufferedImage.
 */

public synchronized BufferedImage exportImage(BufferedImage bufferedImage, Rectangle rectangle, RenderingHints hints, boolean transparent) {
    Graphics2D graphics = bufferedImage.createGraphics();
    graphics.addRenderingHints(_defaultImageRenderingHints());
    if ( !transparent ) {
        graphics.setColor(Color.white);        // set the background color
        graphics.fill(rectangle);
    }
    _drawPlot(graphics, false , rectangle);
    return bufferedImage;
}
 
Example 19
Source Project: netbeans   File: VectorIcon.java    License: Apache License 2.0 3 votes vote down vote up
/**
 * Selectively enable or disable antialiasing during painting. Certain shapes may look slightly
 * better without antialiasing, e.g. entirely regular diagonal lines in very small icons when
 * there is no HiDPI scaling. Text antialiasing is unaffected by this setting.
 *
 * @param g the graphics to set antialiasing setting for
 * @param enabled whether antialiasing should be enabled or disabled
 */
protected static final void setAntiAliasing(Graphics2D g, boolean enabled) {
    Map<Object, Object> hints = new LinkedHashMap<Object, Object>();
    hints.put(RenderingHints.KEY_ANTIALIASING, enabled
            ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
    g.addRenderingHints(hints);
}
 
Example 20
/**
 * Sets the Rendering Hints o nthe Graphics.  This is used so that
 * any painters can set the Rendering Hits to match the view.
 * @param g2d
 */
public static void setRenderingHits(Graphics2D g2d) {
    g2d.addRenderingHints(sysHints);
}