Example usage for javafx.scene.image ImageView setFitHeight

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

Introduction

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

Prototype

public final void setFitHeight(double value) 

Source Link

Usage

From source file:jlotoprint.MainViewController.java

public static void loadAboutWindow() {

    //setup/*w w  w.  j  a  v  a 2  s . c o  m*/
    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);/*from  w ww  .j av a  2s.co  m*/
    imageView.setFitHeight(targetHeight);
    return imageView.snapshot(null, null);
}

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);
    examsIcon.setFitWidth(imgSize);//from   w  w w . j a v  a2  s .  c  om
    return new TreeItem<TreeElement>(box, examsIcon);
}

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

/**
 * Creates a tree item//w w  w  .ja  va2  s . 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: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();/*from w w  w .  j a va2 s.c  o  m*/
    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:vkmanager.controller.PhotosDetailedController.java

public void showPhotosFromAlbum(VKPhotoAlbum album, int userId) {
    this.album = album;
    idForDownload = album.getId();/*from w  w w  .j  ava2s.  c  o 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 w  w  .j av a2s  . com*/
    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:de.perdoctus.ebikeconnect.gui.dialogs.LoginDialog.java

@PostConstruct
public void init() {
    final ImageView graphic = new ImageView(
            new Image(getClass().getResource("/app-icon.png").toExternalForm()));
    graphic.setPreserveRatio(true);/* w ww  .  j  a  v a 2  s .  c  o  m*/
    graphic.setFitHeight(64);
    setGraphic(graphic);
    setResizable(true);
    setWidth(400);
    setResizable(false);

    setTitle(rb.getString("dialogTitle"));
    setHeaderText(rb.getString("dialogMessage"));

    final ButtonType loginButtonType = new ButtonType(rb.getString("loginButton"),
            ButtonBar.ButtonData.OK_DONE);
    getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL);

    // Create the username and password labels and fields.
    final GridPane grid = new GridPane();
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(20, 10, 10, 10));
    grid.setPrefWidth(getWidth());
    grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.NEVER, HPos.LEFT, true));
    grid.getColumnConstraints().add(new ColumnConstraints(-1, -1, -1, Priority.ALWAYS, HPos.LEFT, true));

    final String rbUsername = rb.getString(CFG_USERNAME);
    final TextField txtUsername = new TextField();
    txtUsername.setPromptText(rbUsername);
    txtUsername.setText(config.getString(CFG_USERNAME, ""));

    final Label lblUsername = new Label(rbUsername);
    lblUsername.setLabelFor(txtUsername);
    grid.add(lblUsername, 0, 0);
    grid.add(txtUsername, 1, 0);

    final String rbPassword = rb.getString(CFG_PASSWORD);
    final PasswordField txtPassword = new PasswordField();
    txtPassword.setPromptText(rbPassword);
    if (config.getBoolean(CFG_SAVE_PASSWORD, false)) {
        txtPassword.setText(config.getString(CFG_PASSWORD, ""));
    }

    final Label lblPassword = new Label(rbPassword);
    lblPassword.setLabelFor(txtPassword);
    grid.add(lblPassword, 0, 1);
    grid.add(txtPassword, 1, 1);

    final CheckBox cbSavePassword = new CheckBox(rb.getString("save-password"));
    cbSavePassword.setSelected(config.getBoolean(CFG_SAVE_PASSWORD, false));
    grid.add(cbSavePassword, 1, 2);

    getDialogPane().setContent(grid);

    // Enable/Disable login button depending on whether a username was entered.
    final Node loginButton = getDialogPane().lookupButton(loginButtonType);
    loginButton.disableProperty()
            .bind(txtUsername.textProperty().isEmpty().or(txtPassword.textProperty().isEmpty()));

    setResultConverter(buttonType -> {
        if (buttonType == loginButtonType) {
            config.setProperty(CFG_USERNAME, txtUsername.getText());
            config.setProperty(CFG_SAVE_PASSWORD, cbSavePassword.isSelected());
            if (cbSavePassword.isSelected()) {
                config.setProperty(CFG_PASSWORD, txtPassword.getText());
                config.setProperty(CFG_PASSWORD, txtPassword.getText());
            } else {
                config.clearProperty(CFG_PASSWORD);
            }
            return new Credentials(txtUsername.getText(), txtPassword.getText());
        } else {
            return null;
        }
    });

    if (txtUsername.getText().isEmpty()) {
        txtUsername.requestFocus();
    } else {
        txtPassword.requestFocus();
        txtPassword.selectAll();
    }
}

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/*from   ww w.ja v a 2 s .c o m*/
        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();
}

From source file:uk.ac.bris.cs.scotlandyard.ui.controller.BaseGame.java

BaseGame(ResourceManager manager, Stage stage) {
    this.resourceManager = manager;
    this.stage = stage;
    Controller.bind(this);

    // initialise all controllers
    travelLog = new TravelLog(resourceManager, config);
    ticketsCounter = new TicketsCounter(resourceManager, config);
    notifications = new Notifications(resourceManager, config);
    status = new Status(resourceManager, config);
    board = new Board(resourceManager, notifications, config);

    Rectangle clip = new Rectangle();
    clip.widthProperty().bind(gamePane.widthProperty());
    clip.heightProperty().bind(gamePane.heightProperty());
    gamePane.setClip(clip);/* ww  w. ja va2 s .  com*/

    // system menu
    menu.setUseSystemMenuBar(true);

    // add all views
    mapPane.getChildren().add(board.root());
    roundsPane.getChildren().add(travelLog.root());
    playersPane.getChildren().add(ticketsCounter.root());
    notificationPane.getChildren().add(notifications.root());
    statusPane.getChildren().add(status.root());

    close.setOnAction(e -> stage.close());
    debug.setOnAction(evt -> {
        try {
            Debug.showDebugger(stage);
        } catch (Exception e) {
            Utils.handleFatalException(e);
        }
    });
    about.setOnAction(e -> {
        Alert alert = new Alert(AlertType.INFORMATION,
                "ScotlandYard is part of the CW-MODEL coursework prepared for University of Bristol course COMS100001",
                ButtonType.OK);
        ImageView logo = new ImageView(resourceManager.getImage(ImageResource.UOB_LOGO));
        logo.setPreserveRatio(true);
        logo.setSmooth(true);
        logo.setFitHeight(100);
        alert.setGraphic(logo);
        alert.setTitle("About ScotlandYard");
        alert.setHeaderText("ScotlandYard v0.1");
        alert.show();
    });

    findNode.setOnAction(e -> {
        Stage s = new Stage();
        s.setTitle("Find node");
        s.setScene(new Scene(new FindNode(config, s, resourceManager).root()));
        s.show();
    });
    manual.setOnAction(e -> {
        Stage s = new Stage();
        s.setTitle("Manual");
        s.setScene(new Scene(new Manual(s).root()));
        s.show();
    });

    license.setOnAction(e -> {
        Stage s = new Stage();
        s.setTitle("License");
        s.setScene(new Scene(new License(s).root()));
        s.show();
    });

    // bind all menu values
    resetViewport.setOnAction(e -> {
        board.resetViewport();
    });

    setAndBind(travelLog.root().visibleProperty(), travelLogToggle.selectedProperty());
    setAndBind(ticketsCounter.root().visibleProperty(), ticketToggle.selectedProperty());
    setAndBind(config.scrollPanProperty(), scrollToggle.selectedProperty());
    setAndBind(config.historyProperty(), historyToggle.selectedProperty());
    setAndBind(config.focusPlayerProperty(), focusToggle.selectedProperty());

    if (SystemUtils.IS_OS_WINDOWS)
        config.scrollPanProperty().setValue(false);

}