Java Code Examples for java.awt.geom.GeneralPath

The following are top voted examples for showing how to use java.awt.geom.GeneralPath. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: JavaGraph   File: JVertexView.java   View source code 7 votes vote down vote up
/** Creates a hexagonal shape inscribed in the bounds given in the parameters. */
private Shape createHexagonShape(double x, double y, double width, double height) {
    GeneralPath result = new GeneralPath(Path2D.WIND_NON_ZERO, 5);
    double extend = height * NodeShape.HEX_EXTEND_RATIO;
    // stat at top left corner
    result.moveTo(x + extend, y);
    // to top right
    result.lineTo(x + width - extend, y);
    // to right
    result.lineTo(x + width, y + height / 2);
    // to bottom right
    result.lineTo(x + width - extend, y + height);
    // to bottom left
    result.lineTo(x + extend, y + height);
    // to left
    result.lineTo(x, y + height / 2);
    result.closePath();
    return result;
}
 
Example 2
Project: incubator-netbeans   File: DiffSplitPaneDivider.java   View source code 6 votes vote down vote up
private void paintMatcher(Graphics2D g, Color fillClr, 
        int leftX, int rightX, int upL, int upR, int doR, int doL) {
    int topY = Math.min(upL, upR), bottomY = Math.max(doL, doR);
    // try rendering only curves in viewable area
    if (!g.hitClip(leftX, topY, rightX - leftX, bottomY - topY)) {
        return;
    }
    CubicCurve2D upper = new CubicCurve2D.Float(leftX, upL,
            (rightX -leftX)*.3f, upL,
            (rightX -leftX)*.7f, upR,
            rightX, upR);
    CubicCurve2D bottom = new CubicCurve2D.Float(rightX, doR,
            (rightX - leftX)*.7f, doR,
            (rightX -leftX)*.3f, doL,
            leftX, doL);
    GeneralPath path = new GeneralPath();
    path.append(upper, false);
    path.append(bottom, true);
    path.closePath();
    g.setColor(fillClr);
    g.fill(path);
    g.setColor(master.getColorLines());
    g.draw(upper);
    g.draw(bottom);
}
 
Example 3
Project: rapidminer   File: ProcessDrawUtils.java   View source code 6 votes vote down vote up
/**
 * Creates a spline connector shape from one {@link Point2D} to another.
 *
 * @param from
 *            the starting point
 * @param to
 *            the end point
 * @return the shape representing the connection, never {@code null}
 */
public static Shape createConnectionSpline(final Point2D from, final Point2D to) {
	if (from == null || to == null) {
		throw new IllegalArgumentException("from and to must not be null!");
	}

	int delta = 10;
	GeneralPath connector = new GeneralPath();
	connector.moveTo(from.getX() + 1, from.getY());
	double cx = (from.getX() + to.getX()) / 2;
	double cy = (from.getY() + to.getY()) / 2;
	if (to.getX() >= from.getX() + 2 * delta) {
		connector.curveTo(cx, from.getY(), cx, from.getY(), cx, cy);
		connector.curveTo(cx, to.getY(), cx, to.getY(), to.getX() - 1, to.getY());
	} else {
		connector.curveTo(from.getX() + delta, from.getY(), from.getX() + delta, cy, cx, cy);
		connector.curveTo(to.getX() - delta, cy, to.getX() - delta, to.getY(), to.getX() - 1, to.getY());
	}
	return connector;
}
 
Example 4
Project: rapidminer   File: DropDownButton.java   View source code 6 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath arrow = new GeneralPath();
	int w, h;
	h = (int) (2 * sizeFactor);
	w = (int) (4 * sizeFactor);
	arrow.moveTo(getWidth() / 2 - w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
	arrow.lineTo(getWidth() / 2, getHeight() / 2 + 2 * h);
	arrow.closePath();
	if (isEnabled()) {
		g.setColor(Color.BLACK);
	} else {
		g.setColor(Color.GRAY);
	}
	((Graphics2D) g).fill(arrow);
}
 
Example 5
Project: openjdk-jdk10   File: LayoutPathImpl.java   View source code 6 votes vote down vote up
public Shape mapShape(Shape s) {
    if (LOGMAP) LOG.format("mapshape on path: %s\n", LayoutPathImpl.SegmentPath.this);
    PathIterator pi = s.getPathIterator(null, 1); // cheap way to handle curves.

    if (LOGMAP) LOG.format("start\n");
    init();

    final double[] coords = new double[2];
    while (!pi.isDone()) {
        switch (pi.currentSegment(coords)) {
        case SEG_CLOSE: close(); break;
        case SEG_MOVETO: moveTo(coords[0], coords[1]); break;
        case SEG_LINETO: lineTo(coords[0], coords[1]); break;
        default: break;
        }

        pi.next();
    }
    if (LOGMAP) LOG.format("finish\n\n");

    GeneralPath gp = new GeneralPath();
    for (Segment seg: segments) {
        gp.append(seg.gp, false);
    }
    return gp;
}
 
Example 6
Project: FreeCol   File: Flag.java   View source code 6 votes vote down vote up
/**
 * Returns either a single star, or a circle of stars with the
 * given radius, centered at the origin.
 *
 * @param radius The radius of the circle.
 * @return The circle of stars.
 */
private GeneralPath getCircleOfStars(double radius) {
    double phi = Math.PI * 2 / stars;
    GeneralPath unionPath = new GeneralPath();
    if (stars == 0) {
        // nothing to do
    } else if (stars == 1) {
        // one double sized star
        unionPath = getStar(2, 0, 0);
    } else if (stars == 2) {
        // two larger stars, on the x axis
        unionPath.append(getStar(1.5, -radius, 0), false);
        unionPath.append(getStar(1.5, radius, 0), false);
    } else {
        // a general circle of stars
        for (int i = 0; i < stars; i++) {
            double x = -radius - radius * Math.sin(i * phi);
            double y = -radius * Math.cos(i * phi);
            unionPath.append(getStar(x, y), false);
        }
    }
    return unionPath;
}
 
Example 7
Project: openjdk-jdk10   File: Underline.java   View source code 6 votes vote down vote up
Shape getUnderlineShape(float thickness,
                        float x1,
                        float x2,
                        float y) {

    GeneralPath gp = new GeneralPath();

    Line2D.Float line = new Line2D.Float(x1, y, x2, y);
    gp.append(stroke.createStrokedShape(line), false);

    line.y1 += DEFAULT_THICKNESS;
    line.y2 += DEFAULT_THICKNESS;
    line.x1 += DEFAULT_THICKNESS;

    gp.append(stroke.createStrokedShape(line), false);

    return gp;
}
 
Example 8
Project: Java-Algorithms-Learning   File: StdDraw.java   View source code 6 votes vote down vote up
/**
 * Draws a polygon with the vertices 
 * (<em>x</em><sub>0</sub>, <em>y</em><sub>0</sub>),
 * (<em>x</em><sub>1</sub>, <em>y</em><sub>1</sub>), ...,
 * (<em>x</em><sub><em>n</em>–1</sub>, <em>y</em><sub><em>n</em>–1</sub>).
 *
 * @param  x an array of all the <em>x</em>-coordinates of the polygon
 * @param  y an array of all the <em>y</em>-coordinates of the polygon
 * @throws IllegalArgumentException unless {@code x[]} and {@code y[]}
 *         are of the same length
 */
public static void polygon(double[] x, double[] y) {
    if (x == null) throw new IllegalArgumentException("x-coordinate array is null");
    if (y == null) throw new IllegalArgumentException("y-coordinate array is null");
    int n1 = x.length;
    int n2 = y.length;
    if (n1 != n2) throw new IllegalArgumentException("arrays must be of the same length");
    int n = n1;
    if (n == 0) return;

    GeneralPath path = new GeneralPath();
    path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
    for (int i = 0; i < n; i++)
        path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
    path.closePath();
    offscreen.draw(path);
    draw();
}
 
Example 9
Project: FreeCol   File: Flag.java   View source code 6 votes vote down vote up
private void drawPerSaltire(Graphics2D g) {
    int colors = backgroundColors.size();
    GeneralPath path = new GeneralPath();
    int[] x = { 0, WIDTH, WIDTH, 0 };
    int[] y = { 0, 0, HEIGHT, HEIGHT };
    double halfWidth = WIDTH / 2;
    double halfHeight = HEIGHT / 2;
    for (int index = 0; index < 4; index++) {
        path.moveTo(x[index], y[index]);
        path.lineTo(halfWidth, halfHeight);
        int nextIndex = (index + 1) % 4;
        path.lineTo(x[nextIndex], y[nextIndex]);
        g.setColor(backgroundColors.get(index % colors));
        g.fill(path);
        path.reset();
    }
}
 
Example 10
Project: FreeCol   File: Flag.java   View source code 6 votes vote down vote up
/**
 * Return the basic five-point star.
 *
 * @return the basic star shape
 */
private static GeneralPath getStar() {
    GeneralPath star = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    double angle = 2 * Math.PI / 5;
    double radius = STAR_SIZE / 2;
    double x = 0;
    double y = -radius;
    star.moveTo(x, y);
    int[] vertex = { 2, 4, 1, 3 };
    for (int i : vertex) {
        double phi = i * angle;
        x = radius * Math.sin(phi);
        y = -radius * Math.cos(phi);
        star.lineTo(x, y);
    }
    star.closePath();
    return star;
}
 
Example 11
Project: openjdk-jdk10   File: StandardGlyphVector.java   View source code 6 votes vote down vote up
Rectangle2D getGlyphOutlineBounds(int glyphID, float x, float y) {
    Rectangle2D result = null;
    if (sgv.invdtx == null) {
        result = new Rectangle2D.Float();
        result.setRect(strike.getGlyphOutlineBounds(glyphID)); // don't mutate cached rect
    } else {
        GeneralPath gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        result = gp.getBounds2D();
    }
    /* Since x is the logical advance of the glyph to this point.
     * Because of the way that Rectangle.union is specified, this
     * means that subsequent unioning of a rect including that
     * will be affected, even if the glyph is empty. So skip such
     * cases. This alone isn't a complete solution since x==0
     * may also not be what is wanted. The code that does the
     * unioning also needs to be aware to ignore empty glyphs.
     */
    if (!result.isEmpty()) {
        result.setRect(result.getMinX() + x + dx,
                       result.getMinY() + y + dy,
                       result.getWidth(), result.getHeight());
    }
    return result;
}
 
Example 12
Project: ramus   File: DFDFunctionEllipse.java   View source code 6 votes vote down vote up
protected int getTriangle(final FloatPoint point) {
    int res = -1;

    FloatPoint l = getLocation();

    for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) {
        GeneralPath gp = getTrianglePath(type);
        double y = point.getY() + l.getY();
        double x = point.getX() + l.getX();
        if (gp.contains(new Point2D.Double(x, y))) {
            res = type;
            break;
        }
    }

    return res;
}
 
Example 13
Project: Tarski   File: mxLabelShape.java   View source code 6 votes vote down vote up
/**
 * Draws the glass effect
 */
public static void drawGlassEffect(mxGraphics2DCanvas canvas, mxCellState state) {
  double size = 0.4;
  canvas.getGraphics()
      .setPaint(new GradientPaint((float) state.getX(), (float) state.getY(),
          new Color(1, 1, 1, 0.9f), (float) (state.getX()),
          (float) (state.getY() + state.getHeight() * size), new Color(1, 1, 1, 0.3f)));

  float sw = (float) (mxUtils.getFloat(state.getStyle(), mxConstants.STYLE_STROKEWIDTH, 1)
      * canvas.getScale() / 2);

  GeneralPath path = new GeneralPath();
  path.moveTo((float) state.getX() - sw, (float) state.getY() - sw);
  path.lineTo((float) state.getX() - sw, (float) (state.getY() + state.getHeight() * size));
  path.quadTo((float) (state.getX() + state.getWidth() * 0.5),
      (float) (state.getY() + state.getHeight() * 0.7),
      (float) (state.getX() + state.getWidth() + sw),
      (float) (state.getY() + state.getHeight() * size));
  path.lineTo((float) (state.getX() + state.getWidth() + sw), (float) state.getY() - sw);
  path.closePath();

  canvas.getGraphics().fill(path);
}
 
Example 14
Project: geomapapp   File: UnknownDataSet.java   View source code 6 votes vote down vote up
public static Shape createStar(int arms, Point2D center, double rOuter, double rInner)
{
	double angle = Math.PI / arms;

	GeneralPath path = new GeneralPath();

	for (int i = 0; i < 2 * arms; i++)
	{
		double r = (i & 1) == 0 ? rOuter : rInner;
		Point2D.Double p = new Point2D.Double(center.getX() + Math.cos(i * angle) * r, center.getY() + Math.sin(i * angle) * r);
		if (i == 0) path.moveTo(p.getX(), p.getY());
		else path.lineTo(p.getX(), p.getY());
	}
	path.closePath();
	return path;
}
 
Example 15
Project: freecol   File: Flag.java   View source code 6 votes vote down vote up
private GeneralPath getCross(Decoration decoration) {
    double quarterWidth = (WIDTH - DECORATION_SIZE) / 2;
    double quarterHeight = (HEIGHT - DECORATION_SIZE) / 2;
    double offset = 0;
    double width = WIDTH;
    double height = HEIGHT;
    switch(decoration) {
    case SCANDINAVIAN_CROSS:
        offset = CROSS_OFFSET;
        break;
    case GREEK_CROSS:
        width = height = Math.min(WIDTH, HEIGHT) - 2 * DECORATION_SIZE;
        break;
    default:
        break;
    }
    GeneralPath cross = new GeneralPath();
    cross.append(new Rectangle2D.Double((WIDTH - width) / 2, quarterHeight,
                                        width, DECORATION_SIZE), false);
    cross.append(new Rectangle2D.Double(quarterWidth - offset, (HEIGHT - height) / 2,
                                        DECORATION_SIZE, height), false);
    return cross;
}
 
Example 16
Project: freecol   File: Flag.java   View source code 6 votes vote down vote up
private GeneralPath getBend(boolean sinister) {
    GeneralPath path = new GeneralPath();
    if (sinister) {
        path.moveTo(0, HEIGHT);
        path.lineTo(0, HEIGHT - BEND_Y);
        path.lineTo(WIDTH - BEND_X, 0);
        path.lineTo(WIDTH, 0);
        path.lineTo(WIDTH, BEND_Y);
        path.lineTo(BEND_X, HEIGHT);
    } else {
        path.moveTo(0, 0);
        path.lineTo(BEND_X, 0);
        path.lineTo(WIDTH, HEIGHT - BEND_Y);
        path.lineTo(WIDTH, HEIGHT);
        path.lineTo(WIDTH - BEND_X, HEIGHT);
        path.lineTo(0, BEND_Y);
    }
    return path;
}
 
Example 17
Project: freecol   File: Flag.java   View source code 6 votes vote down vote up
/**
 * Return the basic five-point star.
 *
 * @return the basic star shape
 */
private static GeneralPath getStar() {
    GeneralPath star = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    double angle = 2 * Math.PI / 5;
    double radius = STAR_SIZE / 2;
    double x = 0;
    double y = -radius;
    star.moveTo(x, y);
    int[] vertex = { 2, 4, 1, 3 };
    for (int i : vertex) {
        double phi = i * angle;
        x = radius * Math.sin(phi);
        y = -radius * Math.cos(phi);
        star.lineTo(x, y);
    }
    star.closePath();
    return star;
}
 
Example 18
Project: Princeton_Algorithms   File: StdDraw.java   View source code 6 votes vote down vote up
/**
 * Draws a polygon with the vertices 
 * (<em>x</em><sub>0</sub>, <em>y</em><sub>0</sub>),
 * (<em>x</em><sub>1</sub>, <em>y</em><sub>1</sub>), ...,
 * (<em>x</em><sub><em>n</em>–1</sub>, <em>y</em><sub><em>n</em>–1</sub>).
 *
 * @param  x an array of all the <em>x</em>-coordinates of the polygon
 * @param  y an array of all the <em>y</em>-coordinates of the polygon
 * @throws IllegalArgumentException unless {@code x[]} and {@code y[]}
 *         are of the same length
 */
public static void polygon(double[] x, double[] y) {
    if (x == null) throw new IllegalArgumentException();
    if (y == null) throw new IllegalArgumentException();
    int n1 = x.length;
    int n2 = y.length;
    if (n1 != n2) throw new IllegalArgumentException("arrays must be of the same length");
    int n = n1;
    GeneralPath path = new GeneralPath();
    path.moveTo((float) scaleX(x[0]), (float) scaleY(y[0]));
    for (int i = 0; i < n; i++)
        path.lineTo((float) scaleX(x[i]), (float) scaleY(y[i]));
    path.closePath();
    offscreen.draw(path);
    draw();
}
 
Example 19
Project: openjdk-jdk10   File: PixelToShapeConverter.java   View source code 5 votes vote down vote up
private Shape makePoly(int xPoints[], int yPoints[],
                       int nPoints, boolean close) {
    GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    if (nPoints > 0) {
        gp.moveTo(xPoints[0], yPoints[0]);
        for (int i = 1; i < nPoints; i++) {
            gp.lineTo(xPoints[i], yPoints[i]);
        }
        if (close) {
            gp.closePath();
        }
    }
    return gp;
}
 
Example 20
Project: jdk8u-jdk   File: TextLine.java   View source code 5 votes vote down vote up
public Shape getOutline(AffineTransform tx) {

        GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);

        for (int i=0, n = 0; i < fComponents.length; i++, n += 2) {
            TextLineComponent tlc = fComponents[getComponentLogicalIndex(i)];

            dstShape.append(tlc.getOutline(locs[n], locs[n+1]), false);
        }

        if (tx != null) {
            dstShape.transform(tx);
        }
        return dstShape;
    }
 
Example 21
Project: openjdk-jdk10   File: DashStrokeTest.java   View source code 5 votes vote down vote up
public static void main(String[] args) {

        GeneralPath shape = new GeneralPath();
        int[] pointTypes = {0, 0, 1, 1, 0, 1, 1, 0};
        double[] xpoints = {428, 420, 400, 400, 400, 400, 420, 733};
        double[] ypoints = {180, 180, 180, 160, 30, 10, 10, 10};
        shape.moveTo(xpoints[0], ypoints[0]);
        for (int i = 1; i < pointTypes.length; i++) {
            if (pointTypes[i] == 1 && i < pointTypes.length - 1) {
                shape.quadTo(xpoints[i], ypoints[i],
                             xpoints[i + 1], ypoints[i + 1]);
            } else {
                shape.lineTo(xpoints[i], ypoints[i]);
            }
        }

        BufferedImage image = new
            BufferedImage(1000, 1000, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = image.createGraphics();

        Color color = new Color(124, 0, 124, 255);
        g2.setColor(color);
        Stroke stroke = new BasicStroke(1.0f,
                                        BasicStroke.CAP_BUTT,
                                        BasicStroke.JOIN_BEVEL,
                                        10.0f, new float[] {9, 6}, 0.0f);
        g2.setStroke(stroke);
        g2.draw(shape);
    }
 
Example 22
Project: FreeCol   File: Flag.java   View source code 5 votes vote down vote up
private GeneralPath getRhombus() {
    GeneralPath rhombus = new GeneralPath();
    rhombus.moveTo(WIDTH / 2, BEND_Y);
    rhombus.lineTo(WIDTH - BEND_X, HEIGHT / 2);
    rhombus.lineTo(WIDTH / 2, HEIGHT - BEND_Y);
    rhombus.lineTo(BEND_X, HEIGHT / 2);
    return rhombus;
}
 
Example 23
Project: incubator-netbeans   File: ArrowAnchorShape.java   View source code 5 votes vote down vote up
public ArrowAnchorShape (int degrees, int size) {
    this.size = size;
    path = new GeneralPath ();

    double radians = Math.PI * degrees / 180.0;
    double cos = Math.cos (radians / 2.0);
    double sin = -size * Math.sqrt (1 - cos * cos);
    cos *= size;

    path.moveTo (0.0f, 0.0f);
    path.lineTo ((float) cos, (float) -sin);
    path.moveTo (0.0f, 0.0f);
    path.lineTo ((float) cos, (float) sin);
}
 
Example 24
Project: rapidminer   File: PlotInstanceLegendCreator.java   View source code 5 votes vote down vote up
private static GeneralPath createBarShape() {
	GeneralPath barShape = new GeneralPath();
	barShape.moveTo(0, 0);
	barShape.lineTo(0, -5);
	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;
}
 
Example 25
Project: rapidminer   File: SeriesFormat.java   View source code 5 votes vote down vote up
public static Shape createDiamond() {
	final float s = SHAPE_SIZE;
	double d = Math.round(Math.sqrt(2 * s * s) / 2.0);
	final GeneralPath p = new GeneralPath();
	p.moveTo(0, d);
	p.lineTo(d, 0);
	p.lineTo(0, -d);
	p.lineTo(-d, 0);
	p.closePath();
	return p;

	// final float s = shapeSize;
	// final float l = s / 4.0f;
	// final float t = s / 4.0f;
	//
	// final float SQRT2 = (float) Math.pow(2.0, 0.5);
	// 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;
}
 
Example 26
Project: geomapapp   File: WWMGG.java   View source code 5 votes vote down vote up
protected void setCurrentSegment(GeneralPath path) {
	if (currentSegment != null)
		trackLayer.removeRenderable( currentSegment );
	
	if (path == null)
	{
		currentSegment = null;
		return;
	}
	
	PathIterator pi =
		path.getPathIterator(new AffineTransform());
	List<LatLon> pos = new LinkedList<LatLon>();

	float [] coords = new float[6];
	int t = pi.currentSegment(coords);
	pos.add( LatLon.fromDegrees(coords[1], coords[0]));
	while (!pi.isDone())
	{
		t = pi.currentSegment(coords);
		if (t == PathIterator.SEG_LINETO && 
				!(coords[1] == 0 && coords[0]==0))
			pos.add( LatLon.fromDegrees(coords[1], coords[0]));
		
		pi.next();
	}
	
	Polyline line = new Polyline(pos, 0);
	line.setLineWidth(4);
	line.setFollowTerrain(true);
	line.setColor( Color.red );
	trackLayer.addRenderable(line);
	currentSegment = line;
	
}
 
Example 27
Project: rapidminer   File: ArrowButton.java   View source code 5 votes vote down vote up
@Override
public void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath arrow = new GeneralPath();
	int w, h;
	switch (direction) {
		case SwingConstants.SOUTH:
			h = 2;
			w = 4;
			arrow.moveTo(getWidth() / 2 - w, getHeight() / 2);
			arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
			arrow.lineTo(getWidth() / 2, getHeight() / 2 + 2 * h);
			arrow.closePath();
			break;
		case SwingConstants.EAST:
			h = 4;
			w = 2;
			arrow.moveTo(getWidth() / 2 - w, getHeight() / 2 - h);
			arrow.lineTo(getWidth() / 2 + w, getHeight() / 2);
			arrow.lineTo(getWidth() / 2 - w, getHeight() / 2 + h);
			arrow.closePath();
			break;
		default:
			throw new IllegalArgumentException("Illegal direction: " + direction);
	}
	if (isEnabled()) {
		g.setColor(Color.BLACK);
	} else {
		g.setColor(Color.GRAY);
	}
	((Graphics2D) g).fill(arrow);
}
 
Example 28
Project: jmt   File: JmtEdgeView.java   View source code 5 votes vote down vote up
@Override
public Shape getShape() {
	if (sharedPath != null) {
		return sharedPath;
	} else if (mediator.getIsReleased()) {
		return sharedPath = (GeneralPath) renderer.createShape();
	} else {
		return sharedPath = (GeneralPath) renderer.createShape2();
	}
}
 
Example 29
Project: jdk8u-jdk   File: StandardGlyphVector.java   View source code 5 votes vote down vote up
/**
 * Used by getOutline, getGlyphsOutline
 */
private Shape getGlyphsOutline(int start, int count, float x, float y) {
    setFRCTX();
    initPositions();

    GeneralPath result = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    for (int i = start, e = start + count, n = start * 2; i < e; ++i, n += 2) {
        float px = x + positions[n];
        float py = y + positions[n+1];

        getGlyphStrike(i).appendGlyphOutline(glyphs[i], result, px, py);
    }

    return result;
}
 
Example 30
Project: FreeCol   File: Flag.java   View source code 5 votes vote down vote up
private void drawPerBend(Graphics2D g, boolean sinister) {
    drawBackground(g);
    int colors = backgroundColors.size();
    GeneralPath path = new GeneralPath();
    path.moveTo(0, HEIGHT);
    path.lineTo(sinister ? WIDTH : 0, 0);
    path.lineTo(WIDTH, HEIGHT);
    g.setColor(backgroundColors.get(1 % colors));
    g.fill(path);
}
 
Example 31
Project: openjdk-jdk10   File: StandardGlyphVector.java   View source code 5 votes vote down vote up
void appendGlyphOutline(int glyphID, GeneralPath result, float x, float y) {
    // !!! fontStrike needs a method for this.  For that matter, GeneralPath does.
    GeneralPath gp = null;
    if (sgv.invdtx == null) {
        gp = strike.getGlyphOutline(glyphID, x + dx, y + dy);
    } else {
        gp = strike.getGlyphOutline(glyphID, 0, 0);
        gp.transform(sgv.invdtx);
        gp.transform(AffineTransform.getTranslateInstance(x + dx, y + dy));
    }
    PathIterator iterator = gp.getPathIterator(null);
    result.append(iterator, false);
}
 
Example 32
Project: vexillo   File: Symbol.java   View source code 5 votes vote down vote up
private static void coArcTo(GeneralPath p, double x2, double y2, double x3, double y3) {
	Point2D p1 = p.getCurrentPoint();
	double x1 = p1.getX();
	double y1 = p1.getY();
	boolean xe = (x1 == x2 && x2 == x3);
	boolean ye = (y1 == y2 && y2 == y3);
	if (xe && ye) return;
	if (xe || ye) { p.lineTo(x3, y3); return; }
	double d = arcHK(x1, y1, x2, y2, x3, y3);
	double h = arcH(x1, y1, x2, y2, x3, y3) / d;
	double k = arcK(x1, y1, x2, y2, x3, y3) / d;
	if (Double.isNaN(h) || Double.isInfinite(h)) { p.lineTo(x3, y3); return; }
	if (Double.isNaN(k) || Double.isInfinite(k)) { p.lineTo(x3, y3); return; }
	double r = Math.hypot(k - y1, x1 - h);
	double a1 = Math.toDegrees(Math.atan2(k - y1, x1 - h));
	double a2 = Math.toDegrees(Math.atan2(k - y2, x2 - h));
	double a3 = Math.toDegrees(Math.atan2(k - y3, x3 - h));
	Arc2D.Double arc = new Arc2D.Double();
	arc.x = h - r;
	arc.y = k - r;
	arc.width = r + r;
	arc.height = r + r;
	arc.start = a1;
	if ((a1 <= a2 && a2 <= a3) || (a3 <= a2 && a2 <= a1)) {
		arc.extent = a3 - a1;
	} else if (a3 <= a1) {
		arc.extent = a3 - a1 + 360;
	} else {
		arc.extent = a3 - a1 - 360;
	}
	p.append(arc, true);
}
 
Example 33
Project: jtk   File: TriMeshView.java   View source code 5 votes vote down vote up
private static void drawLine(
  Graphics2D g2d, GeneralPath path, int x1, int y1, int x2, int y2)
{
  if (path==null) {
    g2d.drawLine(x1,y1,x2,y2);
  } else {
    path.moveTo(x1,y1);
    path.lineTo(x2,y2);
  }
}
 
Example 34
Project: OpenJSharp   File: FileFont.java   View source code 5 votes vote down vote up
GeneralPath getGlyphOutline(long pScalerContext, int glyphCode, float x, float y) {
    try {
        return getScaler().getGlyphOutline(pScalerContext, glyphCode, x, y);
    } catch (FontScalerException fe) {
        scaler = FontScaler.getNullScaler();
        return getGlyphOutline(pScalerContext, glyphCode, x, y);
    }
}
 
Example 35
Project: javase   File: Sinx.java   View source code 5 votes vote down vote up
private void drawSinx(GeneralPath gp, Graphics2D g2d) {
	for (double i = 0.000001; i <= 8 * Math.PI; i += 0.0001 * Math.PI) {
		gp.lineTo(20 * i, 100 * -Math.sin(i));
	}
	g2d.draw(gp);
	g2d.rotate(Math.PI);
	g2d.draw(gp);
}
 
Example 36
Project: javase   File: Sinx.java   View source code 5 votes vote down vote up
@SuppressWarnings("unused")
private void drawSinxDX(GeneralPath gp, Graphics2D g) {
	for (double i = 0.000001; i <= 8 * Math.PI; i += 0.0001 * Math.PI) {
		gp.lineTo(20 * i, 100 * -Math.sin(i) / i);
	}
	g.draw(gp);
	g.scale(-1, 1);
	g.draw(gp);
}
 
Example 37
Project: jmonet   File: FlexQuadrilateral.java   View source code 5 votes vote down vote up
public Shape getShape() {
    GeneralPath path = new GeneralPath();
    path.moveTo(topLeft.getX(), topLeft.getY());
    path.lineTo(topRight.getX(), topRight.getY());
    path.lineTo(bottomRight.getX(), bottomRight.getY());
    path.lineTo(bottomLeft.getX(), bottomLeft.getY());
    path.closePath();

    return path;
}
 
Example 38
Project: GIFKR   File: FloatInterpolator.java   View source code 5 votes vote down vote up
@Override
public void paintGraph(Graphics2D g, int width, int height) {
	g.setColor(new Color(0, 0, 0, 127));
	
	g.drawString("1.0", 2, g.getFontMetrics().getHeight());
	g.drawString("0.0", 2, height-g.getFontMetrics().getDescent());
	g.setColor(new Color(0, 0, 0, 200));
	
	g.setStroke(new BasicStroke(3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));
	
	ArrayList<Keyframe<Float>> copy = new ArrayList<>(keyframes);
	if(dragFrame != null)
		copy.add(dragFrame);
	Collections.sort(copy);
	
	if(copy.get(0).getTime() != 0f)
		copy.add(0, new Keyframe<Float>(0f, copy.get(0).getValue()));
	if(copy.get(copy.size()-1).getTime() != 1f)
		copy.add(new Keyframe<Float>(1f, copy.get(copy.size()-1).getValue()));
	
	GeneralPath path = new GeneralPath();
	path.moveTo(copy.get(0).getTime() * width, (1f - copy.get(0).getValue()) * height);
	for(int i = 1; i < copy.size(); i++)
		path.lineTo(copy.get(i).getTime() * width, ((1f - copy.get(i).getValue()) * height-.5f));
	g.draw(path);

	g.setStroke(new BasicStroke(3)); //Draw red bar at each keyframe
	g.setColor(new Color(255, 0, 0, 32));
	for(int i = 1; i < copy.size()-1; i++)
		g.drawLine((int) (copy.get(i).getTime() * width), 0, (int) (copy.get(i).getTime() * width), height);
}
 
Example 39
Project: GIFKR   File: DoubleInterpolator.java   View source code 5 votes vote down vote up
@Override
public void paintGraph(Graphics2D g, int width, int height) {
	FontMetrics fm = g.getFontMetrics();
	double min = (Double) minSpinner.getValue();
	double max = (Double) maxSpinner.getValue();
	double range = max - min;

	g.setColor(scaleTextColor);
	
	g.drawString(String.format("%.1f", range/2d+min), scaleTextInset, (height+fm.getHeight())/2 - fm.getDescent());
	g.setColor(lineColor);

	g.setStroke(new BasicStroke(3f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND));

	ArrayList<Keyframe<Double>> copy = new ArrayList<>(keyframes);
	if(dragFrame != null)
		copy.add(dragFrame);
	Collections.sort(copy);

	if(copy.get(0).getTime() != 0f)
		copy.add(0, new Keyframe<Double>(0f, copy.get(0).getValue()));
	if(copy.get(copy.size()-1).getTime() != 1f)
		copy.add(new Keyframe<Double>(1f, copy.get(copy.size()-1).getValue()));

	GeneralPath path = new GeneralPath();
	path.moveTo(copy.get(0).getTime() * width, Math.round(((1f - (copy.get(0).getValue()-min)/range) * height)));
	for(int i = 1; i < copy.size(); i++)
		path.lineTo(copy.get(i).getTime() * width, Math.round((1f - (copy.get(i).getValue()-min)/range) * height)-.5f);
	g.draw(path);

	g.setStroke(new BasicStroke(3)); //Draw red bar at each keyframe
	g.setColor(keyframeIndicatorColor);
	for(int i = 1; i < copy.size()-1; i++)
		g.drawLine((int) (copy.get(i).getTime() * width), 0, (int) (copy.get(i).getTime() * width), height);
	if(min < 0 && max > 0) {
		g.setColor(zeroLineColor);
		g.drawLine(0, (int) ((1-(-min/range))*height), width, (int) ((1-(-min/range))*height));
	}
}
 
Example 40
Project: openjdk-jdk10   File: CompositeStrike.java   View source code 5 votes vote down vote up
GeneralPath getGlyphVectorOutline(int[] glyphs, float x, float y) {
    GeneralPath path = null;
    GeneralPath gp;
    int glyphIndex = 0;
    int[] tmpGlyphs;

    while (glyphIndex < glyphs.length) {
        int start = glyphIndex;
        int slot = glyphs[glyphIndex] >>> 24;
        while (glyphIndex < glyphs.length &&
               (glyphs[glyphIndex+1] >>> 24) == slot) {
            glyphIndex++;
        }
        int tmpLen = glyphIndex-start+1;
        tmpGlyphs = new int[tmpLen];
        for (int i=0;i<tmpLen;i++) {
            tmpGlyphs[i] = glyphs[i] & SLOTMASK;
        }
        gp = getStrikeForSlot(slot).getGlyphVectorOutline(tmpGlyphs, x, y);
        if (path == null) {
            path = gp;
        } else if (gp != null) {
            path.append(gp, false);
        }
    }
    if (path == null) {
        return new GeneralPath();
    } else {
        return path;
    }
}