Search in sources :

Example 6 with SortedList

use of javafx.collections.transformation.SortedList in project bitsquare by bitsquare.

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);
    priceColumn.textProperty().bind(priceColumnLabel);
    currencySelectionBinding = EasyBind.combine(model.showAllTradeCurrenciesProperty, model.selectedTradeCurrencyProperty, (showAll, selectedTradeCurrency) -> {
        priceChart.setVisible(!showAll);
        priceChart.setManaged(!showAll);
        priceColumn.setSortable(!showAll);
        if (showAll) {
            volumeColumn.setText("Amount");
            priceColumnLabel.set("Price");
            if (!tableView.getColumns().contains(marketColumn))
                tableView.getColumns().add(1, marketColumn);
        } else {
            priceSeries.setName(selectedTradeCurrency.getName());
            String code = selectedTradeCurrency.getCode();
            volumeColumn.setText("Amount in " + code);
            priceColumnLabel.set(formatter.getPriceWithCurrencyCode(code));
            if (tableView.getColumns().contains(marketColumn))
                tableView.getColumns().remove(marketColumn);
        }
        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.getUseAnimations());
    volumeChart.setAnimated(model.preferences.getUseAnimations());
    priceAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    volumeAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
    nrOfTradeStatisticsLabel.setText("Trades: " + model.tradeStatisticsByCurrency.size());
    UserThread.runAfter(this::updateChartData, 100, TimeUnit.MILLISECONDS);
}
Also used : MathUtils(io.bitsquare.common.util.MathUtils) Pos(javafx.geometry.Pos) javafx.scene.control(javafx.scene.control) Date(java.util.Date) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Coin(org.bitcoinj.core.Coin) LoggerFactory(org.slf4j.LoggerFactory) CandleStickChart(io.bitsquare.gui.main.market.trades.charts.price.CandleStickChart) FXCollections(javafx.collections.FXCollections) XYChart(javafx.scene.chart.XYChart) VBox(javafx.scene.layout.VBox) GUIUtil(io.bitsquare.gui.util.GUIUtil) Inject(javax.inject.Inject) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) TradeStatistics(io.bitsquare.trade.statistics.TradeStatistics) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) Callback(javafx.util.Callback) BSFormatter(io.bitsquare.gui.util.BSFormatter) SortedList(javafx.collections.transformation.SortedList) Pane(javafx.scene.layout.Pane) HBox(javafx.scene.layout.HBox) Logger(org.slf4j.Logger) VolumeChart(io.bitsquare.gui.main.market.trades.charts.volume.VolumeChart) CurrencyListItem(io.bitsquare.gui.util.CurrencyListItem) UserThread(io.bitsquare.common.UserThread) Fiat(org.bitcoinj.utils.Fiat) StringConverter(javafx.util.StringConverter) Subscription(org.fxmisc.easybind.Subscription) ActivatableViewAndModel(io.bitsquare.gui.common.view.ActivatableViewAndModel) TimeUnit(java.util.concurrent.TimeUnit) Priority(javafx.scene.layout.Priority) EasyBind(org.fxmisc.easybind.EasyBind) NumberAxis(javafx.scene.chart.NumberAxis) FxmlView(io.bitsquare.gui.common.view.FxmlView) CurrencyUtil(io.bitsquare.locale.CurrencyUtil) StringProperty(javafx.beans.property.StringProperty) ChangeListener(javafx.beans.value.ChangeListener) NotNull(org.jetbrains.annotations.NotNull) BSResources(io.bitsquare.locale.BSResources) CurrencyListItem(io.bitsquare.gui.util.CurrencyListItem)

Aggregations

SortedList (javafx.collections.transformation.SortedList)6 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)5 FilteredList (javafx.collections.transformation.FilteredList)5 ObservableList (javafx.collections.ObservableList)4 Callback (javafx.util.Callback)4 TimeUnit (java.util.concurrent.TimeUnit)3 ChangeListener (javafx.beans.value.ChangeListener)3 Dispute (io.bitsquare.arbitration.Dispute)2 UserThread (io.bitsquare.common.UserThread)2 FxmlView (io.bitsquare.gui.common.view.FxmlView)2 BSFormatter (io.bitsquare.gui.util.BSFormatter)2 GUIUtil (io.bitsquare.gui.util.GUIUtil)2 BigDecimal (java.math.BigDecimal)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ResourceBundle (java.util.ResourceBundle)2 ObjectProperty (javafx.beans.property.ObjectProperty)2