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:TransformTransRotation.java

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

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);//  w w  w. j a v a2 s  . c o  m

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    AffineTransform rat = new AffineTransform();
    rat.setToTranslation(100, 0);
    rat.rotate(Math.PI / 6);
    g2.transform(rat);

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:TransformTranslatedRotation.java

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

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/*from   w w w  .  j av a  2s  .  c om*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    float cm = 72 / 2.54f;
    g2.transform(AffineTransform.getRotateInstance(-Math.PI / 6, 3 * cm, 2 * cm));

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:TransformersRotationTranslation.java

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

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(75, 75);
    g2.transform(at);/*from  w  w  w.  jav a2  s.  c o m*/

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
    AffineTransform rat = new AffineTransform();
    rat.setToRotation(Math.PI / 6);
    rat.translate(100, 100);

    g2.transform(rat);

    // Draw the "new" shapes in dashed.
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
}

From source file:no.met.jtimeseries.chart.XYCloudSymbolRenderer.java

/**
 * Creates a new renderer.// w  ww  .j  a va  2  s  .  c  o m
 * @param numTimeSteps The number of total timesteps in the domain range. Used in the calculation of symbol width
 * @param numTimeStepsPerCloud The number of timesteps a cloudsymbol covers. Used in calculation of symbol width
 */
public XYCloudSymbolRenderer(int numTimeSteps) {
    super();
    renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    this.numTimeSteps = numTimeSteps;
}

From source file:LineStyles.java

/** This method draws the example figure */
public void paint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    // Use anti-aliasing to avoid "jaggies" in the lines
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Define the shape to draw
    GeneralPath shape = new GeneralPath();
    shape.moveTo(xpoints[0], ypoints[0]); // start at point 0
    shape.lineTo(xpoints[1], ypoints[1]); // draw a line to point 1
    shape.lineTo(xpoints[2], ypoints[2]); // and then on to point 2

    // Move the origin to the right and down, creating a margin
    g.translate(20, 40);/*from  w ww  .j  a  v a2 s.c  om*/

    // Now loop, drawing our shape with the three different line styles
    for (int i = 0; i < linestyles.length; i++) {
        g.setColor(Color.gray); // Draw a gray line
        g.setStroke(linestyles[i]); // Select the line style to use
        g.draw(shape); // Draw the shape

        g.setColor(Color.black); // Now use black
        g.setStroke(thindashed); // And the thin dashed line
        g.draw(shape); // And draw the shape again.

        // Highlight the location of the vertexes of the shape
        // This accentuates the cap and join styles we're demonstrating
        for (int j = 0; j < xpoints.length; j++)
            g.fillRect(xpoints[j] - 2, ypoints[j] - 2, 5, 5);

        g.drawString(capNames[i], 5, 105); // Label the cap style
        g.drawString(joinNames[i], 5, 120); // Label the join style

        g.translate(150, 0); // Move over to the right before looping again
    }
}

From source file:DrawingApplet.java

public void init() {
    // Find out how big the applet is and create an offscreen image
    // that size.
    int w = getWidth();
    int h = getHeight();
    image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    // Get a graphics context for drawing into the image
    g = image.createGraphics();//from   w  w w .  jav a2 s.  c  o  m
    // Start with a pure white background
    g.setPaint(Color.WHITE);
    g.fillRect(0, 0, w, h);
    // Turn on antialiasing
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    try {
        // sleep here to simulate a long init method
        Thread.sleep(4000);
    } catch (InterruptedException ie) {
        ie.printStackTrace();
    }
}

From source file:Hypnosis.java

public Hypnosis(double x, double y, double r1, double r2, double a1, double a2, float linewidth, int delay,
        double deltaA, double deltaX, double deltaY) {
    this.x = x;//from   w w w .  j  a  v a2  s.  co  m
    this.y = y;
    this.r1 = r1;
    this.r2 = r2;
    this.a1 = a1;
    this.a2 = a2;
    this.linewidth = linewidth;
    this.deltaA = deltaA;
    this.deltaX = deltaX;
    this.deltaY = deltaY;

    // Set up a timer to call actionPerformed() every delay milliseconds
    timer = new Timer(delay, this);

    // Create a buffer for double-buffering
    buffer = new BufferedImage((int) (2 * r2 + linewidth), (int) (2 * r2 + linewidth),
            BufferedImage.TYPE_INT_RGB);

    // Create a Graphics object for the buffer, and set the linewidth
    // and request antialiasing when drawing with it
    osg = buffer.createGraphics();
    osg.setStroke(new BasicStroke(linewidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    osg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
}

From source file:SWT2D.java

private void run() {
    // Create top level shell
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("Java 2D Example");
    // GridLayout for canvas and button
    shell.setLayout(new GridLayout());
    // Create container for AWT canvas
    final Composite canvasComp = new Composite(shell, SWT.EMBEDDED);
    // Set preferred size
    GridData data = new GridData();
    data.widthHint = 600;/*  w  ww  .j a v a  2  s  . co  m*/
    data.heightHint = 500;
    canvasComp.setLayoutData(data);
    // Create AWT Frame for Canvas
    java.awt.Frame canvasFrame = SWT_AWT.new_Frame(canvasComp);
    // Create Canvas and add it to the Frame
    final java.awt.Canvas canvas = new java.awt.Canvas();
    canvasFrame.add(canvas);
    // Get graphical context and cast to Java2D
    final java.awt.Graphics2D g2d = (java.awt.Graphics2D) canvas.getGraphics();
    // Enable antialiasing
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // Remember initial transform
    final java.awt.geom.AffineTransform origTransform = g2d.getTransform();
    // Create Clear button and position it
    Button clearButton = new Button(shell, SWT.PUSH);
    clearButton.setText("Clear");
    data = new GridData();
    data.horizontalAlignment = GridData.CENTER;
    clearButton.setLayoutData(data);
    // Event processing for Clear button
    clearButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            // Delete word list and redraw canvas
            wordList.clear();
            canvasComp.redraw();
        }
    });
    // Process canvas mouse clicks
    canvas.addMouseListener(new java.awt.event.MouseListener() {
        public void mouseClicked(java.awt.event.MouseEvent e) {
        }

        public void mouseEntered(java.awt.event.MouseEvent e) {
        }

        public void mouseExited(java.awt.event.MouseEvent e) {
        }

        public void mousePressed(java.awt.event.MouseEvent e) {
            // Manage pop-up editor
            display.syncExec(new Runnable() {
                public void run() {
                    if (eShell == null) {
                        // Create new Shell: non-modal!
                        eShell = new Shell(shell, SWT.NO_TRIM | SWT.MODELESS);
                        eShell.setLayout(new FillLayout());
                        // Text input field
                        eText = new Text(eShell, SWT.BORDER);
                        eText.setText("Text rotation in the SWT?");
                        eShell.pack();
                        // Set position (Display coordinates)
                        java.awt.Rectangle bounds = canvas.getBounds();
                        org.eclipse.swt.graphics.Point pos = canvasComp.toDisplay(bounds.width / 2,
                                bounds.height / 2);
                        Point size = eShell.getSize();
                        eShell.setBounds(pos.x, pos.y, size.x, size.y);
                        // Open Shell
                        eShell.open();
                    } else if (!eShell.isVisible()) {
                        // Editor versteckt, sichtbar machen
                        eShell.setVisible(true);
                    } else {
                        // Editor is visible - get text
                        String t = eText.getText();
                        // set editor invisible
                        eShell.setVisible(false);
                        // Add text to list and redraw canvas
                        wordList.add(t);
                        canvasComp.redraw();
                    }
                }
            });
        }

        public void mouseReleased(java.awt.event.MouseEvent e) {
        }
    });
    // Redraw the canvas
    canvasComp.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent e) {
            // Pass the redraw task to AWT event queue
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    // Compute canvas center
                    java.awt.Rectangle bounds = canvas.getBounds();
                    int originX = bounds.width / 2;
                    int originY = bounds.height / 2;
                    // Reset canvas
                    g2d.setTransform(origTransform);
                    g2d.setColor(java.awt.Color.WHITE);
                    g2d.fillRect(0, 0, bounds.width, bounds.height);
                    // Set font
                    g2d.setFont(new java.awt.Font("Myriad", java.awt.Font.PLAIN, 32));
                    double angle = 0d;
                    // Prepare star shape
                    double increment = Math.toRadians(30);
                    Iterator iter = wordList.iterator();
                    while (iter.hasNext()) {
                        // Determine text colors in RGB color cycle
                        float red = (float) (0.5 + 0.5 * Math.sin(angle));
                        float green = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(120)));
                        float blue = (float) (0.5 + 0.5 * Math.sin(angle + Math.toRadians(240)));
                        g2d.setColor(new java.awt.Color(red, green, blue));
                        // Redraw text
                        String text = (String) iter.next();
                        g2d.drawString(text, originX + 50, originY);
                        // Rotate for next text output
                        g2d.rotate(increment, originX, originY);
                        angle += increment;
                    }
                }
            });
        }
    });
    // Finish shell and open it
    shell.pack();
    shell.open();
    // SWT event processing
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:TextLayoutWithCarets.java

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

    if (mInitialized == false)
        initialize(g2);//from ww w . java2s .  c o  m

    float x = 20, y = 80;
    mLayout.draw(g2, x, y);

    // Create a plain stroke and a dashed stroke.
    Stroke[] caretStrokes = new Stroke[2];
    caretStrokes[0] = new BasicStroke();
    caretStrokes[1] = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { 4, 4 },
            0);

    // Now draw the carets
    Shape[] carets = mLayout.getCaretShapes(mHit.getInsertionIndex());
    for (int i = 0; i < carets.length; i++) {
        if (carets[i] != null) {
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            Shape shape = at.createTransformedShape(carets[i]);
            g2.setStroke(caretStrokes[i]);
            g2.draw(shape);
        }
    }
}

From source file:savant.amino.AminoCanvas.java

@Override
public void paintComponent(Graphics g) {
    if (GenomeUtils.getGenome().isSequenceSet()) {

        double aminoWidth = track.transformXPos(3) - track.transformXPos(0);
        if (aminoWidth > 0.5) {

            Graphics2D g2 = (Graphics2D) g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

            // We'll be drawing labels if a 'W' (tryptophan) will fit into the space of 3 bases.
            g2.setFont(g2.getFont().deriveFont(Font.PLAIN, 8));
            boolean labelled = g2.getFontMetrics().charWidth('W') < aminoWidth;

            try {
                List<Record> records = track.getDataInRange();
                if (records != null) {
                    for (Record r : records) {
                        RichIntervalRecord rr = (RichIntervalRecord) r;
                        int recordStart = rr.getInterval().getStart();
                        thickStart = rr.getThickStart();
                        int thickEnd = rr.getThickEnd() + 1;
                        LOG.debug(rr.getAlternateName() + ": thickStart=" + thickStart + ", thickEnd="
                                + thickEnd);

                        if (thickEnd > thickStart) {
                            sequence = GenomeUtils.getGenome().getSequence(
                                    NavigationUtils.getCurrentReferenceName(),
                                    RangeUtils.createRange(thickStart, thickEnd));

                            int pos = thickStart;
                            int leftovers = -1; // Left-overs from the previous block.
                            List<Block> blocks = rr.getBlocks();
                            if (blocks != null) {
                                for (Block b : blocks) {

                                    if (pos + 3 <= thickEnd) {
                                        // Block positions are relative to the start of the record.
                                        int blockStart = b.getPosition() + recordStart;
                                        int blockEnd = b.getEnd() + recordStart;
                                        LOG.debug(rr.getAlternateName() + ": blockStart=" + blockStart
                                                + ", blockEnd=" + blockEnd);

                                        AminoAcid a;

                                        // If we have leftovers, take care of them first.
                                        switch (leftovers) {
                                        case -1:
                                            // Fresh record with no leftovers.
                                            break;
                                        case 0:
                                            // No leftovers, so we can start immediately on the new block.
                                            pos = blockStart;
                                            if (pos < thickStart) {
                                                pos = thickStart;
                                            }
                                            break;
                                        case 1:
                                            // One base from previous block, two bases from current one.
                                            LOG.debug(rr.getAlternateName() + ": handling leftover "
                                                    + getBase(pos) + " at " + pos);
                                            if (rr.getStrand() == Strand.FORWARD) {
                                                a = AminoAcid.lookup(getBase(pos), getBase(blockStart),
                                                        getBase(blockStart + 1));
                                            } else {
                                                a = AminoAcid.lookup(getComplement(blockStart + 1),
                                                        getComplement(blockStart), getComplement(pos));
                                            }
                                            paintAminoAcid(g2, a, pos, 1, pos, labelled);
                                            paintAminoAcid(g2, a, blockStart, 2, blockStart - 1, labelled);
                                            pos = blockStart + 2;
                                            break;
                                        case 2:
                                            // Two bases from previous block, one base from current one.
                                            LOG.debug(rr.getAlternateName() + ": handling leftover "
                                                    + getBase(pos) + "," + getBase(pos + 1) + " at " + pos + ","
                                                    + (pos + 1));
                                            if (rr.getStrand() == Strand.FORWARD) {
                                                a = AminoAcid.lookup(getBase(pos), getBase(pos + 1),
                                                        getBase(blockStart));
                                            } else {
                                                a = AminoAcid.lookup(getComplement(blockStart),
                                                        getComplement(pos + 1), getComplement(pos));
                                            }
                                            paintAminoAcid(g2, a, pos, 2, pos, labelled);
                                            paintAminoAcid(g2, a, blockStart, 1, blockStart - 2, labelled);
                                            pos = blockStart + 1;
                                            break;
                                        }

                                        // Now, handle codons which are entirely contained within the block.
                                        while (pos + 3 <= blockEnd && pos + 3 <= thickEnd) {
                                            if (rr.getStrand() == Strand.FORWARD) {
                                                a = AminoAcid.lookup(getBase(pos), getBase(pos + 1),
                                                        getBase(pos + 2));
                                            } else {
                                                a = AminoAcid.lookup(getComplement(pos + 2),
                                                        getComplement(pos + 1), getComplement(pos));
                                            }
                                            paintAminoAcid(g2, a, pos, 3, pos, labelled);
                                            pos += 3;
                                        }
                                        leftovers = (blockEnd - pos) % 3;
                                        LOG.debug(rr.getAlternateName() + ": breaking out of loop: pos=" + pos
                                                + ", blockEnd=" + blockEnd + ", leftovers=" + leftovers);
                                    }// w ww  . j  a v a2 s.co  m
                                }
                            }
                        }
                    }
                }
            } catch (Exception x) {
                LOG.info("Unable to retrieve sequence.", x);
            }
        }
    }
}