mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Add initial formatting for OfferBookView
This commit is contained in:
parent
021e02d17f
commit
477567b2f4
@ -82,10 +82,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
private ComboBox<TradeCurrency> currencyComboBox;
|
||||
private ComboBox<PaymentMethod> paymentMethodComboBox;
|
||||
private Button createOfferButton;
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> amountColumn;
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> volumeColumn;
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> marketColumn;
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> priceColumn;
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> amountColumn, volumeColumn, marketColumn, priceColumn;
|
||||
private TableView<OfferBookListItem> tableView;
|
||||
|
||||
private OfferView.OfferActionHandler offerActionHandler;
|
||||
@ -491,7 +488,8 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> getAmountColumn() {
|
||||
TableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>(Res.get("shared.BTCMinMax"));
|
||||
column.setMinWidth(150);
|
||||
column.setMinWidth(100);
|
||||
column.getStyleClass().add("number-column");
|
||||
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
|
||||
column.setCellFactory(
|
||||
new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem,
|
||||
@ -504,9 +502,9 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
public void updateItem(final OfferBookListItem item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
if (item != null && !empty)
|
||||
setText(model.getAmount(item));
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getAmount(item)));
|
||||
else
|
||||
setText("");
|
||||
setGraphic(null);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -517,8 +515,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> getMarketColumn() {
|
||||
TableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>(Res.get("shared.market")) {
|
||||
{
|
||||
setMinWidth(120);
|
||||
// setMaxWidth(130);
|
||||
setMinWidth(40);
|
||||
}
|
||||
};
|
||||
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
|
||||
@ -548,9 +545,10 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> getPriceColumn() {
|
||||
TableColumn<OfferBookListItem, OfferBookListItem> column = new TableColumn<OfferBookListItem, OfferBookListItem>() {
|
||||
{
|
||||
setMinWidth(120);
|
||||
setMinWidth(100);
|
||||
}
|
||||
};
|
||||
column.getStyleClass().add("number-column");
|
||||
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
|
||||
column.setCellFactory(
|
||||
new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem,
|
||||
@ -620,6 +618,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
setMinWidth(125);
|
||||
}
|
||||
};
|
||||
column.getStyleClass().add("number-column");
|
||||
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
|
||||
column.setCellFactory(
|
||||
new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem,
|
||||
@ -633,7 +632,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
|
||||
if (offerBookListItem != null && offerBookListItem.getOffer().getVolume() != null) {
|
||||
setText(model.getVolume(offerBookListItem));
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offerBookListItem)));
|
||||
model.priceFeedService.updateCounterProperty().removeListener(listener);
|
||||
}
|
||||
}
|
||||
@ -648,13 +647,15 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
model.priceFeedService.updateCounterProperty().addListener(listener);
|
||||
setText(Res.get("shared.na"));
|
||||
} else {
|
||||
setText(model.getVolume(item));
|
||||
setText("");
|
||||
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(item)));
|
||||
}
|
||||
} else {
|
||||
if (listener != null)
|
||||
model.priceFeedService.updateCounterProperty().removeListener(listener);
|
||||
this.offerBookListItem = null;
|
||||
setText("");
|
||||
setGraphic(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -666,7 +667,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
private TableColumn<OfferBookListItem, OfferBookListItem> getPaymentMethodColumn() {
|
||||
TableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>(Res.get("shared.paymentMethod")) {
|
||||
{
|
||||
setMinWidth(125);
|
||||
setMinWidth(80);
|
||||
}
|
||||
};
|
||||
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
|
||||
|
@ -277,12 +277,7 @@ class OfferBookViewModel extends ActivatableViewModel {
|
||||
|
||||
String getAmount(OfferBookListItem item) {
|
||||
Offer offer = item.getOffer();
|
||||
Coin amount = offer.getAmount();
|
||||
Coin minAmount = offer.getMinAmount();
|
||||
if (amount.equals(minAmount))
|
||||
return formatter.formatAmount(offer);
|
||||
else
|
||||
return formatter.formatAmountWithMinAmount(offer);
|
||||
return formatter.formatAmount(offer, 4, true);
|
||||
}
|
||||
|
||||
String getPrice(OfferBookListItem item) {
|
||||
|
@ -58,7 +58,7 @@ class OpenOffersViewModel extends ActivatableWithDataModel<OpenOffersDataModel>
|
||||
}
|
||||
|
||||
String getAmount(OpenOfferListItem item) {
|
||||
return (item != null) ? formatter.formatAmountWithMinAmount(item.getOffer()) : "";
|
||||
return (item != null) ? formatter.formatAmount(item.getOffer()) : "";
|
||||
}
|
||||
|
||||
String getPrice(OpenOfferListItem item) {
|
||||
|
@ -268,18 +268,18 @@ public class BSFormatter {
|
||||
String formattedVolume = formatVolume(volume);
|
||||
|
||||
if(decimalAligned) {
|
||||
formattedVolume = fillUpPlacesWithEmptyStrings(formattedVolume, 5);
|
||||
formattedVolume = fillUpPlacesWithEmptyStrings(formattedVolume, 8);
|
||||
}
|
||||
return formattedVolume;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String fillUpPlacesWithEmptyStrings(String formattedVolume, int maxNumberOfDigits) {
|
||||
int numberOfPlacesToFill = maxNumberOfDigits - formattedVolume.split("\\.")[0].length();
|
||||
private String fillUpPlacesWithEmptyStrings(String formattedNumber, int maxNumberOfDigits) {
|
||||
int numberOfPlacesToFill = maxNumberOfDigits - formattedNumber.length();
|
||||
for (int i = 0; i < numberOfPlacesToFill; i++) {
|
||||
formattedVolume = " " + formattedVolume;
|
||||
formattedNumber = " " + formattedNumber;
|
||||
}
|
||||
return formattedVolume;
|
||||
return formattedNumber;
|
||||
}
|
||||
|
||||
public String formatVolume(Volume volume) {
|
||||
@ -342,11 +342,24 @@ public class BSFormatter {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String formatAmount(Offer offer) {
|
||||
return formatCoin(offer.getAmount());
|
||||
return formatAmount(offer, false);
|
||||
}
|
||||
|
||||
public String formatAmountWithMinAmount(Offer offer) {
|
||||
return offer.isRange() ? formatCoin(offer.getMinAmount()) + " - " + formatCoin(offer.getAmount()) : formatCoin(offer.getAmount());
|
||||
public String formatAmount(Offer offer, boolean decimalAligned) {
|
||||
String formattedAmount = offer.isRange() ? formatCoin(offer.getMinAmount()) + " - " + formatCoin(offer.getAmount()) : formatCoin(offer.getAmount());
|
||||
if(decimalAligned) {
|
||||
formattedAmount = fillUpPlacesWithEmptyStrings(formattedAmount, 15);
|
||||
}
|
||||
return formattedAmount;
|
||||
}
|
||||
|
||||
public String formatAmount(Offer offer, int decimalPlaces, boolean decimalAligned) {
|
||||
String formattedAmount = offer.isRange() ? formatCoin(offer.getMinAmount(), decimalPlaces) + " - " + formatCoin(offer.getAmount(), decimalPlaces) : formatCoin(offer.getAmount(), decimalPlaces);
|
||||
|
||||
if(decimalAligned) {
|
||||
formattedAmount = fillUpPlacesWithEmptyStrings(formattedAmount, 15);
|
||||
}
|
||||
return formattedAmount;
|
||||
}
|
||||
|
||||
|
||||
@ -375,7 +388,7 @@ public class BSFormatter {
|
||||
String formattedPrice = formatPrice(price);
|
||||
|
||||
if(decimalAligned) {
|
||||
formattedPrice = fillUpPlacesWithEmptyStrings(formattedPrice, 5);
|
||||
formattedPrice = fillUpPlacesWithEmptyStrings(formattedPrice, 10);
|
||||
}
|
||||
return formattedPrice;
|
||||
}
|
||||
|
@ -146,7 +146,7 @@ public class BSFormatterTest {
|
||||
when(offer.getMinAmount()).thenReturn(Coin.valueOf(10000000));
|
||||
when(offer.getAmount()).thenReturn(Coin.valueOf(10000000));
|
||||
|
||||
assertEquals("0.10", formatter.formatAmountWithMinAmount(offer));
|
||||
assertEquals("0.10", formatter.formatAmount(offer));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -156,7 +156,27 @@ public class BSFormatterTest {
|
||||
when(offerPayload.getMinAmount()).thenReturn(10000000L);
|
||||
when(offerPayload.getAmount()).thenReturn(20000000L);
|
||||
|
||||
assertEquals("0.10 - 0.20", formatter.formatAmountWithMinAmount(offer));
|
||||
assertEquals("0.10 - 0.20", formatter.formatAmount(offer));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatAmountWithAlignmenWithDecimals() {
|
||||
OfferPayload offerPayload = mock(OfferPayload.class);
|
||||
Offer offer = new Offer(offerPayload);
|
||||
when(offerPayload.getMinAmount()).thenReturn(10000000L);
|
||||
when(offerPayload.getAmount()).thenReturn(20000000L);
|
||||
|
||||
assertEquals("0.1000 - 0.2000", formatter.formatAmount(offer, 4,true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatAmountWithAlignmenWithDecimalsNoRange() {
|
||||
OfferPayload offerPayload = mock(OfferPayload.class);
|
||||
Offer offer = new Offer(offerPayload);
|
||||
when(offerPayload.getMinAmount()).thenReturn(10000000L);
|
||||
when(offerPayload.getAmount()).thenReturn(10000000L);
|
||||
|
||||
assertEquals(" 0.1000", formatter.formatAmount(offer, 4,true));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -165,6 +185,7 @@ public class BSFormatterTest {
|
||||
when(offer.getMinAmount()).thenReturn(null);
|
||||
when(offer.getAmount()).thenReturn(null);
|
||||
|
||||
assertEquals("", formatter.formatAmountWithMinAmount(offer));
|
||||
assertEquals("", formatter.formatAmount(offer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user