Search in sources :

Example 1 with CurrencyListItem

use of bisq.desktop.util.CurrencyListItem 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)

Example 2 with CurrencyListItem

use of bisq.desktop.util.CurrencyListItem in project bisq-desktop by bisq-network.

the class TradesChartsView 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.showAllTradeCurrenciesProperty.get())
        currencyComboBox.getSelectionModel().select(0);
    else 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);
    });
    toggleGroup.getToggles().get(model.tickUnit.ordinal()).setSelected(true);
    model.priceItems.addListener(itemsChangeListener);
    toggleGroup.selectedToggleProperty().addListener(timeUnitChangeListener);
    priceAxisY.widthProperty().addListener(priceAxisYWidthListener);
    volumeAxisY.widthProperty().addListener(volumeAxisYWidthListener);
    model.tradeStatisticsByCurrency.addListener(tradeStatisticsByCurrencyListener);
    priceAxisY.labelProperty().bind(priceColumnLabel);
    priceColumnLabel.addListener(priceColumnLabelListener);
    currencySelectionBinding = EasyBind.combine(model.showAllTradeCurrenciesProperty, model.selectedTradeCurrencyProperty, (showAll, selectedTradeCurrency) -> {
        priceChart.setVisible(!showAll);
        priceChart.setManaged(!showAll);
        priceColumn.setSortable(!showAll);
        if (showAll) {
            volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amount")));
            priceColumnLabel.set(Res.get("shared.price"));
            if (!tableView.getColumns().contains(marketColumn))
                tableView.getColumns().add(1, marketColumn);
            volumeChart.setPrefHeight(volumeChart.getMaxHeight());
        } else {
            volumeChart.setPrefHeight(volumeChart.getMinHeight());
            priceSeries.setName(selectedTradeCurrency.getName());
            String code = selectedTradeCurrency.getCode();
            volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", code)));
            priceColumnLabel.set(formatter.getPriceWithCurrencyCode(code));
            if (tableView.getColumns().contains(marketColumn))
                tableView.getColumns().remove(marketColumn);
        }
        layout();
        return null;
    });
    currencySelectionSubscriber = currencySelectionBinding.subscribe((observable, oldValue, newValue) -> {
    });
    sortedList = new SortedList<>(model.tradeStatisticsByCurrency);
    sortedList.comparatorProperty().bind(tableView.comparatorProperty());
    tableView.setItems(sortedList);
    priceChart.setAnimated(model.preferences.isUseAnimations());
    volumeChart.setAnimated(model.preferences.isUseAnimations());
    priceAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    volumeAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    nrOfTradeStatisticsLabel.setText(Res.get("market.trades.nrOfTrades", model.tradeStatisticsByCurrency.size()));
    UserThread.runAfter(this::updateChartData, 100, TimeUnit.MILLISECONDS);
    if (root.getParent() instanceof Pane) {
        rootParent = (Pane) root.getParent();
        rootParent.heightProperty().addListener(parentHeightListener);
    }
    layout();
}
Also used : Pos(javafx.geometry.Pos) VolumeChart(bisq.desktop.main.market.trades.charts.volume.VolumeChart) Coin(org.bitcoinj.core.Coin) Date(java.util.Date) 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) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) TableView(javafx.scene.control.TableView) Pane(javafx.scene.layout.Pane) SortedList(javafx.collections.transformation.SortedList) HBox(javafx.scene.layout.HBox) AutoTooltipTableColumn(bisq.desktop.components.AutoTooltipTableColumn) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) SingleSelectionModel(javafx.scene.control.SingleSelectionModel) Subscription(org.fxmisc.easybind.Subscription) MathUtils(bisq.common.util.MathUtils) Priority(javafx.scene.layout.Priority) ToggleButton(javafx.scene.control.ToggleButton) UserThread(bisq.common.UserThread) Toggle(javafx.scene.control.Toggle) NumberAxis(javafx.scene.chart.NumberAxis) StringProperty(javafx.beans.property.StringProperty) NotNull(org.jetbrains.annotations.NotNull) GUIUtil(bisq.desktop.util.GUIUtil) CurrencyListItem(bisq.desktop.util.CurrencyListItem) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) Volume(bisq.core.monetary.Volume) FxmlView(bisq.desktop.common.view.FxmlView) AutoTooltipToggleButton(bisq.desktop.components.AutoTooltipToggleButton) TableColumn(javafx.scene.control.TableColumn) Inject(javax.inject.Inject) TableCell(javafx.scene.control.TableCell) OfferPayload(bisq.core.offer.OfferPayload) Insets(javafx.geometry.Insets) CurrencyUtil(bisq.core.locale.CurrencyUtil) ColoredDecimalPlacesWithZerosText(bisq.desktop.components.ColoredDecimalPlacesWithZerosText) Callback(javafx.util.Callback) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) TradeStatistics2(bisq.core.trade.statistics.TradeStatistics2) StringConverter(javafx.util.StringConverter) CandleStickChart(bisq.desktop.main.market.trades.charts.price.CandleStickChart) TimeUnit(java.util.concurrent.TimeUnit) ToggleGroup(javafx.scene.control.ToggleGroup) EasyBind(org.fxmisc.easybind.EasyBind) Tab(javafx.scene.control.Tab) Price(bisq.core.monetary.Price) ActivatableViewAndModel(bisq.desktop.common.view.ActivatableViewAndModel) ChangeListener(javafx.beans.value.ChangeListener) CurrencyListItem(bisq.desktop.util.CurrencyListItem) AutoTooltipLabel(bisq.desktop.components.AutoTooltipLabel) TabPane(javafx.scene.control.TabPane) Pane(javafx.scene.layout.Pane)

Aggregations

UserThread (bisq.common.UserThread)2 CurrencyUtil (bisq.core.locale.CurrencyUtil)2 Res (bisq.core.locale.Res)2 OfferPayload (bisq.core.offer.OfferPayload)2 ActivatableViewAndModel (bisq.desktop.common.view.ActivatableViewAndModel)2 FxmlView (bisq.desktop.common.view.FxmlView)2 AutoTooltipLabel (bisq.desktop.components.AutoTooltipLabel)2 AutoTooltipTableColumn (bisq.desktop.components.AutoTooltipTableColumn)2 ColoredDecimalPlacesWithZerosText (bisq.desktop.components.ColoredDecimalPlacesWithZerosText)2 BSFormatter (bisq.desktop.util.BSFormatter)2 CurrencyListItem (bisq.desktop.util.CurrencyListItem)2 GUIUtil (bisq.desktop.util.GUIUtil)2 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 StringProperty (javafx.beans.property.StringProperty)2 ChangeListener (javafx.beans.value.ChangeListener)2 FXCollections (javafx.collections.FXCollections)2 ListChangeListener (javafx.collections.ListChangeListener)2 Insets (javafx.geometry.Insets)2 Pos (javafx.geometry.Pos)2