Example usage for java.awt.geom GeneralPath moveTo

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

Introduction

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

Prototype

public abstract void moveTo(double x, double y);

Source Link

Document

Adds a point to the path by moving to the specified coordinates specified in double precision.

Usage

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.
 *///www .ja v  a 2 s .c  o  m
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:org.lmn.fc.frameworks.starbase.plugins.observatory.ui.tabs.charts.ChartUIHelper.java

/***********************************************************************************************
 * Set the shape for the Chart legend items.
 *
 * @param renderer//  w  w w. j  a  v  a2s .  com
 */

static void setLegendShape(final XYLineAndShapeRenderer renderer) {
    final GeneralPath pathBlock;

    pathBlock = new GeneralPath();

    pathBlock.moveTo(-7.0f, -3.0f);
    pathBlock.lineTo(7.0f, -3.0f);

    pathBlock.moveTo(-7.0f, -2.0f);
    pathBlock.lineTo(7.0f, -2.0f);

    pathBlock.moveTo(-7.0f, -1.0f);
    pathBlock.lineTo(7.0f, -1.0f);

    pathBlock.moveTo(-7.0f, 0.0f);
    pathBlock.lineTo(7.0f, 0.0f);

    pathBlock.moveTo(-7.0f, 1.0f);
    pathBlock.lineTo(7.0f, 1.0f);

    pathBlock.moveTo(-7.0f, 2.0f);
    pathBlock.lineTo(7.0f, 2.0f);

    pathBlock.moveTo(-7.0f, 3.0f);
    pathBlock.lineTo(7.0f, 3.0f);

    renderer.setLegendLine(pathBlock);
}

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  w  w . j a  v a2s. c  om*/
    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:DrawShapes_2008.java

/**
 * Generates a star Shape from the given location, radii, and points
 * parameters. The Shape is created by constructing a GeneralPath
 * that moves between the inner and outer rings.
 *//*from w  ww.  j  a  v a  2  s . com*/
private static Shape generateStar(double x, double y, double innerRadius, double outerRadius, int pointsCount) {
    GeneralPath path = new GeneralPath();

    double outerAngleIncrement = 2 * Math.PI / pointsCount;

    double outerAngle = 0.0;
    double innerAngle = outerAngleIncrement / 2.0;

    x += outerRadius;
    y += outerRadius;

    float x1 = (float) (Math.cos(outerAngle) * outerRadius + x);
    float y1 = (float) (Math.sin(outerAngle) * outerRadius + y);

    float x2 = (float) (Math.cos(innerAngle) * innerRadius + x);
    float y2 = (float) (Math.sin(innerAngle) * innerRadius + y);

    path.moveTo(x1, y1);
    path.lineTo(x2, y2);

    outerAngle += outerAngleIncrement;
    innerAngle += outerAngleIncrement;

    for (int i = 1; i < pointsCount; i++) {
        x1 = (float) (Math.cos(outerAngle) * outerRadius + x);
        y1 = (float) (Math.sin(outerAngle) * outerRadius + y);

        path.lineTo(x1, y1);

        x2 = (float) (Math.cos(innerAngle) * innerRadius + x);
        y2 = (float) (Math.sin(innerAngle) * innerRadius + y);

        path.lineTo(x2, y2);

        outerAngle += outerAngleIncrement;
        innerAngle += outerAngleIncrement;
    }

    path.closePath();
    return path;
}

From source file:Main.java

/**
 * Reads a <code>Shape</code> object that has been serialised by the
 * {@link #writeShape(Shape, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The shape object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 *///from   www. j ava2s.  c  o m
public static Shape readShape(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Shape result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (c.equals(Line2D.class)) {
            final double x1 = stream.readDouble();
            final double y1 = stream.readDouble();
            final double x2 = stream.readDouble();
            final double y2 = stream.readDouble();
            result = new Line2D.Double(x1, y1, x2, y2);
        } else if (c.equals(Rectangle2D.class)) {
            final double x = stream.readDouble();
            final double y = stream.readDouble();
            final double w = stream.readDouble();
            final double h = stream.readDouble();
            result = new Rectangle2D.Double(x, y, w, h);
        } else if (c.equals(Ellipse2D.class)) {
            final double x = stream.readDouble();
            final double y = stream.readDouble();
            final double w = stream.readDouble();
            final double h = stream.readDouble();
            result = new Ellipse2D.Double(x, y, w, h);
        } else if (c.equals(Arc2D.class)) {
            final double x = stream.readDouble();
            final double y = stream.readDouble();
            final double w = stream.readDouble();
            final double h = stream.readDouble();
            final double as = stream.readDouble(); // Angle Start
            final double ae = stream.readDouble(); // Angle Extent
            final int at = stream.readInt(); // Arc type
            result = new Arc2D.Double(x, y, w, h, as, ae, at);
        } else if (c.equals(GeneralPath.class)) {
            final GeneralPath gp = new GeneralPath();
            final float[] args = new float[6];
            boolean hasNext = stream.readBoolean();
            while (!hasNext) {
                final int type = stream.readInt();
                for (int i = 0; i < 6; i++) {
                    args[i] = stream.readFloat();
                }
                switch (type) {
                case PathIterator.SEG_MOVETO:
                    gp.moveTo(args[0], args[1]);
                    break;
                case PathIterator.SEG_LINETO:
                    gp.lineTo(args[0], args[1]);
                    break;
                case PathIterator.SEG_CUBICTO:
                    gp.curveTo(args[0], args[1], args[2], args[3], args[4], args[5]);
                    break;
                case PathIterator.SEG_QUADTO:
                    gp.quadTo(args[0], args[1], args[2], args[3]);
                    break;
                case PathIterator.SEG_CLOSE:
                    gp.closePath();
                    break;
                default:
                    throw new RuntimeException("JFreeChart - No path exists");
                }
                gp.setWindingRule(stream.readInt());
                hasNext = stream.readBoolean();
            }
            result = gp;
        } else {
            result = (Shape) stream.readObject();
        }
    }
    return result;

}

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

private static GeneralPath createAreaShape() {
    GeneralPath areaShape = new GeneralPath();
    areaShape.moveTo(0, 0);
    areaShape.lineTo(0, -5);/*from w ww  . j av  a2s  .com*/
    areaShape.lineTo(5, -10);
    areaShape.lineTo(10, -5);
    areaShape.lineTo(15, -7);
    areaShape.lineTo(15, 0);

    areaShape.closePath();
    return areaShape;
}

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

private static GeneralPath createBarShape() {
    GeneralPath barShape = new GeneralPath();
    barShape.moveTo(0, 0);
    barShape.lineTo(0, -5);//  ww w.j  a va2s. co  m
    barShape.lineTo(5, -5);
    barShape.lineTo(5, 0);
    barShape.lineTo(5, -15);
    barShape.lineTo(10, -15);
    barShape.lineTo(10, 0);
    barShape.lineTo(10, -10);
    barShape.lineTo(15, -10);
    barShape.lineTo(15, 0);
    barShape.closePath();
    return barShape;
}

From source file:MainClass.java

protected Shape create() {
    GeneralPath path = new GeneralPath();
    path.moveTo(50, 30);
    path.lineTo(30, 200);/*from  ww  w  . jav  a  2 s  .co m*/
    return path;
}

From source file:Main.java

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

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);//from w ww. j a  v  a  2 s  .com

    BasicStroke bs = new BasicStroke(36.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
    g2.setStroke(bs);

    GeneralPath path = new GeneralPath();
    path.moveTo(30.0f, 90.0f);
    path.lineTo(150.0f, 20.0f);
    path.lineTo(270.0f, 90.0f);
    g2.draw(path);
}

From source file:Main.java

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

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);// ww w .  j av  a2s . c om

    BasicStroke bs = new BasicStroke(36.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    g2.setStroke(bs);

    GeneralPath path = new GeneralPath();
    path.moveTo(30.0f, 90.0f);
    path.lineTo(150.0f, 20.0f);
    path.lineTo(270.0f, 90.0f);
    g2.draw(path);
}