Java Code Examples for javafx.scene.shape.MoveTo#getY()

The following examples show how to use javafx.scene.shape.MoveTo#getY() . 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: ParagraphOverlayGraphicFactory.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected Rectangle2D getBounds(int start, int end) {
	PathElement[] shape = getShape(start, end);
	double minX = 0, minY = 0, maxX = 0, maxY = 0;
	for (PathElement pathElement : shape) {
		if (pathElement instanceof MoveTo) {
			MoveTo moveTo = (MoveTo) pathElement;
			minX = maxX = moveTo.getX();
			minY = maxY = moveTo.getY();
		} else if (pathElement instanceof LineTo) {
			LineTo lineTo = (LineTo) pathElement;
			double x = lineTo.getX();
			double y = lineTo.getY();
			minX = Math.min(minX, x);
			minY = Math.min(minY, y);
			maxX = Math.max(maxX, x);
			maxY = Math.max(maxY, y);
		}
	}
	return new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
}
 
Example 2
Source File: SmoothedChart.java    From OEE-Designer with MIT License 5 votes vote down vote up
private void smooth(ObservableList<PathElement> strokeElements, ObservableList<PathElement> fillElements, final double HEIGHT) {
    if (fillElements.isEmpty()) return;
    // as we do not have direct access to the data, first recreate the list of all the data points we have
    final Point[] dataPoints = new Point[strokeElements.size()];
    for (int i = 0; i < strokeElements.size(); i++) {
        final PathElement element = strokeElements.get(i);
        if (element instanceof MoveTo) {
            final MoveTo move = (MoveTo) element;
            dataPoints[i] = new Point(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            final LineTo line = (LineTo) element;
            final double x = line.getX(), y = line.getY();
            dataPoints[i] = new Point(x, y);
        }
    }
    double firstX = dataPoints[0].getX();
    double lastX  = dataPoints[dataPoints.length - 1].getX();

    Point[] points = Helper.subdividePoints(dataPoints, getSubDivisions());

    fillElements.clear();
    fillElements.add(new MoveTo(firstX, HEIGHT));

    strokeElements.clear();
    strokeElements.add(new MoveTo(points[0].getX(), points[0].getY()));

    for (Point p : points) {
        if (Double.compare(p.getX(), firstX) >= 0) {
            fillElements.add(new LineTo(p.getX(), p.getY()));
            strokeElements.add(new LineTo(p.getX(), p.getY()));
        }
    }

    fillElements.add(new LineTo(lastX, HEIGHT));
    fillElements.add(new LineTo(0, HEIGHT));
    fillElements.add(new ClosePath());
}
 
Example 3
Source File: SmoothedChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void smooth(ObservableList<PathElement> strokeElements, ObservableList<PathElement> fillElements, final double HEIGHT) {
    if (fillElements.isEmpty()) return;
    // as we do not have direct access to the data, first recreate the list of all the data points we have
    final Point[] dataPoints = new Point[strokeElements.size()];
    for (int i = 0; i < strokeElements.size(); i++) {
        final PathElement element = strokeElements.get(i);
        if (element instanceof MoveTo) {
            final MoveTo move = (MoveTo) element;
            dataPoints[i] = new Point(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            final LineTo line = (LineTo) element;
            final double x = line.getX(), y = line.getY();
            dataPoints[i] = new Point(x, y);
        }
    }
    double firstX = dataPoints[0].getX();
    double lastX  = dataPoints[dataPoints.length - 1].getX();

    Point[] points = Helper.subdividePoints(dataPoints, getSubDivisions());

    fillElements.clear();
    fillElements.add(new MoveTo(firstX, HEIGHT));

    strokeElements.clear();
    strokeElements.add(new MoveTo(points[0].getX(), points[0].getY()));

    for (Point p : points) {
        if (Double.compare(p.getX(), firstX) >= 0) {
            fillElements.add(new LineTo(p.getX(), p.getY()));
            strokeElements.add(new LineTo(p.getX(), p.getY()));
        }
    }

    fillElements.add(new LineTo(lastX, HEIGHT));
    fillElements.add(new LineTo(0, HEIGHT));
    fillElements.add(new ClosePath());
}
 
Example 4
Source File: Helper.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
public static final Path smoothPath(final ObservableList<PathElement> ELEMENTS, final boolean FILLED) {
    if (ELEMENTS.isEmpty()) { return new Path(); }
    final Point[] dataPoints = new Point[ELEMENTS.size()];
    for (int i = 0; i < ELEMENTS.size(); i++) {
        final PathElement element = ELEMENTS.get(i);
        if (element instanceof MoveTo) {
            MoveTo move   = (MoveTo) element;
            dataPoints[i] = new Point(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            LineTo line   = (LineTo) element;
            dataPoints[i] = new Point(line.getX(), line.getY());
        }
    }
    double                 zeroY               = ((MoveTo) ELEMENTS.get(0)).getY();
    List<PathElement>      smoothedElements    = new ArrayList<>();
    Pair<Point[], Point[]> result              = calcCurveControlPoints(dataPoints);
    Point[]                firstControlPoints  = result.getKey();
    Point[]                secondControlPoints = result.getValue();
    // Start path dependent on filled or not
    if (FILLED) {
        smoothedElements.add(new MoveTo(dataPoints[0].getX(), zeroY));
        smoothedElements.add(new LineTo(dataPoints[0].getX(), dataPoints[0].getY()));
    } else {
        smoothedElements.add(new MoveTo(dataPoints[0].getX(), dataPoints[0].getY()));
    }
    // Add curves
    for (int i = 2; i < dataPoints.length; i++) {
        final int ci = i - 1;
        smoothedElements.add(new CubicCurveTo(
            firstControlPoints[ci].getX(), firstControlPoints[ci].getY(),
            secondControlPoints[ci].getX(), secondControlPoints[ci].getY(),
            dataPoints[i].getX(), dataPoints[i].getY()));
    }
    // Close the path if filled
    if (FILLED) {
        smoothedElements.add(new LineTo(dataPoints[dataPoints.length - 1].getX(), zeroY));
        smoothedElements.add(new ClosePath());
    }
    return new Path(smoothedElements);
}
 
Example 5
Source File: Helper.java    From OEE-Designer with MIT License 4 votes vote down vote up
public static final Path smoothPath(final ObservableList<PathElement> ELEMENTS, final boolean FILLED) {
	if (ELEMENTS.isEmpty()) {
		return new Path();
	}
	final Point[] dataPoints = new Point[ELEMENTS.size()];
	for (int i = 0; i < ELEMENTS.size(); i++) {
		final PathElement element = ELEMENTS.get(i);
		if (element instanceof MoveTo) {
			MoveTo move = (MoveTo) element;
			dataPoints[i] = new Point(move.getX(), move.getY());
		} else if (element instanceof LineTo) {
			LineTo line = (LineTo) element;
			dataPoints[i] = new Point(line.getX(), line.getY());
		}
	}
	double zeroY = ((MoveTo) ELEMENTS.get(0)).getY();
	List<PathElement> smoothedElements = new ArrayList<>();
	Pair<Point[], Point[]> result = calcCurveControlPoints(dataPoints);
	Point[] firstControlPoints = result.getKey();
	Point[] secondControlPoints = result.getValue();
	// Start path dependent on filled or not
	if (FILLED) {
		smoothedElements.add(new MoveTo(dataPoints[0].getX(), zeroY));
		smoothedElements.add(new LineTo(dataPoints[0].getX(), dataPoints[0].getY()));
	} else {
		smoothedElements.add(new MoveTo(dataPoints[0].getX(), dataPoints[0].getY()));
	}
	// Add curves
	for (int i = 2; i < dataPoints.length; i++) {
		final int ci = i - 1;
		smoothedElements.add(new CubicCurveTo(firstControlPoints[ci].getX(), firstControlPoints[ci].getY(),
				secondControlPoints[ci].getX(), secondControlPoints[ci].getY(), dataPoints[i].getX(),
				dataPoints[i].getY()));
	}
	// Close the path if filled
	if (FILLED) {
		smoothedElements.add(new LineTo(dataPoints[dataPoints.length - 1].getX(), zeroY));
		smoothedElements.add(new ClosePath());
	}
	return new Path(smoothedElements);
}
 
Example 6
Source File: Helper.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
public static final void smoothPath(final Path PATH, final boolean FILLED) {
    List<PathElement> pathElements = PATH.getElements();
    if (pathElements.isEmpty()) { return; }
    final Point[] dataPoints = new Point[pathElements.size()];
    for (int i = 0; i < pathElements.size(); i++) {
        final PathElement element = pathElements.get(i);
        if (element instanceof MoveTo) {
            MoveTo move   = (MoveTo) element;
            dataPoints[i] = new Point(move.getX(), move.getY());
        } else if (element instanceof LineTo) {
            LineTo line   = (LineTo) element;
            dataPoints[i] = new Point(line.getX(), line.getY());
        }
    }
    double                 zeroY               = ((MoveTo) pathElements.get(0)).getY();
    List<PathElement>      smoothedElements    = new ArrayList<>();
    Pair<Point[], Point[]> result              = calcCurveControlPoints(dataPoints);
    Point[]                firstControlPoints  = result.getKey();
    Point[]                secondControlPoints = result.getValue();
    // Start path dependent on filled or not
    if (FILLED) {
        smoothedElements.add(new MoveTo(dataPoints[0].getX(), zeroY));
        smoothedElements.add(new LineTo(dataPoints[0].getX(), dataPoints[0].getY()));
    } else {
        smoothedElements.add(new MoveTo(dataPoints[0].getX(), dataPoints[0].getY()));
    }
    // Add curves
    for (int i = 2; i < dataPoints.length; i++) {
        final int ci = i - 1;
        smoothedElements.add(new CubicCurveTo(
            firstControlPoints[ci].getX(), firstControlPoints[ci].getY(),
            secondControlPoints[ci].getX(), secondControlPoints[ci].getY(),
            dataPoints[i].getX(), dataPoints[i].getY()));
    }
    // Close the path if filled
    if (FILLED) {
        smoothedElements.add(new LineTo(dataPoints[dataPoints.length - 1].getX(), zeroY));
        smoothedElements.add(new ClosePath());
    }
    PATH.getElements().setAll(smoothedElements);
}
 
Example 7
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 8
Source File: ArrowHeadView.java    From JetUML with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the path of the arrowhead.
 * @param pPoint1 a point on the axis of the arrow head
 * @param pEnd the end point of the arrow head
 * @return the path
 */
public Path getPath(Point pPoint1, Point pEnd)
{
	if(aArrowHead == NONE) 
	{
		return new Path();
	}
	
	int dx = pEnd.getX() - pPoint1.getX();
	int dy = pEnd.getY() - pPoint1.getY();
	final double angle = Math.atan2(dy, dx);
	int x1 = (int) Math.round(pEnd.getX() - ARROW_LENGTH * Math.cos(angle + ARROW_ANGLE));
	int y1 = (int) Math.round(pEnd.getY() - ARROW_LENGTH * Math.sin(angle + ARROW_ANGLE));
	int x2 = (int) Math.round(pEnd.getX() - ARROW_LENGTH * Math.cos(angle - ARROW_ANGLE));
	int y2 = (int) Math.round(pEnd.getY() - ARROW_LENGTH * Math.sin(angle - ARROW_ANGLE));

	MoveTo moveToOrigin = new MoveTo(pEnd.getX(), pEnd.getY());
	LineTo lineTo1 = new LineTo(x1, y1);
	Path path = new Path();
	path.getElements().addAll(moveToOrigin, lineTo1);
	if(aArrowHead == V)
	{
		MoveTo moveTo2 = new MoveTo(x2, y2);
		LineTo lineTo2 = new LineTo(pEnd.getX(), pEnd.getY());
		path.getElements().addAll(moveTo2, lineTo2);
	}
	else if(aArrowHead == TRIANGLE || aArrowHead == BLACK_TRIANGLE)
	{
		LineTo lineTo3 = new LineTo(x2, y2); 
		LineTo lineTo4 = new LineTo(moveToOrigin.getX(), moveToOrigin.getY());
		path.getElements().addAll(lineTo3, lineTo4);
	}
	else if(aArrowHead == DIAMOND || aArrowHead == BLACK_DIAMOND)
	{
		final int x3 = (int) Math.round( x2 - ARROW_LENGTH * Math.cos(angle + ARROW_ANGLE));
		final int y3 = (int) Math.round( y2 - ARROW_LENGTH * Math.sin(angle + ARROW_ANGLE));
		LineTo lineTo5 = new LineTo(x3, y3);
		LineTo lineTo6 = new LineTo(x2, y2);
		LineTo lineTo7 = new LineTo(moveToOrigin.getX(), moveToOrigin.getY());
		path.getElements().addAll(lineTo5, lineTo6, lineTo7);
	}      
	return path;
}
 
Example 9
Source File: JFXToSVG.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
public SVGPathSegMoveto createSVGPathSegMoveto(final MoveTo elt) {
	return new SVGPathSegMoveto(elt.getX(), elt.getY(), !elt.isAbsolute());
}