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:components.SizeDisplayer.java

protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g.create(); //copy g
    Dimension minSize = getMinimumSize();
    Dimension prefSize = getPreferredSize();
    Dimension size = getSize();/* w  w  w . j  a va 2s .c o m*/
    int prefX = 0, prefY = 0;

    //Set hints so text looks nice.
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    //Draw the maximum size rectangle if we're opaque.
    if (isOpaque()) {
        g2d.setColor(getBackground());
        g2d.fillRect(0, 0, size.width, size.height);
    }

    //Draw the icon.
    if (icon != null) {
        Composite oldComposite = g2d.getComposite();
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.1f));
        icon.paintIcon(this, g2d, (size.width - icon.getIconWidth()) / 2,
                (size.height - icon.getIconHeight()) / 2);
        g2d.setComposite(oldComposite);
    }

    //Draw the preferred size rectangle.
    prefX = (size.width - prefSize.width) / 2;
    prefY = (size.height - prefSize.height) / 2;
    g2d.setColor(Color.RED);
    g2d.drawRect(prefX, prefY, prefSize.width - 1, prefSize.height - 1);

    //Draw the minimum size rectangle.
    if (minSize.width != prefSize.width || minSize.height != prefSize.height) {
        int minX = (size.width - minSize.width) / 2;
        int minY = (size.height - minSize.height) / 2;
        g2d.setColor(Color.CYAN);
        g2d.drawRect(minX, minY, minSize.width - 1, minSize.height - 1);
    }

    //Draw the text.
    if (text != null) {
        Dimension textSize = getTextSize(g2d);
        g2d.setColor(getForeground());
        g2d.drawString(text, (size.width - textSize.width) / 2,
                (size.height - textSize.height) / 2 + g2d.getFontMetrics().getAscent());
    }
    g2d.dispose();
}

From source file:peakmlviewer.dialog.PCADialog.java

public PCADialog(MainWnd mainwnd, Shell parent, String title) {
    super(parent, SWT.NONE);

    // save the parent pointer
    this.title = title;
    this.parent = parent;

    this.mainwnd = mainwnd;

    // create the window and set its properties
    shell = new Shell(parent, SWT.EMBEDDED | SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
    shell.setSize(500, 300);/*from   w  ww.  j a v  a 2  s. c o m*/
    shell.setText(title);

    // create the jfreechart
    plot = new XYPlot(collection, new NumberAxis("principal component 1"),
            new NumberAxis("principal component 2"), new StandardXYItemRenderer(StandardXYItemRenderer.SHAPES));
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinesVisible(true);
    plot.getRenderer().setBaseItemLabelsVisible(true);
    plot.getRenderer().setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        public String generateLabel(XYDataset dataset, int series, int item) {
            return labels[item];
        }
    });

    chart = new JFreeChart("Principle Component Analysis", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.WHITE);
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // add the components
    // --------------------------------------------------------------------------------
    // This uses the SWT-trick for embedding awt-controls in an SWT-Composit.
    try {
        System.setProperty("sun.awt.noerasebackground", "true");
    } catch (NoSuchMethodError error) {
        ;
    }

    java.awt.Frame frame = org.eclipse.swt.awt.SWT_AWT.new_Frame(shell);

    // create a new ChartPanel, without the popup-menu (5x false)
    frame.add(new ChartPanel(chart, false, false, false, false, false));
    // --------------------------------------------------------------------------------
}

From source file:org.jfree.chart.demo.FastScatterPlotDemo.java

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title  the frame title.//from w ww  .  j  a  va  2 s  .co m
 */
public FastScatterPlotDemo(final String title) {

    super(title);
    populateData();
    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
    //        chart.setLegend(null);

    // force aliasing of the rendered content..
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    //      panel.setHorizontalZoom(true);
    //    panel.setVerticalZoom(true);
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);

    setContentPane(panel);

}

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

/**
 * Creates a new renderer.//from   ww w. j a va  2s.c  o  m
 */
public XYWindArrowRenderer() {
    super();
    renderHints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    renderHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
}

From source file:test.FastScatterDemo.java

/**
 * Creates a new fast scatter plot demo.
 *
 * @param title  the frame title.//w w  w  .  j  av  a  2 s.  c o  m
 */
public FastScatterDemo(final String title) {

    super(title);
    populateData();
    final NumberAxis domainAxis = new NumberAxis("X");
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis("Y");
    rangeAxis.setAutoRangeIncludesZero(false);
    final FastScatterPlot plot = new FastScatterPlot(this.data, domainAxis, rangeAxis);
    final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
    //        chart.setLegend(null);

    // force aliasing of the rendered content..
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    //      panel.setHorizontalZoom(true);
    //    panel.setVerticalZoom(true);
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);

    setContentPane(panel);

}

From source file:org.aludratest.cloud.selenium.SeleniumResourceBean.java

private byte[] takeSeleniumResourceScreenshot(String seleniumUrl) {
    String url = seleniumUrl;//from   w ww. ja  va 2s  .  c  o  m
    url += "/selenium-server/driver/?cmd=captureScreenshotToString";

    InputStream in = null;
    try {
        in = new URL(url).openStream();
        in.read(new byte[3]); // read away "OK,"
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(in, baos);

        // decode Base64
        byte[] rawImageData = Base64.decodeBase64(baos.toByteArray());

        // create image from bytes
        BufferedImage img = ImageIO.read(new ByteArrayInputStream(rawImageData));

        // shrink image
        float sizeFactor = 2;
        BufferedImage imgSmall = new BufferedImage((int) (img.getWidth() / sizeFactor),
                (int) (img.getHeight() / sizeFactor), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = imgSmall.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.drawImage(img, 0, 0, imgSmall.getWidth(), imgSmall.getHeight(), 0, 0, img.getWidth(),
                img.getHeight(), null);
        g2d.dispose();

        // get PNG bytes
        baos = new ByteArrayOutputStream();
        ImageIO.write(imgSmall, "png", baos);
        return baos.toByteArray();
    } catch (IOException e) {
        LOG.warn("Could not take Selenium screenshot: " + e.getMessage());
        return null;
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:Main.java

@Override
protected void paintThumb(Graphics g, JComponent c, Rectangle r) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    Color color = null;// ww  w . ja v a  2 s.  c  om
    JScrollBar sb = (JScrollBar) c;
    if (!sb.isEnabled() || r.width > r.height) {
        return;
    } else if (isDragging) {
        color = Color.DARK_GRAY;
    } else if (isThumbRollover()) {
        color = Color.LIGHT_GRAY;
    } else {
        color = Color.GRAY;
    }
    g2.setPaint(color);
    g2.fillRoundRect(r.x, r.y, r.width, r.height, 10, 10);
    g2.setPaint(Color.WHITE);
    g2.drawRoundRect(r.x, r.y, r.width, r.height, 10, 10);
    g2.dispose();
}

From source file:com.igormaznitsa.mindmap.swing.panel.utils.ScalableIcon.java

public synchronized Image getImage(final double scale) {
    if (Double.compare(this.currentScaleFactor, scale) != 0) {
        this.scaledCachedImage = null;
    }//from  w  w w  .j a  v  a2 s  .co  m

    if (this.scaledCachedImage == null) {
        this.currentScaleFactor = scale;

        final int imgw = this.baseImage.getWidth(null);
        final int imgh = this.baseImage.getHeight(null);
        final int scaledW = (int) Math.round(imgw * this.baseScaleX * scale);
        final int scaledH = (int) Math.round(imgh * this.baseScaleY * scale);

        final BufferedImage img = new BufferedImage(scaledW, scaledH, BufferedImage.TYPE_INT_ARGB);
        final Graphics2D g = (Graphics2D) img.getGraphics();

        g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);

        g.drawImage(this.baseImage, 0, 0, scaledW, scaledH, null);
        g.dispose();

        this.scaledCachedImage = img;
    }
    return this.scaledCachedImage;
}

From source file:com.bbn.c2s2.pint.testdata.chart.ScatterPlot.java

public ScatterPlot(String chartTitle, String domainAxisTitle, String rangeAxisTitle, double[][] data) {
    super(chartTitle);
    this.data = data;
    final NumberAxis domainAxis = new NumberAxis(domainAxisTitle);
    domainAxis.setAutoRangeIncludesZero(false);
    final NumberAxis rangeAxis = new NumberAxis(rangeAxisTitle);
    rangeAxis.setAutoRangeIncludesZero(false);
    XYDataset dataSet = getDataSet(data);
    XYItemRenderer renderer = getRenderer();
    final XYPlot plot = new XYPlot(dataSet, domainAxis, rangeAxis, renderer);
    //      plot.
    //      final FastScatterPlot plot = new FastScatterPlot(data, domainAxis,
    //            rangeAxis);
    //      DrawingSupplier supplier = new ModifiedDrawingSupplier(5.0);
    //      plot.setDrawingSupplier(supplier);
    chart = new JFreeChart(chartTitle, plot);
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    chart.removeLegend();/*from w  w w.j  a  va 2  s .  com*/

    final ChartPanel panel = new ChartPanel(chart, true);
    panel.setPreferredSize(new java.awt.Dimension(500, 270));
    panel.setMinimumDrawHeight(10);
    panel.setMaximumDrawHeight(2000);
    panel.setMinimumDrawWidth(20);
    panel.setMaximumDrawWidth(2000);

    setContentPane(panel);
}

From source file:org.jcurl.core.swing.WCComponent.java

private BufferedImage renderPng(final String watermark) {
    final BufferedImage img = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_INT_ARGB);
    final Graphics2D g2 = (Graphics2D) img.getGraphics();
    {/*from www.j a  va 2  s.co m*/
        final Map<Key, Object> hints = new HashMap<Key, Object>();
        hints.put(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
        hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        hints.put(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
        hints.put(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
        hints.put(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        hints.put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
        hints.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g2.addRenderingHints(hints);
    }
    final Font f0 = g2.getFont();
    paint(g2);
    g2.setTransform(new AffineTransform());
    if (watermark != null) {
        if (log.isDebugEnabled())
            log.debug(f0);
        g2.setFont(f0);
        g2.setColor(new Color(0, 0, 0, 128));
        g2.drawString(watermark, 10, 20);
    }
    g2.dispose();
    return img;
}