Example usage for javafx.scene.image ImageView setFitWidth

List of usage examples for javafx.scene.image ImageView setFitWidth

Introduction

In this page you can find the example usage for javafx.scene.image ImageView setFitWidth.

Prototype

public final void setFitWidth(double value) 

Source Link

Usage

From source file:jlotoprint.MainViewController.java

public static void loadAboutWindow() {

    //setup/*from  w  w w.  java  2 s. c  om*/
    Dialog dialog = new Dialog<>();
    dialog.getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
    dialog.setTitle("About JLotoPanel");
    dialog.setHeaderText("JLotoPanel v1.0");
    ImageView icon = new ImageView("file:resources/icon.png");
    icon.setSmooth(true);
    icon.setFitHeight(48.0);
    icon.setFitWidth(48.0);
    dialog.setGraphic(icon);
    dialog.initModality(Modality.APPLICATION_MODAL);
    dialog.initOwner(JLotoPrint.stage.getScene().getWindow());
    //content
    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 0, 10));

    //text
    TextArea textArea = new TextArea("For more info, please visit: https://github.com/mbppower/JLotoPanel");
    textArea.setWrapText(true);
    grid.add(textArea, 0, 0);
    dialog.getDialogPane().setContent(grid);

    dialog.showAndWait();
}

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

public static Image scaleImage(Image source, double targetWidth, double targetHeight, boolean preserveRatio) {
    ImageView imageView = new ImageView(source);
    imageView.setPreserveRatio(preserveRatio);
    imageView.setFitWidth(targetWidth);
    imageView.setFitHeight(targetHeight);
    return imageView.snapshot(null, 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.  jav  a2 s. com
    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;
}

From source file:main.java.vasolsim.common.GenericUtils.java

public static TreeItem<TreeElement> createTreeItem(Class resourceLoaderClass, TreeElement box,
        String iconLocation, int imgSize) {
    if (resourceLoaderClass == null || box == null || iconLocation == null || imgSize <= 0)
        return null;

    ImageView examsIcon = new ImageView(
            new Image(resourceLoaderClass.getResource(iconLocation).toExternalForm()));
    examsIcon.setFitHeight(imgSize);// ww  w  .  j a  va 2 s.c o m
    examsIcon.setFitWidth(imgSize);
    return new TreeItem<TreeElement>(box, examsIcon);
}

From source file:main.java.vasolsim.common.GenericUtils.java

/**
 * Creates a tree item//from ww  w . j  a  va  2s.c  o  m
 *
 * @param resourceLoaderClass
 * @param title
 * @param iconLocation
 * @param imgSize
 *
 * @return
 */
public static TreeItem<String> createTreeItem(Class resourceLoaderClass, String title, String iconLocation,
        int imgSize) {
    if (resourceLoaderClass == null || title == null || iconLocation == null || imgSize <= 0)
        return null;

    ImageView examsIcon = new ImageView(
            new Image(resourceLoaderClass.getResource(iconLocation).toExternalForm()));
    examsIcon.setFitHeight(imgSize);
    examsIcon.setFitWidth(imgSize);
    return new TreeItem<String>(title, examsIcon);
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Title");
    Group root = new Group();
    Scene scene = new Scene(root, 600, 330, Color.WHITE);

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);/* w ww  .ja v  a 2 s .c  o m*/
    gridpane.setVgap(10);

    final ImageView imv = new ImageView();
    imv.setFitWidth(100);
    final Image image2 = new Image(Main.class.getResourceAsStream("button.png"));
    imv.setImage(image2);

    final HBox pictureRegion = new HBox();

    pictureRegion.getChildren().add(imv);
    gridpane.add(pictureRegion, 1, 1);

    root.getChildren().add(gridpane);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:ubicrypt.ui.ctrl.providers.ProvidersController.java

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
    String fxml = substringBefore(substringAfterLast(url.getFile(), "/"), ".fxml");
    navigator = new StackNavigator(root, fxml, controllerFactory);
    providers.setCellFactory(listView -> new ListCell<ProviderItem>() {
        @Override//from w  w  w  . j  ava  2s . co m
        protected void updateItem(ProviderItem pi, boolean empty) {
            super.updateItem(pi, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
                return;
            }
            setContextMenu(pi.getContextMenu());
            Platform.runLater(() -> setGraphic(pi.getGraphics()));
        }
    });
    providerDescriptors.stream().forEach(pd -> {
        Button button = new Button();
        Image img = pd.getLogo().getImage();
        ImageView view = new ImageView(img);
        view.setFitWidth(30.0);
        view.setPickOnBounds(true);
        view.setPreserveRatio(true);
        button.setGraphic(view);
        button.setOnMouseClicked(mouseEvent -> {
            log.debug("adding provider :{}", pd.getCode());
            navigator.browse(format("provider/%s", pd.getCode()));
        });
        button.setTooltip(new Tooltip("Add " + pd.getDescription()));
        availableProviders.getItems().add(button);
    });

    //provider status events
    providerEvent.subscribe(pevent -> {
        UbiProvider provider = pevent.getHook().getProvider();
        if (!providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst()
                .isPresent()) {
            log.info("add new provider:{}", pevent.getHook().getProvider());
            String code = providerDescriptors.stream().filter(pd -> pd.getType() == provider.getClass())
                    .map(ProviderDescriptor::getCode).findFirst().get();
            final ProviderItem providerItem = new ProviderItem(provider, providerDescriptors.stream()
                    .filter(pd -> pd.getType() == provider.getClass()).findFirst().get(), providerRemover,
                    navigator);
            providers.getItems().add(providerItem);
            pevent.getHook().getStatusEvents().subscribe(providerItem::changeStatus);
        }
        switch (pevent.getEvent()) {
        case removed:
            //TODO: remove provider
            break;
        default:
            log.warn("unmanaged event:{}", pevent.getEvent());
        }
        providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst()
                .ifPresent(pi -> pi.changeStatus(pevent.getEvent()));
    });
}

From source file:vkmanager.controller.PhotosDetailedController.java

public void showPhotosFromAlbum(VKPhotoAlbum album, int userId) {
    this.album = album;
    idForDownload = album.getId();//from  w  ww  . j  av  a2  s.co  m
    albumDescription.setText(album.getDescription());
    photos = vkapi.getPhotosFromAlbum(idForDownload, userId);

    int i = 0;
    int j = 0;
    gridPaneDetailed.addRow(0);
    for (VKPhoto photo : photos) {
        Image photoThumbLink = new Image(photo.getLink_s());
        ImageView photoThumb = new ImageView(photoThumbLink);

        photoThumb.setFitHeight(160);
        photoThumb.setFitWidth(240);

        photoThumb.setPreserveRatio(true);
        photoThumb.setSmooth(true);
        photoThumb.setCache(true);

        Button photoButt = new Button();
        photoButt.setGraphic(photoThumb);
        photoButt.setStyle("-fx-background-color: white;");
        photoButt.setMinSize(240, 160);
        photoButt.setAlignment(Pos.CENTER);

        BorderPane bp = new BorderPane(null, photoButt, null, null, null);
        gridPaneDetailed.add(bp, j, i);

        j++;
        if (j == 3) {
            i++;
            j = 0;
            gridPaneDetailed.addRow(i);
        }
    }
}

From source file:com.playonlinux.ui.impl.javafx.mainwindow.center.ViewApps.java

private void initFailure() {
    failurePanel = new VBox();
    failurePanel.getStyleClass().add("rightPane");

    failurePanel.setSpacing(10);//from   w  ww .j a v a 2s  .c o m
    failurePanel.setAlignment(Pos.CENTER);

    Label failureNotificationLbl = new Label();
    failureNotificationLbl.setText(translate(
            "Connecting to ${application.name} failed.\n" + "Please check your connection and try again."));
    failureNotificationLbl.setTextAlignment(TextAlignment.CENTER);

    ImageView retryImage = new ImageView(new Image(getClass().getResourceAsStream("refresh.png")));
    retryImage.setFitWidth(16);
    retryImage.setFitHeight(16);
    retryButton = new Button(translate("Retry"), retryImage);

    failurePanel.getChildren().addAll(failureNotificationLbl, retryButton);
}

From source file:Main.java

@Override
public void start(Stage stage) throws Exception {
    ImageView imageView = new ImageView();
    ScrollPane scrollPane = new ScrollPane();
    DoubleProperty zoomProperty = new SimpleDoubleProperty(200);

    zoomProperty.addListener(new InvalidationListener() {
        @Override//  w  w  w  .j  a  v  a  2 s  .c  om
        public void invalidated(Observable arg0) {
            imageView.setFitWidth(zoomProperty.get() * 2);
            imageView.setFitHeight(zoomProperty.get() * 3);
        }
    });
    scrollPane.addEventFilter(ScrollEvent.ANY, new EventHandler<ScrollEvent>() {
        @Override
        public void handle(ScrollEvent event) {
            if (event.getDeltaY() > 0) {
                zoomProperty.set(zoomProperty.get() * 1.2);
            } else if (event.getDeltaY() < 0) {
                zoomProperty.set(zoomProperty.get() / 1.1);
            }
        }
    });
    imageView.setImage(new Image("http://yourImageURL"));
    imageView.preserveRatioProperty().set(true);
    scrollPane.setContent(imageView);
    stage.setScene(new Scene(scrollPane, 400, 300));
    stage.show();
}