Example usage for java.awt RenderingHints VALUE_ANTIALIAS_ON

List of usage examples for java.awt RenderingHints VALUE_ANTIALIAS_ON

Introduction

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

Prototype

Object VALUE_ANTIALIAS_ON

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

Click Source Link

Document

Antialiasing hint value -- rendering is done with antialiasing.

Usage

From source file:org.evors.rs.ui.sandpit.WorldViewer.java

@Override
public void draw() {
    Graphics2D g2 = (Graphics2D) getGraphics();
    camera.setWindowSize(new Vector2D(this.getWidth(), this.getHeight()));
    g2.setColor(Color.WHITE);/*  w  ww. j av  a 2  s.c  o  m*/
    g2.fillRect(0, 0, getWidth(), getHeight());
    AffineTransform prevTrans = g2.getTransform();
    g2.setTransform(camera.getTransform());
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    grid.draw(g2);
    if (world != null) {
        SandpitRenderer.drawWorld(g2, world);
    }
    g2.setTransform(prevTrans);
}

From source file:Main.java

ThreeDimensionalBorder(Color color, int transparency, int shadowWidth) {
    this.color = color;
    shadowPad = shadowWidth;//from   w ww . j ava 2 s.  c o  m

    stroke = new BasicStroke(thickness);
    strokePad = thickness / 2;

    hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    int pad = radius + strokePad;
    int bottomPad = pad + strokePad + shadowPad;
    int rightPad = pad + strokePad + shadowPad;
    insets = new Insets(pad, pad, bottomPad + shadowPad, rightPad);
}

From source file:FontRenderContextRenderingHints.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    RenderingHints qualityHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2D.setRenderingHints(qualityHints);

    AffineTransform at = new AffineTransform();
    at.setToTranslation(-300, -400);//from   w w w .  ja v a  2s  .  co  m
    at.shear(-0.5, 0.0);
    FontRenderContext frc = new FontRenderContext(at, false, false);
    TextLayout tl = new TextLayout("World!", font, frc);
    Shape outline = tl.getOutline(null);
    g2D.setColor(Color.blue);

    BasicStroke wideStroke = new BasicStroke(2.0f);
    g2D.setStroke(wideStroke);
    g2D.draw(outline);

}

From source file:Main.java

public void drawImage() {
    Graphics2D g = img.createGraphics();
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHints(hints);/*from w  w w .java 2 s .  c  om*/

    g.setColor(Color.RED);
    int x = (int) mouse.getX();
    int y = (int) mouse.getY();
    g.setStroke(new BasicStroke(2));
    int s = 3;
    g.drawLine(x - s, y, x + s, y);
    g.drawLine(x, y - s, x, y + s);
    l.setIcon(new ImageIcon(img));

    g.dispose();
}

From source file:Main.java

public void drawImage() {
    Graphics2D g = img.createGraphics();
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHints(hints);//from ww w  .  j  av a 2  s  . c om

    g.setStroke(new BasicStroke(4));
    for (Ellipse2D shape : shapes) {
        g.setColor(Color.blue);
        g.fill(shape);
        if (shape.contains(mouse)) {
            g.setColor(Color.RED);
        } else {
            g.setColor(Color.YELLOW);
        }
        g.draw(shape);
    }

    l.setIcon(new ImageIcon(img));

    g.dispose();
}

From source file:MyCanvas.java

public Graphics2D createDemoGraphics2D(Graphics g) {
    Graphics2D g2 = null;//from w w  w.  j a  v a  2s  .co  m

    if (offImg == null || offImg.getWidth() != getSize().width || offImg.getHeight() != getSize().height) {
        offImg = (BufferedImage) createImage(getSize().width, getSize().height);
    }

    if (offImg != null) {
        g2 = offImg.createGraphics();
        g2.setBackground(getBackground());
    }

    // .. set attributes ..
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // .. clear canvas ..
    g2.clearRect(0, 0, getSize().width, getSize().height);

    return g2;
}

From source file:MainClass.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

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

    String s = "www.java2s.com";
    Font font = new Font("Serif", Font.PLAIN, 32);

    if (mTextLayout == null) {
        FontRenderContext frc = g2.getFontRenderContext();
        mTextLayout = new TextLayout(s, font, frc);
    }//from   w w w . j  av  a 2s  .  c  om

    mTextLayout.draw(g2, mX, mY);

}

From source file:dataminning2.KmeanGraphplot.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    int w = getWidth();
    int h = getHeight();
    // Draw ordinate.
    g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
    // Draw abcissa.
    g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
    double xInc = (double) (w - 2 * PAD) / (data.length - 1);
    double scale = (double) (h - 2 * PAD) / 88;
    // Mark data points.

    g2.setPaint(Color.red);/*from  w  ww.  j  a v a  2 s . co m*/

    for (int i = 0; i < cluster0.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }

    g2.setPaint(Color.BLUE);

    for (int i = 0; i < cluster1.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
    g2.setPaint(Color.YELLOW);

    for (int i = 0; i < cluster2.length; i++) {
        double x = PAD + i * dataX[i];
        double y = h - PAD - scale * dataY[i];
        g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
    }
}

From source file:Main.java

public void render(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(Color.WHITE);//from w ww  .  j a  va 2s. co m
    Font font = new Font("Verdana", Font.PLAIN, 20);
    g2d.setFont(font);
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    FontMetrics fm = g2d.getFontMetrics();

    String option = "This is a test";

    int x = (getWidth() - fm.stringWidth(option)) / 2;
    int y = ((getHeight() - fm.getHeight()) / 2);
    g2d.drawString(option, x, y + fm.getAscent());
    g2d.drawRect((int) x - 20, (int) y - 10, (int) fm.stringWidth(option) + 40, (int) fm.getHeight() + 20);
}

From source file:CombiningShapes.java

public void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    String option = (String) mOptions.getSelectedItem();
    if (option.equals("outline")) {
        // draw the outlines and return.
        g2.draw(mShapeOne);/*from w  w  w.ja  v  a2 s  .c  o m*/
        g2.draw(mShapeTwo);
        return;
    }

    // Create Areas from the shapes.
    Area areaOne = new Area(mShapeOne);
    Area areaTwo = new Area(mShapeTwo);
    // Combine the Areas according to the selected option.
    if (option.equals("add"))
        areaOne.add(areaTwo);
    else if (option.equals("intersection"))
        areaOne.intersect(areaTwo);
    else if (option.equals("subtract"))
        areaOne.subtract(areaTwo);
    else if (option.equals("exclusive or"))
        areaOne.exclusiveOr(areaTwo);

    // Fill the resulting Area.
    g2.setPaint(Color.orange);
    g2.fill(areaOne);
    // Draw the outline of the resulting Area.
    g2.setPaint(Color.black);
    g2.draw(areaOne);
}