Java Code Examples for javafx.scene.image.ImageView#setY()

The following examples show how to use javafx.scene.image.ImageView#setY() . 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: SceneMainController.java    From tet-java-client with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private void updateEye(Pane root, ImageView eyeImageView, GazeData.Eye eye, double angle, double scale)
{
    Point2D p = GazeUtils.getRelativeToRect(
            eye.pupilCenterCoordinates,
            (int) Math.round(root.getScene().getWidth()),
            (int) Math.round(root.getScene().getHeight())
    );

    p.x -= eyeImageView.getFitWidth() * .5d;
    p.y -= eyeImageView.getFitHeight() * .5d;

    eyeImageView.setX(p.x);
    eyeImageView.setY(p.y);
    eyeImageView.setRotate(angle);
    eyeImageView.setScaleX(scale);
    eyeImageView.setScaleY(scale);
}
 
Example 2
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image combineImagesColumnFx(List<Image> images,
        Color bgColor, int interval, int Margin) {
    try {
        if (images == null || images.isEmpty()) {
            return null;
        }
        Group group = new Group();

        int x = Margin, y = Margin, width = 0, height = 0;
        for (int i = 0; i < images.size(); ++i) {
            Image image = images.get(i);
            ImageView view = new ImageView(image);
            view.setPreserveRatio(true);
            view.setFitWidth(image.getWidth());
            view.setFitHeight(image.getHeight());
            view.setX(x);
            view.setY(y);
            group.getChildren().add(view);

            x = Margin;
            y += image.getHeight() + interval;

            if (image.getWidth() > width) {
                width = (int) image.getWidth();
            }
        }

        width += 2 * Margin;
        height = y + Margin - interval;
        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, width, height, bgColor));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);

        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 3
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image combineSingleColumnFx(List<Image> images) {
    if (images == null || images.isEmpty()) {
        return null;
    }
    try {
        Group group = new Group();

        double x = 0, y = 0, imageWidth, imageHeight;
        double totalWidth = 0, totalHeight = 0;

        for (Image theImage : images) {
            ImageView view = new ImageView(theImage);
            imageWidth = theImage.getWidth();
            imageHeight = theImage.getHeight();

            view.setPreserveRatio(true);
            view.setX(x);
            view.setY(y);
            view.setFitWidth(imageWidth);
            view.setFitHeight(imageHeight);

            group.getChildren().add(view);
            y += imageHeight;

            if (imageWidth > totalWidth) {
                totalWidth = imageWidth;
            }
        }
        totalHeight = y;
        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, totalWidth, totalHeight, Color.TRANSPARENT));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;
    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 4
Source File: FxmlImageManufacture.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static Image addMarginsFx2(Image image, Color color, int MarginWidth,
        boolean addTop, boolean addBottom, boolean addLeft, boolean addRight) {
    try {
        if (image == null || MarginWidth <= 0) {
            return image;
        }
        Group group = new Group();
        double imageWidth = image.getWidth(), imageHeight = image.getHeight();
        double totalWidth = image.getWidth(), totalHeight = image.getHeight();
        ImageView view = new ImageView(image);
        view.setPreserveRatio(true);
        view.setFitWidth(imageWidth);
        view.setFitHeight(imageHeight);
        if (addLeft) {
            view.setX(MarginWidth);
            totalWidth += MarginWidth;
        } else {
            view.setX(0);
        }
        if (addTop) {
            view.setY(MarginWidth);
            totalHeight += MarginWidth;
        } else {
            view.setY(0);
        }
        if (addBottom) {
            totalHeight += MarginWidth;
        }
        if (addRight) {
            totalWidth += MarginWidth;
        }
        group.getChildren().add(view);

        Blend blend = new Blend(BlendMode.SRC_OVER);
        blend.setBottomInput(new ColorInput(0, 0, totalWidth, totalHeight, color));
        group.setEffect(blend);

        SnapshotParameters parameters = new SnapshotParameters();
        parameters.setFill(Color.TRANSPARENT);
        WritableImage newImage = group.snapshot(parameters, null);
        return newImage;

    } catch (Exception e) {
        logger.error(e.toString());
        return image;
    }

}
 
Example 5
Source File: RaceTrack.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public RaceTrack() {
    ImageView carImageView = new ImageView(new Image(
            DataAppPreloader.class.getResourceAsStream("images/car.png")));
    road = SVGPathBuilder.create()
            .content(trackPath).fill(null).stroke(Color.gray(0.4))
            .strokeWidth(50)
            .effect(DropShadowBuilder.create().radius(20).blurType(BlurType.ONE_PASS_BOX).build())
            .build();
    SVGPath trackLine = SVGPathBuilder.create()
            .content(trackPath).fill(null).stroke(Color.WHITE)
            .strokeDashArray(8d,6d).build();
    Line startLine = LineBuilder.create()
            .startX(610.312).startY(401.055).endX(610.312).endY(450.838)
            .stroke(Color.WHITE).strokeDashArray(2d,2d).build();
    Text startFinish = TextBuilder.create().text("START/FINISH").fill(Color.WHITE)
            .x(570).y(475).build();
    percentage = TextBuilder.create().text("0%")
            .x(390).y(170).font(Font.font("System", 60))
            .fill(Color.web("#ddf3ff"))
            .stroke(Color.web("#73c0f7"))
            .effect(DropShadowBuilder.create().radius(15).color(Color.web("#3382ba")).blurType(BlurType.ONE_PASS_BOX).build())
            .build();
    ImageView raceCarImg = new ImageView(new Image(
            DataAppPreloader.class.getResourceAsStream("images/Mini-red-and-white.png")));
    raceCarImg.setX(raceCarImg.getImage().getWidth()/2);
    raceCarImg.setY(raceCarImg.getImage().getHeight()/2);
    raceCarImg.setRotate(90);
    raceCar = new Group(raceCarImg);
    
    track = new Group(road, trackLine, startLine, startFinish);
    track.setCache(true);
    // add children
    getChildren().addAll(track, raceCar, percentage);
    
    // Create path animation that we will use to drive the car along the track
    race = new PathTransition(Duration.seconds(1), road, raceCar);
    race.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
    race.play();
    race.pause();
    
    // center our content and set our size
    setTranslateX(-road.getBoundsInLocal().getMinX());
    setTranslateY(-road.getBoundsInLocal().getMinY());
    setPrefSize(road.getBoundsInLocal().getWidth(), road.getBoundsInLocal().getHeight());
    setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
}
 
Example 6
Source File: RaceTrack.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public RaceTrack() {
    ImageView carImageView = new ImageView(new Image(
            DataAppPreloader.class.getResourceAsStream("images/car.png")));
    road = SVGPathBuilder.create()
            .content(trackPath).fill(null).stroke(Color.gray(0.4))
            .strokeWidth(50)
            .effect(DropShadowBuilder.create().radius(20).blurType(BlurType.ONE_PASS_BOX).build())
            .build();
    SVGPath trackLine = SVGPathBuilder.create()
            .content(trackPath).fill(null).stroke(Color.WHITE)
            .strokeDashArray(8d,6d).build();
    Line startLine = LineBuilder.create()
            .startX(610.312).startY(401.055).endX(610.312).endY(450.838)
            .stroke(Color.WHITE).strokeDashArray(2d,2d).build();
    Text startFinish = TextBuilder.create().text("START/FINISH").fill(Color.WHITE)
            .x(570).y(475).build();
    percentage = TextBuilder.create().text("0%")
            .x(390).y(170).font(Font.font("System", 60))
            .fill(Color.web("#ddf3ff"))
            .stroke(Color.web("#73c0f7"))
            .effect(DropShadowBuilder.create().radius(15).color(Color.web("#3382ba")).blurType(BlurType.ONE_PASS_BOX).build())
            .build();
    ImageView raceCarImg = new ImageView(new Image(
            DataAppPreloader.class.getResourceAsStream("images/Mini-red-and-white.png")));
    raceCarImg.setX(raceCarImg.getImage().getWidth()/2);
    raceCarImg.setY(raceCarImg.getImage().getHeight()/2);
    raceCarImg.setRotate(90);
    raceCar = new Group(raceCarImg);
    
    track = new Group(road, trackLine, startLine, startFinish);
    track.setCache(true);
    // add children
    getChildren().addAll(track, raceCar, percentage);
    
    // Create path animation that we will use to drive the car along the track
    race = new PathTransition(Duration.seconds(1), road, raceCar);
    race.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
    race.play();
    race.pause();
    
    // center our content and set our size
    setTranslateX(-road.getBoundsInLocal().getMinX());
    setTranslateY(-road.getBoundsInLocal().getMinY());
    setPrefSize(road.getBoundsInLocal().getWidth(), road.getBoundsInLocal().getHeight());
    setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
}