Translates a set of JavaFX Path Elements by passed-in values of x & y - Java javafx.scene.shape

Java examples for javafx.scene.shape:Path

Description

Translates a set of JavaFX Path Elements by passed-in values of x & y

Demo Code


//package com.java2s;

import java.util.List;
import javafx.scene.shape.ArcTo;

import javafx.scene.shape.LineTo;
import javafx.scene.shape.MoveTo;

import javafx.scene.shape.PathElement;

public class Main {
    public static void main(String[] argv) throws Exception {
        List pathSegment = java.util.Arrays.asList("asdf", "java2s.com");
        double tx = 2.45678;
        double ty = 2.45678;
        translatePathElementsInPlace(pathSegment, tx, ty);
    }/* ww  w.j a v a 2 s  .  co  m*/

    public static void translatePathElementsInPlace(
            List<PathElement> pathSegment, double tx, double ty) {
        for (PathElement shp : pathSegment) {
            if (shp instanceof MoveTo) {
                MoveTo mtShp = (MoveTo) shp;
                double x = mtShp.getX() + tx;
                double y = mtShp.getY() + ty;
                mtShp.setX(x);
                mtShp.setY(y);
            } else if (shp instanceof LineTo) {
                LineTo lineShp = (LineTo) shp;
                double x = lineShp.getX() + tx;
                double y = lineShp.getY() + ty;
                lineShp.setX(x);
                lineShp.setY(y);
            } else if (shp instanceof ArcTo) {
                ArcTo arcShp = (ArcTo) shp;
                double x = arcShp.getX() + tx;
                double y = arcShp.getY() + ty;
                arcShp.setX(x);
                arcShp.setY(y);
                // arcShp.getRadiusX(), arcShp.getRadiusY(), arcShp.isSweepFlag();
            } // ???
        }
    }
}

Related Tutorials