mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 10:22:18 +01:00
Use new currency factories
This commit is contained in:
parent
10f1c795a5
commit
4f9ff4412a
@ -26,6 +26,7 @@ import bisq.desktop.components.ColoredDecimalPlacesWithZerosText;
|
||||
import bisq.desktop.main.market.trades.charts.price.CandleStickChart;
|
||||
import bisq.desktop.main.market.trades.charts.volume.VolumeChart;
|
||||
import bisq.desktop.util.CurrencyListItem;
|
||||
import bisq.desktop.util.FormBuilder;
|
||||
import bisq.desktop.util.GUIUtil;
|
||||
|
||||
import bisq.core.locale.CurrencyUtil;
|
||||
@ -38,12 +39,12 @@ import bisq.core.util.BSFormatter;
|
||||
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.util.MathUtils;
|
||||
import bisq.common.util.Tuple3;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.jfoenix.controls.JFXComboBox;
|
||||
import com.jfoenix.controls.JFXTabPane;
|
||||
|
||||
import javafx.scene.chart.NumberAxis;
|
||||
@ -441,14 +442,15 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private HBox getToolBox() {
|
||||
Label currencyLabel = new AutoTooltipLabel(Res.getWithCol("shared.currency"));
|
||||
currencyLabel.setPadding(new Insets(0, 4, 0, 0));
|
||||
|
||||
currencyComboBox = new JFXComboBox<>();
|
||||
final Tuple3<VBox, Label, ComboBox<CurrencyListItem>> currencyComboBoxTuple = FormBuilder.addTopLabelComboBox(Res.get("shared.currency"), Res.get("list.currency.select"), 10);
|
||||
currencyComboBox = currencyComboBoxTuple.third;
|
||||
currencyComboBox.setButtonCell(GUIUtil.getCurrencyListItemButtonCell(Res.get("shared.oneOffer"),
|
||||
Res.get("shared.multipleOffers"), model.preferences));
|
||||
currencyComboBox.setCellFactory(GUIUtil.getCurrencyListItemCellFactory(Res.get("shared.oneOffer"),
|
||||
Res.get("shared.multipleOffers"), model.preferences));
|
||||
|
||||
currencyComboBox.setPromptText(Res.get("list.currency.select"));
|
||||
currencyComboBox.setConverter(GUIUtil.getCurrencyListItemConverter(Res.get("shared.trade"),
|
||||
Res.get("shared.trades"),
|
||||
model.preferences));
|
||||
|
||||
Pane spacer = new Pane();
|
||||
HBox.setHgrow(spacer, Priority.ALWAYS);
|
||||
@ -468,7 +470,7 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
|
||||
hBox.setSpacing(0);
|
||||
hBox.setPadding(new Insets(5, 9, -10, 10));
|
||||
hBox.setAlignment(Pos.CENTER_LEFT);
|
||||
hBox.getChildren().addAll(currencyLabel, currencyComboBox, spacer, label, year, month, week, day, hour, minute10);
|
||||
hBox.getChildren().addAll(currencyComboBoxTuple.first, spacer, label, year, month, week, day, hour, minute10);
|
||||
return hBox;
|
||||
}
|
||||
|
||||
|
@ -272,34 +272,6 @@ public class GUIUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static StringConverter<CurrencyListItem> getCurrencyListItemConverter(String postFixSingle, String postFixMulti, Preferences preferences) {
|
||||
return new StringConverter<CurrencyListItem>() {
|
||||
@Override
|
||||
public String toString(CurrencyListItem item) {
|
||||
TradeCurrency tradeCurrency = item.tradeCurrency;
|
||||
String code = tradeCurrency.getCode();
|
||||
switch (code) {
|
||||
case GUIUtil.SHOW_ALL_FLAG:
|
||||
return "▶ " + Res.get("list.currency.showAll");
|
||||
case GUIUtil.EDIT_FLAG:
|
||||
return "▼ " + Res.get("list.currency.editList");
|
||||
default:
|
||||
String displayString = CurrencyUtil.getNameByCode(code) + " (" + code + ")";
|
||||
if (preferences.isSortMarketCurrenciesNumerically()) {
|
||||
final int numTrades = item.numTrades;
|
||||
displayString += " - " + numTrades + " " + (numTrades == 1 ? postFixSingle : postFixMulti);
|
||||
}
|
||||
return tradeCurrency.getDisplayPrefix() + displayString;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CurrencyListItem fromString(String s) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static ListCell<CurrencyListItem> getCurrencyListItemButtonCell(String postFixSingle, String postFixMulti,
|
||||
Preferences preferences) {
|
||||
return new ListCell<>() {
|
||||
@ -309,19 +281,30 @@ public class GUIUtil {
|
||||
super.updateItem(item, empty);
|
||||
|
||||
if (item != null && !empty) {
|
||||
String code = item.tradeCurrency.getCode();
|
||||
|
||||
AnchorPane pane = new AnchorPane();
|
||||
Label currency = new AutoTooltipLabel(item.tradeCurrency.getCode() + " - " + item.tradeCurrency.getName());
|
||||
currency.getStyleClass().add("currency-label-selected");
|
||||
AnchorPane.setLeftAnchor(currency, 0.0);
|
||||
pane.getChildren().add(currency);
|
||||
|
||||
if (preferences.isSortMarketCurrenciesNumerically()) {
|
||||
Label numberOfOffers = new AutoTooltipLabel(item.numTrades + " " +
|
||||
(item.numTrades == 1 ? postFixSingle : postFixMulti));
|
||||
numberOfOffers.getStyleClass().add("offer-label-small");
|
||||
AnchorPane.setRightAnchor(numberOfOffers, 0.0);
|
||||
AnchorPane.setBottomAnchor(numberOfOffers, 0.0);
|
||||
pane.getChildren().add(numberOfOffers);
|
||||
switch (code) {
|
||||
case GUIUtil.SHOW_ALL_FLAG:
|
||||
currency.setText("▶ " + Res.get("list.currency.showAll"));
|
||||
break;
|
||||
case GUIUtil.EDIT_FLAG:
|
||||
currency.setText(Res.get("▼ " + "list.currency.editList"));
|
||||
break;
|
||||
default:
|
||||
if (preferences.isSortMarketCurrenciesNumerically()) {
|
||||
Label numberOfOffers = new AutoTooltipLabel(item.numTrades + " " +
|
||||
(item.numTrades == 1 ? postFixSingle : postFixMulti));
|
||||
numberOfOffers.getStyleClass().add("offer-label-small");
|
||||
AnchorPane.setRightAnchor(numberOfOffers, 0.0);
|
||||
AnchorPane.setBottomAnchor(numberOfOffers, 0.0);
|
||||
pane.getChildren().add(numberOfOffers);
|
||||
}
|
||||
}
|
||||
|
||||
setGraphic(pane);
|
||||
@ -342,22 +325,39 @@ public class GUIUtil {
|
||||
super.updateItem(item, empty);
|
||||
|
||||
if (item != null && !empty) {
|
||||
|
||||
String code = item.tradeCurrency.getCode();
|
||||
|
||||
HBox box = new HBox();
|
||||
box.setSpacing(20);
|
||||
Label currencyType = new AutoTooltipLabel(
|
||||
CurrencyUtil.isFiatCurrency(item.tradeCurrency.getCode()) ? Res.get("shared.fiat") : Res.get("shared.crypto"));
|
||||
|
||||
currencyType.getStyleClass().add("currency-label-small");
|
||||
Label currency = new AutoTooltipLabel(item.tradeCurrency.getCode());
|
||||
currency.getStyleClass().add("currency-label");
|
||||
box.getChildren().addAll(currencyType, currency);
|
||||
|
||||
if (preferences.isSortMarketCurrenciesNumerically()) {
|
||||
Label offers = new AutoTooltipLabel(item.tradeCurrency.getName() + " (" + item.numTrades + " " +
|
||||
(item.numTrades == 1 ? postFixSingle : postFixMulti) + ")");
|
||||
offers.getStyleClass().add("currency-label");
|
||||
box.getChildren().add(offers);
|
||||
switch (code) {
|
||||
case GUIUtil.SHOW_ALL_FLAG:
|
||||
currencyType.setText("▶");
|
||||
currency.setText(Res.get("list.currency.showAll"));
|
||||
break;
|
||||
case GUIUtil.EDIT_FLAG:
|
||||
currencyType.setText("▼");
|
||||
currency.setText(Res.get("list.currency.editList"));
|
||||
break;
|
||||
default:
|
||||
if (preferences.isSortMarketCurrenciesNumerically()) {
|
||||
Label offers = new AutoTooltipLabel(item.tradeCurrency.getName() + " (" + item.numTrades + " " +
|
||||
(item.numTrades == 1 ? postFixSingle : postFixMulti) + ")");
|
||||
offers.getStyleClass().add("currency-label");
|
||||
box.getChildren().add(offers);
|
||||
}
|
||||
}
|
||||
|
||||
setGraphic(box);
|
||||
|
||||
} else {
|
||||
setGraphic(null);
|
||||
}
|
||||
|
@ -30,14 +30,8 @@ import java.util.Map;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static bisq.desktop.maker.CurrencyListItemMakers.bitcoinItem;
|
||||
import static bisq.desktop.maker.CurrencyListItemMakers.euroItem;
|
||||
import static bisq.desktop.maker.CurrencyListItemMakers.numberOfTrades;
|
||||
import static bisq.desktop.maker.PreferenceMakers.empty;
|
||||
import static bisq.desktop.maker.TradeCurrencyMakers.bitcoin;
|
||||
import static bisq.desktop.maker.TradeCurrencyMakers.euro;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.make;
|
||||
import static com.natpryce.makeiteasy.MakeItEasy.with;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class GUIUtilTest {
|
||||
@ -63,18 +57,4 @@ public class GUIUtilTest {
|
||||
assertEquals("✦ BTC (BTC) - 11 offers", tradeCurrencyConverter.toString(bitcoin));
|
||||
assertEquals("★ Euro (EUR) - 10 offers", tradeCurrencyConverter.toString(euro));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrencyListWithOffersConverter() {
|
||||
Res.setBaseCurrencyCode("BTC");
|
||||
Res.setBaseCurrencyName("Bitcoin");
|
||||
StringConverter<CurrencyListItem> currencyListItemConverter = GUIUtil.getCurrencyListItemConverter(Res.get("shared.oneOffer"),
|
||||
Res.get("shared.multipleOffers"),
|
||||
empty);
|
||||
|
||||
assertEquals("✦ BTC (BTC) - 10 offers", currencyListItemConverter.toString(make(bitcoinItem.but(with(numberOfTrades, 10)))));
|
||||
assertEquals("★ Euro (EUR) - 0 offers", currencyListItemConverter.toString(make(euroItem)));
|
||||
assertEquals("★ Euro (EUR) - 1 offer", currencyListItemConverter.toString(make(euroItem.but(with(numberOfTrades, 1)))));
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user