Search in sources :

Example 1 with InfoAutoTooltipLabel

use of bisq.desktop.components.InfoAutoTooltipLabel in project bisq-desktop by bisq-network.

the class OfferBookView method getPriceColumn.

private AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> getPriceColumn() {
    AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>("") {

        {
            setMinWidth(100);
        }
    };
    column.getStyleClass().add("number-column");
    column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {

        @Override
        public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
            return new TableCell<OfferBookListItem, OfferBookListItem>() {

                private OfferBookListItem offerBookListItem;

                private ChangeListener<Number> priceChangedListener;

                ChangeListener<Scene> sceneChangeListener;

                @Override
                public void updateItem(final OfferBookListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        if (getTableView().getScene() != null && sceneChangeListener == null) {
                            sceneChangeListener = (observable, oldValue, newValue) -> {
                                if (newValue == null) {
                                    if (priceChangedListener != null) {
                                        model.priceFeedService.updateCounterProperty().removeListener(priceChangedListener);
                                        priceChangedListener = null;
                                    }
                                    offerBookListItem = null;
                                    setGraphic(null);
                                    getTableView().sceneProperty().removeListener(sceneChangeListener);
                                    sceneChangeListener = null;
                                }
                            };
                            getTableView().sceneProperty().addListener(sceneChangeListener);
                        }
                        this.offerBookListItem = item;
                        if (priceChangedListener == null) {
                            priceChangedListener = (observable, oldValue, newValue) -> {
                                if (offerBookListItem != null && offerBookListItem.getOffer().getPrice() != null) {
                                    setGraphic(getPriceLabel(model.getPrice(offerBookListItem), offerBookListItem));
                                }
                            };
                            model.priceFeedService.updateCounterProperty().addListener(priceChangedListener);
                        }
                        setGraphic(getPriceLabel(item.getOffer().getPrice() == null ? Res.get("shared.na") : model.getPrice(item), item));
                    } else {
                        if (priceChangedListener != null) {
                            model.priceFeedService.updateCounterProperty().removeListener(priceChangedListener);
                            priceChangedListener = null;
                        }
                        if (sceneChangeListener != null) {
                            getTableView().sceneProperty().removeListener(sceneChangeListener);
                            sceneChangeListener = null;
                        }
                        this.offerBookListItem = null;
                        setGraphic(null);
                    }
                }

                @NotNull
                private AutoTooltipLabel getPriceLabel(String priceString, OfferBookListItem item) {
                    final Offer offer = item.getOffer();
                    final MaterialDesignIcon icon = offer.isUseMarketBasedPrice() ? MaterialDesignIcon.CHART_LINE : MaterialDesignIcon.LOCK;
                    String info;
                    if (offer.isUseMarketBasedPrice()) {
                        if (offer.getMarketPriceMargin() == 0) {
                            if (offer.isBuyOffer()) {
                                info = Res.get("offerbook.info.sellAtMarketPrice");
                            } else {
                                info = Res.get("offerbook.info.buyAtMarketPrice");
                            }
                        } else if (offer.getMarketPriceMargin() > 0) {
                            if (offer.isBuyOffer()) {
                                info = Res.get("offerbook.info.sellBelowMarketPrice", model.getAbsolutePriceMargin(offer));
                            } else {
                                info = Res.get("offerbook.info.buyAboveMarketPrice", model.getAbsolutePriceMargin(offer));
                            }
                        } else {
                            if (offer.isBuyOffer()) {
                                info = Res.get("offerbook.info.sellAboveMarketPrice", model.getAbsolutePriceMargin(offer));
                            } else {
                                info = Res.get("offerbook.info.buyBelowMarketPrice", model.getAbsolutePriceMargin(offer));
                            }
                        }
                    } else {
                        if (offer.isBuyOffer()) {
                            info = Res.get("offerbook.info.sellAtFixedPrice");
                        } else {
                            info = Res.get("offerbook.info.buyAtFixedPrice");
                        }
                    }
                    return new InfoAutoTooltipLabel(priceString, icon, ContentDisplay.RIGHT, info);
                }
            };
        }
    });
    return column;
}
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) MaterialDesignIcon(de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon) Scene(javafx.scene.Scene) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) TableColumn(javafx.scene.control.TableColumn) NotNull(org.jetbrains.annotations.NotNull) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel) TableCell(javafx.scene.control.TableCell) Offer(bisq.core.offer.Offer) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) InfoAutoTooltipLabel(bisq.desktop.components.InfoAutoTooltipLabel)

Aggregations

Tuple3 (bisq.common.util.Tuple3)1 PrivateNotificationManager (bisq.core.alert.PrivateNotificationManager)1 AppOptionKeys (bisq.core.app.AppOptionKeys)1 FiatCurrency (bisq.core.locale.FiatCurrency)1 Res (bisq.core.locale.Res)1 TradeCurrency (bisq.core.locale.TradeCurrency)1 Price (bisq.core.monetary.Price)1 Volume (bisq.core.monetary.Volume)1 Offer (bisq.core.offer.Offer)1 OfferPayload (bisq.core.offer.OfferPayload)1 PaymentAccount (bisq.core.payment.PaymentAccount)1 PaymentMethod (bisq.core.payment.payload.PaymentMethod)1 DontShowAgainLookup (bisq.core.user.DontShowAgainLookup)1 Navigation (bisq.desktop.Navigation)1 ActivatableViewAndModel (bisq.desktop.common.view.ActivatableViewAndModel)1 FxmlView (bisq.desktop.common.view.FxmlView)1 AutoTooltipButton (bisq.desktop.components.AutoTooltipButton)1 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)1 AutoTooltipTableColumn (bisq.desktop.components.AutoTooltipTableColumn)1 ColoredDecimalPlacesWithZerosText (bisq.desktop.components.ColoredDecimalPlacesWithZerosText)1