List of usage examples for javafx.scene.image ImageView setPreserveRatio
public final void setPreserveRatio(boolean value)
From source file:com.imesha.imageprocessor.controllers.MainController.java
/** * Show a given BufferedImage in the UI. * * @param bufferedImage The image to be shown in the UI * @param imageView The JavaFX ImageView element in which the BufferedImage to be shown. *//*from w w w . j a v a2 s. c o m*/ private static void showImageInUI(final BufferedImage bufferedImage, final ImageView imageView) { Platform.runLater(new Runnable() { public void run() { Image loadedImage = SwingFXUtils.toFXImage(bufferedImage, null); imageView.setImage(loadedImage); imageView.setPreserveRatio(true); imageView.setSmooth(true); imageView.setCache(true); } }); }
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.ja va 2 s. co m*/ imageView.setFitHeight(targetHeight); return imageView.snapshot(null, null); }
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 w w. j a v a 2s . c o m gridpane.setVgap(10); final ImageView imv = new ImageView(); imv.setPreserveRatio(true); 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:vkmanager.controller.PhotosDetailedController.java
public void showPhotosFromAlbum(VKPhotoAlbum album, int userId) { this.album = album; idForDownload = album.getId();//from www .j a va 2 s . c om 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:TimeShift.Picture.java
private ImageView getImage() { ImageView imgView; String thmbFile = file.getParent() + "\\thmb\\" + FilenameUtils.getBaseName(file.getName()) + "_thmb.jpg"; imgView = new ImageView(new File(thmbFile).toURI().toString()); imgView.setPreserveRatio(true); imgView.setSmooth(true);//w w w .ja v a 2 s .c om imgView.setCache(true); return imgView; }
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// www .j a v a 2 s .c o 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: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); graphic.setFitHeight(64);// w ww.j av a 2 s. co m 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: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);//from w ww . j a v a2s .c o m // 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); }
From source file:fruitproject.FruitProject.java
public void second(final String pfname) { final Stage st = new Stage(); Scene scene = null;//from ww w. j a v a 2 s. c o m final GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(10); grid.setPadding(new Insets(25, 25, 25, 25)); TableView tv = new TableView(); final TableColumn<Map, String> firstDataColumn = new TableColumn<>("Name"); final TableColumn<Map, String> secondDataColumn = new TableColumn<>("Amount"); final TableColumn<Map, String> thirdDataColumn = new TableColumn<>("Remove"); firstDataColumn.setMinWidth(130); secondDataColumn.setMinWidth(130); thirdDataColumn.setMinWidth(130); if (!pfname.equals("")) { firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey)); secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey)); thirdDataColumn.setCellValueFactory(new MapValueFactory(Column3MapKey)); rows = 0; tv = new TableView<>(generateDataInMap(pfname, addPairs)); } tv.getColumns().setAll(firstDataColumn, secondDataColumn, thirdDataColumn); // secondDataColumn.setCellFactory(TextFieldTableCell.forTableColumn()); ScrollPane sp = new ScrollPane(); sp.setMinWidth(400); sp.setHbarPolicy(ScrollBarPolicy.NEVER); sp.setContent(tv); grid.add(sp, 0, 3); final ComboBox comboBox = new ComboBox(); HBox hb1 = new HBox(); comboBox.setValue("FILE"); comboBox.getItems().addAll("Save this file", "Load a new file"); Button btnOk = new Button(); btnOk.setText("OK"); hb1.getChildren().addAll(comboBox, btnOk); hb1.setSpacing(10); grid.add(hb1, 0, 1); Label label1 = new Label("Title:"); final TextField tfFilename = new TextField(); tfFilename.setText(getTitle(pfname)); HBox hb = new HBox(); hb.getChildren().addAll(label1, tfFilename); hb.setSpacing(10); grid.add(hb, 0, 2); final Stage ps = new Stage(); final TableView tv1 = tv; btnOk.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //System.out.println("Hello World!"); if (comboBox.getValue().equals("Load a new file")) { first(ps); st.close(); } else { PrintWriter pw = null; try { pw = new PrintWriter("abc.json"); BufferedWriter bw = new BufferedWriter(new FileWriter(pfname, false)); bw.write("{title:\"" + tfFilename.getText() + "\""); bw.write(",fruits:["); for (int i = 0; i < rows; i++) { bw.write("{name:\"" + String.valueOf(firstDataColumn.getCellData(i)) + "\",amount:" + String.valueOf(secondDataColumn.getCellData(i)) + "}"); if (i != rows - 1) bw.write(","); } bw.write("]}"); bw.close(); } catch (Exception e) { System.out.println(e.toString()); } } } }); Button btn = new Button(); btn.setText("New Fruit"); grid.add(btn, 1, 2); // TableView tv=new TableView(); // TableColumn Col1 = new TableColumn("Name"); // TableColumn Col2 = new TableColumn("Amount"); // TableColumn Col3 = new TableColumn("Remove"); // tv.getColumns().addAll(Col1, Col2, Col3); //sp.setFitToWidth(true); Image img = new Image("file:music.jpg"); ImageView iv2 = new ImageView(); iv2.setImage(img); iv2.setFitWidth(200); iv2.setPreserveRatio(true); iv2.setSmooth(true); iv2.setCache(true); grid.add(iv2, 1, 3); btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { //System.out.println("Hello World!"); System.out.println(comboBox.valueProperty()); st.close(); third(pfname); } }); scene = new Scene(grid, 700, 450); st.setScene(scene); st.show(); }
From source file:calendarioSeries.vistas.NewSerieController.java
@FXML public void handleOk() { String tituloAux = titulo.getText().replaceAll(" ", "+").toLowerCase(); String toJson = readUrl(BASE + tituloAux + "&type=series" + "&r=json"); resultados.getChildren().clear();//from ww w .java 2 s . c o m try { JSONObject busqueda = new JSONObject(toJson); if (busqueda.getString("Response").equals("True")) { JSONArray res = busqueda.getJSONArray("Search"); resultados.setPrefRows(res.length()); for (int i = 0; i < res.length(); i++) { JSONObject resActual = new JSONObject(res.get(i).toString()); HBox resultadoActual = new HBox(50); resultadoActual.setMaxWidth(Double.MAX_VALUE); resultadoActual.setAlignment(Pos.CENTER_LEFT); ImageView posterActual = new ImageView(); try { Image image = new Image(resActual.getString("Poster")); posterActual.setImage(image); posterActual.setFitHeight(240); posterActual.setFitWidth(180); posterActual.setPreserveRatio(false); resultadoActual.getChildren().add(posterActual); } catch (IllegalArgumentException e) { // System.out.println("Bad url"); Image image = new Image( MainApp.class.getResource("resources/no-image.png").toExternalForm()); posterActual.setImage(image); posterActual.setFitHeight(240); posterActual.setFitWidth(180); posterActual.setPreserveRatio(false); resultadoActual.getChildren().add(posterActual); } String details; String nomSerie = new String(resActual.getString("Title").getBytes(), "UTF-8"); String anoSerie = new String(resActual.getString("Year").getBytes(), "UTF-8"); if (nomSerie.length() > 15) { details = "%-12.12s...\t\t Ao: %-10s"; } else { details = "%-12s\t\t Ao: %-10s"; } details = String.format(details, nomSerie, anoSerie); Label elemento = new Label(details); elemento.setMaxWidth(Double.MAX_VALUE); elemento.setMaxHeight(Double.MAX_VALUE); resultadoActual.getChildren().add(elemento); posterActual.setId(resActual.getString("imdbID")); posterActual.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { ImageView clickedButton = (ImageView) event.getSource(); Stage stage = (Stage) clickedButton.getScene().getWindow(); Task task = new Task() { @Override protected Object call() throws Exception { mainController.mainApp.scene.setCursor(Cursor.WAIT); Serie toAdd = new Serie(clickedButton.getId()); boolean possible = true; for (Serie serie : mainController.getSeries()) { if (serie.equals(toAdd)) possible = false; } if (possible) mainController.getSeries().add(toAdd); try { mainController.populateImagenes(); mainController.showDetallesMes(mainController.getMesActual()); } catch (Exception e) { e.printStackTrace(); } finally { mainController.mainApp.scene.setCursor(Cursor.DEFAULT); return mainController.getSeries(); } } }; Thread th = new Thread(task); th.setDaemon(true); th.start(); stage.close(); } }); resultados.getChildren().add(resultadoActual); } } else { resultados.getChildren().add(new Label("La busqueda no obtuvo resultados")); } } catch (JSONException e) { e.printStackTrace(); } catch (UnsupportedEncodingException ex) { Logger.getLogger(NewSerieController.class.getName()).log(Level.SEVERE, null, ex); } }