Example usage for java.awt Graphics2D fill

List of usage examples for java.awt Graphics2D fill

Introduction

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

Prototype

public abstract void fill(Shape s);

Source Link

Document

Fills the interior of a Shape using the settings of the Graphics2D context.

Usage

From source file:com.rapidminer.gui.plotter.charts.RapidXYBarPainter.java

@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar,
        RectangleEdge base) {// w  ww  . j  a  v a2  s  .  com
    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0 = null;

    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
    } else {
        c0 = SwingTools.DARK_BLUE;
    }

    // as a special case, if the bar color has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    g2.setPaint(c0);
    g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight()));

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
}

From source file:ColorBlocks.java

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

    Dimension d = getSize();/*ww w .  j ava 2  s.  c o m*/
    g2.translate(d.width / 2, d.height / 2);

    Color[] colors = { Color.white, Color.lightGray, Color.gray, Color.darkGray, Color.black, Color.red,
            Color.pink, Color.orange, Color.yellow, Color.green, Color.magenta, Color.cyan, Color.blue };

    float size = 25;
    float x = -size * colors.length / 2;
    float y = -size * 3 / 2;

    // Show all the predefined colors.
    for (int i = 0; i < colors.length; i++) {
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(colors[i]);
        g2.fill(r);
    }

    //a linear gradient.
    y += size;
    Color c1 = Color.yellow;
    Color c2 = Color.blue;
    for (int i = 0; i < colors.length; i++) {
        float ratio = (float) i / (float) colors.length;
        int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
        int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
        int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
        Color c = new Color(red, green, blue);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Show an alpha gradient.
    y += size;
    c1 = Color.red;
    for (int i = 0; i < colors.length; i++) {
        int alpha = (int) (255 * (float) i / (float) colors.length);
        Color c = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), alpha);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Draw a frame around the whole thing.
    y -= size * 2;
    Rectangle2D frame = new Rectangle2D.Float(x, y, size * colors.length, size * 3);
    g2.setPaint(Color.black);
    g2.draw(frame);
}

From source file:io.github.dsheirer.spectrum.SpectrumPanel.java

/**
 * Draws the current fft spectrum with a line and a gradient fill.
 *//*from w w w.j a  va2 s.c  om*/
private void drawSpectrum(Graphics2D graphics) {
    Dimension size = getSize();

    //Draw the background
    Rectangle background = new Rectangle(0, 0, size.width, size.height);
    graphics.setColor(mColorSpectrumBackground);
    graphics.draw(background);
    graphics.fill(background);

    //Define the gradient
    GradientPaint gradient = new GradientPaint(0, (getSize().height - mSpectrumInset) / 2,
            mColorSpectrumGradientTop, 0, getSize().height, mColorSpectrumGradientBottom);

    graphics.setBackground(mColorSpectrumBackground);

    GeneralPath spectrumShape = new GeneralPath();

    //Start at the lower right inset point
    spectrumShape.moveTo(size.getWidth(), size.getHeight() - mSpectrumInset);

    //Draw to the lower left
    spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);

    float[] bins = getBins();

    //If we have FFT data to display ...
    if (bins != null) {
        float insideHeight = size.height - mSpectrumInset;

        float scalor = insideHeight / -mDBScale;

        /* Calculate based on bin size - 1, since bin 0 is rendered at zero
           * and the last bin is rendered at the width */
        float binSize = (float) size.width / ((float) (bins.length));

        for (int x = 0; x < bins.length; x++) {
            float height;

            height = bins[x] * scalor;

            if (height > insideHeight) {
                height = insideHeight;
            }

            if (height < 0) {
                height = 0;
            }

            float xAxis = (float) x * binSize;

            spectrumShape.lineTo(xAxis, height);
        }
    }
    //Otherwise show an empty spectrum
    else {
        //Draw Left Size
        graphics.setPaint(gradient);
        spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset);
        //Draw Middle
        spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset);
    }

    //Draw Right Side
    spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset);

    graphics.setPaint(gradient);
    graphics.draw(spectrumShape);
    graphics.fill(spectrumShape);

    graphics.setPaint(mColorSpectrumLine);

    //Draw the bottom line under the spectrum
    graphics.draw(new Line2D.Float(0, size.height - mSpectrumInset, size.width, size.height - mSpectrumInset));
}

From source file:org.geotools.renderer.chart.GeometryRenderer.java

void drawCoordinate(Coordinate c, Graphics2D g2, int series, int item, Rectangle2D dataArea, XYPlot plot,
        ValueAxis domainAxis, ValueAxis rangeAxis) {

    double tx = domainAxis.valueToJava2D(c.x, dataArea, plot.getDomainAxisEdge());
    double ty = rangeAxis.valueToJava2D(c.y, dataArea, plot.getRangeAxisEdge());

    Shape shape = getItemShape(series, item);
    shape = ShapeUtilities.createTranslatedShape(shape, tx, ty);

    if (fillCoordinates) {
        g2.fill(shape);
    } else {//  w  ww  .jav  a2  s  .  co m
        g2.draw(shape);
    }
}

From source file:com.rapidminer.gui.plotter.charts.RapidBarPainter.java

/**
 * Paints a single bar instance.//w w  w  . ja va2 s .c  o  m
 * 
 * @param g2
 *            the graphics target.
 * @param renderer
 *            the renderer.
 * @param row
 *            the row index.
 * @param column
 *            the column index.
 * @param bar
 *            the bar
 * @param base
 *            indicates which side of the rectangle is the base of the bar.
 */
@Override
public void paintBar(final Graphics2D g2, final BarRenderer renderer, final int row, final int column,
        final RectangularShape bar, final RectangleEdge base) {
    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0 = null;

    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
    } else {
        c0 = SwingTools.DARK_BLUE;
    }

    // as a special case, if the bar color has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    g2.setPaint(c0);
    g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight()));

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }

}

From source file:org.jfree.experimental.chart.plot.dial.SimpleDialFrame.java

/**
 * Draws the frame.  This method is called by the {@link DialPlot} class,
 * you shouldn't need to call it directly.
 *
 * @param g2  the graphics target (<code>null</code> not permitted).
 * @param plot  the plot (<code>null</code> not permitted).
 * @param frame  the frame (<code>null</code> not permitted).
 * @param view  the view (<code>null</code> not permitted).
 *//*from  ww  w.ja  v  a 2 s  .c  om*/
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Shape window = getWindow(frame);

    Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius + 0.02, this.radius + 0.02);
    Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight());

    Area area = new Area(e);
    Area area2 = new Area(window);
    area.subtract(area2);
    g2.setPaint(this.backgroundPaint);
    g2.fill(area);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(e);
}

From source file:org.jfree.experimental.chart.plot.dial.StandardDialFrame.java

/**
 * Draws the frame.//ww w.  ja  v  a 2  s.  c  o  m
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame.
 * @param view  the dial's view rectangle.
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Shape window = getWindow(frame);
    Shape outerWindow = getOuterWindow(frame);

    Area area1 = new Area(outerWindow);
    Area area2 = new Area(window);
    area1.subtract(area2);
    g2.setPaint(Color.lightGray);
    g2.fill(area1);

    g2.setStroke(this.stroke);
    g2.setPaint(this.foregroundPaint);
    g2.draw(window);
    g2.draw(outerWindow);

}

From source file:dataminning2.Graphplot.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 www.  jav a2  s  . c  om
    int length1 = 0;
    int length2 = data.length / 3;
    for (int i = 0; i < length2; 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);
    int lengthnew = length1 + length2;
    length2 = length2 + lengthnew;
    for (int i = lengthnew; i < length2; 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);
    lengthnew = lengthnew + lengthnew;
    for (int i = length2; i < data.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:RotatedText.java

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

    String s = "111111111111111111111111111111";

    Font font = new Font("Courier", Font.PLAIN, 12);
    g2d.translate(20, 20);/*w  w  w .j  av  a2  s .c o m*/

    FontRenderContext frc = g2d.getFontRenderContext();

    GlyphVector gv = font.createGlyphVector(frc, s);
    int length = gv.getNumGlyphs();
    for (int i = 0; i < length; i++) {
        Point2D p = gv.getGlyphPosition(i);
        AffineTransform at = AffineTransform.getTranslateInstance(p.getX(), p.getY());
        at.rotate((double) i / (double) (length - 1) * Math.PI / 3);

        Shape glyph = gv.getGlyphOutline(i);
        Shape transformedGlyph = at.createTransformedShape(glyph);
        g2d.fill(transformedGlyph);
    }
}

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  w  w .  j a  va 2  s  .c om

    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));
    }
}