run trade charts view listeners on user thread to fix npe

This commit is contained in:
woodser 2025-03-05 08:39:03 -05:00 committed by GitHub
parent fff0fa0186
commit 5720ee74b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -208,29 +208,29 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
root.getChildren().addAll(toolBox, priceChartPane, volumeChartPane, tableView, footer);
timeUnitChangeListener = (observable, oldValue, newValue) -> {
timeUnitChangeListener = (observable, oldValue, newValue) -> UserThread.execute(() -> {
if (newValue != null) {
model.setTickUnit((TradesChartsViewModel.TickUnit) newValue.getUserData());
priceAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
volumeAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
volumeInUsdAxisX.setTickLabelFormatter(getTimeAxisStringConverter());
}
};
priceAxisYWidthListener = (observable, oldValue, newValue) -> {
});
priceAxisYWidthListener = (observable, oldValue, newValue) -> UserThread.execute(() -> {
priceAxisYWidth = (double) newValue;
layoutChart();
};
volumeAxisYWidthListener = (observable, oldValue, newValue) -> {
});
volumeAxisYWidthListener = (observable, oldValue, newValue) -> UserThread.execute(() -> {
volumeAxisYWidth = (double) newValue;
layoutChart();
};
tradeStatisticsByCurrencyListener = c -> {
});
tradeStatisticsByCurrencyListener = c -> UserThread.execute(() -> {
nrOfTradeStatisticsLabel.setText(Res.get("market.trades.nrOfTrades", model.tradeStatisticsByCurrency.size()));
fillList();
};
parentHeightListener = (observable, oldValue, newValue) -> layout();
});
parentHeightListener = (observable, oldValue, newValue) -> UserThread.execute(this::layout);
priceColumnLabelListener = (o, oldVal, newVal) -> priceColumn.setGraphic(new AutoTooltipLabel(newVal));
priceColumnLabelListener = (o, oldVal, newVal) -> UserThread.execute(() -> priceColumn.setGraphic(new AutoTooltipLabel(newVal)));
// Need to render on next frame as otherwise there are issues in the chart rendering
itemsChangeListener = c -> UserThread.execute(this::updateChartData);
@ -238,31 +238,34 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
currencySelectionBinding = EasyBind.combine(
model.showAllTradeCurrenciesProperty, model.selectedTradeCurrencyProperty,
(showAll, selectedTradeCurrency) -> {
priceChart.setVisible(!showAll);
priceChart.setManaged(!showAll);
priceColumn.setSortable(!showAll);
UserThread.execute(() -> {
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);
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());
volumeInUsdChart.setPrefHeight(volumeInUsdChart.getMaxHeight());
} else {
volumeChart.setPrefHeight(volumeChart.getMinHeight());
volumeInUsdChart.setPrefHeight(volumeInUsdChart.getMinHeight());
priceSeries.setName(selectedTradeCurrency.getName());
String code = selectedTradeCurrency.getCode();
volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", code)));
volumeChart.setPrefHeight(volumeChart.getMaxHeight());
volumeInUsdChart.setPrefHeight(volumeInUsdChart.getMaxHeight());
} else {
volumeChart.setPrefHeight(volumeChart.getMinHeight());
volumeInUsdChart.setPrefHeight(volumeInUsdChart.getMinHeight());
priceSeries.setName(selectedTradeCurrency.getName());
String code = selectedTradeCurrency.getCode();
volumeColumn.setGraphic(new AutoTooltipLabel(Res.get("shared.amountWithCur", code)));
priceColumnLabel.set(CurrencyUtil.getPriceWithCurrencyCode(code));
priceColumnLabel.set(CurrencyUtil.getPriceWithCurrencyCode(code));
tableView.getColumns().remove(marketColumn);
}
tableView.getColumns().remove(marketColumn);
}
layout();
});
layout();
return null;
});
}
@ -286,14 +289,14 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
currencyComboBox.getSelectionModel().select(model.getSelectedCurrencyListItem().get());
currencyComboBox.getEditor().setText(new CurrencyStringConverter(currencyComboBox).toString(currencyComboBox.getSelectionModel().getSelectedItem()));
currencyComboBox.setOnChangeConfirmed(e -> {
currencyComboBox.setOnChangeConfirmed(e -> UserThread.execute(() -> {
if (currencyComboBox.getEditor().getText().isEmpty())
currencyComboBox.getSelectionModel().select(SHOW_ALL);
CurrencyListItem selectedItem = currencyComboBox.getSelectionModel().getSelectedItem();
if (selectedItem != null) {
model.onSetTradeCurrency(selectedItem.tradeCurrency);
}
});
}));
toggleGroup.getToggles().get(model.tickUnit.ordinal()).setSelected(true);