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

The following are Jave code examples for showing how to use addRenderingHints() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jaer   File: RNNfilter.java   View Source Code Vote up 6 votes
private BufferedImage getScaledImage() {
    BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
    g2d.drawImage(this.image.getImage(), 0, 0, getWidth(), getHeight(), null);
    return image;
}
 
Example 2
Project: brModelo   File: InspectorItemBase.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g) {
    super.paint(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);

    paint2D(Canvas);
}
 
Example 3
Project: brModelo   File: Editor.java   View Source Code Vote up 6 votes
@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 4
Project: brModelo   File: PainelPintador.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g) {
    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);

    super.paint(g);
    for (IObjetoPintavel p: pintaveis) {
        p.setOutroPintor(true);
        p.DoPaint(Canvas);
        p.setOutroPintor(false);
    }
}
 
Example 5
Project: incubator-netbeans   File: LinkButton.java   View Source Code Vote up 5 votes
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 6
Project: incubator-netbeans   File: Utils.java   View Source Code Vote up 5 votes
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 7
Project: brModelo   File: Desenhador.java   View Source Code Vote up 5 votes
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 8
Project: incubator-netbeans   File: LinkButton.java   View Source Code Vote up 5 votes
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 9
Project: COE1186   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 10
Project: COE1186   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 11
Project: powertext   File: BufferedImageBackgroundPainterStrategy.java   View Source Code Vote up 5 votes
/**
 * Rescales the displayed image to be the specified size.
 *
 * @param width The new width of the image.
 * @param height The new height of the image.
 * @param hint The scaling hint to use.
 */
@Override
protected void rescaleImage(int width, int height, int hint) {

	Image master = getMasterImage();
	if (master!=null) {

		Map<RenderingHints.Key, Object> hints =
				new HashMap<RenderingHints.Key, Object>();
		switch (hint) {
			default:
			case Image.SCALE_AREA_AVERAGING:
			case Image.SCALE_SMOOTH:
				hints.put(RenderingHints.KEY_INTERPOLATION,
						RenderingHints.VALUE_INTERPOLATION_BICUBIC);
				hints.put(RenderingHints.KEY_RENDERING,
						RenderingHints.VALUE_RENDER_QUALITY);
				hints.put(RenderingHints.KEY_ANTIALIASING,
						RenderingHints.VALUE_ANTIALIAS_ON);
		}

		bgImage = createAcceleratedImage(width, height);
		Graphics2D g = bgImage.createGraphics();
		g.addRenderingHints(hints);
		g.drawImage(master, 0,0, width,height, null);
		g.dispose();

	}
	else {
		bgImage = null;
	}
}
 
Example 12
Project: powertext   File: RSyntaxTextArea.java   View Source Code Vote up 5 votes
/**
 * Returns a <code>Graphics2D</code> version of the specified graphics
 * that has been initialized with the proper rendering hints.
 *
 * @param g The graphics context for which to get a
 *        <code>Graphics2D</code>.
 * @return The <code>Graphics2D</code>.
 */
private Graphics2D getGraphics2D(Graphics g) {
	Graphics2D g2d = (Graphics2D)g;
	if (aaHints!=null) {
		g2d.addRenderingHints(aaHints);
	}
	if (fractionalFontMetricsEnabled) {
		g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
						RenderingHints.VALUE_FRACTIONALMETRICS_ON);
	}
	return g2d;
}
 
Example 13
Project: jaer   File: RNNfilterExpFeatures.java   View Source Code Vote up 5 votes
private BufferedImage getScaledImage() {
    BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_RGB);
    Graphics2D g2d = image.createGraphics();
    g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
    g2d.drawImage(this.image.getImage(), 0, 0, getWidth(), getHeight(), null);
    return image;
}
 
Example 14
Project: COE1186   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 15
Project: AquamarineLake   File: MaterialButtonUI.java   View Source Code Vote up 5 votes
private void paintBackground (final Graphics g, final JComponent c) {
  Dimension size = c.getSize();
  Graphics2D g2 = (Graphics2D) g;
  
  g2.addRenderingHints (new RenderingHints (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
  
  g.setColor (c.getBackground ());
  g.fillRoundRect (0, 0, size.width, size.height, 7, 7);//button
}
 
Example 16
Project: brModelo   File: Diagrama.java   View Source Code Vote up 5 votes
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 17
Project: brModelo   File: JListItemParaItemLegenda.java   View Source Code Vote up 5 votes
@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 18
Project: GlitchKernel   File: StretchIcon.java   View Source Code Vote up 4 votes
/**
 * Paints the icon. The image is reduced or magnified to fit the component to which it is painted.
 * <P>
 * If the proportion has not been specified, or has been specified as <code>true</code>, the aspect ratio of the image will be preserved
 * by padding and centering the image horizontally or vertically. Otherwise the image may be distorted to fill the component it is
 * painted to.
 * <P>
 * If this icon has no image observer,this method uses the <code>c</code> component as the observer.
 *
 * @param c the component to which the Icon is painted. This is used as the observer if this icon has no image observer
 * @param g the graphics context
 * @param x not used.
 * @param y not used.
 *
 * @see ImageIcon#paintIcon(java.awt.Component, java.awt.Graphics, int, int)
 */
@Override
public synchronized void paintIcon(Component c, Graphics g, int x, int y)
{
    Image image = getImage();
    if (image == null)
    {
        return;
    }
    Insets insets = ((Container) c).getInsets();
    x = insets.left;
    y = insets.top;
    int w = c.getWidth() - x - insets.right;
    int h = c.getHeight() - y - insets.bottom;
    this.glitchArt.lblImageRender.setSize(w, h);

    if (proportionate && w >=510)
    {
        int iw = image.getWidth(c);
        int ih = image.getHeight(c);

        if ((iw * h) < (ih * w))
        {
            iw = (h * iw) / ih;
            x += (w - iw) / 2;
            w = iw;
        }
        else
        {
            ih = (w * ih) / iw;
            y += (h - ih) / 2;
            h = ih;
        }
    }
    ImageObserver io = getImageObserver();

    /*
     * Added this code to generate nicer looking results when scaling. - bspkrs
     * BEGIN CHANGES
     */
    this.glitchArt.resizedHeight = h;
    this.glitchArt.resizedWidth = w;
    this.glitchArt.lblImageRender.setSize(w, h);
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR);
    Graphics2D g2d = bi.createGraphics();
    g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY));
    g2d.drawImage(image, 0, 0, w, h, io == null ? c : io);
    g2d.dispose();
    /*
     * END CHANGES
     */

    g.drawImage(bi, x, y, w, h, io == null ? c : io);
}
 
Example 19
Project: 2D-Elliptic-Mesh-Generator   File: PlotCanvas.java   View Source Code Vote up 4 votes
public void paint(Graphics gcomp) {
    // System.out.println("PlotCanvas.paint");

    Graphics2D gcomp2D = (Graphics2D) gcomp;

    // anti-aliasing methods
    gcomp2D.addRenderingHints(AALIAS);
    gcomp2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    gcomp2D.setColor(getBackground());
    gcomp2D.fillRect(0, 0, getSize().width, getSize().height);

    draw.initGraphics(gcomp2D);

    // draw plot
    grid.plot(draw);

    for (int i = 0; i < plots.size(); i++) {
        getPlot(i).plot(draw);
        if (linkedLegendPanel != null) {
            linkedLegendPanel.nonote(i);
        }
    }

    for (int i = 0; i < objects.size(); i++) {
        getPlotable(i).plot(draw);
    }

    if (drawRect != null) {
        gcomp2D.setColor(Color.black);
        gcomp2D.setStroke(rectStroke);
        gcomp2D.drawRect(drawRect[0], drawRect[1], drawRect[2], drawRect[3]);
    }

    // draw note
    if (allowNote) {
        /*if (allowNoteCoord && coordNoted != null) {
        draw.setColor(NOTE_COLOR);
        draw.drawCoordinate(coordNoted);
        draw.drawText(Array.cat(reverseMapedData(coordNoted)), coordNoted);
        }*/
        for (int i = 0; i < plots.size(); i++) {
            if (getPlot(i).noted) {
                if (linkedLegendPanel != null) {
                    linkedLegendPanel.note(i);
                }
                getPlot(i).note(draw);
                //return;
            }
            if (allowNoteCoord && getPlot(i).coordNoted != null) {
                getPlot(i).noteCoord(draw, getPlot(i).coordNoted);
            }
        }
    }
}
 
Example 20
Project: brModelo   File: ImpressorPreview.java   View Source Code Vote up 4 votes
@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);
    }