Example usage for java.awt Graphics2D draw

List of usage examples for java.awt Graphics2D draw

Introduction

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

Prototype

public abstract void draw(Shape s);

Source Link

Document

Strokes the outline of a Shape using the settings of the current Graphics2D context.

Usage

From source file:eu.hydrologis.jgrass.charting.impl.LineDrawer.java

/**
 * Draws the circle./*from  w  w w.  j a  v  a 2  s  . co  m*/
 * 
 * @param g2 the graphics device.
 * @param area the area in which to draw.
 */
public void draw(Graphics2D g2, Rectangle2D area) {
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
    } else {
        g2.setPaint(Color.black);
        g2.setStroke(new BasicStroke(1.0f));
    }

    Line2D line = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY());
    g2.draw(line);
}

From source file:Main.java

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

    Point2D.Float p1 = new Point2D.Float(150.f, 75.f);
    Point2D.Float p2 = new Point2D.Float(250.f, 75.f);
    float width = 300;
    float height = 50;
    GradientPaint g1 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY);
    Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g1);/*  w w w  . j  a va2s . c  o  m*/
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Cyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);

    p1.setLocation(150, 200);
    p2.setLocation(250, 200);
    GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false);
    rect1.setRect(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g2);
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Acyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);
}

From source file:com.bwc.ora.models.Lrp.java

@Override
public void drawOverlay(BufferedImage baseImg) {
    Graphics2D graphics = baseImg.createGraphics();
    graphics.setColor(Color.green);
    graphics.draw(this);
    //        System.out.println("Drawing selection on OCT...");
}

From source file:MainClass.java

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

    Point2D.Float p1 = new Point2D.Float(150.f, 75.f);
    Point2D.Float p2 = new Point2D.Float(250.f, 75.f);
    float width = 300;
    float height = 50;
    GradientPaint g1 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, true);
    Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g1);/*from  w  w w .java2s. co  m*/
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Cyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);

    p1.setLocation(150, 200);
    p2.setLocation(250, 200);
    GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false);
    rect1.setRect(p1.x - 100, p1.y - 25, width, height);
    g2D.setPaint(g2);
    g2D.fill(rect1);
    g2D.setPaint(Color.BLACK);
    g2D.draw(rect1);
    g2D.draw(new Line2D.Float(p1, p2));
    g2D.drawString("Acyclic Gradient Paint", p1.x - 100, p1.y - 50);
    g2D.drawString("p1", p1.x - 20, p1.y);
    g2D.drawString("p2", p2.x + 10, p2.y);
}

From source file:BookTest.java

/**
 * Draws 1/2" crop marks in the corners of the page.
 * @param g2 the graphics context//  ww w  .  j a  v a2s.  com
 * @param pf the page format
 */
public void drawCropMarks(Graphics2D g2, PageFormat pf) {
    final double C = 36; // crop mark length = 1/2 inch
    double w = pf.getImageableWidth();
    double h = pf.getImageableHeight();
    g2.draw(new Line2D.Double(0, 0, 0, C));
    g2.draw(new Line2D.Double(0, 0, C, 0));
    g2.draw(new Line2D.Double(w, 0, w, C));
    g2.draw(new Line2D.Double(w, 0, w - C, 0));
    g2.draw(new Line2D.Double(0, h, 0, h - C));
    g2.draw(new Line2D.Double(0, h, C, h));
    g2.draw(new Line2D.Double(w, h, w, h - C));
    g2.draw(new Line2D.Double(w, h, w - C, h));
}

From source file:AlgorithmAnimation.java

public synchronized void paintComponent(Graphics g) // Called on the event dispatch thread
{
    if (values == null)
        return;/*from   ww  w .j  a v  a2 s  .c o  m*/
    Graphics2D g2 = (Graphics2D) g;
    int width = getWidth() / values.length;
    for (int i = 0; i < values.length; i++) {
        double height = values[i] * getHeight();
        Rectangle2D bar = new Rectangle2D.Double(width * i, 0, width, height);
        if (values[i] == marked1 || values[i] == marked2)
            g2.fill(bar);
        else
            g2.draw(bar);
    }
}

From source file:edu.ucla.stat.SOCR.chart.gui.CircleDrawer.java

/**
 * Draws the circle.//from  w  w  w  . ja v a 2 s .com
 * 
 * @param g2  the graphics device.
 * @param area  the area in which to draw.
 */
public void draw(Graphics2D g2, Rectangle2D area) {
    Ellipse2D ellipse = new Ellipse2D.Double(area.getX(), area.getY(), area.getWidth(), area.getHeight());
    if (this.fillPaint != null) {
        g2.setPaint(this.fillPaint);
        g2.fill(ellipse);
    }
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
        g2.draw(ellipse);
    }

    g2.setPaint(Color.black);
    g2.setStroke(new BasicStroke(1.0f));
    Line2D line1 = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY());
    Line2D line2 = new Line2D.Double(area.getMinX(), area.getCenterY(), area.getMaxX(), area.getCenterY());
    g2.draw(line1);
    g2.draw(line2);
}

From source file:gov.nih.nci.caintegrator.application.geneexpression.BoxAndWhiskerCoinPlotRenderer.java

private void drawEllipse(Point2D point, double oRadius, Graphics2D g2) {
    Ellipse2D dot = new Ellipse2D.Double(point.getX() + oRadius / 2, point.getY(), oRadius, oRadius);
    g2.draw(dot);
}

From source file:org.squidy.designer.zoom.impl.DataTypeShape.java

/**
 * Draws an empty data type filter. This will be drawn if all data types are unselected.
 * /*from   w w  w . j a va  2  s . c  o  m*/
 * @param g The graphics device to draw on.
 */
void drawNoDataType(Graphics2D g) {
    g.setStroke(STROKE_ARROW_THIN);
    g.setColor(Color.BLACK);
    g.draw(arrowShape);
}

From source file:Main.java

public void drawImage() {
    Graphics2D g = img.createGraphics();
    RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g.setRenderingHints(hints);/*  www . j  ava  2  s.com*/

    g.setStroke(new BasicStroke(4));
    for (Ellipse2D shape : shapes) {
        g.setColor(Color.blue);
        g.fill(shape);
        if (shape.contains(mouse)) {
            g.setColor(Color.RED);
        } else {
            g.setColor(Color.YELLOW);
        }
        g.draw(shape);
    }

    l.setIcon(new ImageIcon(img));

    g.dispose();
}