List of usage examples for javafx.scene.image ImageView setOnMouseClicked
public final void setOnMouseClicked(EventHandler<? super MouseEvent> value)
From source file:gov.va.isaac.gui.util.ErrorMarkerUtils.java
/** * Setup an 'INFORMATION' info marker on the component. Automatically displays anytime that the initialControl is disabled. * Put the initial control in the provided stack pane *///from w w w .j a v a 2s. co m public static Node setupDisabledInfoMarker(Control initialControl, StackPane stackPane, ObservableStringValue reasonWhyControlDisabled) { ImageView information = Images.INFORMATION.createImageView(); information.visibleProperty().bind(initialControl.disabledProperty()); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(reasonWhyControlDisabled); Tooltip.install(information, tooltip); tooltip.setAutoHide(true); information.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { tooltip.show(information, event.getScreenX(), event.getScreenY()); } }); stackPane.setMaxWidth(Double.MAX_VALUE); stackPane.getChildren().add(initialControl); StackPane.setAlignment(initialControl, Pos.CENTER_LEFT); stackPane.getChildren().add(information); if (initialControl instanceof Button) { StackPane.setAlignment(information, Pos.CENTER); } else if (initialControl instanceof CheckBox) { StackPane.setAlignment(information, Pos.CENTER_LEFT); StackPane.setMargin(information, new Insets(0, 0, 0, 1)); } else { StackPane.setAlignment(information, Pos.CENTER_RIGHT); double insetFromRight = (initialControl instanceof ComboBox ? 30.0 : 5.0); StackPane.setMargin(information, new Insets(0.0, insetFromRight, 0.0, 0.0)); } return stackPane; }
From source file:gov.va.isaac.gui.util.ErrorMarkerUtils.java
/** * Setup an 'EXCLAMATION' error marker on the component. Automatically displays anytime that the reasonWhyControlInvalid value * is false. Hides when the isControlCurrentlyValid is true. * @param stackPane - optional - created if necessary *//* ww w . ja v a 2s . c o m*/ public static StackPane setupErrorMarker(Node initialNode, StackPane stackPane, ValidBooleanBinding isNodeCurrentlyValid) { ImageView exclamation = Images.EXCLAMATION.createImageView(); if (stackPane == null) { stackPane = new StackPane(); } exclamation.visibleProperty().bind(isNodeCurrentlyValid.not()); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(isNodeCurrentlyValid.getReasonWhyInvalid()); Tooltip.install(exclamation, tooltip); tooltip.setAutoHide(true); exclamation.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { tooltip.show(exclamation, event.getScreenX(), event.getScreenY()); } }); stackPane.setMaxWidth(Double.MAX_VALUE); stackPane.getChildren().add(initialNode); StackPane.setAlignment(initialNode, Pos.CENTER_LEFT); stackPane.getChildren().add(exclamation); StackPane.setAlignment(exclamation, Pos.CENTER_RIGHT); double insetFromRight; if (initialNode instanceof ComboBox) { insetFromRight = 30.0; } else if (initialNode instanceof ChoiceBox) { insetFromRight = 25.0; } else { insetFromRight = 5.0; } StackPane.setMargin(exclamation, new Insets(0.0, insetFromRight, 0.0, 0.0)); return stackPane; }
From source file:photobooth.views.ExplorerPane.java
private BorderPane createImageView(final File imageFile) { // DEFAULT_THUMBNAIL_WIDTH is a constant you need to define // The last two arguments are: preserveRatio, and use smooth (slower) // resizing/*w ww . j av a 2 s.c om*/ ExplorerPane explorerPane = this; ImageView imageView = null; BorderPane borderPane = new BorderPane(); try { borderPane.setMaxSize(100, 100); borderPane.setMinSize(100, 100); FileInputStream fileInputStream = new FileInputStream(imageFile); final Image image = new Image(fileInputStream, 100, 100, true, true); imageView = new ImageView(image); fileInputStream.close(); imageView.getStyleClass().add("image-view"); borderPane.setCenter(imageView); //imageView.setFitWidth(80); imageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) { if (mouseEvent.getClickCount() == 1) { Global.getInstance().setSceneRoot(LoadingPane.getInstance()); Platform.runLater(() -> { new Thread(new Runnable() { @Override public void run() { ImagePane.getInstance().init(explorerPane, imageFile); Global.getInstance().setSceneRoot(ImagePane.getInstance()); } }).start(); }); } } } }); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { Logger.getLogger(ExplorerPane.class.getName()).log(Level.SEVERE, null, ex); } return borderPane; }
From source file:dpfmanager.shell.interfaces.gui.component.report.ReportsView.java
public void addFormatIcons() { colFormats.setCellFactory(/* w ww .j a va 2 s . c o m*/ new Callback<TableColumn<ReportRow, ObservableMap<String, String>>, TableCell<ReportRow, ObservableMap<String, String>>>() { @Override public TableCell<ReportRow, ObservableMap<String, String>> call( TableColumn<ReportRow, ObservableMap<String, String>> param) { TableCell<ReportRow, ObservableMap<String, String>> cell = new TableCell<ReportRow, ObservableMap<String, String>>() { @Override public void updateItem(ObservableMap<String, String> item, boolean empty) { super.updateItem(item, empty); if (!empty && item != null) { HBox box = new HBox(); box.setSpacing(3); box.setAlignment(Pos.CENTER_LEFT); for (String i : item.keySet()) { ImageView icon = new ImageView(); icon.setId("but" + i); icon.setFitHeight(20); icon.setFitWidth(20); icon.setImage(new Image("images/formats/" + i + ".png")); icon.setCursor(Cursor.HAND); String type = i; String path = item.get(i); icon.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { ArrayMessage am = new ArrayMessage(); am.add(GuiConfig.PERSPECTIVE_SHOW, new UiMessage()); am.add(GuiConfig.PERSPECTIVE_SHOW + "." + GuiConfig.COMPONENT_SHOW, new ShowMessage(type, path)); getContext().send(GuiConfig.PERSPECTIVE_SHOW, am); } }); ContextMenu contextMenu = new ContextMenu(); javafx.scene.control.MenuItem download = new javafx.scene.control.MenuItem( "Download report"); contextMenu.getItems().add(download); icon.setOnContextMenuRequested(new EventHandler<ContextMenuEvent>() { public void handle(ContextMenuEvent e) { contextMenu.show(icon, e.getScreenX(), e.getScreenY()); } }); box.getChildren().add(icon); } setGraphic(box); } else { setGraphic(null); } } }; return cell; } }); }
From source file:gov.va.isaac.gui.refexViews.refexEdit.AddSememePopup.java
private void buildDataFields(boolean assemblageValid, DynamicSememeDataBI[] currentValues) { if (assemblageValid) { for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) { allValid_.removeBinding(ssp); }/* ww w . ja v a 2s .c om*/ currentDataFieldWarnings_.clear(); for (SememeGUIDataTypeNodeDetails nd : currentDataFields_) { nd.cleanupListener(); } currentDataFields_.clear(); GridPane gp = new GridPane(); gp.setHgap(10.0); gp.setVgap(10.0); gp.setStyle("-fx-padding: 5;"); int row = 0; boolean extraInfoColumnIsRequired = false; for (DynamicSememeColumnInfo ci : assemblageInfo_.getColumnInfo()) { SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("") : null); SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null && ci.getValidator() == null) ? null : new SimpleStringProperty()); ComboBox<DynamicSememeDataType> polymorphicType = null; Label l = new Label(ci.getColumnName()); l.getStyleClass().add("boldLabel"); l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l)); Tooltip.install(l, new Tooltip(ci.getColumnDescription())); int col = 0; gp.add(l, col++, row); if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) { polymorphicType = new ComboBox<>(); polymorphicType.setEditable(false); polymorphicType.setConverter(new StringConverter<DynamicSememeDataType>() { @Override public String toString(DynamicSememeDataType object) { return object.getDisplayName(); } @Override public DynamicSememeDataType fromString(String string) { throw new RuntimeException("unecessary"); } }); for (DynamicSememeDataType type : DynamicSememeDataType.values()) { if (type == DynamicSememeDataType.POLYMORPHIC || type == DynamicSememeDataType.UNKNOWN) { continue; } else { polymorphicType.getItems().add(type); } } polymorphicType.getSelectionModel() .select((currentValues == null ? DynamicSememeDataType.STRING : (currentValues[row] == null ? DynamicSememeDataType.STRING : currentValues[row].getDynamicSememeDataType()))); } SememeGUIDataTypeNodeDetails nd = SememeGUIDataTypeFXNodeBuilder.buildNodeForType( ci.getColumnDataType(), ci.getDefaultColumnValue(), (currentValues == null ? null : currentValues[row]), valueIsRequired, defaultValueTooltip, (polymorphicType == null ? null : polymorphicType.getSelectionModel().selectedItemProperty()), allValid_, ci.getValidator(), ci.getValidatorData()); currentDataFieldWarnings_.addAll(nd.getBoundToAllValid()); if (ci.getColumnDataType() == DynamicSememeDataType.POLYMORPHIC) { nd.addUpdateParentListListener(currentDataFieldWarnings_); } currentDataFields_.add(nd); gp.add(nd.getNodeForDisplay(), col++, row); Label colType = new Label(ci.getColumnDataType().getDisplayName()); colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType)); gp.add((polymorphicType == null ? colType : polymorphicType), col++, row); if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) { extraInfoColumnIsRequired = true; StackPane stackPane = new StackPane(); stackPane.setMaxWidth(Double.MAX_VALUE); if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) { ImageView information = Images.INFORMATION.createImageView(); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(defaultValueTooltip); Tooltip.install(information, tooltip); tooltip.setAutoHide(true); information.setOnMouseClicked( event -> tooltip.show(information, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(information); } if (ci.isColumnRequired()) { ImageView exclamation = Images.EXCLAMATION.createImageView(); final BooleanProperty showExclamation = new SimpleBooleanProperty( StringUtils.isNotBlank(valueIsRequired.get())); valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue, newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue))); exclamation.visibleProperty().bind(showExclamation); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(valueIsRequired); Tooltip.install(exclamation, tooltip); tooltip.setAutoHide(true); exclamation.setOnMouseClicked( event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(exclamation); } gp.add(stackPane, col++, row); } row++; } ColumnConstraints cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.ALWAYS); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); if (extraInfoColumnIsRequired) { cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); } if (row == 0) { sp_.setContent(new Label("This assemblage does not allow data fields")); } else { sp_.setContent(gp); } allValid_.invalidate(); } else { sp_.setContent(null); } }
From source file:gov.va.isaac.gui.refexViews.refexEdit.AddRefexPopup.java
private void buildDataFields(boolean assemblageValid, RefexDynamicDataBI[] currentValues) { if (assemblageValid) { for (ReadOnlyStringProperty ssp : currentDataFieldWarnings_) { allValid_.removeBinding(ssp); }//ww w.j a v a2 s. c o m currentDataFieldWarnings_.clear(); for (RefexDataTypeNodeDetails nd : currentDataFields_) { nd.cleanupListener(); } currentDataFields_.clear(); GridPane gp = new GridPane(); gp.setHgap(10.0); gp.setVgap(10.0); gp.setStyle("-fx-padding: 5;"); int row = 0; boolean extraInfoColumnIsRequired = false; for (RefexDynamicColumnInfo ci : assemblageInfo_.getColumnInfo()) { SimpleStringProperty valueIsRequired = (ci.isColumnRequired() ? new SimpleStringProperty("") : null); SimpleStringProperty defaultValueTooltip = ((ci.getDefaultColumnValue() == null && ci.getValidator() == null) ? null : new SimpleStringProperty()); ComboBox<RefexDynamicDataType> polymorphicType = null; Label l = new Label(ci.getColumnName()); l.getStyleClass().add("boldLabel"); l.setMinWidth(FxUtils.calculateNecessaryWidthOfBoldLabel(l)); Tooltip.install(l, new Tooltip(ci.getColumnDescription())); int col = 0; gp.add(l, col++, row); if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) { polymorphicType = new ComboBox<>(); polymorphicType.setEditable(false); polymorphicType.setConverter(new StringConverter<RefexDynamicDataType>() { @Override public String toString(RefexDynamicDataType object) { return object.getDisplayName(); } @Override public RefexDynamicDataType fromString(String string) { throw new RuntimeException("unecessary"); } }); for (RefexDynamicDataType type : RefexDynamicDataType.values()) { if (type == RefexDynamicDataType.POLYMORPHIC || type == RefexDynamicDataType.UNKNOWN) { continue; } else { polymorphicType.getItems().add(type); } } polymorphicType.getSelectionModel() .select((currentValues == null ? RefexDynamicDataType.STRING : (currentValues[row] == null ? RefexDynamicDataType.STRING : currentValues[row].getRefexDataType()))); } RefexDataTypeNodeDetails nd = RefexDataTypeFXNodeBuilder.buildNodeForType(ci.getColumnDataType(), ci.getDefaultColumnValue(), (currentValues == null ? null : currentValues[row]), valueIsRequired, defaultValueTooltip, (polymorphicType == null ? null : polymorphicType.getSelectionModel().selectedItemProperty()), allValid_, new SimpleObjectProperty<>(ci.getValidator()), new SimpleObjectProperty<>(ci.getValidatorData())); currentDataFieldWarnings_.addAll(nd.getBoundToAllValid()); if (ci.getColumnDataType() == RefexDynamicDataType.POLYMORPHIC) { nd.addUpdateParentListListener(currentDataFieldWarnings_); } currentDataFields_.add(nd); gp.add(nd.getNodeForDisplay(), col++, row); Label colType = new Label(ci.getColumnDataType().getDisplayName()); colType.setMinWidth(FxUtils.calculateNecessaryWidthOfLabel(colType)); gp.add((polymorphicType == null ? colType : polymorphicType), col++, row); if (ci.isColumnRequired() || ci.getDefaultColumnValue() != null || ci.getValidator() != null) { extraInfoColumnIsRequired = true; StackPane stackPane = new StackPane(); stackPane.setMaxWidth(Double.MAX_VALUE); if (ci.getDefaultColumnValue() != null || ci.getValidator() != null) { ImageView information = Images.INFORMATION.createImageView(); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(defaultValueTooltip); Tooltip.install(information, tooltip); tooltip.setAutoHide(true); information.setOnMouseClicked( event -> tooltip.show(information, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(information); } if (ci.isColumnRequired()) { ImageView exclamation = Images.EXCLAMATION.createImageView(); final BooleanProperty showExclamation = new SimpleBooleanProperty( StringUtils.isNotBlank(valueIsRequired.get())); valueIsRequired.addListener((ChangeListener<String>) (observable, oldValue, newValue) -> showExclamation.set(StringUtils.isNotBlank(newValue))); exclamation.visibleProperty().bind(showExclamation); Tooltip tooltip = new Tooltip(); tooltip.textProperty().bind(valueIsRequired); Tooltip.install(exclamation, tooltip); tooltip.setAutoHide(true); exclamation.setOnMouseClicked( event -> tooltip.show(exclamation, event.getScreenX(), event.getScreenY())); stackPane.getChildren().add(exclamation); } gp.add(stackPane, col++, row); } row++; } ColumnConstraints cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.ALWAYS); gp.getColumnConstraints().add(cc); cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); if (extraInfoColumnIsRequired) { cc = new ColumnConstraints(); cc.setHgrow(Priority.NEVER); gp.getColumnConstraints().add(cc); } if (row == 0) { sp_.setContent(new Label("This assemblage does not allow data fields")); } else { sp_.setContent(gp); } allValid_.invalidate(); } else { sp_.setContent(null); } }
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 w w w . j a v a2 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); } }
From source file:ui.main.MainViewController.java
private synchronized void paintSentPhoto(Chat chat, File file, String time) { //this method paints the recieved picture message Task<HBox> recievedMessages = new Task<HBox>() { @Override/* w w w.j a v a 2s . c o m*/ protected HBox call() throws Exception { // Thread.sleep(100); VBox vbox = new VBox(); //to add text ImageView imageRec = new ImageView(myAvatar.getImage()); //image imageRec.setFitHeight(60); imageRec.setFitWidth(50); Label chatterName = new Label(name.getText()); chatterName.setDisable(true); Label timeL = new Label(time); timeL.setDisable(true); timeL.setFont(new Font("Arial", 10)); try { Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(file), null); ImageView receivedImageView = new ImageView(recievedImage); receivedImageView.setFitHeight(300); receivedImageView.setFitWidth(300); receivedImageView.setPreserveRatio(true); receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { Desktop dt = Desktop.getDesktop(); try { dt.open(file); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } } }); receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.HAND); } }); receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.DEFAULT); } }); vbox.getChildren().addAll(chatterName, receivedImageView, timeL); } catch (IOException e) { e.printStackTrace(); } vbox.setAlignment(Pos.CENTER_LEFT); HBox hbox = new HBox(); hbox.setAlignment(Pos.CENTER_RIGHT); //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER); hbox.getChildren().addAll(vbox, imageRec); return hbox; } }; recievedMessages.setOnSucceeded(event -> { chatList.getChildren().add(recievedMessages.getValue()); }); if (chat.getParticipant().contains(currentChat.getParticipant())) { Thread t = new Thread(recievedMessages); t.start(); try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:ui.main.MainViewController.java
private synchronized void paintReceivedPhotoLoad(Chat chat, File recievedFile, String time) { //this method paints the recieved picture message Task<HBox> recievedMessages = new Task<HBox>() { @Override/* ww w . ja v a 2s. c om*/ protected HBox call() throws Exception { Thread.sleep(100); VBox vbox = new VBox(); //to add text ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image imageRec.setFitHeight(60); imageRec.setFitWidth(50); String strChatterName = chat.getParticipant(); //add name of the chatter with light color strChatterName = Character.toUpperCase(strChatterName.charAt(0)) + strChatterName.substring(1, strChatterName.indexOf("@")); Label chatterName = new Label(strChatterName); chatterName.setDisable(true); Label timeL = new Label(time); timeL.setDisable(true); timeL.setFont(new Font("Arial", 10)); try { Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null); ImageView receivedImageView = new ImageView(recievedImage); receivedImageView.setFitHeight(300); receivedImageView.setFitWidth(300); receivedImageView.setPreserveRatio(true); receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { Desktop dt = Desktop.getDesktop(); try { dt.open(recievedFile); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } } }); receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.HAND); } }); receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.DEFAULT); } }); vbox.getChildren().addAll(chatterName, receivedImageView, timeL); } catch (IOException e) { e.printStackTrace(); } vbox.setAlignment(Pos.CENTER_RIGHT); HBox hbox = new HBox(); //bbl.setBubbleSpec(BubbleSpec.FACE_LEFT_CENTER); hbox.getChildren().addAll(imageRec, vbox); return hbox; } }; recievedMessages.setOnSucceeded(event -> { chatList.getChildren().add(recievedMessages.getValue()); }); if (chat.getParticipant().contains(currentChat.getParticipant())) { Thread t = new Thread(recievedMessages); t.start(); try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:ui.main.MainViewController.java
private synchronized void paintReceivedPhotoOnTransmit(Chat chat, File recievedFile, String time) { //this method paints the recieved picture message Task<HBox> recievedMessages = new Task<HBox>() { @Override/*from w w w .j a v a 2 s . com*/ protected HBox call() throws Exception { VBox vbox = new VBox(); //to add text Thread.sleep(2000); ImageView imageRec = new ImageView(chatterAvatar.getImage()); //image imageRec.setFitHeight(60); imageRec.setFitWidth(50); String strChatterName = chat.getParticipant(); //add name of the chatter with light color strChatterName = Character.toUpperCase(strChatterName.charAt(0)) + strChatterName.substring(1, strChatterName.indexOf("@")); Label chatterName = new Label(strChatterName); chatterName.setDisable(true); Label timeL = new Label(time); timeL.setDisable(true); timeL.setFont(new Font("Arial", 10)); try { Image recievedImage = SwingFXUtils.toFXImage(ImageIO.read(recievedFile), null); ImageView receivedImageView = new ImageView(recievedImage); receivedImageView.setFitHeight(300); receivedImageView.setFitWidth(300); receivedImageView.setPreserveRatio(true); receivedImageView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getButton() == MouseButton.PRIMARY) { Desktop dt = Desktop.getDesktop(); try { dt.open(recievedFile); } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } } }); receivedImageView.setOnMouseEntered(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.HAND); } }); receivedImageView.setOnMouseExited(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { chatList.getScene().setCursor(Cursor.DEFAULT); } }); vbox.getChildren().addAll(chatterName, receivedImageView, timeL); } catch (IOException e) { e.printStackTrace(); } vbox.setAlignment(Pos.CENTER_RIGHT); HBox hbox = new HBox(); hbox.getChildren().addAll(imageRec, vbox); return hbox; } }; recievedMessages.setOnSucceeded(event -> { chatList.getChildren().add(recievedMessages.getValue()); }); //set the received chat message appear on the screen if (chat.getParticipant().contains(currentChat.getParticipant())) { Thread t = new Thread(recievedMessages); t.start(); } Task t = new Task() { @Override protected Object call() throws Exception { Thread.sleep(2500); return new Object(); } }; t.setOnSucceeded(value -> scrollPane.setVvalue(scrollPane.getHmax())); Thread thread1 = new Thread(t); thread1.start(); }