Example usage for javafx.geometry Rectangle2D Rectangle2D

List of usage examples for javafx.geometry Rectangle2D Rectangle2D

Introduction

In this page you can find the example usage for javafx.geometry Rectangle2D Rectangle2D.

Prototype

public Rectangle2D(@NamedArg("minX") double minX, @NamedArg("minY") double minY,
        @NamedArg("width") double width, @NamedArg("height") double height) 

Source Link

Document

Creates a new instance of Rectangle2D .

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);/* w ww.  ja v a2 s.com*/
    stage.setHeight(500);
    Scene scene = new Scene(new Group());
    VBox root = new VBox();

    final ImageView selectedImage = new ImageView();
    Image image1 = new Image(Main.class.getResourceAsStream("a.jpg"));
    selectedImage.setImage(image1);

    Rectangle2D viewportRect = new Rectangle2D(40, 35, 110, 110);
    selectedImage.setViewport(viewportRect);

    root.getChildren().addAll(selectedImage);

    scene.setRoot(root);

    stage.setScene(scene);
    stage.show();
}

From source file:com.eviware.loadui.ui.fx.util.NodeUtils.java

public static Rectangle2D localToScreen(Node node, Scene scene) {
    Bounds selectableBounds = node.localToScene(node.getBoundsInLocal());

    return new Rectangle2D(selectableBounds.getMinX() + scene.getX() + scene.getWindow().getX(),
            selectableBounds.getMinY() + scene.getY() + scene.getWindow().getY(),
            node.getBoundsInLocal().getWidth(), node.getBoundsInLocal().getHeight());
}

From source file:projavafx.videoplayer3.VideoPlayer3.java

@Override
public void start(Stage primaryStage) {
    final Label message = new Label("I \u2764 Robots");
    message.setVisible(false);/*from ww  w .j ava  2  s . c  o  m*/

    String workingDir = System.getProperty("user.dir");
    final File f = new File(workingDir, "../media/omgrobots.flv");

    final Media m = new Media(f.toURI().toString());
    m.getMarkers().put("Split", Duration.millis(3000));
    m.getMarkers().put("Join", Duration.millis(9000));

    final MediaPlayer mp = new MediaPlayer(m);

    final MediaView mv1 = new MediaView(mp);
    mv1.setViewport(new Rectangle2D(0, 0, 960 / 2, 540));
    StackPane.setAlignment(mv1, Pos.CENTER_LEFT);

    final MediaView mv2 = new MediaView(mp);
    mv2.setViewport(new Rectangle2D(960 / 2, 0, 960 / 2, 540));
    StackPane.setAlignment(mv2, Pos.CENTER_RIGHT);

    StackPane root = new StackPane();
    root.getChildren().addAll(message, mv1, mv2);
    root.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            mp.seek(Duration.ZERO);
            message.setVisible(false);
        }
    });

    final Scene scene = new Scene(root, 960, 540);
    final URL stylesheet = getClass().getResource("media.css");
    scene.getStylesheets().add(stylesheet.toString());

    primaryStage.setScene(scene);
    primaryStage.setTitle("Video Player 3");
    primaryStage.show();

    mp.setOnMarker(new EventHandler<MediaMarkerEvent>() {

        @Override
        public void handle(final MediaMarkerEvent event) {
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    if (event.getMarker().getKey().equals("Split")) {
                        message.setVisible(true);
                        buildSplitTransition(mv1, mv2).play();
                    } else {
                        buildJoinTransition(mv1, mv2).play();
                    }
                }

            });
        }
    });
    mp.play();
}

From source file:net.rptools.tokentool.util.ImageUtil.java

private static Image autoCropImage(Image imageSource) {
    ImageView croppedImageView = new ImageView(imageSource);
    PixelReader pixelReader = imageSource.getPixelReader();

    int imageWidth = (int) imageSource.getWidth();
    int imageHeight = (int) imageSource.getHeight();
    int minX = imageWidth, minY = imageHeight, maxX = 0, maxY = 0;

    // Find the first and last pixels that are not transparent to create a bounding viewport
    for (int readY = 0; readY < imageHeight; readY++) {
        for (int readX = 0; readX < imageWidth; readX++) {
            Color pixelColor = pixelReader.getColor(readX, readY);

            if (!pixelColor.equals(Color.TRANSPARENT)) {
                if (readX < minX)
                    minX = readX;//from   www  .ja v a  2  s.  com
                if (readX > maxX)
                    maxX = readX;

                if (readY < minY)
                    minY = readY;
                if (readY > maxY)
                    maxY = readY;
            }
        }
    }

    if (maxX - minX <= 0 || maxY - minY <= 0)
        return new WritableImage(1, 1);

    // Create a viewport to clip the image using snapshot
    Rectangle2D viewPort = new Rectangle2D(minX, minY, maxX - minX, maxY - minY);
    SnapshotParameters parameter = new SnapshotParameters();
    parameter.setViewport(viewPort);
    parameter.setFill(Color.TRANSPARENT);

    return croppedImageView.snapshot(parameter, null);
}

From source file:net.rptools.tokentool.util.ImageUtil.java

public static Image composePreview(StackPane compositeTokenPane, Color bgColor, ImageView portraitImageView,
        ImageView maskImageView, ImageView overlayImageView, boolean useAsBase, boolean clipImage) {
    // Process layout as maskImage may have changed size if the overlay was changed
    compositeTokenPane.layout();//  w w w . ja v a  2s .  c om
    SnapshotParameters parameter = new SnapshotParameters();
    Image finalImage = null;
    Group blend;

    if (clipImage) {
        // We need to clip the portrait image first then blend the overlay image over it
        // We will first get a snapshot of the portrait equal to the mask overlay image width/height
        double x, y, width, height;

        x = maskImageView.getParent().getLayoutX();
        y = maskImageView.getParent().getLayoutY();
        width = maskImageView.getFitWidth();
        height = maskImageView.getFitHeight();

        Rectangle2D viewPort = new Rectangle2D(x, y, width, height);
        Rectangle2D maskViewPort = new Rectangle2D(1, 1, width, height);
        WritableImage newImage = new WritableImage((int) width, (int) height);
        WritableImage newMaskImage = new WritableImage((int) width, (int) height);

        ImageView overlayCopyImageView = new ImageView();
        ImageView clippedImageView = new ImageView();

        parameter.setViewport(viewPort);
        parameter.setFill(bgColor);
        portraitImageView.snapshot(parameter, newImage);

        parameter.setViewport(maskViewPort);
        parameter.setFill(Color.TRANSPARENT);
        maskImageView.setVisible(true);
        maskImageView.snapshot(parameter, newMaskImage);
        maskImageView.setVisible(false);

        clippedImageView.setFitWidth(width);
        clippedImageView.setFitHeight(height);
        clippedImageView.setImage(clipImageWithMask(newImage, newMaskImage));

        // Our masked portrait image is now stored in clippedImageView, lets now blend the overlay image over it
        // We'll create a temporary group to hold our temporary ImageViews's and blend them and take a snapshot
        overlayCopyImageView.setImage(overlayImageView.getImage());
        overlayCopyImageView.setFitWidth(overlayImageView.getFitWidth());
        overlayCopyImageView.setFitHeight(overlayImageView.getFitHeight());
        overlayCopyImageView.setOpacity(overlayImageView.getOpacity());

        if (useAsBase) {
            blend = new Group(overlayCopyImageView, clippedImageView);
        } else {
            blend = new Group(clippedImageView, overlayCopyImageView);
        }

        // Last, we'll clean up any excess transparent edges by cropping it
        finalImage = autoCropImage(blend.snapshot(parameter, null));
    } else {
        parameter.setFill(Color.TRANSPARENT);
        finalImage = autoCropImage(compositeTokenPane.snapshot(parameter, null));
    }

    return finalImage;
}