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();
}
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();
}
Aggregations