Java 类javafx.scene.transform.Transform 实例源码

项目:LivroJavaComoProgramar10Edicao    文件:DrawStarsController.java   
public void initialize() 
{
   // points that define a five-pointed star shape
   Double[] points = {205.0,150.0, 217.0,186.0, 259.0,186.0, 
      223.0,204.0, 233.0,246.0, 205.0,222.0, 177.0,246.0, 187.0,204.0, 
      151.0,186.0, 193.0,186.0};

   // create 18 more stars
   for (int count = 0; count < 18; ++count)
   {
      // create a new Polygon and copy existing points into it
      Polygon newStar = new Polygon();
      newStar.getPoints().addAll(points); 

      // create random Color and set as newStar's fill
      newStar.setStroke(Color.GREY);
      newStar.setFill(Color.rgb(random.nextInt(255), 
         random.nextInt(255), random.nextInt(255), 
         random.nextDouble())); 

      // apply a rotation to the shape
      newStar.getTransforms().add(
         Transform.rotate(count * 20, 150, 150));
      anchorPane.getChildren().add(newStar);
   } 
}
项目:CORNETTO    文件:ViewPane.java   
/**
 * sets up transforming of selections
 */
private void setupTransforms() {
    viewTransformProperty = new SimpleObjectProperty<>(new Transform() {
        @Override
        public void impl_apply(Affine3D t) {

        }

        @Override
        public BaseTransform impl_derive(BaseTransform t) {
            return null;
        }
    });
    viewTransformProperty.addListener((observable, oldValue, newValue) -> {
        myGraphView.getTransforms().setAll(newValue);
    });
}
项目:GestureFX    文件:GesturePaneTest.java   
@Test
public void testDragAndDrop() throws Exception {
    pane.zoomTo(2, pane.targetPointAtViewportCentre());
    Transform expected = target.captureTransform();
    FxRobot robot = new FxRobot();
    robot.moveTo(pane)
            .drag(MouseButton.PRIMARY).dropBy(100, 100);
    Transform actual = target.captureTransform();
    assertThat(actual).isEqualToComparingOnlyGivenFields(expected,
            "xx", "xy", "xz",
            "yx", "yy", "yz",
            "zx", "zy", "zz",
            /* "xt", "yt", */ "zt"); // x y will have delta
    assertThat(actual.getTx()).isCloseTo(expected.getTx() + 100, Offset.offset(10d));
    assertThat(actual.getTy()).isCloseTo(expected.getTy() + 100, Offset.offset(10d));
}
项目:GestureFX    文件:GesturePaneTest.java   
@Test
public void testGestureDisabling() throws Exception {
    pane.setGestureEnabled(false);
    pane.zoomTo(2, pane.targetPointAtViewportCentre());
    Transform expected = target.captureTransform();
    FxRobot robot = new FxRobot();
    robot.moveTo(pane)
            .scroll(2, VerticalDirection.UP)
            .scroll(2, VerticalDirection.DOWN)
            .drag(MouseButton.PRIMARY).dropBy(100, 100);
    assertThat(target.captureTransform()).isEqualToComparingOnlyGivenFields(expected,
            "xx", "xy", "xz",
            "yx", "yy", "yz",
            "zx", "zy", "zz",
            "xt", "yt", "zt");
}
项目:GestureFX    文件:GesturePaneTest.java   
@Test
public void testScaleByScroll() throws Exception {
    pane.scrollModeProperty().set(ScrollMode.ZOOM);
    pane.zoomTo(5, pane.targetPointAtViewportCentre());
    FxRobot robot = new FxRobot();
    assertThat(pane.getCurrentXScale()).isEqualTo(5d);
    Thread.sleep(100);
    robot.moveTo(pane);
    robot.scroll(5, VerticalDirection.UP); // direction is platform dependent
    Thread.sleep(100);
    double expectedUp = 5 * Math.pow(1 + DEFAULT_SCROLL_FACTOR, 5);
    double expectedDown = 5 * Math.pow(1 - DEFAULT_SCROLL_FACTOR, 5);

    Condition<Double> eitherUpOrDown = new Condition<>(
            v -> Math.abs(v - expectedUp) < 0.01 || Math.abs(v - expectedDown) < 0.01,
                                                              "either close to %s or %s",
                                                              expectedUp, expectedDown);
    assertThat(pane.getCurrentXScale()).is(eitherUpOrDown);
    Transform t = target.captureTransform();
    assertThat(t.getMxx()).is(eitherUpOrDown);
    assertThat(t.getMyy()).is(eitherUpOrDown);
}
项目:Shapify    文件:Ellipse.java   
public static Ellipse createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("ellipse")) {
        throw new MalformedParametersException("SVG Element is not an Ellipse.");
    }

    Ellipse ellipse = new Ellipse();

    ellipse.setCenterX(Double.parseDouble(element.getAttributeValue("cx")));
    ellipse.setCenterY(Double.parseDouble(element.getAttributeValue("cy")));
    ellipse.setRadiusX(Double.parseDouble(element.getAttributeValue("rx")));
    ellipse.setRadiusY(Double.parseDouble(element.getAttributeValue("ry")));

    ellipse.setFill(Color.web(element.getAttributeValue("fill"), Double.parseDouble(element.getAttributeValue("fill-opacity"))));

    ellipse.setStroke(Color.web(element.getAttributeValue("stroke"), Double.parseDouble(element.getAttributeValue("stroke-opacity"))));
    ellipse.setStrokeWidth(Double.parseDouble(element.getAttributeValue("stroke-width")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        ellipse.getTransforms().addAll(transforms);
    }

    return ellipse;
}
项目:Shapify    文件:Line.java   
public static Line createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("line")) {
        throw new MalformedParametersException("SVG Element is not a Line.");
    }

    Line line = new Line();

    line.setStartX(Double.parseDouble(element.getAttributeValue("x1")));
    line.setStartY(Double.parseDouble(element.getAttributeValue("y1")));
    line.setEndX(Double.parseDouble(element.getAttributeValue("x2")));
    line.setEndY(Double.parseDouble(element.getAttributeValue("y2")));

    line.setStroke(Color.web(element.getAttributeValue("stroke"), Double.parseDouble(element.getAttributeValue("stroke-opacity"))));
    line.setStrokeWidth(Double.parseDouble(element.getAttributeValue("stroke-width")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        line.getTransforms().addAll(transforms);
    }

    return line;
}
项目:Shapify    文件:Image.java   
public static Image createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("image")) {
        throw new MalformedParametersException("SVG Element is not a Rectangle.");
    }

    Image image = new Image();

    image.setImage(getImageFromBase64(element.getAttributeValue("href", SvgController.XLINK_NAMESPACE)));

    image.setX(Double.parseDouble(element.getAttributeValue("x")));
    image.setY(Double.parseDouble(element.getAttributeValue("y")));
    image.setFitWidth(Double.parseDouble(element.getAttributeValue("width")));
    image.setFitHeight(Double.parseDouble(element.getAttributeValue("height")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        image.getTransforms().addAll(transforms);
    }

    return image;
}
项目:Shapify    文件:Rectangle.java   
public static Rectangle createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("rect")) {
        throw new MalformedParametersException("SVG Element is not a Rectangle.");
    }

    Rectangle rectangle = new Rectangle();

    rectangle.setX(Double.parseDouble(element.getAttributeValue("x")));
    rectangle.setY(Double.parseDouble(element.getAttributeValue("y")));
    rectangle.setWidth(Double.parseDouble(element.getAttributeValue("width")));
    rectangle.setHeight(Double.parseDouble(element.getAttributeValue("height")));

    rectangle.setFill(Color.web(element.getAttributeValue("fill"), Double.parseDouble(element.getAttributeValue("fill-opacity"))));

    rectangle.setStroke(Color.web(element.getAttributeValue("stroke"), Double.parseDouble(element.getAttributeValue("stroke-opacity"))));
    rectangle.setStrokeWidth(Double.parseDouble(element.getAttributeValue("stroke-width")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        rectangle.getTransforms().addAll(transforms);
    }

    return rectangle;
}
项目:openjfx-8u-dev-tests    文件:LocalTo_TransformsTest.java   
@Test
public void differentParentAndSceneTransforms()
{
    Node node = circleTwoWrap.getControl();
    Transform localToScene = node.localToSceneTransformProperty().getValue();
    Transform localToParent = node.localToParentTransformProperty().getValue();

    realTranform.setTx(node.getTranslateX() + node.getLayoutX());
    realTranform.setTy(node.getTranslateY() + node.getLayoutY());
    realTranform.setTz(0);

    Assert.assertFalse(isTransformsEqual(localToParent, localToScene));
    Assert.assertTrue(isTransformsEqual(localToParent, realTranform));

    realTranform.setTx(node.getTranslateX() + node.getLayoutX() +
            node.getParent().getTranslateX() + node.getParent().getLayoutX());
    realTranform.setTy(node.getTranslateY() + node.getLayoutY() +
            node.getParent().getTranslateY() + node.getParent().getLayoutY());

    Assert.assertTrue(isTransformsEqual(localToScene, realTranform));
}
项目:openjfx-8u-dev-tests    文件:LocalTo_TransformsTest.java   
@Test
public void doubleNestedNodeParentAndSceneTransforms()
{
    Node node = circleThreeWrap.getControl();
    Transform localToScene = node.localToSceneTransformProperty().getValue();
    Transform localToParent = node.localToParentTransformProperty().getValue();

    realTranform.setTx(node.getTranslateX() + node.getLayoutX());
    realTranform.setTy(node.getTranslateY() + node.getLayoutY());
    realTranform.setTz(0);

    Assert.assertFalse(isTransformsEqual(localToParent, localToScene));
    Assert.assertTrue(isTransformsEqual(localToParent, realTranform));

    double tx = 0, ty = 0;
    for(Node n = node; n != null; n = n.getParent())
    {
        tx += n.getTranslateX() + n.getLayoutX();
        ty += n.getTranslateY() + n.getLayoutY();
    }
    realTranform.setTx(tx);
    realTranform.setTy(ty);

    Assert.assertTrue(isTransformsEqual(localToScene, realTranform));
}
项目:openjfx-8u-dev-tests    文件:LocalTo_TransformsTest.java   
@Test
public void parentAndScene3DTransforms()
{
    Node node = circleFourWrap.getControl();
    Transform localToScene = node.localToSceneTransformProperty().getValue();
    Transform localToParent = node.localToParentTransformProperty().getValue();

    realTranform.setTx(node.getTranslateX() + node.getLayoutX());
    realTranform.setTy(node.getTranslateY() + node.getLayoutY());
    realTranform.setTz(node.getTranslateZ());

    Assert.assertFalse(isTransformsEqual(localToParent, localToScene));
    Assert.assertTrue(isTransformsEqual(localToParent, realTranform));

    double tx = 0, ty = 0;
    for(Node n = node; n != null; n = n.getParent())
    {
        tx += n.getTranslateX() + n.getLayoutX();
        ty += n.getTranslateY() + n.getLayoutY();
    }
    realTranform.setTx(tx);
    realTranform.setTy(ty);

    Assert.assertTrue(isTransformsEqual(localToScene, realTranform));
}
项目:LuoYing    文件:CanvasJfxBindingController.java   
private void updateCanvasBinding() {
        if (canvas == null || jfxRegion == null)
            return;
        Jfx.runOnSwing(() -> {
            Transform transform = jfxRegion.localToSceneTransformProperty().getValue();
            int width = jfxRegion.widthProperty().intValue();
            int height = jfxRegion.heightProperty().intValue();
            int localX = (int) transform.getTx();
            int localY = (int) transform.getTy();
//            System.out.println("resizeCanvasSize, width=" + jfxRegion.widthProperty().intValue() 
//                    + ", height=" + jfxRegion.heightProperty().intValue()
//                    + ", locationX=" + transform.getTx()
//                    + ", locationY=" + transform.getTy()
//            );
            canvas.setSize(width, height);
            canvas.setLocation(localX, localY);
        });
    }
项目:BudgetMaster    文件:MonthLineChart.java   
@Override
public WritableImage export(int width, int height) {
    VBox root = new VBox();
    root.setStyle("-fx-background-color: transparent;");
    root.setPadding(new Insets(25));

    root.getChildren().add(generate(false));         

    Stage newStage = new Stage();
    newStage.initModality(Modality.NONE);
    newStage.setScene(new Scene(root, width, height));
    newStage.setResizable(false);       
    newStage.show();

    SnapshotParameters sp = new SnapshotParameters();
    sp.setTransform(Transform.scale(width / root.getWidth(), height / root.getHeight()));
    newStage.close();

    return root.snapshot(sp, null);
}
项目:Shapify    文件:Ellipse.java   
public static Ellipse createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("ellipse")) {
        throw new MalformedParametersException("SVG Element is not an Ellipse.");
    }

    Ellipse ellipse = new Ellipse();

    ellipse.setCenterX(Double.parseDouble(element.getAttributeValue("cx")));
    ellipse.setCenterY(Double.parseDouble(element.getAttributeValue("cy")));
    ellipse.setRadiusX(Double.parseDouble(element.getAttributeValue("rx")));
    ellipse.setRadiusY(Double.parseDouble(element.getAttributeValue("ry")));

    ellipse.setFill(Color.web(element.getAttributeValue("fill"), Double.parseDouble(element.getAttributeValue("fill-opacity"))));

    ellipse.setStroke(Color.web(element.getAttributeValue("stroke"), Double.parseDouble(element.getAttributeValue("stroke-opacity"))));
    ellipse.setStrokeWidth(Double.parseDouble(element.getAttributeValue("stroke-width")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        ellipse.getTransforms().addAll(transforms);
    }

    return ellipse;
}
项目:Shapify    文件:Line.java   
public static Line createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("line")) {
        throw new MalformedParametersException("SVG Element is not a Line.");
    }

    Line line = new Line();

    line.setStartX(Double.parseDouble(element.getAttributeValue("x1")));
    line.setStartY(Double.parseDouble(element.getAttributeValue("y1")));
    line.setEndX(Double.parseDouble(element.getAttributeValue("x2")));
    line.setEndY(Double.parseDouble(element.getAttributeValue("y2")));

    line.setStroke(Color.web(element.getAttributeValue("stroke"), Double.parseDouble(element.getAttributeValue("stroke-opacity"))));
    line.setStrokeWidth(Double.parseDouble(element.getAttributeValue("stroke-width")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        line.getTransforms().addAll(transforms);
    }

    return line;
}
项目:Shapify    文件:Image.java   
public static Image createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("image")) {
        throw new MalformedParametersException("SVG Element is not a Rectangle.");
    }

    Image image = new Image();

    image.setImage(getImageFromBase64(element.getAttributeValue("href", SvgController.XLINK_NAMESPACE)));

    image.setX(Double.parseDouble(element.getAttributeValue("x")));
    image.setY(Double.parseDouble(element.getAttributeValue("y")));
    image.setFitWidth(Double.parseDouble(element.getAttributeValue("width")));
    image.setFitHeight(Double.parseDouble(element.getAttributeValue("height")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        image.getTransforms().addAll(transforms);
    }

    return image;
}
项目:Shapify    文件:Rectangle.java   
public static Rectangle createFromSvg(Element element) throws MalformedParametersException {
    if (!element.getName().toLowerCase().trim().equals("rect")) {
        throw new MalformedParametersException("SVG Element is not a Rectangle.");
    }

    Rectangle rectangle = new Rectangle();

    rectangle.setX(Double.parseDouble(element.getAttributeValue("x")));
    rectangle.setY(Double.parseDouble(element.getAttributeValue("y")));
    rectangle.setWidth(Double.parseDouble(element.getAttributeValue("width")));
    rectangle.setHeight(Double.parseDouble(element.getAttributeValue("height")));

    rectangle.setFill(Color.web(element.getAttributeValue("fill"), Double.parseDouble(element.getAttributeValue("fill-opacity"))));

    rectangle.setStroke(Color.web(element.getAttributeValue("stroke"), Double.parseDouble(element.getAttributeValue("stroke-opacity"))));
    rectangle.setStrokeWidth(Double.parseDouble(element.getAttributeValue("stroke-width")));

    String svgTransforms = element.getAttributeValue("transform");

    if (svgTransforms != null) {
        List<Transform> transforms = ShapeUtils.getTransformsFromSvg(svgTransforms);
        rectangle.getTransforms().addAll(transforms);
    }

    return rectangle;
}
项目:FlagMaker-2    文件:OverlayTransformer.java   
@Override
  public String ExportSvg(int width, int height)
  {
if (Overlay == null) return "";
if (!Overlay.IsEnabled) return "";

Transform matrix = GetTransformation(width, height);

return String.format("<g transform=\"matrix(%.3f,%.3f,%.3f,%.3f,%.3f,%.3f)\">%s</g>",
    matrix.getMxx(),
    matrix.getMxy(),
    matrix.getMyx(),
    matrix.getMyy(),
    matrix.getTx(),
    matrix.getTy(),
    Overlay.ExportSvg(width, height));
  }
项目:FlagMaker-2    文件:OverlayTransformer.java   
private Transform GetTransformation(int width, int height)
{
    double centerX = width * GetDoubleAttribute("X") / MaximumX;
    double centerY = height * GetDoubleAttribute("Y") / MaximumY;

    double skewX = 90 * (GetDoubleAttribute("SkewX") - MaximumX / 2.0) / MaximumX;
    double skewY = 90 * (GetDoubleAttribute("SkewY") - MaximumY / 2.0) / MaximumY;

    double scaleX = GetDoubleAttribute("Width");
    double scaleY = GetDoubleAttribute("Height");

    double rotation = (GetDoubleAttribute("Rotation") / MaximumX) * 360;

    Shear skewTransform = new Shear(skewX, skewY, centerX, centerY);
    Rotate rotateTransform = new Rotate(rotation, centerX, centerY);
    Scale scaleTransform = new Scale(scaleX, scaleY, centerX, centerY);

    return rotateTransform.createConcatenation(scaleTransform).createConcatenation(skewTransform);
}
项目:org.csstudio.display.builder    文件:JFXRepresentation.java   
/** Update lines that indicate model's size in edit mode */
private void updateModelSizeIndicators()
{
    int width = model.propWidth().getValue();
    int height = model.propHeight().getValue();

    final ObservableList<Transform> transforms = widget_parent.getTransforms();
    if (transforms.size() > 0  &&  transforms.get(0) instanceof Scale)
    {
        final Scale scale = (Scale) transforms.get(0);
        width  *= scale.getX();
        height *= scale.getY();
    }

    horiz_bound.setStartY(height);
    horiz_bound.setEndX(width);
    horiz_bound.setEndY(height);

    vert_bound.setStartX(width);
    vert_bound.setEndY(height);
    vert_bound.setEndX(width);
}
项目:FX-Map-Control    文件:MapImage.java   
private void updateLayout() {
    Affine viewportTransform = null;
    Bounds bounds = null;
    MapBase map = getMap();
    MapBoundingBox boundingBox = getBoundingBox();

    if (map != null && boundingBox != null) {
        bounds = map.getProjection().boundingBoxToBounds(boundingBox);
        viewportTransform = map.getProjection().getViewportTransform();
    }

    if (bounds != null) {
        getTransforms().setAll(viewportTransform, Transform.scale(1d, -1d, 0d, bounds.getMaxY()));
        setX(bounds.getMinX());
        setY(bounds.getMaxY());
        setFitWidth(bounds.getWidth());
        setFitHeight(bounds.getHeight());
    } else {
        getTransforms().clear();
        setX(0);
        setY(0);
        setFitWidth(0);
        setFitHeight(0);
    }
}
项目:gomoku    文件:Main.java   
/**
 * Take a pixel-aware screenshot of some pane.
 * @param pane Input pane
 * @param pixelScale Scaling factor applied to snapshot (1 is no scaling)
 * @return WritableImage snapshot, scaled by given amount
 */
public static WritableImage screenshot(Pane pane, double pixelScale) {
    int width = (int) Math.rint(pixelScale * pane.getWidth());
    int height = (int) Math.rint(pixelScale * pane.getHeight());

    WritableImage writableImage = new WritableImage(width, height);
    SnapshotParameters params = new SnapshotParameters();
    params.setTransform(Transform.scale(pixelScale, pixelScale));
    return pane.snapshot(params, writableImage);
}
项目:GestureFX    文件:GesturePaneTest.java   
@Test
public void testAnimatedScale() throws Exception {
    pane.setScrollBarEnabled(false);
    Runnable before = mock(Runnable.class);
    Runnable finished = mock(Runnable.class);
    double zoom = 3d;
    pane.zoomTo(2, new Point2D(512, 512));
    pane.animate(Duration.millis(200))
            .interpolateWith(Interpolator.EASE_BOTH)
            .beforeStart(before)
            .afterFinished(finished)
            .zoomTo(zoom, Point2D.ZERO);
    final Transform init = target.captureTransform();
    verify(before, timeout(10)).run();
    Thread.sleep(100);
    final Transform mid = target.captureTransform();
    // mid should not be at destination
    assertThat(mid.getTx()).isNotEqualTo(0);
    assertThat(mid.getTy()).isNotEqualTo(0);
    assertThat(mid.getMxx()).isNotEqualTo(zoom);
    assertThat(mid.getMyy()).isNotEqualTo(zoom);

    Thread.sleep(110);
    verify(finished, timeout(100)).run();
    // should be done at this point
    final Transform last = target.captureTransform();
    assertThat(last.getTx()).isEqualTo(-512);
    assertThat(last.getTy()).isEqualTo(-512);
    assertThat(last.getMxx()).isEqualTo(zoom);
    assertThat(last.getMyy()).isEqualTo(zoom);
}
项目:GestureFX    文件:GesturePaneTest.java   
@Test
public void testCentreOn() throws Exception {
    final double zoom = 2d;
    final double dx = 300d;
    final double dy = 200d;
    pane.setScrollBarEnabled(false);
    pane.zoomTo(zoom, pane.targetPointAtViewportCentre());
    final Transform last = target.captureTransform();
    pane.centreOn(new Point2D(dx, dy));
    final Transform now = target.captureTransform();
    assertThat(now.getTx()).isEqualTo(-last.getTx() - dx * zoom);
    assertThat(now.getTy()).isEqualTo(-last.getTy() - dy * zoom);
}
项目:GestureFX    文件:GesturePaneTest.java   
@Test
public void testTranslateRelative() throws Exception {
    final double zoom = 2d;
    final double dx = 30d;
    final double dy = -40d;
    pane.setScrollBarEnabled(false);
    pane.zoomTo(zoom, pane.targetPointAtViewportCentre());
    pane.centreOn(new Point2D(256, 256));
    final Transform previous = target.captureTransform();
    pane.translateBy(new Dimension2D(dx, dy));
    final Transform now = target.captureTransform();
    assertThat(now.getTx() - previous.getTy()).isEqualTo(-dx * zoom);
    assertThat(now.getTy() - previous.getTy()).isEqualTo(-dy * zoom);
}
项目:GestureFX    文件:GesturePaneTest.java   
@Test
public void testAnimatedTranslate() throws Exception {
    final double zoom = 2d;
    pane.setScrollBarEnabled(false);
    pane.zoomTo(zoom, pane.targetPointAtViewportCentre());
    pane.centreOn(Point2D.ZERO);
    Runnable before = mock(Runnable.class);
    Runnable finished = mock(Runnable.class);
    pane.animate(Duration.millis(200))
            .interpolateWith(Interpolator.EASE_BOTH)
            .beforeStart(before)
            .afterFinished(finished)
            .centreOn(new Point2D(256, 256));
    final Transform init = target.captureTransform();
    verify(before, timeout(10)).run();
    Thread.sleep(100);
    final Transform mid = target.captureTransform();
    // mid should not be at destination
    assertThat(mid.getTx() - init.getTy()).isNotEqualTo(-256);
    assertThat(mid.getTy() - init.getTy()).isNotEqualTo(-256);

    Thread.sleep(110);
    verify(finished, timeout(100)).run();
    // should be done at this point
    final Transform last = target.captureTransform();
    assertThat(last.getTx() - init.getTy()).isEqualTo(-256);
    assertThat(last.getTy() - init.getTy()).isEqualTo(-256);
}
项目:stvs    文件:ViewUtils.java   
/**
 * Calculates the {@link Transform Transformation} from children node coordinates to
 * parent node coordinates.
 * <p>
 * {@code child} must be a direct or indirect child of {@code rootOfCalculation}.
 *
 * @param rootOfCalculation Any node in a scene graph
 * @param child             A direct/indirect child of rootOfCalculation
 * @return A Transformation between coordinates of child and rootOfCalculation
 */
public static Transform calculateTransformRelativeTo(Node rootOfCalculation, Node child) {
    if (child.getScene() == null) {
        throw new IllegalStateException("Child is not displayed in any scene currently.");
    }
    if (child.getParent() == null) {
        throw new IllegalStateException(
                "rootOfCalculation is not in the scenegraph between root node and child.");
    }
    if (child == rootOfCalculation) {
        return new Affine();
    }
    Transform parentTransform = calculateTransformRelativeTo(rootOfCalculation, child.getParent());
    return child.getLocalToParentTransform().createConcatenation(parentTransform);
}
项目:openjfx-8u-dev-tests    文件:AffineManual.java   
/**
 * The same as {@link Affine#append(Transform transform)}
 */
@Override
public void append(Transform transform)
{
    append(transform.getMxx(), transform.getMxy(), transform.getMxz(), transform.getTx(),
            transform.getMyx(), transform.getMyy(), transform.getMyz(), transform.getTy(),
            transform.getMzx(), transform.getMzy(), transform.getMzz(), transform.getTz());
}
项目:openjfx-8u-dev-tests    文件:LocalTo_TransformsTest.java   
@Test
public void sameParentAndSceneTransforms()
{
    Node node = circleOneWrap.getControl();
    Transform localToScene = node.localToSceneTransformProperty().getValue();
    Transform localToParent = node.localToParentTransformProperty().getValue();

    realTranform.setTx(node.getTranslateX() + node.getLayoutX());
    realTranform.setTy(node.getTranslateY() + node.getLayoutY());
    realTranform.setTz(0);

    Assert.assertTrue(isTransformsEqual(localToParent, localToScene));
    Assert.assertTrue(isTransformsEqual(localToParent, realTranform));
}
项目:openjfx-8u-dev-tests    文件:LocalTo_TransformsTest.java   
private boolean isTransformsEqual(Transform first, Transform second)
{
    return first.getMxx() == second.getMxx() &&
            first.getMxy() == second.getMxy() &&
            first.getMxz() == second.getMxz() &&
            first.getMyx() == second.getMyx() &&
            first.getMyy() == second.getMyy() &&
            first.getMyz() == second.getMyz() &&
            first.getMzx() == second.getMzx() &&
            first.getMzy() == second.getMzy() &&
            first.getMzz() == second.getMzz() &&
            first.getTx() == second.getTx() &&
            first.getTy() == second.getTy() &&
            first.getTz() == second.getTz();
}
项目:qupath    文件:ExportChartPanel.java   
/**
 * Get a Image of the Chart, scaled according to the requested resolution as required.
 * 
 * @return
 */
public Image getChartImage() {
    // Create a snapshot at the requested resolution
    double scale = exportResolutionProperty.get().getScale();
    int w = (int)(chart.getWidth() * scale + 0.5);
    int h = (int)(chart.getHeight() * scale + 0.5);
    SnapshotParameters params = new SnapshotParameters();
    params.setTransform(Transform.scale(scale, scale));
    return chart.snapshot(params, new WritableImage(w, h));
}
项目:BudgetMaster    文件:MonthBarChart.java   
@Override
  public WritableImage export(int width, int height) 
  {
      VBox root = new VBox();
      root.setStyle("-fx-background-color: transparent;");
      root.setPadding(new Insets(25));

      HBox generatedChart = generate();
      root.getChildren().add(generatedChart);        
      VBox.setVgrow(generatedChart, Priority.ALWAYS);

      Region spacer = new Region();
      spacer.setMinHeight(30);
root.getChildren().add(spacer);

      root.getChildren().add(generateLegend());       

      Stage newStage = new Stage();
      newStage.initModality(Modality.NONE);
      newStage.setScene(new Scene(root, width, height));
      newStage.setResizable(false);       
      newStage.show();

      SnapshotParameters sp = new SnapshotParameters();
      sp.setTransform(Transform.scale(width / root.getWidth(), height / root.getHeight()));
      newStage.close();

      return root.snapshot(sp, null);
  }
项目:BudgetMaster    文件:CategoriesChart.java   
@Override
public WritableImage export(int width, int height)
{
    VBox root = new VBox();

       root.setStyle("-fx-background-color: transparent;");
       root.setPadding(new Insets(25));
       root.setSpacing(10);

       root.getChildren().add(generate(titleIncomes, true));
       root.getChildren().add(generate(titlePayments, false));

       Region spacer = new Region();
       spacer.setMinHeight(25);
       root.getChildren().add(spacer);
       VBox.setVgrow(spacer, Priority.ALWAYS);

       root.getChildren().add(generateFullLegend());        

    Stage newStage = new Stage();
    newStage.initModality(Modality.NONE);
    newStage.setScene(new Scene(root, width, height));
    newStage.setResizable(false);       
    newStage.show();

    SnapshotParameters sp = new SnapshotParameters();
    sp.setTransform(Transform.scale(width / root.getWidth(), height / root.getHeight()));
    newStage.close();

    return root.snapshot(sp, null);
}
项目:eavp    文件:FPSCameraController.java   
@Override
public void pitchCamera(double radians) {

    // Get the x direction for the camera's current heading
    Transform worldTransform = xform.getLocalToSceneTransform();
    double xx = worldTransform.getMxx();
    double xy = worldTransform.getMxy();
    double xz = worldTransform.getMxz();
    Point3D xDir = new Point3D(xx, xy, xz).normalize();

    // Create a new rotation along that axis and apply it to the camera
    Rotate rotation = new Rotate(radians * 180 / Math.PI, xDir);
    affine.append(rotation);
}
项目:eavp    文件:FPSCameraController.java   
@Override
public void rollCamera(double radians) {

    // Get the z direction of the camera's current heading
    Transform worldTransform = xform.getLocalToSceneTransform();
    double zx = worldTransform.getMzx();
    double zy = worldTransform.getMzy();
    double zz = worldTransform.getMzz();
    Point3D zDir = new Point3D(zx, zy, zz).normalize();

    // Create a new rotation along that axis and apply it to the camera
    Rotate rotation = new Rotate(radians * 180 / Math.PI, zDir);
    affine.append(rotation);
}
项目:eavp    文件:FPSCameraController.java   
@Override
public void strafeCamera(double distance) {

    Transform worldTransform = xform.getLocalToSceneTransform();

    double xx = worldTransform.getMxx();
    double xy = worldTransform.getMxy();
    double xz = worldTransform.getMxz();
    Point3D xDir = new Point3D(xx, xy, xz).normalize();

    Point3D moveVec = xDir.multiply(distance);
    affine.appendTranslation(moveVec.getX(), moveVec.getY(),
            moveVec.getZ());
}
项目:eavp    文件:FPSCameraController.java   
@Override
public void thrustCamera(double distance) {

    Transform worldTransform = xform.getLocalToSceneTransform();
    double zx = worldTransform.getMzx();
    double zy = worldTransform.getMzy();
    double zz = worldTransform.getMzz();

    Point3D zDir = new Point3D(zx, zy, zz).normalize();

    Point3D moveVec = zDir.multiply(distance);
    affine.appendTranslation(moveVec.getX(), moveVec.getY(),
            moveVec.getZ());
}
项目:eavp    文件:FPSCameraController.java   
@Override
public void yawCamera(double radians) {

    // Get the y direction of the camera's current heading
    Transform worldTransform = xform.getLocalToSceneTransform();
    double yx = worldTransform.getMyx();
    double yy = worldTransform.getMyy();
    double yz = worldTransform.getMyz();
    Point3D yDir = new Point3D(yx, yy, yz).normalize();

    // Create a new rotation along that axis and apply it to the camera
    Rotate rotation = new Rotate(radians * 180 / Math.PI, yDir);
    affine.append(rotation);
}
项目:eavp    文件:Util.java   
/**
 * <p>
 * Converts an ICE Geometry Transformation data structure to a JavaFX
 * Transform.
 * </p>
 * 
 * @param transform
 *            ICE Transformation data structure
 * @return a JavaFX transformation that is analagous to the Transformation
 */
public static Transform convertTransformation(
        Transformation transformation) {
    Affine transform = new Affine();

    if (transformation == null) {
        return transform;
    }

    double size = transformation.getSize();
    double[] scale = transformation.getScale();
    double[] rotation = transformation.getRotation();
    double[] translation = transformation.getTranslation();

    Scale sizeXform = new Scale(size, size, size);
    Scale scaleXform = new Scale(scale[0], scale[1], scale[2]);
    Rotate rotateXform = eulerToRotate(rotation[0], rotation[1],
            rotation[2]);
    Translate translateXform = new Translate(translation[0], translation[1],
            translation[2]);
    Transform transformOutput = transform
            .createConcatenation(translateXform)
            .createConcatenation(rotateXform).createConcatenation(sizeXform)
            .createConcatenation(scaleXform);

    return transformOutput;
}