Example usage for java.awt.geom GeneralPath closePath

List of usage examples for java.awt.geom GeneralPath closePath

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath closePath.

Prototype

public final synchronized void closePath() 

Source Link

Document

Closes the current subpath by drawing a straight line back to the coordinates of the last moveTo .

Usage

From source file:Main.java

public static void main(String[] args) {
    GeneralPath shape = new GeneralPath();
    shape.moveTo(1, 1);// w w  w.j  a v  a  2s.  co m
    shape.lineTo(2, 2);
    shape.quadTo(3, 3, 4, 4);
    shape.curveTo(5, 5, 6, 6, 7, 7);
    shape.closePath();
}

From source file:Main.java

public static void main(String[] args) {
    GeneralPath shape = new GeneralPath();
    shape.moveTo(1, 1);//from w w  w  .  j av  a  2 s .co  m
    shape.lineTo(2, 2);
    shape.quadTo(3, 3, 4, 4);
    shape.curveTo(5, 5, 6, 6, 7, 7);
    shape.closePath();

    System.out.println("done");
}

From source file:Main.java

/**
 * Creates a triangle shape that points upwards.
 *
 * @param s  the size factor (equal to half the height of the triangle).
 *
 * @return A triangle shape./*from  ww w . jav  a  2 s  .c  o  m*/
 */
public static Shape createUpTriangle(final float s) {
    final GeneralPath p0 = new GeneralPath();
    p0.moveTo(0.0f, -s);
    p0.lineTo(s, s);
    p0.lineTo(-s, s);
    p0.closePath();
    return p0;
}

From source file:Main.java

/**
 * Creates a triangle shape that points downwards.
 *
 * @param s  the size factor (equal to half the height of the triangle).
 *
 * @return A triangle shape.//from w w w. ja va 2s .  c o  m
 */
public static Shape createDownTriangle(final float s) {
    final GeneralPath p0 = new GeneralPath();
    p0.moveTo(0.0f, s);
    p0.lineTo(s, -s);
    p0.lineTo(-s, -s);
    p0.closePath();
    return p0;
}

From source file:Main.java

/**
 * Creates a diamond shape.//  w  ww  . j a  va 2 s .  c  o  m
 *
 * @param s  the size factor (equal to half the height of the diamond).
 *
 * @return A diamond shape.
 */
public static Shape createDiamond(final float s) {
    final GeneralPath p0 = new GeneralPath();
    p0.moveTo(0.0f, -s);
    p0.lineTo(s, 0.0f);
    p0.lineTo(0.0f, s);
    p0.lineTo(-s, 0.0f);
    p0.closePath();
    return p0;
}

From source file:Main.java

/**
 * Creates a diagonal cross shape.//from  www  .  ja va 2s . c o m
 *
 * @param l  the length of each 'arm'.
 * @param t  the thickness.
 *
 * @return A diagonal cross shape.
 */
public static Shape createRegularCross(final float l, final float t) {
    final GeneralPath p0 = new GeneralPath();
    p0.moveTo(-l, t);
    p0.lineTo(-t, t);
    p0.lineTo(-t, l);
    p0.lineTo(t, l);
    p0.lineTo(t, t);
    p0.lineTo(l, t);
    p0.lineTo(l, -t);
    p0.lineTo(t, -t);
    p0.lineTo(t, -l);
    p0.lineTo(-t, -l);
    p0.lineTo(-t, -t);
    p0.lineTo(-l, -t);
    p0.closePath();
    return p0;
}

From source file:Main.java

/**
 * Creates a diagonal cross shape./*  w  ww.  j a  va2s .  co m*/
 *
 * @param l  the length of each 'arm'.
 * @param t  the thickness.
 *
 * @return A diagonal cross shape.
 */
public static Shape createDiagonalCross(final float l, final float t) {
    final GeneralPath p0 = new GeneralPath();
    p0.moveTo(-l - t, -l + t);
    p0.lineTo(-l + t, -l - t);
    p0.lineTo(0.0f, -t * SQRT2);
    p0.lineTo(l - t, -l - t);
    p0.lineTo(l + t, -l + t);
    p0.lineTo(t * SQRT2, 0.0f);
    p0.lineTo(l + t, l - t);
    p0.lineTo(l - t, l + t);
    p0.lineTo(0.0f, t * SQRT2);
    p0.lineTo(-l + t, l + t);
    p0.lineTo(-l - t, l - t);
    p0.lineTo(-t * SQRT2, 0.0f);
    p0.closePath();
    return p0;
}

From source file:Main.java

/**
 * Creates a region surrounding a line segment by 'widening' the line
 * segment.  A typical use for this method is the creation of a
 * 'clickable' region for a line that is displayed on-screen.
 *
 * @param line  the line (<code>null</code> not permitted).
 * @param width  the width of the region.
 *
 * @return A region that surrounds the line.
 *///ww  w .j a va 2s  . c om
public static Shape createLineRegion(final Line2D line, final float width) {
    final GeneralPath result = new GeneralPath();
    final float x1 = (float) line.getX1();
    final float x2 = (float) line.getX2();
    final float y1 = (float) line.getY1();
    final float y2 = (float) line.getY2();
    if ((x2 - x1) != 0.0) {
        final double theta = Math.atan((y2 - y1) / (x2 - x1));
        final float dx = (float) Math.sin(theta) * width;
        final float dy = (float) Math.cos(theta) * width;
        result.moveTo(x1 - dx, y1 + dy);
        result.lineTo(x1 + dx, y1 - dy);
        result.lineTo(x2 + dx, y2 - dy);
        result.lineTo(x2 - dx, y2 + dy);
        result.closePath();
    } else {
        // special case, vertical line
        result.moveTo(x1 - width / 2.0f, y1);
        result.lineTo(x1 + width / 2.0f, y1);
        result.lineTo(x2 + width / 2.0f, y2);
        result.lineTo(x2 - width / 2.0f, y2);
        result.closePath();
    }
    return result;
}

From source file:edu.gmu.cs.sim.util.media.chart.ScatterPlotSeriesAttributes.java

static Shape[] buildShapes() {
    Shape[] s = new Shape[7];
    GeneralPath g = null;

    // Circle//w  ww. j a  v a 2 s . c  o  m
    s[0] = new Ellipse2D.Double(-3, -3, 6, 6);

    // Rectangle
    Rectangle2D.Double r = new Rectangle2D.Double(-3, -3, 6, 6);
    s[1] = r;

    // Diamond
    s[2] = AffineTransform.getRotateInstance(Math.PI / 4.0).createTransformedShape(r);

    // Cross +
    g = new GeneralPath();
    g.moveTo(-0.5f, -3);
    g.lineTo(-0.5f, -0.5f);
    g.lineTo(-3, -0.5f);
    g.lineTo(-3, 0.5f);
    g.lineTo(-0.5f, 0.5f);
    g.lineTo(-0.5f, 3);
    g.lineTo(0.5f, 3);
    g.lineTo(0.5f, 0.5f);
    g.lineTo(3, 0.5f);
    g.lineTo(3, -0.5f);
    g.lineTo(0.5f, -0.5f);
    g.lineTo(0.5f, -3);
    g.closePath();
    s[3] = g;

    // X 
    s[4] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI / 4.0));

    // Up Triangle
    g = new GeneralPath();
    g.moveTo(0f, -3);
    g.lineTo(-3, 3);
    g.lineTo(3, 3);
    g.closePath();
    s[5] = g;

    // Down Triangle
    s[6] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI));

    return s;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

private static GeneralPath createAreaShape() {
    GeneralPath areaShape = new GeneralPath();
    areaShape.moveTo(0, 0);/*w  ww  .  j  ava 2  s . c o m*/
    areaShape.lineTo(0, -5);
    areaShape.lineTo(5, -10);
    areaShape.lineTo(10, -5);
    areaShape.lineTo(15, -7);
    areaShape.lineTo(15, 0);

    areaShape.closePath();
    return areaShape;
}