Example usage for java.awt Graphics2D setPaint

List of usage examples for java.awt Graphics2D setPaint

Introduction

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

Prototype

public abstract void setPaint(Paint paint);

Source Link

Document

Sets the Paint attribute for the Graphics2D context.

Usage

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);
    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));
    }//from   w  w  w  .java2s.c o  m
    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:org.openmeetings.app.data.record.BatikMethods.java

public void paintLine(Graphics2D g2d, int x1, int y1, int x2, int y2, Color col) throws Exception {
    g2d.setPaint(col);
    g2d.drawLine(x1, y1, x2, y2);/*from ww w  .j a v  a 2  s.co  m*/
}

From source file:org.openmeetings.app.data.record.BatikMethods.java

public void drawThickLine(Graphics2D g2d, int x1, int y1, int x2, int y2, int width, Color c) throws Exception {
    g2d.setPaint(c);
    g2d.setStroke(new BasicStroke(width, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    g2d.drawLine(x1, y1, x2, y2);/* w  w w .j a v a  2  s. c  om*/
}

From source file:dataminning2.DBScanGraphplot.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);
    int length1 = 0;
    int length2 = data.length / 3;
    for (int i = 0; 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  www .  j a  v  a  2s.c  o  m*/

}

From source file:GradientPane.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    Point2D.Float p1 = new Point2D.Float(150.f, 75.f); // Gradient line start
    Point2D.Float p2 = new Point2D.Float(250.f, 75.f); // Gradient line end
    float width = 300;
    float height = 50;
    Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height);
    GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false); // Acyclic
                                                                                       // gradient
    rect1.setRect(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g2); // Gradient color fill
    g2D.fill(rect1); // Fill the rectangle
    g2D.setPaint(Color.BLACK); // Outline in black
    g2D.draw(rect1); // Fill the rectangle
    g2D.draw(new Line2D.Float(p1, p2));
}

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

private void drawItemShape(Graphics2D g2, int row, int column, Shape shape) {
    if (getItemShapeFilled(row, column)) {
        g2.setPaint(getUseFillPaint() ? getItemFillPaint(row, column) : getItemPaint(row, column));

        g2.fill(shape);/*www  . j av  a2s  .  co  m*/
    }

    if (getDrawOutlines()) {
        g2.setPaint(getUseOutlinePaint() ? getItemOutlinePaint(row, column) : getItemPaint(row, column));

        g2.setStroke(getItemOutlineStroke(row, column));

        g2.draw(shape);
    }
}

From source file:net.sourceforge.processdash.ui.lib.chart.StandardDiscItemRenderer.java

protected void drawDiscLabel(Graphics2D g2, Ellipse2D shape, Paint labelPaint, Font labelFont, String label) {
    g2.setFont(labelFont);/*www  . j a va2 s .  c o m*/
    g2.setPaint(labelPaint);
    FontMetrics m = g2.getFontMetrics();
    int height = m.getAscent();
    double halfHeight = height / 2.0;

    double radius = shape.getWidth() / 2;
    double availableRadius = radius - getLabelPadding();
    double halfWidth = Math.sqrt(availableRadius * availableRadius - halfHeight * halfHeight);

    int width = (int) Math.floor(halfWidth * 2 + 0.99);

    Rectangle viewR = new Rectangle(width, height);
    Rectangle iconR = new Rectangle();
    Rectangle textR = new Rectangle();
    String text = SwingUtilities.layoutCompoundLabel(m, label, null, SwingConstants.CENTER,
            SwingConstants.CENTER, SwingConstants.CENTER, SwingConstants.TRAILING, viewR, iconR, textR, 0);
    if (text.equals(label) || text.length() >= 3 + minLabelChars) {
        double x = shape.getCenterX() - halfWidth + textR.x;
        double y = shape.getCenterY() + halfHeight + textR.y;
        g2.drawString(text, (float) x, (float) y);
    }
}

From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.CompassRenderer.java

@Override
public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot,
        XYDataset dataset, int seriesIndex) {

    // compute the right color for the paint
    int length = GuiUtils.getAvailableColors().length;
    Color color = GuiUtils.getAvailableColors()[index % length];
    // get all the data points
    int numPoints = dataset.getItemCount(seriesIndex);
    // set STroke and Paint of the graphics
    g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175));

    // iterate through the points of the dataset
    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i); // the angle at the center         
        double radius = dataset.getYValue(seriesIndex, i); // the frequency

        Point p0 = plot.translateToJava2D(0, 0, plot.getAxis(), dataArea);
        Point p1 = plot.translateToJava2D(theta, radius, plot.getAxis(), dataArea);

        Line2D line = new Line2D.Double(p0, p1);
        g2.draw(line);/*  www  .j  av a 2 s.  c om*/
    }
}

From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java

/**
 * Draws zoom rectangle (if present).//from w ww . j ava  2s  .  com
 * The drawing is performed in XOR mode, therefore
 * when this method is called twice in a row,
 * the second call will completely restore the state
 * of the canvas.
 *
 * @param g2 the graphics device.
 */
private void drawCoElutionRegion(Graphics2D g2) {
    // Set XOR mode to draw the zoom rectangle
    if (g2 == null)
        return;
    Paint origColor = g2.getPaint();
    //        g2.setXORMode(Color.gray);
    g2.setXORMode(new Color(30, 10, 30, 5));
    if (this.coElutionRegion != null) {
        g2.fill(this.coElutionRegion);
        g2.setPaint(Color.white);
        g2.setStroke(new BasicStroke(3.0f));
        g2.draw(this.coElutionRegion);
    }
    g2.setPaintMode();
    g2.setPaint(origColor);
}

From source file:net.team2xh.crt.gui.editor.EditorTextPane.java

/**
 * Paints the background, the margin background and the margin line.
 *
 * @param g// w  w w. java2 s.co  m
 */
@Override
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    int m = marginSize;
    int w = getWidth(), h = getHeight();
    // Background
    g2d.setPaint(Theme.getTheme().COLOR_02);
    g2d.fillRect(0, 0, m, h);
    // Margin background
    if (m < w) {
        g2d.setColor(Theme.getTheme().COLOR_01);
        g2d.fillRect(m, 0, w - m, h);
    }
    // Margin line
    g2d.setColor(Theme.getTheme().COLOR_04);
    g2d.drawLine(m, 0, m, h);
    // Draw the rest
    super.paintComponent(g);
}