List of usage examples for javafx.geometry Pos CENTER_RIGHT
Pos CENTER_RIGHT
To view the source code for javafx.geometry Pos CENTER_RIGHT.
Click Source Link
From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java
private void initialize() { textField = new TextField(); textField.setFocusTraversable(true); textField.setEditable(!lookupField.getDisableManualInput()); textField.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override/*from w w w.j av a 2s . co m*/ public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) { textField.selectEnd(); } }); button = new Button(); button.setFocusTraversable(false); button.setGraphic(TiwulFXUtil.getGraphicFactory().createLookupGraphic()); StackPane.setAlignment(textField, Pos.CENTER_LEFT); StackPane.setAlignment(button, Pos.CENTER_RIGHT); this.getChildren().addAll(textField, button); button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent t) { if (!lookupField.isFocused()) { /** * Need to make this control become focused. Otherwise * changing value in LookupColumn while the LookuField cell * editor * is not focused before, won't trigger commitEdit() */ lookupField.requestFocus(); } getSkinnable().showLookupDialog(); } }); updateTextField(); lookupField.valueProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, Object t, Object t1) { updateTextField(); } }); lookupField.markInvalidProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (oldValue && !newValue && needValidation) { validate(); } } }); textField.textProperty().addListener(new InvalidationListener() { @Override public void invalidated(Observable o) { if (detectTextChanged) { if (waitTimer != null) { loaderTimerTask.setObsolete(true); waitTimer.cancel(); waitTimer.purge(); } if (textField.getText() == null || textField.getText().trim().isEmpty()) { lookupField.setValue(null); return; } lookupField.markInvalidProperty().set(true); needValidation = true; if (lookupField.getShowSuggestionWaitTime() >= 0) { waitTimer = new Timer("lookupTimer"); loaderTimerTask = new LoaderTimerTask(waitTimer); waitTimer.schedule(loaderTimerTask, lookupField.getShowSuggestionWaitTime()); } } } }); }
From source file:gov.va.isaac.gui.ConceptNode.java
/** * descriptionReader is optional// w ww . j a va 2 s .c o m */ public ConceptNode(ConceptVersionBI initialConcept, boolean flagAsInvalidWhenBlank, ObservableList<SimpleDisplayConcept> dropDownOptions, Function<ConceptVersionBI, String> descriptionReader) { c_ = initialConcept; //We can't simply use the ObservableList from the CommonlyUsedConcepts, because it infinite loops - there doesn't seem to be a way //to change the items in the drop down without changing the selection. So, we have this hack instead. listChangeListener_ = new ListChangeListener<SimpleDisplayConcept>() { @Override public void onChanged(Change<? extends SimpleDisplayConcept> c) { //TODO I still have an infinite loop here. Find and fix. logger.debug("updating concept dropdown"); disableChangeListener_ = true; SimpleDisplayConcept temp = cb_.getValue(); cb_.setItems(FXCollections.observableArrayList(dropDownOptions_)); cb_.setValue(temp); cb_.getSelectionModel().select(temp); disableChangeListener_ = false; } }; descriptionReader_ = (descriptionReader == null ? (conceptVersion) -> { return conceptVersion == null ? "" : OTFUtility.getDescription(conceptVersion); } : descriptionReader); dropDownOptions_ = dropDownOptions == null ? AppContext.getService(CommonlyUsedConcepts.class).getObservableConcepts() : dropDownOptions; dropDownOptions_.addListener(new WeakListChangeListener<SimpleDisplayConcept>(listChangeListener_)); conceptBinding_ = new ObjectBinding<ConceptVersionBI>() { @Override protected ConceptVersionBI computeValue() { return c_; } }; flagAsInvalidWhenBlank_ = flagAsInvalidWhenBlank; cb_ = new ComboBox<>(); cb_.setConverter(new StringConverter<SimpleDisplayConcept>() { @Override public String toString(SimpleDisplayConcept object) { return object == null ? "" : object.getDescription(); } @Override public SimpleDisplayConcept fromString(String string) { return new SimpleDisplayConcept(string, 0); } }); cb_.setValue(new SimpleDisplayConcept("", 0)); cb_.setEditable(true); cb_.setMaxWidth(Double.MAX_VALUE); cb_.setPrefWidth(ComboBox.USE_COMPUTED_SIZE); cb_.setMinWidth(200.0); cb_.setPromptText("Type, drop or select a concept"); cb_.setItems(FXCollections.observableArrayList(dropDownOptions_)); cb_.setVisibleRowCount(11); cm_ = new ContextMenu(); MenuItem copyText = new MenuItem("Copy Description"); copyText.setGraphic(Images.COPY.createImageView()); copyText.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { CustomClipboard.set(cb_.getEditor().getText()); } }); cm_.getItems().add(copyText); CommonMenusNIdProvider nidProvider = new CommonMenusNIdProvider() { @Override public Set<Integer> getNIds() { Set<Integer> nids = new HashSet<>(); if (c_ != null) { nids.add(c_.getNid()); } return nids; } }; CommonMenuBuilderI menuBuilder = CommonMenus.CommonMenuBuilder.newInstance(); menuBuilder.setInvisibleWhenFalse(isValid); CommonMenus.addCommonMenus(cm_, menuBuilder, nidProvider); cb_.getEditor().setContextMenu(cm_); updateGUI(); new LookAheadConceptPopup(cb_); if (cb_.getValue().getNid() == 0) { if (flagAsInvalidWhenBlank_) { isValid.setInvalid("Concept Required"); } } else { isValid.setValid(); } cb_.valueProperty().addListener(new ChangeListener<SimpleDisplayConcept>() { @Override public void changed(ObservableValue<? extends SimpleDisplayConcept> observable, SimpleDisplayConcept oldValue, SimpleDisplayConcept newValue) { if (newValue == null) { logger.debug("Combo Value Changed - null entry"); } else { logger.debug("Combo Value Changed: {} {}", newValue.getDescription(), newValue.getNid()); } if (disableChangeListener_) { logger.debug("change listener disabled"); return; } if (newValue == null) { //This can happen if someone calls clearSelection() - it passes in a null. cb_.setValue(new SimpleDisplayConcept("", 0)); return; } else { if (newValue.shouldIgnoreChange()) { logger.debug("One time change ignore"); return; } //Whenever the focus leaves the combo box editor, a new combo box is generated. But, the new box will have 0 for an id. detect and ignore if (oldValue != null && oldValue.getDescription().equals(newValue.getDescription()) && newValue.getNid() == 0) { logger.debug("Not a real change, ignore"); newValue.setNid(oldValue.getNid()); return; } lookup(); } } }); AppContext.getService(DragRegistry.class).setupDragAndDrop(cb_, new SingleConceptIdProvider() { @Override public String getConceptId() { return cb_.getValue().getNid() + ""; } }, true); pi_ = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS); pi_.visibleProperty().bind(isLookupInProgress_); pi_.setPrefHeight(16.0); pi_.setPrefWidth(16.0); pi_.setMaxWidth(16.0); pi_.setMaxHeight(16.0); lookupFailImage_ = Images.EXCLAMATION.createImageView(); lookupFailImage_.visibleProperty().bind(isValid.not().and(isLookupInProgress_.not())); Tooltip t = new Tooltip(); t.textProperty().bind(isValid.getReasonWhyInvalid()); Tooltip.install(lookupFailImage_, t); StackPane sp = new StackPane(); sp.setMaxWidth(Double.MAX_VALUE); sp.getChildren().add(cb_); sp.getChildren().add(lookupFailImage_); sp.getChildren().add(pi_); StackPane.setAlignment(cb_, Pos.CENTER_LEFT); StackPane.setAlignment(lookupFailImage_, Pos.CENTER_RIGHT); StackPane.setMargin(lookupFailImage_, new Insets(0.0, 30.0, 0.0, 0.0)); StackPane.setAlignment(pi_, Pos.CENTER_RIGHT); StackPane.setMargin(pi_, new Insets(0.0, 30.0, 0.0, 0.0)); hbox_ = new HBox(); hbox_.setSpacing(5.0); hbox_.setAlignment(Pos.CENTER_LEFT); hbox_.getChildren().add(sp); HBox.setHgrow(sp, Priority.SOMETIMES); }
From source file:com.panemu.tiwulfx.table.TableControl.java
private void initControls() { this.getStyleClass().add("table-control"); btnAdd = buildButton(TiwulFXUtil.getGraphicFactory().createAddGraphic()); btnDelete = buildButton(TiwulFXUtil.getGraphicFactory().createDeleteGraphic()); btnEdit = buildButton(TiwulFXUtil.getGraphicFactory().createEditGraphic()); btnExport = buildButton(TiwulFXUtil.getGraphicFactory().createExportGraphic()); btnReload = buildButton(TiwulFXUtil.getGraphicFactory().createReloadGraphic()); btnSave = buildButton(TiwulFXUtil.getGraphicFactory().createSaveGraphic()); btnFirstPage = new Button(); btnFirstPage.setGraphic(TiwulFXUtil.getGraphicFactory().createPageFirstGraphic()); btnFirstPage.setOnAction(paginationHandler); btnFirstPage.setDisable(true);// www . j a va 2 s . co m btnFirstPage.setFocusTraversable(false); btnFirstPage.getStyleClass().addAll("pill-button", "pill-button-left"); btnPrevPage = new Button(); btnPrevPage.setGraphic(TiwulFXUtil.getGraphicFactory().createPagePrevGraphic()); btnPrevPage.setOnAction(paginationHandler); btnPrevPage.setDisable(true); btnPrevPage.setFocusTraversable(false); btnPrevPage.getStyleClass().addAll("pill-button", "pill-button-center"); btnNextPage = new Button(); btnNextPage.setGraphic(TiwulFXUtil.getGraphicFactory().createPageNextGraphic()); btnNextPage.setOnAction(paginationHandler); btnNextPage.setDisable(true); btnNextPage.setFocusTraversable(false); btnNextPage.getStyleClass().addAll("pill-button", "pill-button-center"); btnLastPage = new Button(); btnLastPage.setGraphic(TiwulFXUtil.getGraphicFactory().createPageLastGraphic()); btnLastPage.setOnAction(paginationHandler); btnLastPage.setDisable(true); btnLastPage.setFocusTraversable(false); btnLastPage.getStyleClass().addAll("pill-button", "pill-button-right"); cmbPage = new ComboBox<>(); cmbPage.setEditable(true); cmbPage.setOnAction(paginationHandler); cmbPage.setFocusTraversable(false); cmbPage.setDisable(true); cmbPage.getStyleClass().addAll("combo-page"); cmbPage.setPrefWidth(75); paginationBox = new HBox(); paginationBox.setAlignment(Pos.CENTER); paginationBox.getChildren().addAll(btnFirstPage, btnPrevPage, cmbPage, btnNextPage, btnLastPage); spacer = new Region(); HBox.setHgrow(spacer, Priority.ALWAYS); toolbar = new ToolBar(btnReload, btnAdd, btnEdit, btnSave, btnDelete, btnExport, spacer, paginationBox); toolbar.getStyleClass().add("table-toolbar"); footer = new StackPane(); footer.getStyleClass().add("table-footer"); lblRowIndex = new Label(); lblTotalRow = new Label(); menuButton = new TableControlMenu(this); StackPane.setAlignment(lblRowIndex, Pos.CENTER_LEFT); StackPane.setAlignment(lblTotalRow, Pos.CENTER); StackPane.setAlignment(menuButton, Pos.CENTER_RIGHT); lblTotalRow.visibleProperty().bind(progressIndicator.visibleProperty().not()); progressIndicator.setProgress(-1); progressIndicator.visibleProperty().bind(service.runningProperty()); toolbar.disableProperty().bind(service.runningProperty()); menuButton.disableProperty().bind(service.runningProperty()); footer.getChildren().addAll(lblRowIndex, lblTotalRow, menuButton, progressIndicator); VBox.setVgrow(tblView, Priority.ALWAYS); getChildren().addAll(toolbar, tblView, footer); }
From source file:ui.main.MainViewController.java
private synchronized void paintReceivedMessage(Chat chat, String msg, String time) { //this method draws the recievied text message Task<HBox> recievedMessages = new Task<HBox>() { @Override/*from w w w. jav a 2s. com*/ protected HBox call() throws Exception { 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)); //chat message BubbledLabel bbl = new BubbledLabel(); bbl.setText(msg); bbl.setBackground(new Background(new BackgroundFill(Color.GAINSBORO, null, null))); vbox.getChildren().addAll(chatterName, bbl, timeL); 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.setDaemon(true); t.start(); try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } scrollPane.setVvalue(scrollPane.getHmax()); } }
From source file:ui.main.MainViewController.java
private synchronized void paintWarningInRecieve(Chat chat, String Warning, String time) { //this method draws the recievied text message Task<HBox> recievedMessages = new Task<HBox>() { @Override// w ww . j av a 2 s .co m protected HBox call() throws Exception { 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)); //chat message BubbledLabel bbl = new BubbledLabel(); bbl.setText(Warning); bbl.setBackground(new Background(new BackgroundFill(Color.RED, null, null))); vbox.getChildren().addAll(chatterName, bbl, timeL); 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()); scrollPane.setVvalue(scrollPane.getHmax()); scrollPane.setVvalue(scrollPane.getHmax()); }); 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); } //t.setDaemon(true); } }
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//w ww . j av a2s. co m 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// w w w . j a v a 2s . c o m 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(); }
From source file:ui.main.MainViewController.java
private synchronized void paintReceivedFile(Chat chat, String path, 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.c o m*/ 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)); Hyperlink link = new Hyperlink("File Recieved: " + path); link.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<javafx.scene.input.MouseEvent>() { @Override public void handle(javafx.scene.input.MouseEvent event) { try { if (event.getButton() == MouseButton.PRIMARY) { Runtime.getRuntime().exec("explorer.exe /select," + path); } } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } }); vbox.getChildren().addAll(chatterName, link, timeL); 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.setDaemon(true); t.start(); try { t.join(); } catch (InterruptedException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } //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(); }
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 va 2 s .c om 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 paintSentFile(Chat chat, String path, String time) { //this method paints the recieved picture message Task<HBox> recievedMessages = new Task<HBox>() { @Override// www . jav a 2 s . co 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 timeL = new Label(time); timeL.setDisable(true); timeL.setFont(new Font("Arial", 10)); Label chatterName = new Label(name.getText()); chatterName.setDisable(true); Hyperlink link = new Hyperlink("File Sent: " + path); link.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<javafx.scene.input.MouseEvent>() { @Override public void handle(javafx.scene.input.MouseEvent event) { try { if (event.getButton() == MouseButton.PRIMARY) { Runtime.getRuntime().exec("explorer.exe /select," + path); } } catch (IOException ex) { Logger.getLogger(MainViewController.class.getName()).log(Level.SEVERE, null, ex); } } }); vbox.getChildren().addAll(chatterName, link, timeL); 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); } } }