Search in sources :

Example 11 with StringConverter

use of javafx.util.StringConverter in project bisq-desktop by bisq-network.

the class ArbitratorRegistrationView method buildUI.

private void buildUI() {
    GridPane gridPane = new GridPane();
    gridPane.setPadding(new Insets(30, 25, -1, 25));
    gridPane.setHgap(5);
    gridPane.setVgap(5);
    ColumnConstraints columnConstraints1 = new ColumnConstraints();
    columnConstraints1.setHalignment(HPos.RIGHT);
    columnConstraints1.setHgrow(Priority.SOMETIMES);
    columnConstraints1.setMinWidth(200);
    ColumnConstraints columnConstraints2 = new ColumnConstraints();
    columnConstraints2.setHgrow(Priority.ALWAYS);
    gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2);
    root.getChildren().add(gridPane);
    addTitledGroupBg(gridPane, gridRow, 3, Res.get("account.tab.arbitratorRegistration"));
    TextField pubKeyTextField = FormBuilder.addLabelTextField(gridPane, gridRow, Res.get("account.arbitratorRegistration.pubKey"), model.registrationPubKeyAsHex.get(), Layout.FIRST_ROW_DISTANCE).second;
    pubKeyTextField.textProperty().bind(model.registrationPubKeyAsHex);
    Tuple2<Label, ListView> tuple = addLabelListView(gridPane, ++gridRow, Res.get("shared.yourLanguage"));
    GridPane.setValignment(tuple.first, VPos.TOP);
    // noinspection unchecked
    languagesListView = tuple.second;
    languagesListView.disableProperty().bind(model.registrationEditDisabled);
    languagesListView.setMinHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
    languagesListView.setMaxHeight(6 * Layout.LIST_ROW_HEIGHT + 2);
    languagesListView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {

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

                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 String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(LanguageUtil.getDisplayName(item));
                        removeButton.setOnAction(e -> onRemoveLanguage(item));
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    // noinspection unchecked
    languageComboBox = addLabelComboBox(gridPane, ++gridRow).second;
    languageComboBox.disableProperty().bind(model.registrationEditDisabled);
    languageComboBox.setPromptText(Res.get("shared.addLanguage"));
    languageComboBox.setConverter(new StringConverter<String>() {

        @Override
        public String toString(String code) {
            return LanguageUtil.getDisplayName(code);
        }

        @Override
        public String fromString(String s) {
            return null;
        }
    });
    languageComboBox.setOnAction(e -> onAddLanguage());
    Button registerButton = addButtonAfterGroup(gridPane, ++gridRow, Res.get("account.arbitratorRegistration.register"));
    registerButton.disableProperty().bind(model.registrationEditDisabled);
    registerButton.setOnAction(e -> onRegister());
    Button revokeButton = addButton(gridPane, ++gridRow, Res.get("account.arbitratorRegistration.revoke"));
    revokeButton.setDefaultButton(false);
    revokeButton.disableProperty().bind(model.revokeButtonDisabled);
    revokeButton.setOnAction(e -> onRevoke());
    addTitledGroupBg(gridPane, ++gridRow, 2, Res.get("shared.information"), Layout.GROUP_DISTANCE);
    Label infoLabel = addMultilineLabel(gridPane, gridRow);
    GridPane.setMargin(infoLabel, new Insets(Layout.FIRST_ROW_AND_GROUP_DISTANCE, 0, 0, 0));
    infoLabel.setText(Res.get("account.arbitratorRegistration.info.msg"));
}
Also used : Button(javafx.scene.control.Button) Arbitrator(bisq.core.arbitration.Arbitrator) HPos(javafx.geometry.HPos) ListView(javafx.scene.control.ListView) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ListCell(javafx.scene.control.ListCell) UnlockArbitrationRegistrationWindow(bisq.desktop.main.overlays.windows.UnlockArbitrationRegistrationWindow) Layout(bisq.desktop.util.Layout) VBox(javafx.scene.layout.VBox) FxmlView(bisq.desktop.common.view.FxmlView) Inject(javax.inject.Inject) Tuple2(bisq.common.util.Tuple2) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) ListChangeListener(javafx.collections.ListChangeListener) VPos(javafx.geometry.VPos) Res(bisq.core.locale.Res) Callback(javafx.util.Callback) GridPane(javafx.scene.layout.GridPane) Popup(bisq.desktop.main.overlays.popups.Popup) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder(bisq.desktop.util.FormBuilder) StringConverter(javafx.util.StringConverter) Priority(javafx.scene.layout.Priority) ImageUtil(bisq.desktop.util.ImageUtil) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) AppOptionKeys(bisq.core.app.AppOptionKeys) LanguageUtil(bisq.core.locale.LanguageUtil) UserThread(bisq.common.UserThread) Named(com.google.inject.name.Named) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) ColumnConstraints(javafx.scene.layout.ColumnConstraints) ListCell(javafx.scene.control.ListCell) Label(javafx.scene.control.Label) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) ListView(javafx.scene.control.ListView) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) TextField(javafx.scene.control.TextField) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) AnchorPane(javafx.scene.layout.AnchorPane)

Example 12 with StringConverter

use of javafx.util.StringConverter in project bisq-desktop by bisq-network.

the class ArbitratorSelectionView method addLanguageGroup.

// /////////////////////////////////////////////////////////////////////////////////////////
// UI builder
// /////////////////////////////////////////////////////////////////////////////////////////
private void addLanguageGroup() {
    addTitledGroupBg(root, gridRow, 1, Res.get("account.arbitratorSelection.whichLanguages"));
    Tuple2<Label, ListView> tuple = addLabelListView(root, gridRow, Res.get("shared.yourLanguage"), Layout.FIRST_ROW_DISTANCE);
    GridPane.setValignment(tuple.first, VPos.TOP);
    // noinspection unchecked
    languagesListView = tuple.second;
    languagesListView.setMinHeight(3 * Layout.LIST_ROW_HEIGHT + 2);
    languagesListView.setMaxHeight(6 * Layout.LIST_ROW_HEIGHT + 2);
    languagesListView.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {

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

                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 String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        label.setText(LanguageUtil.getDisplayName(item));
                        removeButton.setOnAction(e -> onRemoveLanguage(item));
                        setGraphic(pane);
                    } else {
                        setGraphic(null);
                    }
                }
            };
        }
    });
    // noinspection unchecked
    languageComboBox = addLabelComboBox(root, ++gridRow, "", 15).second;
    languageComboBox.setPromptText(Res.get("shared.addLanguage"));
    languageComboBox.setConverter(new StringConverter<String>() {

        @Override
        public String toString(String code) {
            return LanguageUtil.getDisplayName(code);
        }

        @Override
        public String fromString(String s) {
            return null;
        }
    });
    languageComboBox.setOnAction(e -> onAddLanguage());
}
Also used : TableGroupHeadline(bisq.desktop.components.TableGroupHeadline) Button(javafx.scene.control.Button) HPos(javafx.geometry.HPos) ListView(javafx.scene.control.ListView) ListCell(javafx.scene.control.ListCell) Layout(bisq.desktop.util.Layout) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) Tuple2(bisq.common.util.Tuple2) TableCell(javafx.scene.control.TableCell) FormBuilder.addLabelComboBox(bisq.desktop.util.FormBuilder.addLabelComboBox) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) VPos(javafx.geometry.VPos) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GridPane(javafx.scene.layout.GridPane) FormBuilder.addLabelListView(bisq.desktop.util.FormBuilder.addLabelListView) Popup(bisq.desktop.main.overlays.popups.Popup) Label(javafx.scene.control.Label) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) TableRow(javafx.scene.control.TableRow) FormBuilder.addTitledGroupBg(bisq.desktop.util.FormBuilder.addTitledGroupBg) CheckBox(javafx.scene.control.CheckBox) StringConverter(javafx.util.StringConverter) FormBuilder.addCheckBox(bisq.desktop.util.FormBuilder.addCheckBox) BooleanProperty(javafx.beans.property.BooleanProperty) ImageUtil(bisq.desktop.util.ImageUtil) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) LanguageUtil(bisq.core.locale.LanguageUtil) UserThread(bisq.common.UserThread) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) AutoTooltipCheckBox(bisq.desktop.components.AutoTooltipCheckBox) ChangeListener(javafx.beans.value.ChangeListener) ListCell(javafx.scene.control.ListCell) Label(javafx.scene.control.Label) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) ListView(javafx.scene.control.ListView) FormBuilder.addLabelListView(bisq.desktop.util.FormBuilder.addLabelListView) Button(javafx.scene.control.Button) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) ImageView(javafx.scene.image.ImageView) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) AnchorPane(javafx.scene.layout.AnchorPane)

Example 13 with StringConverter

use of javafx.util.StringConverter in project bisq-desktop by bisq-network.

the class OfferBookView method initialize.

@Override
public void initialize() {
    root.setPadding(new Insets(20, 25, 5, 25));
    addTitledGroupBg(root, gridRow, 2, Res.get("offerbook.availableOffers"));
    final Tuple3<HBox, AutoTooltipLabel, ComboBox> filterBoxTuple = addHBoxLabelComboBox(root, gridRow, Res.get("offerbook.filterByCurrency"), Layout.FIRST_ROW_DISTANCE);
    final HBox filterBox = filterBoxTuple.first;
    currencyComboBox = filterBoxTuple.third;
    currencyComboBox.setPromptText(Res.get("list.currency.select"));
    // noinspection unchecked
    paymentMethodComboBox = new ComboBox<>();
    final Label paymentMethodLabel = new AutoTooltipLabel(Res.getWithCol("offerbook.filterByPaymentMethod"));
    paymentMethodLabel.setPadding(new Insets(0, 0, 0, 10));
    filterBox.getChildren().addAll(paymentMethodLabel, paymentMethodComboBox);
    paymentMethodComboBox.setPromptText(Res.get("shared.selectPaymentMethod"));
    paymentMethodComboBox.setVisibleRowCount(20);
    paymentMethodComboBox.setConverter(new StringConverter<PaymentMethod>() {

        @Override
        public String toString(PaymentMethod paymentMethod) {
            String id = paymentMethod.getId();
            if (id.equals(GUIUtil.SHOW_ALL_FLAG))
                return "▶ " + Res.get("list.currency.showAll");
            else if (paymentMethod.equals(PaymentMethod.BLOCK_CHAINS))
                return "✦ " + Res.get(id);
            else
                return "★ " + Res.get(id);
        }

        @Override
        public PaymentMethod fromString(String s) {
            return null;
        }
    });
    tableView = new TableView<>();
    GridPane.setRowIndex(tableView, ++gridRow);
    GridPane.setColumnIndex(tableView, 0);
    GridPane.setColumnSpan(tableView, 2);
    GridPane.setMargin(tableView, new Insets(10, -10, -10, -10));
    GridPane.setVgrow(tableView, Priority.ALWAYS);
    root.getChildren().add(tableView);
    marketColumn = getMarketColumn();
    priceColumn = getPriceColumn();
    tableView.getColumns().add(priceColumn);
    amountColumn = getAmountColumn();
    tableView.getColumns().add(amountColumn);
    volumeColumn = getVolumeColumn();
    tableView.getColumns().add(volumeColumn);
    TableColumn<OfferBookListItem, OfferBookListItem> paymentMethodColumn = getPaymentMethodColumn();
    tableView.getColumns().add(paymentMethodColumn);
    TableColumn<OfferBookListItem, OfferBookListItem> avatarColumn = getAvatarColumn();
    tableView.getColumns().add(avatarColumn);
    tableView.getColumns().add(getActionColumn());
    tableView.getSortOrder().add(priceColumn);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.multipleOffers")));
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    marketColumn.setComparator((o1, o2) -> {
        String str1 = formatter.getCurrencyPair(o1.getOffer().getCurrencyCode());
        String str2 = formatter.getCurrencyPair(o2.getOffer().getCurrencyCode());
        return str1 != null && str2 != null ? str1.compareTo(str2) : 0;
    });
    priceColumn.setComparator((o1, o2) -> {
        Price price1 = o1.getOffer().getPrice();
        Price price2 = o2.getOffer().getPrice();
        return price1 != null && price2 != null ? price1.compareTo(price2) : 0;
    });
    amountColumn.setComparator(Comparator.comparing(o -> o.getOffer().getAmount()));
    volumeColumn.setComparator((o1, o2) -> {
        Volume offerVolume1 = o1.getOffer().getVolume();
        Volume offerVolume2 = o2.getOffer().getVolume();
        return offerVolume1 != null && offerVolume2 != null ? offerVolume1.compareTo(offerVolume2) : 0;
    });
    paymentMethodColumn.setComparator(Comparator.comparing(o -> o.getOffer().getPaymentMethod()));
    avatarColumn.setComparator(Comparator.comparing(o -> o.getOffer().getOwnerNodeAddress().getFullAddress()));
    nrOfOffersLabel = new AutoTooltipLabel("");
    nrOfOffersLabel.setId("num-offers");
    GridPane.setHalignment(nrOfOffersLabel, HPos.LEFT);
    GridPane.setVgrow(nrOfOffersLabel, Priority.NEVER);
    GridPane.setValignment(nrOfOffersLabel, VPos.TOP);
    GridPane.setRowIndex(nrOfOffersLabel, ++gridRow);
    GridPane.setColumnIndex(nrOfOffersLabel, 0);
    GridPane.setMargin(nrOfOffersLabel, new Insets(10, 0, 0, -5));
    root.getChildren().add(nrOfOffersLabel);
    createOfferButton = addButton(root, gridRow, "");
    createOfferButton.setMinHeight(40);
    createOfferButton.setPadding(new Insets(0, 20, 0, 20));
    createOfferButton.setGraphicTextGap(10);
    GridPane.setMargin(createOfferButton, new Insets(15, 0, 0, 0));
    GridPane.setHalignment(createOfferButton, HPos.RIGHT);
    GridPane.setVgrow(createOfferButton, Priority.NEVER);
    GridPane.setValignment(createOfferButton, VPos.TOP);
    offerListListener = c -> nrOfOffersLabel.setText(Res.get("offerbook.nrOffers", model.getOfferList().size()));
    // Fixes incorrect ordering of Available offers:
    // https://github.com/bisq-network/exchange/issues/588
    priceFeedUpdateCounterListener = (observable, oldValue, newValue) -> tableView.sort();
}
Also used : Button(javafx.scene.control.Button) HPos(javafx.geometry.HPos) HyperlinkWithIcon(bisq.desktop.components.HyperlinkWithIcon) ArbitratorSelectionView(bisq.desktop.main.account.content.arbitratorselection.ArbitratorSelectionView) Coin(org.bitcoinj.core.Coin) Layout(bisq.desktop.util.Layout) FiatAccountsView(bisq.desktop.main.account.content.fiataccounts.FiatAccountsView) BSFormatter(bisq.desktop.util.BSFormatter) FormBuilder.getIcon(bisq.desktop.util.FormBuilder.getIcon) ComboBox(javafx.scene.control.ComboBox) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) TableView(javafx.scene.control.TableView) Navigation(bisq.desktop.Navigation) HBox(javafx.scene.layout.HBox) Popup(bisq.desktop.main.overlays.popups.Popup) Offer(bisq.core.offer.Offer) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) FormBuilder.addTitledGroupBg(bisq.desktop.util.FormBuilder.addTitledGroupBg) Canvas(javafx.scene.canvas.Canvas) Subscription(org.fxmisc.easybind.Subscription) PaymentMethod(bisq.core.payment.payload.PaymentMethod) Priority(javafx.scene.layout.Priority) PaymentAccount(bisq.core.payment.PaymentAccount) NodeAddress(bisq.network.p2p.NodeAddress) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) AppOptionKeys(bisq.core.app.AppOptionKeys) AccountSettingsView(bisq.desktop.main.account.settings.AccountSettingsView) Optional(java.util.Optional) MaterialDesignIcon(de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon) NotNull(org.jetbrains.annotations.NotNull) GUIUtil(bisq.desktop.util.GUIUtil) Scene(javafx.scene.Scene) TradeCurrency(bisq.core.locale.TradeCurrency) FormBuilder.addHBoxLabelComboBox(bisq.desktop.util.FormBuilder.addHBoxLabelComboBox) OfferDetailsWindow(bisq.desktop.main.overlays.windows.OfferDetailsWindow) FiatCurrency(bisq.core.locale.FiatCurrency) Volume(bisq.core.monetary.Volume) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) WithdrawalView(bisq.desktop.main.funds.withdrawal.WithdrawalView) OfferPayload(bisq.core.offer.OfferPayload) Tuple3(bisq.common.util.Tuple3) Insets(javafx.geometry.Insets) VPos(javafx.geometry.VPos) ColoredDecimalPlacesWithZerosText(bisq.desktop.components.ColoredDecimalPlacesWithZerosText) Callback(javafx.util.Callback) FundsView(bisq.desktop.main.funds.FundsView) Tooltip(javafx.scene.control.Tooltip) AccountView(bisq.desktop.main.account.AccountView) PrivateNotificationManager(bisq.core.alert.PrivateNotificationManager) GridPane(javafx.scene.layout.GridPane) Label(javafx.scene.control.Label) TableRow(javafx.scene.control.TableRow) DontShowAgainLookup(bisq.core.user.DontShowAgainLookup) OfferView(bisq.desktop.main.offer.OfferView) StringConverter(javafx.util.StringConverter) PeerInfoIcon(bisq.desktop.components.PeerInfoIcon) FormBuilder.addButton(bisq.desktop.util.FormBuilder.addButton) MainView(bisq.desktop.main.MainView) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) Price(bisq.core.monetary.Price) ObservableValue(javafx.beans.value.ObservableValue) Named(com.google.inject.name.Named) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) Comparator(java.util.Comparator) ContentDisplay(javafx.scene.control.ContentDisplay) HBox(javafx.scene.layout.HBox) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) FormBuilder.addHBoxLabelComboBox(bisq.desktop.util.FormBuilder.addHBoxLabelComboBox) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel) Label(javafx.scene.control.Label) Price(bisq.core.monetary.Price) Volume(bisq.core.monetary.Volume) PaymentMethod(bisq.core.payment.payload.PaymentMethod) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel)

Example 14 with StringConverter

use of javafx.util.StringConverter in project bisq-desktop by bisq-network.

the class SelectBaseCurrencyWindow method addContent.

// /////////////////////////////////////////////////////////////////////////////////////////
// Protected
// /////////////////////////////////////////////////////////////////////////////////////////
private void addContent() {
    Label label = addMultilineLabel(gridPane, ++rowIndex, Res.get("selectBaseCurrencyWindow.msg", BisqEnvironment.getBaseCurrencyNetwork().getCurrencyName()), 10);
    GridPane.setMargin(label, new Insets(0, 0, 10, 0));
    Tuple2<Label, ComboBox> tuple = addLabelComboBox(gridPane, ++rowIndex, Res.get("selectBaseCurrencyWindow.select"));
    // noinspection unchecked
    comboBox = tuple.second;
    comboBox.setPromptText(Res.get("shared.select"));
    List<BaseCurrencyNetwork> baseCurrencyNetworks = Arrays.asList(BaseCurrencyNetwork.values());
    // show ony mainnet in production version
    if (!DevEnv.isDevMode())
        baseCurrencyNetworks = baseCurrencyNetworks.stream().filter(e -> e.isMainnet()).collect(Collectors.toList());
    comboBox.setItems(FXCollections.observableArrayList(baseCurrencyNetworks));
    comboBox.setConverter(new StringConverter<BaseCurrencyNetwork>() {

        @Override
        public String toString(BaseCurrencyNetwork baseCurrencyNetwork) {
            return DevEnv.isDevMode() ? (baseCurrencyNetwork.getCurrencyName() + "_" + baseCurrencyNetwork.getNetwork()) : baseCurrencyNetwork.getCurrencyName();
        }

        @Override
        public BaseCurrencyNetwork fromString(String string) {
            return null;
        }
    });
    comboBox.setOnAction(event -> {
        selectHandlerOptional.get().accept(comboBox.getSelectionModel().getSelectedItem());
        hide();
    });
}
Also used : Arrays(java.util.Arrays) Label(javafx.scene.control.Label) FXCollections(javafx.collections.FXCollections) BisqEnvironment(bisq.core.app.BisqEnvironment) StringConverter(javafx.util.StringConverter) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Consumer(java.util.function.Consumer) Tuple2(bisq.common.util.Tuple2) List(java.util.List) FormBuilder.addLabelComboBox(bisq.desktop.util.FormBuilder.addLabelComboBox) Insets(javafx.geometry.Insets) DevEnv(bisq.common.app.DevEnv) ComboBox(javafx.scene.control.ComboBox) Res(bisq.core.locale.Res) Overlay(bisq.desktop.main.overlays.Overlay) Optional(java.util.Optional) FormBuilder.addMultilineLabel(bisq.desktop.util.FormBuilder.addMultilineLabel) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) FormBuilder.addLabelComboBox(bisq.desktop.util.FormBuilder.addLabelComboBox) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) FormBuilder.addMultilineLabel(bisq.desktop.util.FormBuilder.addMultilineLabel) BaseCurrencyNetwork(bisq.core.btc.BaseCurrencyNetwork)

Example 15 with StringConverter

use of javafx.util.StringConverter in project bisq-desktop by bisq-network.

the class OfferBookChartView method activate.

@Override
protected void activate() {
    // root.getParent() is null at initialize
    tabPaneSelectionModel = GUIUtil.getParentOfType(root, TabPane.class).getSelectionModel();
    selectedTabIndexListener = (observable, oldValue, newValue) -> model.setSelectedTabIndex((int) newValue);
    model.setSelectedTabIndex(tabPaneSelectionModel.getSelectedIndex());
    tabPaneSelectionModel.selectedIndexProperty().addListener(selectedTabIndexListener);
    currencyComboBox.setItems(model.getCurrencyListItems());
    currencyComboBox.setVisibleRowCount(25);
    if (model.getSelectedCurrencyListItem().isPresent())
        currencyComboBox.getSelectionModel().select(model.getSelectedCurrencyListItem().get());
    currencyComboBox.setOnAction(e -> {
        CurrencyListItem selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
        if (selectedItem != null) {
            model.onSetTradeCurrency(selectedItem.tradeCurrency);
            updateChartData();
        }
    });
    model.currencyListItems.addListener(currencyListItemsListener);
    model.getOfferBookListItems().addListener(changeListener);
    tradeCurrencySubscriber = EasyBind.subscribe(model.selectedTradeCurrencyProperty, tradeCurrency -> {
        String code = tradeCurrency.getCode();
        areaChart.setTitle(Res.get("market.offerBook.chart.title", formatter.getCurrencyNameAndCurrencyPair(code)));
        volumeColumnLabel.set(Res.get("shared.amountWithCur", code));
        xAxis.setTickLabelFormatter(new StringConverter<Number>() {

            @Override
            public String toString(Number object) {
                final double doubleValue = (double) object;
                if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
                    final String withPrecision3 = formatter.formatRoundedDoubleWithPrecision(doubleValue, 3);
                    if (withPrecision3.equals("0.000"))
                        return formatter.formatRoundedDoubleWithPrecision(doubleValue, 8);
                    else
                        return withPrecision3;
                } else {
                    return formatter.formatRoundedDoubleWithPrecision(doubleValue, 2);
                }
            }

            @Override
            public Number fromString(String string) {
                return null;
            }
        });
        if (CurrencyUtil.isCryptoCurrency(code)) {
            if (bottomHBox.getChildren().size() == 2 && bottomHBox.getChildren().get(0).getUserData().equals(OfferPayload.Direction.BUY.name())) {
                bottomHBox.getChildren().get(0).toFront();
                reverseTableColumns();
            }
            leftHeaderLabel.setText(Res.get("market.offerBook.buyOffersHeaderLabel", code));
            leftButton.setText(Res.get("market.offerBook.buyAltcoin", code, Res.getBaseCurrencyCode()));
            rightHeaderLabel.setText(Res.get("market.offerBook.sellOffersHeaderLabel", code));
            rightButton.setText(Res.get("market.offerBook.sellAltcoin", code, Res.getBaseCurrencyCode()));
            priceColumnLabel.set(Res.get("shared.priceWithCur", Res.getBaseCurrencyCode()));
        } else {
            if (bottomHBox.getChildren().size() == 2 && bottomHBox.getChildren().get(0).getUserData().equals(OfferPayload.Direction.SELL.name())) {
                bottomHBox.getChildren().get(0).toFront();
                reverseTableColumns();
            }
            leftHeaderLabel.setText(Res.get("market.offerBook.sellOffersHeaderLabel", Res.getBaseCurrencyCode()));
            leftButton.setText(Res.get("market.offerBook.sellWithFiat", Res.getBaseCurrencyCode(), code));
            rightHeaderLabel.setText(Res.get("market.offerBook.buyOffersHeaderLabel", Res.getBaseCurrencyCode()));
            rightButton.setText(Res.get("market.offerBook.buyWithFiat", Res.getBaseCurrencyCode(), code));
            priceColumnLabel.set(Res.get("shared.priceWithCur", code));
        }
        xAxis.setLabel(formatter.getPriceWithCurrencyCode(code));
        seriesBuy.setName(leftHeaderLabel.getText() + "   ");
        seriesSell.setName(rightHeaderLabel.getText());
    });
    buyOfferTableView.setItems(model.getTopBuyOfferList());
    sellOfferTableView.setItems(model.getTopSellOfferList());
    buyTableRowSelectionListener = (observable, oldValue, newValue) -> {
        model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
        // noinspection unchecked
        navigation.navigateTo(MainView.class, SellOfferView.class);
    };
    sellTableRowSelectionListener = (observable, oldValue, newValue) -> {
        model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
        // noinspection unchecked
        navigation.navigateTo(MainView.class, BuyOfferView.class);
    };
    buyOfferTableView.getSelectionModel().selectedItemProperty().addListener(buyTableRowSelectionListener);
    sellOfferTableView.getSelectionModel().selectedItemProperty().addListener(sellTableRowSelectionListener);
    bisqWindowVerticalSizeListener = (observable, oldValue, newValue) -> {
        double newTableViewHeight = offerTableViewHeight.apply(newValue.doubleValue());
        if (buyOfferTableView.getHeight() != newTableViewHeight) {
            buyOfferTableView.setMinHeight(newTableViewHeight);
            sellOfferTableView.setMinHeight(newTableViewHeight);
        }
    };
    root.getScene().heightProperty().addListener(bisqWindowVerticalSizeListener);
    updateChartData();
}
Also used : Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) LoggerFactory(org.slf4j.LoggerFactory) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) BSFormatter(bisq.desktop.util.BSFormatter) TabPane(javafx.scene.control.TabPane) ComboBox(javafx.scene.control.ComboBox) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Res(bisq.core.locale.Res) TableView(javafx.scene.control.TableView) Navigation(bisq.desktop.Navigation) HBox(javafx.scene.layout.HBox) Offer(bisq.core.offer.Offer) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) Subscription(org.fxmisc.easybind.Subscription) OfferBookListItem(bisq.desktop.main.offer.offerbook.OfferBookListItem) Priority(javafx.scene.layout.Priority) AutoTooltipButton(bisq.desktop.components.AutoTooltipButton) UserThread(bisq.common.UserThread) AreaChart(javafx.scene.chart.AreaChart) NumberAxis(javafx.scene.chart.NumberAxis) ObservableList(javafx.collections.ObservableList) INITIAL_SCENE_HEIGHT(bisq.desktop.util.Layout.INITIAL_SCENE_HEIGHT) StringProperty(javafx.beans.property.StringProperty) GUIUtil(bisq.desktop.util.GUIUtil) CurrencyListItem(bisq.desktop.util.CurrencyListItem) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) Function(java.util.function.Function) FxmlView(bisq.desktop.common.view.FxmlView) TableColumn(javafx.scene.control.TableColumn) Tuple4(bisq.common.util.Tuple4) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) OfferPayload(bisq.core.offer.OfferPayload) Insets(javafx.geometry.Insets) BuyOfferView(bisq.desktop.main.offer.BuyOfferView) CurrencyUtil(bisq.core.locale.CurrencyUtil) ColoredDecimalPlacesWithZerosText(bisq.desktop.components.ColoredDecimalPlacesWithZerosText) Callback(javafx.util.Callback) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) SellOfferView(bisq.desktop.main.offer.SellOfferView) StringConverter(javafx.util.StringConverter) MainView(bisq.desktop.main.MainView) EasyBind(org.fxmisc.easybind.EasyBind) Tab(javafx.scene.control.Tab) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) Collections(java.util.Collections) CurrencyListItem(bisq.desktop.util.CurrencyListItem) StringConverter(javafx.util.StringConverter)

Aggregations

StringConverter (javafx.util.StringConverter)33 Label (javafx.scene.control.Label)14 Callback (javafx.util.Callback)14 FXCollections (javafx.collections.FXCollections)12 Insets (javafx.geometry.Insets)12 Button (javafx.scene.control.Button)11 ImageView (javafx.scene.image.ImageView)11 Inject (javax.inject.Inject)11 ChangeListener (javafx.beans.value.ChangeListener)10 ObservableList (javafx.collections.ObservableList)10 ComboBox (javafx.scene.control.ComboBox)10 Priority (javafx.scene.layout.Priority)9 Arrays (java.util.Arrays)8 List (java.util.List)8 ListChangeListener (javafx.collections.ListChangeListener)8 GridPane (javafx.scene.layout.GridPane)8 HBox (javafx.scene.layout.HBox)8 Consumer (java.util.function.Consumer)7 Res (bisq.core.locale.Res)6 VPos (javafx.geometry.VPos)6