javafx.scene.shape.LineTo Java Examples

The following examples show how to use javafx.scene.shape.LineTo. 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: SectionSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
private void createNeedle() {
    double needleWidth  = size * 0.04;
    double needleHeight = size * 0.4675;
    needle.getElements().clear();
    needle.getElements().add(new MoveTo(0.3125 * needleWidth, 0.015957446808510637 * needleHeight));
    needle.getElements().add(new CubicCurveTo(0.3125 * needleWidth, 0.005319148936170213 * needleHeight,
                                              0.4375 * needleWidth, 0.0,
                                              0.5 * needleWidth, 0.0));
    needle.getElements().add(new CubicCurveTo(0.5625 * needleWidth, 0.0,
                                              0.6875 * needleWidth, 0.005319148936170213 * needleHeight,
                                              0.6875 * needleWidth, 0.015957446808510637 * needleHeight));
    needle.getElements().add(new CubicCurveTo(0.6875 * needleWidth, 0.015957446808510637 * needleHeight,
                                              needleWidth, 0.9946808510638298 * needleHeight,
                                              needleWidth, 0.9946808510638298 * needleHeight));
    needle.getElements().add(new LineTo(0.0, 0.9946808510638298 * needleHeight));
    needle.getElements().add(new CubicCurveTo(0.0, 0.9946808510638298 * needleHeight,
                                              0.3125 * needleWidth, 0.015957446808510637 * needleHeight,
                                              0.3125 * needleWidth, 0.015957446808510637 * needleHeight));
    needle.getElements().add(new ClosePath());
    needle.setFill(new LinearGradient(needle.getLayoutBounds().getMinX(), 0,
                                      needle.getLayoutBounds().getMaxX(), 0,
                                      false, CycleMethod.NO_CYCLE,
                                      new Stop(0.0, gauge.getNeedleColor().darker()),
                                      new Stop(0.5, gauge.getNeedleColor()),
                                      new Stop(1.0, gauge.getNeedleColor().darker())));
}
 
Example #2
Source File: ViewFactory.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Optional<PathElement> createPathElement(final PathElement elt) {
	if(elt instanceof LineTo) {
		return Optional.of(createLineTo(((LineTo) elt).getX(), ((LineTo) elt).getY()));
	}
	if(elt instanceof MoveTo) {
		return Optional.of(createMoveTo(((MoveTo) elt).getX(), ((MoveTo) elt).getY()));
	}
	if(elt instanceof ClosePath) {
		return Optional.of(createClosePath());
	}
	if(elt instanceof CubicCurveTo) {
		final CubicCurveTo curve = (CubicCurveTo) elt;
		return Optional.of(createCubicCurveTo(curve.getControlX1(), curve.getControlY1(), curve.getControlX2(), curve.getControlY2(), curve.getX(), curve.getY()));
	}
	return Optional.empty();
}
 
Example #3
Source File: SmoothAreaChartTileSkin.java    From OEE-Designer with MIT License 6 votes vote down vote up
private void drawChart(final List<Point> POINTS) {
    if (POINTS.isEmpty()) return;
    Point[] points = smoothing ? Helper.subdividePoints(POINTS.toArray(new Point[0]), 8) : POINTS.toArray(new Point[0]);

    fillPath.getElements().clear();
    fillPath.getElements().add(new MoveTo(0, height));

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

    for (Point p : points) {
        fillPath.getElements().add(new LineTo(p.getX(), p.getY()));
        strokePath.getElements().add(new LineTo(p.getX(), p.getY()));
    }

    fillPath.getElements().add(new LineTo(width, height));
    fillPath.getElements().add(new LineTo(0, height));
    fillPath.getElements().add(new ClosePath());

    if (dataPointsVisible) { drawDataPoints(POINTS, tile.isFillWithGradient() ? tile.getGradientStops().get(0).getColor() : tile.getBarColor()); }
}
 
Example #4
Source File: ViewFactory.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void flushPathElement(final PathElement elt) {
	if(elt instanceof LineTo) {
		final LineTo lineTo = (LineTo) elt;
		lineTo.xProperty().unbind();
		lineTo.yProperty().unbind();
	}else {
		if(elt instanceof MoveTo) {
			final MoveTo moveTo = (MoveTo) elt;
			moveTo.xProperty().unbind();
			moveTo.yProperty().unbind();
		}else {
			if(elt instanceof CubicCurveTo) {
				final CubicCurveTo cct = (CubicCurveTo) elt;
				cct.xProperty().unbind();
				cct.yProperty().unbind();
				cct.controlX1Property().unbind();
				cct.controlX2Property().unbind();
				cct.controlY1Property().unbind();
				cct.controlY2Property().unbind();
			}
		}
	}
}
 
Example #5
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 #6
Source File: GaugeSparkLineTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void smooth(final List<Double> DATA_LIST) {
    Task<Point[]> smoothTask = new Task<Point[]>() {
        @Override protected Point[] call() {
            return Helper.smoothSparkLine(DATA_LIST, minValue, maxValue, graphBounds, noOfDatapoints);
        }
    };
    smoothTask.setOnSucceeded(t -> {
        Point[] smoothedPoints = smoothTask.getValue();
        int lengthMinusOne = smoothedPoints.length - 1;
        sparkLine.getElements().clear();
        sparkLine.getElements().add(new MoveTo(smoothedPoints[0].getX(), smoothedPoints[0].getY()));
        for (int i = 1 ; i < lengthMinusOne ; i++) {
            sparkLine.getElements().add(new LineTo(smoothedPoints[i].getX(), smoothedPoints[i].getY()));
        }
        dot.setCenterX(smoothedPoints[lengthMinusOne].getX());
        dot.setCenterY(smoothedPoints[lengthMinusOne].getY());
    });
    Thread smoothThread = new Thread(smoothTask);
    smoothThread.setDaemon(true);
    smoothThread.start();
}
 
Example #7
Source File: RenderBoxHelperFX.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public void renderCanvas(final Interval targetInterval, final Path canvas)
{
	final double tX0 = targetInterval.min(0);
	final double tX1 = targetInterval.max(0);
	final double tY0 = targetInterval.min(1);
	final double tY1 = targetInterval.max(1);

	final double[] c000 = new double[] {tX0, tY0, 0};
	final double[] c100 = new double[] {tX1, tY0, 0};
	final double[] c010 = new double[] {tX0, tY1, 0};
	final double[] c110 = new double[] {tX1, tY1, 0};

	canvas.getElements().add(new MoveTo(perspectiveX(c000), perspectiveY(c000)));
	canvas.getElements().add(new LineTo(perspectiveX(c100), perspectiveY(c100)));
	canvas.getElements().add(new LineTo(perspectiveX(c110), perspectiveY(c110)));
	canvas.getElements().add(new LineTo(perspectiveX(c010), perspectiveY(c010)));
	canvas.getElements().add(new ClosePath());
}
 
Example #8
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 #9
Source File: TextFlowExt.java    From RichTextFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @param from The index of the first character.
 * @param to The index of the last character.
 * @return An array with the PathElement objects which define an
 *         underline from the first to the last character.
 */
PathElement[] getUnderlineShape(int from, int to) {
    // get a Path for the text underline
    List<PathElement> result = new ArrayList<>();
    
    PathElement[] shape = rangeShape( from, to );
    // The shape is a closed Path for one or more rectangles AROUND the selected text. 
    // shape: [MoveTo origin, LineTo top R, LineTo bottom R, LineTo bottom L, LineTo origin, *]

    // Extract the bottom left and right coordinates for each rectangle to get the underline path.
    for ( int ele = 2; ele < shape.length; ele += 5 )
    {
        LineTo bl = (LineTo) shape[ele+1];
        LineTo br = (LineTo) shape[ele];
        double y = br.getY() - 2.5;
        
        result.add( new MoveTo( bl.getX(), y ) );
        result.add( new LineTo( br.getX(), y ) );
    }

    return result.toArray(new PathElement[0]);
}
 
Example #10
Source File: SnowFlake.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void updatePath() {
    getElements().clear();
    final int n = Math.max(getRecursion(), 1);
    final double flakeRadius = getRadius();
    final double side = Math.abs(flakeRadius * Math.sqrt(3) / Math.pow(3, n));
    xState = 0.0;
    yState = 0.0;
    angleState = 0.0;
    getElements().add(new MoveTo(flakeRadius, 0.0f));
    for (int i = 0; i < 3; i++) {
        koch(n, side);
        angleState -= 120.0;
    }
    getElements().add(new LineTo(flakeRadius, 0.0f));

    setTranslateX(this.getCenterX() - flakeRadius);
    setTranslateY(this.getCenterY() - flakeRadius);
}
 
Example #11
Source File: AmpSkin.java    From Medusa with Apache License 2.0 6 votes vote down vote up
private void drawAverage() {
    double scaledWidth = width * 1.106;
    double centerX     = width * 0.5;
    double centerY     = height * 0.77;
    double minValue    = gauge.getMinValue();
    // Draw average
    average.getElements().clear();
    double averageAngle = START_ANGLE - (gauge.getAverage() - minValue) * angleStep;
    double averageSize  = Helper.clamp(2.0, 2.5, 0.01 * scaledWidth);
    double sinValue     = Math.sin(Math.toRadians(averageAngle));
    double cosValue     = Math.cos(Math.toRadians(averageAngle));
    average.getElements().add(new MoveTo(centerX + scaledWidth * 0.38 * sinValue, centerY + scaledWidth * 0.38 * cosValue));
    sinValue = Math.sin(Math.toRadians(averageAngle - averageSize));
    cosValue = Math.cos(Math.toRadians(averageAngle - averageSize));
    average.getElements().add(new LineTo(centerX + scaledWidth * 0.35 * sinValue, centerY + scaledWidth * 0.35 * cosValue));
    sinValue = Math.sin(Math.toRadians(averageAngle + averageSize));
    cosValue = Math.cos(Math.toRadians(averageAngle + averageSize));
    average.getElements().add(new LineTo(centerX + scaledWidth * 0.35 * sinValue, centerY + scaledWidth * 0.35 * cosValue));
    average.getElements().add(new ClosePath());
    average.setFill(gauge.getAverageColor());
    average.setStroke(gauge.getTickMarkColor());
}
 
Example #12
Source File: SparkLineTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
private void smooth(final List<Double> DATA_LIST) {
    Task<Point[]> smoothTask = new Task<Point[]>() {
        @Override protected Point[] call() {
            return Helper.smoothSparkLine(DATA_LIST, minValue, maxValue, graphBounds, noOfDatapoints);
        }
    };
    smoothTask.setOnSucceeded(t -> {
        Point[] smoothedPoints = smoothTask.getValue();
        int lengthMinusOne = smoothedPoints.length - 1;
        sparkLine.getElements().clear();
        sparkLine.getElements().add(new MoveTo(smoothedPoints[0].getX(), smoothedPoints[0].getY()));
        for (int i = 1 ; i < lengthMinusOne ; i++) {
            sparkLine.getElements().add(new LineTo(smoothedPoints[i].getX(), smoothedPoints[i].getY()));
        }
        dot.setCenterX(smoothedPoints[lengthMinusOne].getX());
        dot.setCenterY(smoothedPoints[lengthMinusOne].getY());
    });
    Thread smoothThread = new Thread(smoothTask);
    smoothThread.setDaemon(true);
    smoothThread.start();
}
 
Example #13
Source File: StockTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
@Override protected void handleEvents(final String EVENT_TYPE) {
    super.handleEvents(EVENT_TYPE);

    if ("VISIBILITY".equals(EVENT_TYPE)) {
        Helper.enableNode(titleText, !tile.getTitle().isEmpty());
        Helper.enableNode(valueText, tile.isValueVisible());
        Helper.enableNode(timeSpanText, !tile.isTextVisible());
        redraw();
    } else if ("VALUE".equals(EVENT_TYPE)) {
        if(tile.isAnimated()) { tile.setAnimated(false); }
        if (!tile.isAveragingEnabled()) { tile.setAveragingEnabled(true); }
        double value = clamp(minValue, maxValue, tile.getValue());
        addData(value);
        handleCurrentValue(value);
    } else if ("AVERAGING".equals(EVENT_TYPE)) {
        noOfDatapoints = tile.getAveragingPeriod();
        // To get smooth lines in the chart we need at least 4 values
        if (noOfDatapoints < 4) throw new IllegalArgumentException("Please increase the averaging period to a value larger than 3.");
        for (int i = 0; i < noOfDatapoints; i++) { dataList.add(minValue); }
        pathElements.clear();
        pathElements.add(0, new MoveTo());
        for (int i = 1 ; i < noOfDatapoints ; i++) { pathElements.add(i, new LineTo()); }
        sparkLine.getElements().setAll(pathElements);
        redraw();
    }
}
 
Example #14
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 #15
Source File: FatClockSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void createHourPointer() {
    double width  = size * 0.09733333;
    double height = size * 0.42066667;
    hour.setCache(false);
    hour.getElements().clear();
    hour.getElements().add(new MoveTo(0.0, 0.0));
    hour.getElements().add(new CubicCurveTo(0.0, 0.0, 0.0, 0.884310618066561 * height, 0.0, 0.884310618066561 * height));
    hour.getElements().add(new CubicCurveTo(0.0, 0.9477020602218701 * height, 0.22602739726027396 * width, height, 0.5 * width, height));
    hour.getElements().add(new CubicCurveTo(0.773972602739726 * width, height, width, 0.9477020602218701 * height, width, 0.884310618066561 * height));
    hour.getElements().add(new CubicCurveTo(width, 0.884310618066561 * height, width, 0.0, width, 0.0));
    hour.getElements().add(new LineTo(0.0, 0.0));
    hour.getElements().add(new ClosePath());
    hour.setCache(true);
    hour.setCacheHint(CacheHint.ROTATE);
}
 
Example #16
Source File: ParagraphText.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private PathElement[] createRectangle(double topLeftX, double topLeftY, double bottomRightX, double bottomRightY) {
    return new PathElement[] {
            new MoveTo(topLeftX, topLeftY),
            new LineTo(bottomRightX, topLeftY),
            new LineTo(bottomRightX, bottomRightY),
            new LineTo(topLeftX, bottomRightY),
            new LineTo(topLeftX, topLeftY)
    };
}
 
Example #17
Source File: RotationHandler.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The constructor by default.
 * @param border The selection border.
 */
public RotationHandler(final @NotNull Rectangle border) {
	super();
	final Arc arc = new Arc();
	arc.setCenterX(DEFAULT_SIZE / 2d);
	arc.setRadiusX(DEFAULT_SIZE / 2d);
	arc.setRadiusY(DEFAULT_SIZE / 2d);
	arc.setType(ArcType.OPEN);
	arc.setLength(270d);
	arc.setStroke(DEFAULT_COLOR);
	arc.setStrokeWidth(2.5d);
	arc.setStrokeLineCap(StrokeLineCap.BUTT);
	arc.setFill(new Color(1d, 1d, 1d, 0d));
	getChildren().add(arc);

	final Path arrows = new Path();
	arrows.setStroke(null);
	arrows.setFill(new Color(0d, 0d, 0d, 0.4));
	arrows.getElements().add(new MoveTo(DEFAULT_SIZE + DEFAULT_SIZE / 4d, 0d));
	arrows.getElements().add(new LineTo(DEFAULT_SIZE, DEFAULT_SIZE / 2d));
	arrows.getElements().add(new LineTo(DEFAULT_SIZE - DEFAULT_SIZE / 4d, 0d));
	arrows.getElements().add(new ClosePath());
	getChildren().add(arrows);

	translateXProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutX() + border.getWidth(), border.xProperty(),
		border.widthProperty(), border.layoutXProperty()));
	translateYProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutY() + DEFAULT_SIZE, border.yProperty(),
		border.heightProperty(), border.layoutYProperty()));
}
 
Example #18
Source File: LowerRightRegion.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));
            path.getElements().add(new LineTo(size, size * 0.81));
            path.getElements().add(new CubicCurveTo(size, size * 0.915, size * 0.915, size, size * 0.81, size));
            path.getElements().add(new LineTo(0, size));
            path.getElements().add(new ClosePath());
        } else {
            path.getElements().add(new MoveTo(size, 0));
            path.getElements().add(new LineTo(size, size));
            path.getElements().add(new LineTo(0, size));
            path.getElements().add(new ClosePath());
        }

        icon.getElements().clear();
        icon.getElements().add(new MoveTo(size * 0.688, size * 0.494));
        icon.getElements().add(new LineTo(size * 0.746, size * 0.494));
        icon.getElements().add(new LineTo(size * 0.746, size * 0.768));
        icon.getElements().add(new LineTo(size * 0.812, size * 0.704));
        icon.getElements().add(new LineTo(size * 0.852, size * 0.744));
        icon.getElements().add(new LineTo(size * 0.718, size * 0.878));
        icon.getElements().add(new LineTo(size * 0.582, size * 0.744));
        icon.getElements().add(new LineTo(size * 0.624, size * 0.704));
        icon.getElements().add(new LineTo(size * 0.688, size * 0.768));
        icon.getElements().add(new ClosePath());

        redraw();
    }
}
 
Example #19
Source File: InteractiveGaugeSkin.java    From medusademo with Apache License 2.0 5 votes vote down vote up
private void drawAverage() {
    double centerX = size * 0.5;
    double centerY = size * 0.5;
    // Draw average
    average.getElements().clear();
    double averageAngle;
    if (ScaleDirection.CLOCKWISE == scaleDirection) {
        averageAngle = startAngle - (getSkinnable().getAverage() - minValue) * angleStep;
    } else {
        averageAngle = startAngle + (getSkinnable().getAverage() - minValue) * angleStep;
    }
    double averageSize = Helper.clamp(3.0, 3.5, 0.01 * size);
    double sinValue      = Math.sin(Math.toRadians(averageAngle));
    double cosValue      = Math.cos(Math.toRadians(averageAngle));
    switch (tickLabelLocation) {
        case OUTSIDE:
            average.getElements().add(new MoveTo(centerX + size * 0.38 * sinValue, centerY + size * 0.38 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle - averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle - averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.34 * sinValue, centerY + size * 0.34 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle + averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle + averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.34 * sinValue, centerY + size * 0.34 * cosValue));
            average.getElements().add(new ClosePath());
            break;
        case INSIDE:
        default:
            average.getElements().add(new MoveTo(centerX + size * 0.465 * sinValue, centerY + size * 0.465 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle - averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle - averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.425 * sinValue, centerY + size * 0.425 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle + averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle + averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.425 * sinValue, centerY + size * 0.425 * cosValue));
            average.getElements().add(new ClosePath());
            break;
    }
    average.setFill(getSkinnable().getAverageColor());
    average.setStroke(getSkinnable().getTickMarkColor());
}
 
Example #20
Source File: RadarNodeChart.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private void drawOverlay() {
    final Paint  CHART_BKG     = getChartBackgroundColor();
    final double CENTER_X      = 0.5 * width;
    final double CENTER_Y      = 0.5 * height;
    final double CIRCLE_RADIUS = 0.45 * size;
    final int    NO_OF_SECTORS = getNoOfSectors();

    // clear the overlayPath
    overlayPath.getElements().clear();

    // draw center point
    centerCircle.setCenterX(CENTER_X);
    centerCircle.setCenterY(CENTER_Y);
    centerCircle.setRadius(0.28571 * CIRCLE_RADIUS);
    centerCircle.setFill(CHART_BKG);
    centerCircle.setStroke(getGridColor());
    overlayPath.setStroke(getGridColor());
    overlayPath.setStrokeWidth(1);
    addCircle(overlayPath, CENTER_X, CENTER_Y, CIRCLE_RADIUS);

    // draw concentric rings
    double ringStepSize = (CIRCLE_RADIUS - CIRCLE_RADIUS * 0.28571) / 20.0;
    double ringSize     = CIRCLE_RADIUS;

    for (int i = 0 ; i < 11 ; i++) {
        addCircle(overlayPath,CENTER_X, CENTER_Y, ringSize);
        ringSize -= 2 * ringStepSize;
    }

    // draw star lines
    for (int i = 0 ; i < NO_OF_SECTORS ; i++) {
        double[] xy = Helper.rotatePointAroundRotationCenter(CENTER_X, CENTER_Y - CIRCLE_RADIUS, CENTER_X, CENTER_Y, i * angleStep);
        overlayPath.getElements().add(new MoveTo(CENTER_X, CENTER_Y));
        overlayPath.getElements().add(new LineTo(xy[0], xy[1]));
    }
}
 
Example #21
Source File: ViewFactory.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean equals(final Object obj) {
	if(obj == this) {
		return true;
	}
	if(!(obj instanceof LineTo)) {
		return false;
	}
	final LineTo lt = (LineTo) obj;
	return MathUtils.INST.equalsDouble(lt.getX(), getX()) && MathUtils.INST.equalsDouble(lt.getY(), getY()) && lt.isAbsolute() == isAbsolute();
}
 
Example #22
Source File: TestViewShape.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
protected List<PathElement> duplicatePath(final List<PathElement> path) {
	return path.stream().map(elt -> {
		final PathElement dupelt;
		if(elt instanceof MoveTo) {
			final MoveTo moveTo = (MoveTo) elt;
			dupelt = factory.createMoveTo(moveTo.getX(), moveTo.getY());
		}else {
			if(elt instanceof LineTo) {
				final LineTo lineTo = (LineTo) elt;
				dupelt = factory.createLineTo(lineTo.getX(), lineTo.getY());
			}else {
				if(elt instanceof ClosePath) {
					dupelt = factory.createClosePath();
				}else {
					if(elt instanceof CubicCurveTo) {
						final CubicCurveTo cct = (CubicCurveTo) elt;
						dupelt = factory.createCubicCurveTo(cct.getControlX1(), cct.getControlY1(), cct.getControlX2(), cct.getControlY2(), cct.getX(), cct.getY());
					}else {
						throw new IllegalArgumentException();
					}
				}
			}
		}

		dupelt.setAbsolute(elt.isAbsolute());
		return dupelt;
	}).collect(Collectors.toList());
}
 
Example #23
Source File: GaugeSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void drawAverage() {
    double centerX = size * 0.5;
    double centerY = size * 0.5;
    // Draw average
    average.getElements().clear();
    double averageAngle;
    if (ScaleDirection.CLOCKWISE == scaleDirection) {
        averageAngle = startAngle - (gauge.getAverage() - minValue) * angleStep;
    } else {
        averageAngle = startAngle + (gauge.getAverage() - minValue) * angleStep;
    }
    double averageSize = Helper.clamp(3.0, 3.5, 0.01 * size);
    double sinValue      = Math.sin(Math.toRadians(averageAngle));
    double cosValue      = Math.cos(Math.toRadians(averageAngle));
    switch (tickLabelLocation) {
        case OUTSIDE:
            average.getElements().add(new MoveTo(centerX + size * 0.38 * sinValue, centerY + size * 0.38 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle - averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle - averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.34 * sinValue, centerY + size * 0.34 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle + averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle + averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.34 * sinValue, centerY + size * 0.34 * cosValue));
            average.getElements().add(new ClosePath());
            break;
        case INSIDE:
        default:
            average.getElements().add(new MoveTo(centerX + size * 0.465 * sinValue, centerY + size * 0.465 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle - averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle - averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.425 * sinValue, centerY + size * 0.425 * cosValue));
            sinValue = Math.sin(Math.toRadians(averageAngle + averageSize));
            cosValue = Math.cos(Math.toRadians(averageAngle + averageSize));
            average.getElements().add(new LineTo(centerX + size * 0.425 * sinValue, centerY + size * 0.425 * cosValue));
            average.getElements().add(new ClosePath());
            break;
    }
    average.setFill(gauge.getAverageColor());
    average.setStroke(gauge.getTickMarkColor());
}
 
Example #24
Source File: BatterySkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private Path createHorizontalBattery(final Path PATH) {
    PATH.getElements().clear();
    PATH.getElements().add(new MoveTo(0.825 * size, 0.25 * size));
    PATH.getElements().add(new CubicCurveTo(0.825 * size, 0.25 * size,
                                                  0.075 * size, 0.25 * size,
                                                  0.075 * size, 0.25 * size));
    PATH.getElements().add(new CubicCurveTo(0.03125 * size, 0.25 * size,
                                                  0.0, 0.28125 * size,
                                                  0.0, 0.325 * size));
    PATH.getElements().add(new CubicCurveTo(0.0, 0.325 * size,
                                                  0.0, 0.675 * size,
                                                  0.0, 0.675 * size));
    PATH.getElements().add(new CubicCurveTo(0.0, 0.71875 * size,
                                                  0.03125 * size, 0.75 * size,
                                                  0.075 * size, 0.75 * size));
    PATH.getElements().add(new CubicCurveTo(0.075 * size, 0.75 * size,
                                                  0.825 * size, 0.75 * size,
                                                  0.825 * size, 0.75 * size));
    PATH.getElements().add(new CubicCurveTo(0.86875 * size, 0.75 * size,
                                                  0.9 * size, 0.71875 * size,
                                                  0.9 * size, 0.675 * size));
    PATH.getElements().add(new CubicCurveTo(0.9 * size, 0.675 * size,
                                                  0.9 * size, 0.6 * size,
                                                  0.9 * size, 0.6 * size));
    PATH.getElements().add(new LineTo(size, 0.6 * size));
    PATH.getElements().add(new LineTo(size, 0.4 * size));
    PATH.getElements().add(new LineTo(0.9 * size, 0.4 * size));
    PATH.getElements().add(new CubicCurveTo(0.9 * size, 0.4 * size,
                                                  0.9 * size, 0.325 * size,
                                                  0.9 * size, 0.325 * size));
    PATH.getElements().add(new CubicCurveTo(0.9 * size, 0.28125 * size,
                                                  0.86875 * size, 0.25 * size,
                                                  0.825 * size, 0.25 * size));
    PATH.getElements().add(new ClosePath());
    return PATH;
}
 
Example #25
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 #26
Source File: SmoothAreaChartTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
private double[] getXYFromPathElement(final PathElement ELEMENT) {
    if (ELEMENT instanceof MoveTo) {
        return new double[]{ ((MoveTo) ELEMENT).getX(), ((MoveTo) ELEMENT).getY() };
    } else {
        return new double[] { ((LineTo) ELEMENT).getX(), ((LineTo) ELEMENT).getY() };
    }
}
 
Example #27
Source File: TagBoard.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
private void onMouseClicked(MouseEvent me) {
   if (!me.getButton().equals(MouseButton.PRIMARY)) {
      me.consume();
      return;
   }
   if (Settings.getEditShape() == POLYGON) {
      Point2D pt = imageView.parentToLocal(me.getX(), me.getY());
      if (path == null) {
         // Start a polygon shape with double-click or SHORTCUT + mouse click
         if (!me.isShortcutDown() && me.getClickCount() != 2) {
            me.consume();
            return;
         }
         beginShape(pt);
      }
      else {
         // End a polygon shape with double-click (and space key)
         if (me.getClickCount() == 2) {
            endShape(pt);
            return;
         }
         path.getElements().add(new LineTo(pt.getX(), pt.getY()));
         points.add(pt);
         updatePath(pt);
      }
   }
   me.consume();
}
 
Example #28
Source File: SunburstChart.java    From charts with Apache License 2.0 5 votes vote down vote up
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Paint FILL, final Color STROKE, final TreeNode NODE) {
    double  startAngleRad = Math.toRadians(START_ANGLE + 90);
    double  endAngleRad   = Math.toRadians(END_ANGLE + 90);
    boolean largeAngle    = Math.abs(END_ANGLE - START_ANGLE) > 180.0;

    double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad);
    double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad);

    double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad);
    double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad);

    double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad);
    double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad);

    double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad);
    double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad);

    MoveTo moveTo1 = new MoveTo(x1, y1);
    LineTo lineTo2 = new LineTo(x2, y2);
    ArcTo  arcTo3  = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true);
    LineTo lineTo4 = new LineTo(x4, y4);
    ArcTo  arcTo1  = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false);

    Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1);

    path.setFill(FILL);
    path.setStroke(STROKE);

    String tooltipText = new StringBuilder(NODE.getItem().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getItem().getValue())).toString();
    Tooltip.install(path, new Tooltip(tooltipText));

    path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED))));

    return path;
}
 
Example #29
Source File: Bubble.java    From ChatRoom-JavaFX with Apache License 2.0 5 votes vote down vote up
private void drawRectBubbleLeftCenterIndicator() {
	getElements().addAll(new MoveTo(1.0f, 2.5f),
			new LineTo(1.2f, 2.4f),
			new VLineTo(1f),
			new HLineTo(2.9f),
			new VLineTo(4f),
			new HLineTo(1.2f),
			new VLineTo(2.7f),
			new LineTo(1.0f, 2.5f)
			);
}
 
Example #30
Source File: Bubble.java    From ChatRoom-JavaFX with Apache License 2.0 5 votes vote down vote up
private void drawRectBubbleRightCenterIndicator() {
	getElements().addAll(new MoveTo(3.0f, 2.5f),
			new LineTo(2.8f, 2.4f),
			new VLineTo(1f),
			new HLineTo(0f),
			new VLineTo(4f),
			new HLineTo(2.8f),
			new VLineTo(2.7f),
			new LineTo(3.0f, 2.5f)
			);
}