Search in sources :

Example 51 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class FeeOptionWindow method addContent.

private void addContent() {
    Label label = addLabel(gridPane, ++rowIndex, Res.get("feeOptionWindow.info"));
    GridPane.setColumnSpan(label, 2);
    GridPane.setHalignment(label, HPos.LEFT);
    toggleGroup = new ToggleGroup();
    Tuple3<Label, RadioButton, RadioButton> tuple = addLabelRadioButtonRadioButton(gridPane, ++rowIndex, toggleGroup, Res.get("feeOptionWindow.optionsLabel"), "BTC", "BSQ");
    RadioButton radioButtonBTC = tuple.second;
    RadioButton radioButtonBSQ = tuple.third;
    makerFeeTextField = addLabelTextField(gridPane, ++rowIndex, Res.getWithCol("createOffer.currencyForFee"), makerFeeWithCodeProperty.get()).second;
    toggleChangeListener = (observable, oldValue, newValue) -> {
        final boolean isBtc = newValue == radioButtonBTC;
        selectionChangedHandler.accept(isBtc);
        if (!isBsqForFeeAvailable && !isBtc) {
            if (missingBsq != null) {
                // We don't call hide() because we want to keep the blurred bg
                if (stage != null)
                    stage.hide();
                else
                    log.warn("Stage is null");
                cleanup();
                onHidden();
                // noinspection unchecked
                new Popup().warning(missingBsq).actionButtonTextWithGoTo("navigation.dao.wallet.receive").onAction(() -> {
                    UserThread.runAfter(() -> {
                        hide();
                        navigation.navigateTo(MainView.class, DaoView.class, BsqWalletView.class, BsqReceiveView.class);
                    }, 100, TimeUnit.MILLISECONDS);
                }).closeButtonText(Res.get("feeOptionWindow.useBTC")).onClose(() -> {
                    selectionChangedHandler.accept(true);
                    closeHandler.run();
                }).show();
            }
            UserThread.execute(() -> {
                toggleGroup.selectToggle(radioButtonBTC);
                radioButtonBSQ.setDisable(true);
            });
        }
    };
    toggleGroup.selectedToggleProperty().addListener(toggleChangeListener);
    toggleGroup.selectToggle(!isBsqForFeeAvailable || isCurrencyForMakerFeeBtc ? radioButtonBTC : radioButtonBSQ);
    makerFeeTextField.textProperty().bind(makerFeeWithCodeProperty);
}
Also used : MainView(bisq.desktop.main.MainView) DaoView(bisq.desktop.main.dao.DaoView) BsqReceiveView(bisq.desktop.main.dao.wallet.receive.BsqReceiveView) ToggleGroup(javafx.scene.control.ToggleGroup) Popup(bisq.desktop.main.overlays.popups.Popup) FormBuilder.addLabel(bisq.desktop.util.FormBuilder.addLabel) Label(javafx.scene.control.Label) FormBuilder.addLabelRadioButtonRadioButton(bisq.desktop.util.FormBuilder.addLabelRadioButtonRadioButton) RadioButton(javafx.scene.control.RadioButton) BsqWalletView(bisq.desktop.main.dao.wallet.BsqWalletView)

Example 52 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class OfferDetailsWindow method addConfirmAndCancelButtons.

private void addConfirmAndCancelButtons(boolean isPlaceOffer) {
    boolean isBuyOffer = offer.isBuyOffer();
    boolean isBuyerRole = isPlaceOffer ? isBuyOffer : !isBuyOffer;
    String placeOfferButtonText = isBuyerRole ? Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.buy")) : Res.get("offerDetailsWindow.confirm.maker", Res.get("shared.sell"));
    String takeOfferButtonText = isBuyerRole ? Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.buy")) : Res.get("offerDetailsWindow.confirm.taker", Res.get("shared.sell"));
    ImageView iconView = new ImageView();
    iconView.setId(isBuyerRole ? "image-buy-white" : "image-sell-white");
    Tuple3<Button, BusyAnimation, Label> placeOfferTuple = addButtonBusyAnimationLabelAfterGroup(gridPane, ++rowIndex, isPlaceOffer ? placeOfferButtonText : takeOfferButtonText);
    Button button = placeOfferTuple.first;
    button.setMinHeight(40);
    button.setPadding(new Insets(0, 20, 0, 20));
    button.setGraphic(iconView);
    button.setGraphicTextGap(10);
    button.setId(isBuyerRole ? "buy-button-big" : "sell-button-big");
    button.setText(isPlaceOffer ? placeOfferButtonText : takeOfferButtonText);
    busyAnimation = placeOfferTuple.second;
    Label spinnerInfoLabel = placeOfferTuple.third;
    Button cancelButton = addButton(gridPane, ++rowIndex, Res.get("shared.cancel"));
    cancelButton.setDefaultButton(false);
    cancelButton.setId("cancel-button");
    cancelButton.setOnAction(e -> {
        closeHandlerOptional.ifPresent(Runnable::run);
        hide();
    });
    button.setOnAction(e -> {
        if (user.getAcceptedArbitrators().size() > 0) {
            button.setDisable(true);
            cancelButton.setDisable(true);
            busyAnimation.play();
            if (isPlaceOffer) {
                spinnerInfoLabel.setText(Res.get("createOffer.fundsBox.placeOfferSpinnerInfo"));
                placeOfferHandlerOptional.get().run();
            } else {
                spinnerInfoLabel.setText(Res.get("takeOffer.fundsBox.takeOfferSpinnerInfo"));
                takeOfferHandlerOptional.get().run();
            }
        } else {
            new Popup<>().warning(Res.get("offerDetailsWindow.warn.noArbitrator")).show();
            // noinspection unchecked
            navigation.navigateTo(MainView.class, AccountView.class, AccountSettingsView.class, ArbitratorSelectionView.class);
        }
    });
}
Also used : BusyAnimation(bisq.desktop.components.BusyAnimation) Insets(javafx.geometry.Insets) Button(javafx.scene.control.Button) Popup(bisq.desktop.main.overlays.popups.Popup) Label(javafx.scene.control.Label) ImageView(javafx.scene.image.ImageView)

Example 53 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class DisplayUpdateDownloadWindow method addContent.

// /////////////////////////////////////////////////////////////////////////////////////////
// Protected
// /////////////////////////////////////////////////////////////////////////////////////////
private void addContent() {
    headLine = "Important update information!";
    headLineLabel.getStyleClass().addAll("headline-label", "highlight");
    checkNotNull(alert, "alertMessage must not be null");
    addMultilineLabel(gridPane, ++rowIndex, alert.getMessage(), 10);
    Separator separator = new Separator();
    separator.setMouseTransparent(true);
    separator.setOrientation(Orientation.HORIZONTAL);
    separator.getStyleClass().add("separator");
    GridPane.setHalignment(separator, HPos.CENTER);
    GridPane.setRowIndex(separator, ++rowIndex);
    GridPane.setColumnSpan(separator, 2);
    GridPane.setMargin(separator, new Insets(20, 0, 20, 0));
    gridPane.getChildren().add(separator);
    Button downloadButton = new AutoTooltipButton(Res.get("displayUpdateDownloadWindow.button.label"));
    downloadButton.setDefaultButton(true);
    busyAnimation = new BusyAnimation(false);
    Label statusLabel = new AutoTooltipLabel();
    statusLabel.managedProperty().bind(statusLabel.visibleProperty());
    HBox hBox = new HBox();
    hBox.setSpacing(10);
    hBox.setAlignment(Pos.CENTER_LEFT);
    hBox.getChildren().addAll(downloadButton, busyAnimation, statusLabel);
    GridPane.setRowIndex(hBox, ++rowIndex);
    GridPane.setColumnIndex(hBox, 0);
    GridPane.setColumnSpan(hBox, 2);
    gridPane.getChildren().add(hBox);
    Label downloadingFileLabel = addLabel(gridPane, ++rowIndex, Res.get("displayUpdateDownloadWindow.downloadingFile", ""));
    GridPane.setColumnIndex(downloadingFileLabel, 0);
    downloadingFileLabel.setOpacity(0.2);
    progressBar = new ProgressBar(0L);
    progressBar.setPrefWidth(200);
    progressBar.setMaxHeight(4);
    progressBar.managedProperty().bind(progressBar.visibleProperty());
    progressBar.setVisible(false);
    GridPane.setRowIndex(progressBar, rowIndex);
    GridPane.setColumnIndex(progressBar, 1);
    GridPane.setHalignment(progressBar, HPos.LEFT);
    GridPane.setFillWidth(progressBar, true);
    GridPane.setMargin(progressBar, new Insets(3, 0, 0, 10));
    gridPane.getChildren().add(progressBar);
    final String downloadedFilesLabelTitle = Res.get("displayUpdateDownloadWindow.downloadedFiles");
    Label downloadedFilesLabel = addLabel(gridPane, ++rowIndex, downloadedFilesLabelTitle);
    GridPane.setColumnIndex(downloadedFilesLabel, 0);
    GridPane.setHalignment(downloadedFilesLabel, HPos.LEFT);
    GridPane.setColumnSpan(downloadedFilesLabel, 2);
    downloadedFilesLabel.setOpacity(0.2);
    final String verifiedSigLabelTitle = Res.get("displayUpdateDownloadWindow.verifiedSigs");
    Label verifiedSigLabel = addLabel(gridPane, ++rowIndex, verifiedSigLabelTitle);
    GridPane.setColumnIndex(verifiedSigLabel, 0);
    GridPane.setColumnSpan(verifiedSigLabel, 2);
    GridPane.setHalignment(verifiedSigLabel, HPos.LEFT);
    verifiedSigLabel.setOpacity(0.2);
    Separator separator2 = new Separator();
    separator2.setMouseTransparent(true);
    separator2.setOrientation(Orientation.HORIZONTAL);
    separator2.getStyleClass().add("separator");
    GridPane.setHalignment(separator2, HPos.CENTER);
    GridPane.setRowIndex(separator2, ++rowIndex);
    GridPane.setColumnSpan(separator2, 2);
    GridPane.setMargin(separator2, new Insets(20, 0, 20, 0));
    gridPane.getChildren().add(separator2);
    BisqInstaller installer = new BisqInstaller();
    String downloadFailedString = Res.get("displayUpdateDownloadWindow.download.failed");
    downloadButton.setOnAction(e -> {
        if (installer.isSupportedOS()) {
            List<String> downloadedFiles = new ArrayList<>();
            List<String> verifiedSigs = new ArrayList<>();
            downloadButton.setDisable(true);
            progressBar.setVisible(true);
            downloadedFilesLabel.setOpacity(1);
            downloadingFileLabel.setOpacity(1);
            busyAnimation.play();
            statusLabel.setText(Res.get("displayUpdateDownloadWindow.status.downloading"));
            // download installer
            downloadTaskOptional = installer.download(alert.getVersion());
            if (downloadTaskOptional.isPresent()) {
                final DownloadTask downloadTask = downloadTaskOptional.get();
                final ChangeListener<String> downloadedFilesListener = (observable, oldValue, newValue) -> {
                    if (!newValue.endsWith("-local")) {
                        downloadingFileLabel.setText(Res.get("displayUpdateDownloadWindow.downloadingFile", newValue));
                        downloadedFilesLabel.setText(downloadedFilesLabelTitle + " " + Joiner.on(", ").join(downloadedFiles));
                        downloadedFiles.add(newValue);
                    }
                };
                downloadTask.messageProperty().addListener(downloadedFilesListener);
                progressBar.progressProperty().unbind();
                progressBar.progressProperty().bind(downloadTask.progressProperty());
                downloadTask.setOnSucceeded(workerStateEvent -> {
                    downloadedFilesLabel.setText(downloadedFilesLabelTitle + " " + Joiner.on(", ").join(downloadedFiles));
                    downloadTask.messageProperty().removeListener(downloadedFilesListener);
                    progressBar.setVisible(false);
                    downloadingFileLabel.setText("");
                    downloadingFileLabel.setOpacity(0.2);
                    statusLabel.setText(Res.get("displayUpdateDownloadWindow.status.verifying"));
                    List<BisqInstaller.FileDescriptor> downloadResults = downloadTask.getValue();
                    Optional<BisqInstaller.FileDescriptor> downloadFailed = downloadResults.stream().filter(fileDescriptor -> !BisqInstaller.DownloadStatusEnum.OK.equals(fileDescriptor.getDownloadStatus())).findFirst();
                    downloadedFilesLabel.getStyleClass().removeAll("error-text", "success-text");
                    if (downloadResults == null || downloadResults.isEmpty() || downloadFailed.isPresent()) {
                        showErrorMessage(downloadButton, statusLabel, downloadFailedString);
                        downloadedFilesLabel.getStyleClass().add("error-text");
                    } else {
                        log.debug("Download completed successfully.");
                        downloadedFilesLabel.getStyleClass().add("success-text");
                        verifyTask = installer.verify(downloadResults);
                        verifiedSigLabel.setOpacity(1);
                        final ChangeListener<String> verifiedSigLabelListener = (observable, oldValue, newValue) -> {
                            verifiedSigs.add(newValue);
                            verifiedSigLabel.setText(verifiedSigLabelTitle + " " + Joiner.on(", ").join(verifiedSigs));
                        };
                        verifyTask.messageProperty().addListener(verifiedSigLabelListener);
                        verifyTask.setOnSucceeded(event -> {
                            verifyTask.messageProperty().removeListener(verifiedSigLabelListener);
                            statusLabel.setText("");
                            stopAnimations();
                            List<BisqInstaller.VerifyDescriptor> verifyResults = verifyTask.getValue();
                            // check that there are no failed verifications
                            Optional<BisqInstaller.VerifyDescriptor> verifyFailed = verifyResults.stream().filter(verifyDescriptor -> !BisqInstaller.VerifyStatusEnum.OK.equals(verifyDescriptor.getVerifyStatusEnum())).findFirst();
                            if (verifyResults == null || verifyResults.isEmpty() || verifyFailed.isPresent()) {
                                showErrorMessage(downloadButton, statusLabel, Res.get("displayUpdateDownloadWindow.verify.failed"));
                            } else {
                                verifiedSigLabel.getStyleClass().add("success-text");
                                new Popup<>().feedback(Res.get("displayUpdateDownloadWindow.success")).actionButtonText(Res.get("displayUpdateDownloadWindow.download.openDir")).onAction(() -> {
                                    try {
                                        Utilities.openFile(new File(Utilities.getDownloadOfHomeDir()));
                                        doClose();
                                    } catch (IOException e2) {
                                        log.error(e2.getMessage());
                                        e2.printStackTrace();
                                    }
                                }).onClose(this::doClose).show();
                                log.info("Download & verification succeeded.");
                            }
                        });
                    }
                });
            } else {
                showErrorMessage(downloadButton, statusLabel, downloadFailedString);
            }
        } else {
            showErrorMessage(downloadButton, statusLabel, (Res.get("displayUpdateDownloadWindow.installer.failed")));
        }
    });
}
Also used : Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) HPos(javafx.geometry.HPos) Pos(javafx.geometry.Pos) FormBuilder.addLabel(bisq.desktop.util.FormBuilder.addLabel) BusyAnimation(bisq.desktop.components.BusyAnimation) Utilities(bisq.common.util.Utilities) ArrayList(java.util.ArrayList) ProgressBar(javafx.scene.control.ProgressBar) Insets(javafx.geometry.Insets) Alert(bisq.core.alert.Alert) Res(bisq.core.locale.Res) Overlay(bisq.desktop.main.overlays.Overlay) GridPane(javafx.scene.layout.GridPane) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) Orientation(javafx.geometry.Orientation) Popup(bisq.desktop.main.overlays.popups.Popup) Label(javafx.scene.control.Label) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) File(java.io.File) Separator(javafx.scene.control.Separator) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Optional(java.util.Optional) FormBuilder.addMultilineLabel(bisq.desktop.util.FormBuilder.addMultilineLabel) ChangeListener(javafx.beans.value.ChangeListener) Joiner(com.google.common.base.Joiner) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) FormBuilder.addLabel(bisq.desktop.util.FormBuilder.addLabel) Label(javafx.scene.control.Label) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder.addMultilineLabel(bisq.desktop.util.FormBuilder.addMultilineLabel) ArrayList(java.util.ArrayList) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) ProgressBar(javafx.scene.control.ProgressBar) BusyAnimation(bisq.desktop.components.BusyAnimation) IOException(java.io.IOException) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) File(java.io.File) Separator(javafx.scene.control.Separator)

Example 54 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class PendingTradesView method initialize.

@Override
public void initialize() {
    priceColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.price")));
    amountColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode())));
    volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amount")));
    marketColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.market")));
    roleColumn.setGraphic(new AutoTooltipLabel(Res.get("portfolio.pending.role")));
    dateColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.dateTime")));
    tradeIdColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.tradeId")));
    paymentMethodColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.paymentMethod")));
    avatarColumn.setText("");
    setTradeIdColumnCellFactory();
    setDateColumnCellFactory();
    setAmountColumnCellFactory();
    setPriceColumnCellFactory();
    setVolumeColumnCellFactory();
    setPaymentMethodColumnCellFactory();
    setMarketColumnCellFactory();
    setRoleColumnCellFactory();
    setAvatarColumnCellFactory();
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    tableView.setPlaceholder(new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.openTrades"))));
    tableView.setMinHeight(100);
    tradeIdColumn.setComparator((o1, o2) -> o1.getTrade().getId().compareTo(o2.getTrade().getId()));
    dateColumn.setComparator((o1, o2) -> o1.getTrade().getDate().compareTo(o2.getTrade().getDate()));
    volumeColumn.setComparator((o1, o2) -> {
        if (o1.getTrade().getTradeVolume() != null && o2.getTrade().getTradeVolume() != null)
            return o1.getTrade().getTradeVolume().compareTo(o2.getTrade().getTradeVolume());
        else
            return 0;
    });
    amountColumn.setComparator((o1, o2) -> {
        if (o1.getTrade().getTradeAmount() != null && o2.getTrade().getTradeAmount() != null)
            return o1.getTrade().getTradeAmount().compareTo(o2.getTrade().getTradeAmount());
        else
            return 0;
    });
    priceColumn.setComparator((o1, o2) -> o1.getPrice().compareTo(o2.getPrice()));
    paymentMethodColumn.setComparator((o1, o2) -> o1.getTrade().getOffer().getPaymentMethod().getId().compareTo(o2.getTrade().getOffer().getPaymentMethod().getId()));
    avatarColumn.setComparator((o1, o2) -> {
        if (o1.getTrade().getTradingPeerNodeAddress() != null && o2.getTrade().getTradingPeerNodeAddress() != null)
            return o1.getTrade().getTradingPeerNodeAddress().getFullAddress().compareTo(o2.getTrade().getTradingPeerNodeAddress().getFullAddress());
        else
            return 0;
    });
    roleColumn.setComparator((o1, o2) -> model.getMyRole(o1).compareTo(model.getMyRole(o2)));
    marketColumn.setComparator((o1, o2) -> model.getMarketLabel(o1).compareTo(model.getMarketLabel(o2)));
    dateColumn.setSortType(TableColumn.SortType.DESCENDING);
    tableView.getSortOrder().add(dateColumn);
    // we use a hidden emergency shortcut to open support ticket
    keyEventEventHandler = keyEvent -> {
        if (Utilities.isAltOrCtrlPressed(KeyCode.O, keyEvent)) {
            Popup popup = new Popup<>();
            popup.headLine(Res.get("portfolio.pending.openSupportTicket.headline")).message(Res.get("portfolio.pending.openSupportTicket.msg")).actionButtonText(Res.get("portfolio.pending.openSupportTicket.headline")).onAction(model.dataModel::onOpenSupportTicket).closeButtonText(Res.get("shared.cancel")).onClose(popup::hide).show();
        } else if (Utilities.isAltPressed(KeyCode.Y, keyEvent)) {
            new Popup<>().warning(Res.get("portfolio.pending.removeFailedTrade")).onAction(model.dataModel::onMoveToFailedTrades).show();
        }
    };
}
Also used : Popup(bisq.desktop.main.overlays.popups.Popup) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel)

Example 55 with Popup

use of bisq.desktop.main.overlays.popups.Popup in project bisq-desktop by bisq-network.

the class PreferencesView method initializeDisplayCurrencies.

private void initializeDisplayCurrencies() {
    TitledGroupBg titledGroupBg = addTitledGroupBg(root, ++gridRow, 3, Res.get("setting.preferences.currenciesInList"), Layout.GROUP_DISTANCE);
    GridPane.setColumnSpan(titledGroupBg, 4);
    // noinspection unchecked
    preferredTradeCurrencyComboBox = addLabelComboBox(root, gridRow, Res.get("setting.preferences.prefCurrency"), Layout.FIRST_ROW_AND_GROUP_DISTANCE).second;
    preferredTradeCurrencyComboBox.setConverter(new StringConverter<TradeCurrency>() {

        @Override
        public String toString(TradeCurrency tradeCurrency) {
            // http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
            return tradeCurrency.getDisplayPrefix() + tradeCurrency.getNameAndCode();
        }

        @Override
        public TradeCurrency fromString(String s) {
            return null;
        }
    });
    Tuple2<Label, ListView> fiatTuple = addLabelListView(root, ++gridRow, Res.get("setting.preferences.displayFiat"));
    GridPane.setValignment(fiatTuple.first, VPos.TOP);
    // noinspection unchecked
    fiatCurrenciesListView = fiatTuple.second;
    fiatCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
    fiatCurrenciesListView.setPrefHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
    Label placeholder = new AutoTooltipLabel(Res.get("setting.preferences.noFiat"));
    placeholder.setWrapText(true);
    fiatCurrenciesListView.setPlaceholder(placeholder);
    fiatCurrenciesListView.setCellFactory(new Callback<ListView<FiatCurrency>, ListCell<FiatCurrency>>() {

        @Override
        public ListCell<FiatCurrency> call(ListView<FiatCurrency> list) {
            return new ListCell<FiatCurrency>() {

                final Label label = new AutoTooltipLabel();

                final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);

                final Button removeButton = new AutoTooltipButton("", icon);

                final AnchorPane pane = new AnchorPane(label, removeButton);

                {
                    label.setLayoutY(5);
                    removeButton.setId("icon-button");
                    AnchorPane.setRightAnchor(removeButton, 0d);
                }

                @Override
                public void updateItem(final FiatCurrency item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(item.getNameAndCode());
                        removeButton.setOnAction(e -> {
                            if (item.equals(preferences.getPreferredTradeCurrency())) {
                                new Popup<>().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show();
                            } else {
                                preferences.removeFiatCurrency(item);
                                if (!allFiatCurrencies.contains(item))
                                    allFiatCurrencies.add(item);
                            }
                        });
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                        removeButton.setOnAction(null);
                    }
                }
            };
        }
    });
    Tuple2<Label, ListView> cryptoCurrenciesTuple = addLabelListView(root, gridRow, Res.get("setting.preferences.displayAltcoins"));
    GridPane.setValignment(cryptoCurrenciesTuple.first, VPos.TOP);
    GridPane.setMargin(cryptoCurrenciesTuple.first, new Insets(0, 0, 0, 20));
    // noinspection unchecked
    cryptoCurrenciesListView = cryptoCurrenciesTuple.second;
    GridPane.setColumnIndex(cryptoCurrenciesTuple.first, 2);
    GridPane.setColumnIndex(cryptoCurrenciesListView, 3);
    cryptoCurrenciesListView.setMinHeight(2 * Layout.LIST_ROW_HEIGHT + 2);
    cryptoCurrenciesListView.setPrefHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
    placeholder = new AutoTooltipLabel(Res.get("setting.preferences.noAltcoins"));
    placeholder.setWrapText(true);
    cryptoCurrenciesListView.setPlaceholder(placeholder);
    cryptoCurrenciesListView.setCellFactory(new Callback<ListView<CryptoCurrency>, ListCell<CryptoCurrency>>() {

        @Override
        public ListCell<CryptoCurrency> call(ListView<CryptoCurrency> list) {
            return new ListCell<CryptoCurrency>() {

                final Label label = new AutoTooltipLabel();

                final ImageView icon = ImageUtil.getImageViewById(ImageUtil.REMOVE_ICON);

                final Button removeButton = new AutoTooltipButton("", icon);

                final AnchorPane pane = new AnchorPane(label, removeButton);

                {
                    label.setLayoutY(5);
                    removeButton.setId("icon-button");
                    AnchorPane.setRightAnchor(removeButton, 0d);
                }

                @Override
                public void updateItem(final CryptoCurrency item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(item.getNameAndCode());
                        removeButton.setOnAction(e -> {
                            if (item.equals(preferences.getPreferredTradeCurrency())) {
                                new Popup<>().warning(Res.get("setting.preferences.cannotRemovePrefCurrency")).show();
                            } else {
                                preferences.removeCryptoCurrency(item);
                                if (!allCryptoCurrencies.contains(item))
                                    allCryptoCurrencies.add(item);
                            }
                        });
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                        removeButton.setOnAction(null);
                    }
                }
            };
        }
    });
    // noinspection unchecked
    fiatCurrenciesComboBox = addLabelComboBox(root, ++gridRow).second;
    fiatCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addFiat"));
    fiatCurrenciesComboBox.setConverter(new StringConverter<FiatCurrency>() {

        @Override
        public String toString(FiatCurrency tradeCurrency) {
            return tradeCurrency.getNameAndCode();
        }

        @Override
        public FiatCurrency fromString(String s) {
            return null;
        }
    });
    Tuple2<Label, ComboBox> labelComboBoxTuple2 = addLabelComboBox(root, gridRow);
    // noinspection unchecked
    cryptoCurrenciesComboBox = labelComboBoxTuple2.second;
    GridPane.setColumnIndex(cryptoCurrenciesComboBox, 3);
    cryptoCurrenciesComboBox.setPromptText(Res.get("setting.preferences.addAltcoin"));
    cryptoCurrenciesComboBox.setConverter(new StringConverter<CryptoCurrency>() {

        @Override
        public String toString(CryptoCurrency tradeCurrency) {
            return tradeCurrency.getNameAndCode();
        }

        @Override
        public CryptoCurrency fromString(String s) {
            return null;
        }
    });
}
Also used : Button(javafx.scene.control.Button) Arrays(java.util.Arrays) Coin(org.bitcoinj.core.Coin) ListCell(javafx.scene.control.ListCell) Layout(bisq.desktop.util.Layout) StringUtils(org.apache.commons.lang3.StringUtils) BSFormatter(bisq.desktop.util.BSFormatter) InputTextField(bisq.desktop.components.InputTextField) ComboBox(javafx.scene.control.ComboBox) Res(bisq.core.locale.Res) BisqApp(bisq.desktop.app.BisqApp) Popup(bisq.desktop.main.overlays.popups.Popup) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder(bisq.desktop.util.FormBuilder) BlockChainExplorer(bisq.core.user.BlockChainExplorer) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) Collectors(java.util.stream.Collectors) List(java.util.List) CryptoCurrency(bisq.core.locale.CryptoCurrency) DevEnv(bisq.common.app.DevEnv) AnchorPane(javafx.scene.layout.AnchorPane) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) Preferences(bisq.core.user.Preferences) UserThread(bisq.common.UserThread) CountryUtil(bisq.core.locale.CountryUtil) Activatable(bisq.desktop.common.model.Activatable) FeeService(bisq.core.provider.fee.FeeService) ObservableList(javafx.collections.ObservableList) TradeCurrency(bisq.core.locale.TradeCurrency) ListView(javafx.scene.control.ListView) FXCollections(javafx.collections.FXCollections) FiatCurrency(bisq.core.locale.FiatCurrency) FxmlView(bisq.desktop.common.view.FxmlView) Inject(javax.inject.Inject) Tuple2(bisq.common.util.Tuple2) Tuple3(bisq.common.util.Tuple3) Insets(javafx.geometry.Insets) Country(bisq.core.locale.Country) VPos(javafx.geometry.VPos) CurrencyUtil(bisq.core.locale.CurrencyUtil) Callback(javafx.util.Callback) TitledGroupBg(bisq.desktop.components.TitledGroupBg) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) CheckBox(javafx.scene.control.CheckBox) BisqEnvironment(bisq.core.app.BisqEnvironment) StringConverter(javafx.util.StringConverter) TimeUnit(java.util.concurrent.TimeUnit) ImageUtil(bisq.desktop.util.ImageUtil) ImageView(javafx.scene.image.ImageView) LanguageUtil(bisq.core.locale.LanguageUtil) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) Insets(javafx.geometry.Insets) ListCell(javafx.scene.control.ListCell) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) Label(javafx.scene.control.Label) CryptoCurrency(bisq.core.locale.CryptoCurrency) ListView(javafx.scene.control.ListView) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) FiatCurrency(bisq.core.locale.FiatCurrency) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) AnchorPane(javafx.scene.layout.AnchorPane) TradeCurrency(bisq.core.locale.TradeCurrency) ComboBox(javafx.scene.control.ComboBox) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) TitledGroupBg(bisq.desktop.components.TitledGroupBg)

Aggregations

Popup (bisq.desktop.main.overlays.popups.Popup)57 Label (javafx.scene.control.Label)22 Coin (org.bitcoinj.core.Coin)17 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)16 Button (javafx.scene.control.Button)16 Res (bisq.core.locale.Res)13 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)13 Insets (javafx.geometry.Insets)13 InputTextField (bisq.desktop.components.InputTextField)12 BSFormatter (bisq.desktop.util.BSFormatter)12 Transaction (org.bitcoinj.core.Transaction)12 List (java.util.List)11 UserThread (bisq.common.UserThread)10 ChangeListener (javafx.beans.value.ChangeListener)9 BusyAnimation (bisq.desktop.components.BusyAnimation)8 ObservableList (javafx.collections.ObservableList)8 HBox (javafx.scene.layout.HBox)8 Tuple2 (bisq.common.util.Tuple2)7 FxmlView (bisq.desktop.common.view.FxmlView)7 TradeCurrency (bisq.core.locale.TradeCurrency)6