Example usage for java.awt RadialGradientPaint RadialGradientPaint

List of usage examples for java.awt RadialGradientPaint RadialGradientPaint

Introduction

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

Prototype

public RadialGradientPaint(Rectangle2D gradientBounds, float[] fractions, Color[] colors,
        CycleMethod cycleMethod) 

Source Link

Document

Constructs a RadialGradientPaint with a default SRGB color space.

Usage

From source file:HighlightedButton.java

/**
 * Creates a new instance of HighlightedButton
 */// w  w w .  j ava2 s.  co  m
public HighlightedButton(String label) {
    super(label);

    // Get the Graphics for the image
    Graphics2D g2d = highlight.createGraphics();

    // Erase the image with a transparent background
    g2d.setComposite(AlphaComposite.Clear);
    g2d.fillRect(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE);
    g2d.setComposite(AlphaComposite.SrcOver);

    // Draw the highlight
    Point2D center = new Point2D.Float((float) HIGHLIGHT_SIZE / 2.0f, (float) HIGHLIGHT_SIZE / 2.0f);
    float radius = (float) HIGHLIGHT_SIZE / 2.0f;
    float[] dist = { 0.0f, .85f };
    Color[] colors = { Color.white, new Color(255, 255, 255, 0) };
    RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors);
    g2d.setPaint(paint);
    g2d.fillOval(0, 0, HIGHLIGHT_SIZE, HIGHLIGHT_SIZE);
    g2d.dispose();
}

From source file:st.jigasoft.dbutil.util.ReportTheme.java

private static RadialGradientPaint createGradientPaint(Color c1, Color c2) {
    Point2D center = new Point2D.Float(0, 0);
    float radius = 200;
    float[] dist = { 0.0f, 1.0f };
    return new RadialGradientPaint(center, radius, dist, new Color[] { c1, c2 });
}

From source file:Diva.java

@Override
public void paint(Graphics g, JComponent c) {
    Graphics2D g2 = (Graphics2D) g.create();

    // Paint the view.
    super.paint(g2, c);

    if (mActive) {
        // Create a radial gradient, transparent in the middle.
        java.awt.geom.Point2D center = new java.awt.geom.Point2D.Float(mX, mY);
        float radius = 72;
        float[] dist = { 0.0f, 1.0f };
        Color[] colors = { new Color(0.0f, 0.0f, 0.0f, 0.0f), Color.BLACK };
        RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors);
        g2.setPaint(p);//from  www.  j  a va2  s .  c  om
        g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .6f));
        g2.fillRect(0, 0, c.getWidth(), c.getHeight());
    }

    g2.dispose();
}

From source file:uom.research.thalassemia.util.PieChartCreator.java

/**
 * A utility method for creating gradient paints.
 *
 * @param c1 color 1./*w ww.java2s . c  om*/
 * @param c2 color 2.
 *
 * @return A radial gradient paint.
 */
private RadialGradientPaint createGradientPaint(Color c1, Color c2) {
    Point2D center = new Point2D.Float(0, 0);
    float radius = 200;
    float[] dist = { 0.0f, 1.0f };
    return new RadialGradientPaint(center, radius, dist, new Color[] { c1, c2 });
}

From source file:PieChartDemo1.java

/**
 * A utility method for creating gradient paints.
 * //from  w  w w. j a  v a2s. c  o  m
 * @param c1  color 1.
 * @param c2  color 2.
 * 
 * @return A radial gradient paint.
 */
private static RadialGradientPaint createGradientPaint(Color c1, Color c2) {
    Point2D center = new Point2D.Float(0, 0);
    float radius = 200;
    float[] dist = { 0.0f, 1.0f };
    return new RadialGradientPaint(center, radius, dist, new Color[] { c1, c2 });
}

From source file:RadialGradientApp.java

@Override
protected void paintComponent(Graphics g) {
    setFont(getFont().deriveFont(70.f).deriveFont(Font.BOLD));

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

    // Retains the previous state
    Paint oldPaint = g2.getPaint();

    // Fills the circle with solid blue color
    g2.setColor(new Color(0x0153CC));
    g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1);

    // Adds shadows at the top
    Paint p;/* ww w  . j  a v a  2s . c om*/
    p = new GradientPaint(0, 0, new Color(0.0f, 0.0f, 0.0f, 0.4f), 0, getHeight(),
            new Color(0.0f, 0.0f, 0.0f, 0.0f));
    g2.setPaint(p);
    g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1);

    // Adds highlights at the bottom 
    p = new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 0.0f), 0, getHeight(),
            new Color(1.0f, 1.0f, 1.0f, 0.4f));
    g2.setPaint(p);
    g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1);

    // Creates dark edges for 3D effect
    p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 2.0f,
            new float[] { 0.0f, 1.0f },
            new Color[] { new Color(6, 76, 160, 127), new Color(0.0f, 0.0f, 0.0f, 0.8f) });
    g2.setPaint(p);
    g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1);

    // Adds oval inner highlight at the bottom
    p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() * 1.5), getWidth() / 2.3f,
            new Point2D.Double(getWidth() / 2.0, getHeight() * 1.75 + 6), new float[] { 0.0f, 0.8f },
            new Color[] { new Color(64, 142, 203, 255), new Color(64, 142, 203, 0) },
            RadialGradientPaint.CycleMethod.NO_CYCLE, RadialGradientPaint.ColorSpaceType.SRGB,
            AffineTransform.getScaleInstance(1.0, 0.5));
    g2.setPaint(p);
    g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1);

    // Adds oval specular highlight at the top left
    p = new RadialGradientPaint(new Point2D.Double(getWidth() / 2.0, getHeight() / 2.0), getWidth() / 1.4f,
            new Point2D.Double(45.0, 25.0), new float[] { 0.0f, 0.5f },
            new Color[] { new Color(1.0f, 1.0f, 1.0f, 0.4f), new Color(1.0f, 1.0f, 1.0f, 0.0f) },
            RadialGradientPaint.CycleMethod.NO_CYCLE);
    g2.setPaint(p);
    g2.fillOval(0, 0, getWidth() - 1, getHeight() - 1);

    // Restores the previous state
    g2.setPaint(oldPaint);

    // Draws the logo        
    //        FontRenderContext context = g2.getFontRenderContext();
    //        TextLayout layout = new TextLayout("R", getFont(), context);
    //        Rectangle2D bounds = layout.getBounds();
    //        
    //        float x = (getWidth() - (float) bounds.getWidth()) / 2.0f;
    //        float y = (getHeight() + (float) bounds.getHeight()) / 2.0f;
    //        
    //        g2.setColor(Color.WHITE);
    //        layout.draw(g2, x, y);
    //        
    //        Area shadow = new Area(layout.getOutline(null));
    //        shadow.subtract(new Area(layout.getOutline(AffineTransform.getTranslateInstance(1.0, 1.0))));
    //        g2.setColor(Color.BLACK);
    //        g2.translate(x, y);
    //        g2.fill(shadow);
    //        g2.translate(-x, -y);
}

From source file:DrawShapes_2008.java

@Override
protected void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    // Paint a gradient for the sky
    GradientPaint background = new GradientPaint(0f, 0f, Color.GRAY.darker(), 0f, (float) getHeight(),
            Color.GRAY.brighter());
    g2d.setPaint(background);// w  w w.  j  a va2  s.co m
    g2d.fillRect(0, 0, getWidth(), 4 * getHeight() / 5);

    // Paint a gradient for the ground
    background = new GradientPaint(0f, (float) 4 * getHeight() / 5, Color.BLACK, 0f, (float) getHeight(),
            Color.GRAY.darker());
    g2d.setPaint(background);
    g2d.fillRect(0, 4 * getHeight() / 5, getWidth(), getHeight() / 5);

    // Enable anti-aliasing to get smooth outlines
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Iterate through all of the current shapes
    for (Shape shape : shapes) {
        // Get the bounds to compute the RadialGradient properties
        Rectangle rect = shape.getBounds();
        Point2D center = new Point2D.Float(rect.x + (float) rect.width / 2.0f,
                rect.y + (float) rect.height / 2.0f);
        float radius = (float) rect.width / 2.0f;
        float[] dist = { 0.1f, 0.9f };
        Color[] colors = { Color.WHITE, Color.BLACK };

        // Create and set a RadialGradient centered on the object,
        // going from white at the center to black at the edges
        RadialGradientPaint paint = new RadialGradientPaint(center, radius, dist, colors);
        g2d.setPaint(paint);

        // Finally, render our shape
        g2d.fill(shape);
    }
}