javafx.scene.shape.QuadCurveTo Java Examples

The following examples show how to use javafx.scene.shape.QuadCurveTo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ToolGraphics.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private static void applyPath(GraphicsContext pGraphics, Path pPath)
{
	pGraphics.beginPath();
	for(PathElement element : pPath.getElements())
	{
		if(element instanceof MoveTo)
		{
			pGraphics.moveTo(((int)((MoveTo) element).getX()) + 0.5, ((int)((MoveTo) element).getY()) + 0.5);
		}
		else if(element instanceof LineTo)
		{
			pGraphics.lineTo(((int)((LineTo) element).getX()) + 0.5, ((int)((LineTo) element).getY()) + 0.5);
		}
		else if (element instanceof QuadCurveTo)
		{
			QuadCurveTo curve = (QuadCurveTo) element;
			pGraphics.quadraticCurveTo(((int)curve.getControlX())+0.5, ((int)curve.getControlY()) + 0.5, 
					((int) curve.getX()) + 0.5, ((int) curve.getY()) + 0.5);
		}
	}
}
 
Example #2
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Canvas createIcon(Edge pEdge)
{   //CSOFF: Magic numbers
	Canvas canvas = new Canvas(BUTTON_SIZE, BUTTON_SIZE);
	GraphicsContext graphics = canvas.getGraphicsContext2D();
	graphics.scale(0.6, 0.6);
	Line line = new Line(new Point(2,2), new Point(40,40));
	final double tangent = Math.tan(Math.toRadians(DEGREES_10));
	double dx = (line.getX2() - line.getX1()) / 2;
	double dy = (line.getY2() - line.getY1()) / 2;
	Point control = new Point((int)((line.getX1() + line.getX2()) / 2 + tangent * dy), 
			(int)((line.getY1() + line.getY2()) / 2 - tangent * dx));         
	
	Path path = new Path();
	MoveTo moveTo = new MoveTo(line.getPoint1().getX(), line.getPoint1().getY());
	QuadCurveTo curveTo = new QuadCurveTo(control.getX(), control.getY(), line.getPoint2().getX(), line.getPoint2().getY());
	path.getElements().addAll(moveTo, curveTo);
	
	ToolGraphics.strokeSharpPath(graphics, path, LineStyle.SOLID);
	ArrowHead.V.view().draw(graphics, control, new Point(40, 40));
	return canvas;
}
 
Example #3
Source File: ObjectReferenceEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Path getSShape(Line pConnectionPoints)
{
	final int x1 = pConnectionPoints.getX1() + ENDSIZE;
	final int y1 = pConnectionPoints.getY1();
	final int x2 = pConnectionPoints.getX2() - ENDSIZE;
	final int y2 = pConnectionPoints.getY2();
	final int xmid = (pConnectionPoints.getX1() + pConnectionPoints.getX2()) / 2;
	final int ymid = (pConnectionPoints.getY1() + pConnectionPoints.getY2()) / 2;
    
	MoveTo moveTo = new MoveTo(pConnectionPoints.getX1(), y1);
	LineTo lineTo1 = new LineTo(x1, y1);
	QuadCurveTo quadTo1 = new QuadCurveTo((x1 + xmid) / 2, y1, xmid, ymid);
	QuadCurveTo quadTo2 = new QuadCurveTo((x2 + xmid) / 2, y2, x2, y2);
	LineTo lineTo2 = new LineTo(pConnectionPoints.getX2(), y2);
	
	Path path = new Path();
	path.getElements().addAll(moveTo, lineTo1, quadTo1, quadTo2, lineTo2);
	return path;
}
 
Example #4
Source File: ObjectReferenceEdgeViewer.java    From JetUML with GNU General Public License v3.0 6 votes vote down vote up
private Path getCShape(Line pConnectionPoints)
{
	final int x1 = Math.max(pConnectionPoints.getX1(), pConnectionPoints.getX2()) + ENDSIZE;
	final int y1 = pConnectionPoints.getY1();
	final int x2 = x1 + ENDSIZE;
	final int y2 = pConnectionPoints.getY2();
	final int ymid = (pConnectionPoints.getY1() + pConnectionPoints.getY2()) / 2;
	
	MoveTo moveTo = new MoveTo(pConnectionPoints.getX1(), y1);
	LineTo lineTo1 = new LineTo(x1, y1);
	QuadCurveTo quadTo1 = new QuadCurveTo(x2, y1, x2, ymid);
	QuadCurveTo quadTo2 = new QuadCurveTo(x2, y2, x1, y2);
	LineTo lineTo2 = new LineTo(pConnectionPoints.getX2(), y2);
	
	Path path = new Path();
	path.getElements().addAll(moveTo, lineTo1, quadTo1, quadTo2, lineTo2);
	return path;
}
 
Example #5
Source File: ShapeConverter.java    From Enzo with Apache License 2.0 6 votes vote down vote up
private static Path processPath(final List<String> PATH_LIST, final PathReader READER) {
    final Path PATH = new Path();
    PATH.setFillRule(FillRule.EVEN_ODD);
    while (!PATH_LIST.isEmpty()) {
        if ("M".equals(READER.read())) {
            PATH.getElements().add(new MoveTo(READER.nextX(), READER.nextY()));
        } else if ("L".equals(READER.read())) {
            PATH.getElements().add(new LineTo(READER.nextX(), READER.nextY()));
        } else if ("C".equals(READER.read())) {
            PATH.getElements().add(new CubicCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY()));
        } else if ("Q".equals(READER.read())) {
            PATH.getElements().add(new QuadCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY()));
        } else if ("H".equals(READER.read())) {
            PATH.getElements().add(new HLineTo(READER.nextX()));
        } else if ("L".equals(READER.read())) {
            PATH.getElements().add(new VLineTo(READER.nextY()));
        } else if ("A".equals(READER.read())) {
            PATH.getElements().add(new ArcTo(READER.nextX(), READER.nextY(), 0, READER.nextX(), READER.nextY(), false, false));
        } else if ("Z".equals(READER.read())) {
            PATH.getElements().add(new ClosePath());
        }
    }
    return PATH;
}
 
Example #6
Source File: PathSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PathSample() {
    super(180,90);
    // Create path shape - square
    Path path1 = new Path();
    path1.getElements().addAll(
            new MoveTo(25, 25),
            new HLineTo(65),
            new VLineTo(65),
            new LineTo(25, 65),
            new ClosePath()         
            );
    path1.setFill(null);
    path1.setStroke(Color.RED);
    path1.setStrokeWidth(2);

    // Create path shape - curves
    Path path2 = new Path();
    path2.getElements().addAll(
            new MoveTo(100, 45),
            new CubicCurveTo(120, 20, 130, 80, 140, 45),
            new QuadCurveTo(150, 0, 160, 45),
            new ArcTo(20, 40, 0, 180, 45, true, true)
            );
    path2.setFill(null);
    path2.setStroke(Color.DODGERBLUE);
    path2.setStrokeWidth(2);

    // show the path shapes;
    getChildren().add(new Group(path1, path2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()),
            new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example #7
Source File: PathSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PathSample() {
    super(180,90);
    // Create path shape - square
    Path path1 = new Path();
    path1.getElements().addAll(
            new MoveTo(25, 25),
            new HLineTo(65),
            new VLineTo(65),
            new LineTo(25, 65),
            new ClosePath()         
            );
    path1.setFill(null);
    path1.setStroke(Color.RED);
    path1.setStrokeWidth(2);

    // Create path shape - curves
    Path path2 = new Path();
    path2.getElements().addAll(
            new MoveTo(100, 45),
            new CubicCurveTo(120, 20, 130, 80, 140, 45),
            new QuadCurveTo(150, 0, 160, 45),
            new ArcTo(20, 40, 0, 180, 45, true, true)
            );
    path2.setFill(null);
    path2.setStroke(Color.DODGERBLUE);
    path2.setStrokeWidth(2);

    // show the path shapes;
    getChildren().add(new Group(path1, path2));
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()),
            new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty())
    );
    // END REMOVE ME
}
 
Example #8
Source File: InfoRegion.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void resize() {
    width  = getWidth() - getInsets().getLeft() - getInsets().getRight();
    height = getHeight() - getInsets().getTop() - getInsets().getBottom();
    size   = width < height ? width : height;

    if (width > 0 && height > 0) {
        path.getElements().clear();
        if (isRoundedCorner()) {
            path.getElements().add(new MoveTo(size * 0.23809524, 0));
            path.getElements().add(new LineTo(size, 0));
            path.getElements().add(new LineTo(0, size));
            path.getElements().add(new LineTo(0, size * 0.23809524));
            path.getElements().add(new QuadCurveTo(0, 0, size * 0.23809524, 0));
            path.getElements().add(new ClosePath());
        } else {
            path.getElements().add(new MoveTo(0, 0));
            path.getElements().add(new LineTo(size, 0));
            path.getElements().add(new LineTo(0, size));
            path.getElements().add(new ClosePath());
        }

        icon.getElements().clear();
        icon.getElements().add(new MoveTo(size * 0.185714285714286, size * 0.119047619047619));
        icon.getElements().add(new LineTo(size * 0.254761904761905, size * 0.185714285714286));
        icon.getElements().add(new LineTo(size * 0.185714285714286, size * 0.254761904761905));
        icon.getElements().add(new LineTo(size * 0.119047619047619, size * 0.185714285714286));
        icon.getElements().add(new ClosePath());
        icon.getElements().add(new MoveTo(size * 0.304761904761905, size * 0.238095238095238));
        icon.getElements().add(new LineTo(size * 0.466666666666667, size * 0.4));
        icon.getElements().add(new LineTo(size * 0.4, size * 0.466666666666667));
        icon.getElements().add(new LineTo(size * 0.238095238095238, size * 0.304761904761905));
        icon.getElements().add(new ClosePath());

        redraw();
    }
}
 
Example #9
Source File: NotifyRegion.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void resize() {
    width  = getWidth() - getInsets().getLeft() - getInsets().getRight();
    height = getHeight() - getInsets().getTop() - getInsets().getBottom();
    size   = width < height ? width : height;

    if (width > 0 && height > 0) {
        path.getElements().clear();
        if (isRoundedCorner()) {
            path.getElements().add(new MoveTo(0, 0));
            path.getElements().add(new LineTo(size - size * 0.23809524, 0));
            path.getElements().add(new QuadCurveTo(size, 0, size, size * 0.23809524));
            path.getElements().add(new LineTo(size, size * 0.23809524));
            path.getElements().add(new LineTo(size, size));
            path.getElements().add(new ClosePath());
        } else {
            path.getElements().add(new MoveTo(0, 0));
            path.getElements().add(new LineTo(size, 0));
            path.getElements().add(new LineTo(size, size));
            path.getElements().add(new ClosePath());
        }

        icon.getElements().clear();
        icon.getElements().add(new MoveTo(size * 0.802380952380952, size * 0.123809523809524));
        icon.getElements().add(new LineTo(size * 0.871428571428571, size * 0.19047619047619));
        icon.getElements().add(new LineTo(size * 0.70952380952381, size * 0.352380952380952));
        icon.getElements().add(new LineTo(size * 0.642857142857143, size * 0.283333333333333));
        icon.getElements().add(new ClosePath());
        icon.getElements().add(new MoveTo(size * 0.588095238095238, size * 0.338095238095238));
        icon.getElements().add(new LineTo(size * 0.657142857142857, size * 0.404761904761905));
        icon.getElements().add(new LineTo(size * 0.588095238095238, size * 0.471428571428571));
        icon.getElements().add(new LineTo(size * 0.521428571428571, size * 0.404761904761905));
        icon.getElements().add(new ClosePath());

        redraw();
    }
}
 
Example #10
Source File: Geometry2Shape.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Converts the given {@link Path} to an array of JavaFX {@link PathElement}
 * s.
 *
 * @param path
 *            The {@link Path} to convert.
 * @return The new array of {@link PathElement}s.
 */
public static PathElement[] toPathElements(Path path) {
	Segment[] segments = path.getSegments();
	PathElement[] elements = new PathElement[segments.length];
	for (int i = 0; i < segments.length; i++) {
		Point[] points = segments[i].getPoints();
		// if (points.length > 0) {
		// System.out.println(i + ": " + points[points.length - 1]);
		// }
		switch (segments[i].getType()) {
		case Segment.MOVE_TO:
			elements[i] = new MoveTo(points[0].x, points[0].y);
			break;
		case Segment.LINE_TO:
			elements[i] = new LineTo(points[0].x, points[0].y);
			break;
		case Segment.QUAD_TO:
			elements[i] = new QuadCurveTo(points[0].x, points[0].y,
					points[1].x, points[1].y);
			break;
		case Segment.CUBIC_TO:
			elements[i] = new CubicCurveTo(points[0].x, points[0].y,
					points[1].x, points[1].y, points[2].x, points[2].y);
			break;
		case Segment.CLOSE:
			elements[i] = new ClosePath();
			break;
		default:
			throw new IllegalStateException(
					"Unknown Path.Segment: <" + segments[i] + ">");
		}
	}
	return elements;
}
 
Example #11
Source File: StateTransitionEdgeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
private Shape getNormalEdgeShape(Edge pEdge)
{
	Line line = getConnectionPoints(pEdge);
	Path path = new Path();
	MoveTo moveTo = new MoveTo(line.getPoint1().getX(), line.getPoint1().getY());
	QuadCurveTo curveTo = new QuadCurveTo(getControlPoint(pEdge).getX(), getControlPoint(pEdge).getY(), 
			line.getPoint2().getX(), line.getPoint2().getY());
	path.getElements().addAll(moveTo, curveTo);
	return path;
}
 
Example #12
Source File: ActorNodeViewer.java    From JetUML with GNU General Public License v3.0 5 votes vote down vote up
private Path createStickManPath(Node pNode)
{
	Path path = new Path();
	
	int neckX = pNode.position().getX() + WIDTH / 2;
	int neckY = pNode.position().getY() + HEAD_SIZE + PADDING;
	int hipX = neckX;
	int hipY = neckY + BODY_SIZE;
	float dx = (float) (LEG_SIZE / Math.sqrt(2));
	float feetX1 = hipX - dx;
	float feetX2 = hipX + dx + 1;
	float feetY  = hipY + dx + 1;
	
	path.getElements().addAll(
			new MoveTo(neckX, neckY),
			new QuadCurveTo(neckX + HEAD_SIZE / 2, neckY, neckX + HEAD_SIZE / 2, neckY - HEAD_SIZE / 2),
			new QuadCurveTo(neckX + HEAD_SIZE / 2, neckY - HEAD_SIZE, neckX, neckY - HEAD_SIZE),
			new QuadCurveTo(neckX - HEAD_SIZE / 2, neckY - HEAD_SIZE, neckX-HEAD_SIZE / 2, neckY - HEAD_SIZE / 2),
			new QuadCurveTo(neckX - HEAD_SIZE / 2, neckY, neckX, neckY),
			new LineTo(hipX, hipY),
			new MoveTo(neckX - ARMS_SIZE / 2, neckY + BODY_SIZE / 3),
			new LineTo(neckX + ARMS_SIZE / 2, neckY + BODY_SIZE / 3),
			new MoveTo(feetX1, feetY),
			new LineTo(hipX, hipY),
			new LineTo(feetX2, feetY));	
	return path;
}
 
Example #13
Source File: Text3DHelper.java    From FXyzLib with GNU General Public License v3.0 5 votes vote down vote up
private Point3D evalQuadBezier(QuadCurveTo c, Point3D ini, double t){
    Point3D p=new Point3D((float)(Math.pow(1-t,2)*ini.x+
            2*(1-t)*t*c.getControlX()+
            Math.pow(t, 2)*c.getX()),
            (float)(Math.pow(1-t,2)*ini.y+
            2*(1-t)*t*c.getControlY()+
            Math.pow(t, 2)*c.getY()),
            0f);
    return p;
}
 
Example #14
Source File: Shape2Geometry.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Converts the given JavaFX {@link Path} to a
 * {@link org.eclipse.gef.geometry.planar.Path}.
 *
 * @param path
 *            The JavaFX {@link Path} to convert.
 * @return The newly created {@link org.eclipse.gef.geometry.planar.Path}
 *         that describes the given {@link Path}.
 */
public static final org.eclipse.gef.geometry.planar.Path toPath(
		Path path) {
	ObservableList<PathElement> elements = path.getElements();
	org.eclipse.gef.geometry.planar.Path.Segment[] segments = new org.eclipse.gef.geometry.planar.Path.Segment[elements
			.size()];

	for (int i = 0; i < segments.length; i++) {
		PathElement element = elements.get(i);
		if (element instanceof MoveTo) {
			MoveTo moveTo = (MoveTo) element;
			segments[i] = new Segment(Segment.MOVE_TO,
					new Point(moveTo.getX(), moveTo.getY()));
		} else if (element instanceof LineTo) {
			LineTo lineTo = (LineTo) element;
			segments[i] = new Segment(Segment.LINE_TO,
					new Point(lineTo.getX(), lineTo.getY()));
		} else if (element instanceof QuadCurveTo) {
			QuadCurveTo quadTo = (QuadCurveTo) element;
			segments[i] = new Segment(Segment.QUAD_TO,
					new Point(quadTo.getControlX(), quadTo.getControlY()),
					new Point(quadTo.getX(), quadTo.getY()));
		} else if (element instanceof CubicCurveTo) {
			CubicCurveTo cubicTo = (CubicCurveTo) element;
			segments[i] = new Segment(Segment.CUBIC_TO,
					new Point(cubicTo.getControlX1(),
							cubicTo.getControlY1()),
					new Point(cubicTo.getControlX2(),
							cubicTo.getControlY2()),
					new Point(cubicTo.getX(), cubicTo.getY()));
		} else if (element instanceof ClosePath) {
			segments[i] = new Segment(Segment.CLOSE);
		}
	}

	int windingRule = path.getFillRule() == FillRule.EVEN_ODD
			? org.eclipse.gef.geometry.planar.Path.WIND_EVEN_ODD
			: org.eclipse.gef.geometry.planar.Path.WIND_NON_ZERO;

	return new org.eclipse.gef.geometry.planar.Path(windingRule, segments);
}
 
Example #15
Source File: ShapeConverter.java    From Enzo with Apache License 2.0 4 votes vote down vote up
public static String convertPath(final Path PATH) {
    final StringBuilder fxPath = new StringBuilder();
    for (PathElement element : PATH.getElements()) {
        if (MoveTo.class.equals(element.getClass())) {
            fxPath.append("M ")
                  .append(((MoveTo) element).getX()).append(" ")
                  .append(((MoveTo) element).getY()).append(" ");
        } else if (LineTo.class.equals(element.getClass())) {
            fxPath.append("L ")
                  .append(((LineTo) element).getX()).append(" ")
                  .append(((LineTo) element).getY()).append(" ");
        } else if (CubicCurveTo.class.equals(element.getClass())) {
            fxPath.append("C ")
                  .append(((CubicCurveTo) element).getControlX1()).append(" ")
                  .append(((CubicCurveTo) element).getControlY1()).append(" ")
                  .append(((CubicCurveTo) element).getControlX2()).append(" ")
                  .append(((CubicCurveTo) element).getControlY2()).append(" ")
                  .append(((CubicCurveTo) element).getX()).append(" ")
                  .append(((CubicCurveTo) element).getY()).append(" ");
        } else if (QuadCurveTo.class.equals(element.getClass())) {
            fxPath.append("Q ")
                  .append(((QuadCurveTo) element).getControlX()).append(" ")
                  .append(((QuadCurveTo) element).getControlY()).append(" ")
                  .append(((QuadCurveTo) element).getX()).append(" ")
                  .append(((QuadCurveTo) element).getY()).append(" ");
        } else if (ArcTo.class.equals(element.getClass())) {
            fxPath.append("A ")
                  .append(((ArcTo) element).getX()).append(" ")
                  .append(((ArcTo) element).getY()).append(" ")
                  .append(((ArcTo) element).getRadiusX()).append(" ")
                  .append(((ArcTo) element).getRadiusY()).append(" ");
        } else if (HLineTo.class.equals(element.getClass())) {
            fxPath.append("H ")
                  .append(((HLineTo) element).getX()).append(" ");
        } else if (VLineTo.class.equals(element.getClass())) {
            fxPath.append("V ")
                  .append(((VLineTo) element).getY()).append(" ");
        } else if (ClosePath.class.equals(element.getClass())) {
            fxPath.append("Z");
        }
    }
    return fxPath.toString();
}