use of bisq.desktop.components.AutoTooltipTableColumn in project bisq-desktop by bisq-network.
the class OfferBookView method getPaymentMethodColumn.
private TableColumn<OfferBookListItem, OfferBookListItem> getPaymentMethodColumn() {
TableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>(Res.get("shared.paymentMethod")) {
{
setMinWidth(80);
}
};
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {
@Override
public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
return new TableCell<OfferBookListItem, OfferBookListItem>() {
private HyperlinkWithIcon field;
@Override
public void updateItem(final OfferBookListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
field = new HyperlinkWithIcon(model.getPaymentMethod(item));
field.setOnAction(event -> offerDetailsWindow.show(item.getOffer()));
field.setTooltip(new Tooltip(model.getPaymentMethodToolTip(item)));
setGraphic(field);
} else {
setGraphic(null);
if (field != null)
field.setOnAction(null);
}
}
};
}
});
return column;
}
use of bisq.desktop.components.AutoTooltipTableColumn in project bisq-desktop by bisq-network.
the class OfferBookView method getActionColumn.
private TableColumn<OfferBookListItem, OfferBookListItem> getActionColumn() {
TableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>("") {
{
setMinWidth(80);
setSortable(false);
}
};
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {
@Override
public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
return new TableCell<OfferBookListItem, OfferBookListItem>() {
final ImageView iconView = new ImageView();
final Button button = new AutoTooltipButton();
boolean isTradable, isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isCurrencyBanned, isPaymentMethodBanned, isNodeAddressBanned, isInsufficientTradeLimit;
{
button.setGraphic(iconView);
button.setMinWidth(130);
button.setMaxWidth(130);
button.setGraphicTextGap(10);
}
@Override
public void updateItem(final OfferBookListItem newItem, boolean empty) {
super.updateItem(newItem, empty);
TableRow tableRow = getTableRow();
if (newItem != null && !empty) {
final Offer offer = newItem.getOffer();
boolean myOffer = model.isMyOffer(offer);
if (tableRow != null) {
isPaymentAccountValidForOffer = model.isAnyPaymentAccountValidForOffer(offer);
hasMatchingArbitrator = model.hasMatchingArbitrator(offer);
hasSameProtocolVersion = model.hasSameProtocolVersion(offer);
isIgnored = model.isIgnored(offer);
isOfferBanned = model.isOfferBanned(offer);
isCurrencyBanned = model.isCurrencyBanned(offer);
isPaymentMethodBanned = model.isPaymentMethodBanned(offer);
isNodeAddressBanned = model.isNodeAddressBanned(offer);
isInsufficientTradeLimit = model.isInsufficientTradeLimit(offer);
isTradable = isPaymentAccountValidForOffer && hasMatchingArbitrator && hasSameProtocolVersion && !isIgnored && !isOfferBanned && !isCurrencyBanned && !isPaymentMethodBanned && !isNodeAddressBanned && !isInsufficientTradeLimit;
tableRow.setOpacity(isTradable || myOffer ? 1 : 0.4);
if (isTradable) {
// set first row button as default
button.setDefaultButton(getIndex() == 0);
tableRow.setOnMousePressed(null);
} else {
button.setDefaultButton(false);
tableRow.setOnMousePressed(e -> {
// ugly hack to get the icon clickable when deactivated
if (!(e.getTarget() instanceof ImageView || e.getTarget() instanceof Canvas))
onShowInfo(offer, isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isCurrencyBanned, isPaymentMethodBanned, isNodeAddressBanned, isInsufficientTradeLimit);
});
}
}
String title;
if (myOffer) {
iconView.setId("image-remove");
title = Res.get("shared.remove");
button.setId("cancel-button");
// does not take the font colors sometimes from the style
button.setStyle("-fx-text-fill: #444;");
button.setOnAction(e -> onRemoveOpenOffer(offer));
} else {
boolean isSellOffer = offer.getDirection() == OfferPayload.Direction.SELL;
iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
button.setId(isSellOffer ? "buy-button" : "sell-button");
// does not take the font colors sometimes from the style
button.setStyle("-fx-text-fill: white;");
title = Res.get("offerbook.takeOffer");
button.setTooltip(new Tooltip(Res.get("offerbook.takeOfferButton.tooltip", model.getDirectionLabelTooltip(offer))));
button.setOnAction(e -> onTakeOffer(offer));
}
if (!myOffer && !isTradable)
button.setOnAction(e -> onShowInfo(offer, isPaymentAccountValidForOffer, hasMatchingArbitrator, hasSameProtocolVersion, isIgnored, isOfferBanned, isCurrencyBanned, isPaymentMethodBanned, isNodeAddressBanned, isInsufficientTradeLimit));
button.setText(title);
setGraphic(button);
} else {
setGraphic(null);
if (button != null)
button.setOnAction(null);
if (tableRow != null) {
tableRow.setOpacity(1);
tableRow.setOnMousePressed(null);
}
}
}
};
}
});
return column;
}
use of bisq.desktop.components.AutoTooltipTableColumn in project bisq-desktop by bisq-network.
the class OfferBookView method getVolumeColumn.
private AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> getVolumeColumn() {
AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>("") {
{
setMinWidth(125);
}
};
column.getStyleClass().add("number-column");
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {
@Override
public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
return new TableCell<OfferBookListItem, OfferBookListItem>() {
private OfferBookListItem offerBookListItem;
final ChangeListener<Number> listener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offerBookListItem != null && offerBookListItem.getOffer().getVolume() != null) {
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offerBookListItem), model.getNumberOfDecimalsForVolume(offerBookListItem)));
model.priceFeedService.updateCounterProperty().removeListener(listener);
}
}
};
@Override
public void updateItem(final OfferBookListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
if (item.getOffer().getPrice() == null) {
this.offerBookListItem = item;
model.priceFeedService.updateCounterProperty().addListener(listener);
setText(Res.get("shared.na"));
setGraphic(null);
} else {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(item), model.getNumberOfDecimalsForVolume(item)));
}
} else {
if (listener != null)
model.priceFeedService.updateCounterProperty().removeListener(listener);
this.offerBookListItem = null;
setText("");
setGraphic(null);
}
}
};
}
});
return column;
}
use of bisq.desktop.components.AutoTooltipTableColumn in project bisq-desktop by bisq-network.
the class OfferBookView method getPriceColumn.
private AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> getPriceColumn() {
AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem> column = new AutoTooltipTableColumn<OfferBookListItem, OfferBookListItem>("") {
{
setMinWidth(100);
}
};
column.getStyleClass().add("number-column");
column.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
column.setCellFactory(new Callback<TableColumn<OfferBookListItem, OfferBookListItem>, TableCell<OfferBookListItem, OfferBookListItem>>() {
@Override
public TableCell<OfferBookListItem, OfferBookListItem> call(TableColumn<OfferBookListItem, OfferBookListItem> column) {
return new TableCell<OfferBookListItem, OfferBookListItem>() {
private OfferBookListItem offerBookListItem;
private ChangeListener<Number> priceChangedListener;
ChangeListener<Scene> sceneChangeListener;
@Override
public void updateItem(final OfferBookListItem item, boolean empty) {
super.updateItem(item, empty);
if (item != null && !empty) {
if (getTableView().getScene() != null && sceneChangeListener == null) {
sceneChangeListener = (observable, oldValue, newValue) -> {
if (newValue == null) {
if (priceChangedListener != null) {
model.priceFeedService.updateCounterProperty().removeListener(priceChangedListener);
priceChangedListener = null;
}
offerBookListItem = null;
setGraphic(null);
getTableView().sceneProperty().removeListener(sceneChangeListener);
sceneChangeListener = null;
}
};
getTableView().sceneProperty().addListener(sceneChangeListener);
}
this.offerBookListItem = item;
if (priceChangedListener == null) {
priceChangedListener = (observable, oldValue, newValue) -> {
if (offerBookListItem != null && offerBookListItem.getOffer().getPrice() != null) {
setGraphic(getPriceLabel(model.getPrice(offerBookListItem), offerBookListItem));
}
};
model.priceFeedService.updateCounterProperty().addListener(priceChangedListener);
}
setGraphic(getPriceLabel(item.getOffer().getPrice() == null ? Res.get("shared.na") : model.getPrice(item), item));
} else {
if (priceChangedListener != null) {
model.priceFeedService.updateCounterProperty().removeListener(priceChangedListener);
priceChangedListener = null;
}
if (sceneChangeListener != null) {
getTableView().sceneProperty().removeListener(sceneChangeListener);
sceneChangeListener = null;
}
this.offerBookListItem = null;
setGraphic(null);
}
}
@NotNull
private AutoTooltipLabel getPriceLabel(String priceString, OfferBookListItem item) {
final Offer offer = item.getOffer();
final MaterialDesignIcon icon = offer.isUseMarketBasedPrice() ? MaterialDesignIcon.CHART_LINE : MaterialDesignIcon.LOCK;
String info;
if (offer.isUseMarketBasedPrice()) {
if (offer.getMarketPriceMargin() == 0) {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellAtMarketPrice");
} else {
info = Res.get("offerbook.info.buyAtMarketPrice");
}
} else if (offer.getMarketPriceMargin() > 0) {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellBelowMarketPrice", model.getAbsolutePriceMargin(offer));
} else {
info = Res.get("offerbook.info.buyAboveMarketPrice", model.getAbsolutePriceMargin(offer));
}
} else {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellAboveMarketPrice", model.getAbsolutePriceMargin(offer));
} else {
info = Res.get("offerbook.info.buyBelowMarketPrice", model.getAbsolutePriceMargin(offer));
}
}
} else {
if (offer.isBuyOffer()) {
info = Res.get("offerbook.info.sellAtFixedPrice");
} else {
info = Res.get("offerbook.info.buyAtFixedPrice");
}
}
return new InfoAutoTooltipLabel(priceString, icon, ContentDisplay.RIGHT, info);
}
};
}
});
return column;
}
use of bisq.desktop.components.AutoTooltipTableColumn in project bisq-desktop by bisq-network.
the class OfferBookChartView method getOfferTable.
private Tuple4<TableView<OfferListItem>, VBox, Button, Label> getOfferTable(OfferPayload.Direction direction) {
TableView<OfferListItem> tableView = new TableView<>();
tableView.setMinHeight(initialOfferTableViewHeight);
tableView.setPrefHeight(121);
tableView.setMinWidth(480);
tableView.getStyleClass().add("offer-table");
// price
TableColumn<OfferListItem, OfferListItem> priceColumn = new TableColumn<>();
priceColumn.textProperty().bind(priceColumnLabel);
priceColumn.setMinWidth(115);
priceColumn.setMaxWidth(115);
priceColumn.setSortable(false);
priceColumn.getStyleClass().add("number-column");
priceColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
priceColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {
@Override
public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
return new TableCell<OfferListItem, OfferListItem>() {
private Offer offer;
final ChangeListener<Number> listener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offer != null && offer.getPrice() != null) {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
model.priceFeedService.updateCounterProperty().removeListener(listener);
}
}
};
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty) {
final Offer offer = offerListItem.offer;
if (offer.getPrice() == null) {
this.offer = offer;
model.priceFeedService.updateCounterProperty().addListener(listener);
setText(Res.get("shared.na"));
} else {
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getPrice(offer), model.getZeroDecimalsForPrice(offer)));
}
} else {
if (listener != null)
model.priceFeedService.updateCounterProperty().removeListener(listener);
this.offer = null;
setText("");
setGraphic(null);
}
}
};
}
});
// volume
TableColumn<OfferListItem, OfferListItem> volumeColumn = new TableColumn<>();
volumeColumn.setMinWidth(115);
volumeColumn.setSortable(false);
volumeColumn.textProperty().bind(volumeColumnLabel);
volumeColumn.getStyleClass().add("number-column");
volumeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
volumeColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {
@Override
public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
return new TableCell<OfferListItem, OfferListItem>() {
private Offer offer;
final ChangeListener<Number> listener = new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
if (offer != null && offer.getPrice() != null) {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
model.priceFeedService.updateCounterProperty().removeListener(listener);
}
}
};
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty) {
this.offer = offerListItem.offer;
if (offer.getPrice() == null) {
this.offer = offerListItem.offer;
model.priceFeedService.updateCounterProperty().addListener(listener);
setText(Res.get("shared.na"));
} else {
setText("");
setGraphic(new ColoredDecimalPlacesWithZerosText(model.getVolume(offer), model.getMaxNumberOfPriceZeroDecimalsToColorize(offer)));
}
} else {
if (listener != null)
model.priceFeedService.updateCounterProperty().removeListener(listener);
this.offer = null;
setText("");
setGraphic(null);
}
}
};
}
});
// amount
TableColumn<OfferListItem, OfferListItem> amountColumn = new AutoTooltipTableColumn<>(Res.get("shared.amountWithCur", Res.getBaseCurrencyCode()));
amountColumn.setMinWidth(115);
amountColumn.setSortable(false);
amountColumn.getStyleClass().add("number-column");
amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
amountColumn.setCellFactory(new Callback<TableColumn<OfferListItem, OfferListItem>, TableCell<OfferListItem, OfferListItem>>() {
@Override
public TableCell<OfferListItem, OfferListItem> call(TableColumn<OfferListItem, OfferListItem> column) {
return new TableCell<OfferListItem, OfferListItem>() {
@Override
public void updateItem(final OfferListItem offerListItem, boolean empty) {
super.updateItem(offerListItem, empty);
if (offerListItem != null && !empty) {
setGraphic(new ColoredDecimalPlacesWithZerosText(formatter.formatCoin(offerListItem.offer.getAmount(), 4), GUIUtil.AMOUNT_DECIMALS_WITH_ZEROS));
} else {
setGraphic(null);
}
}
};
}
});
tableView.getColumns().add(volumeColumn);
tableView.getColumns().add(amountColumn);
tableView.getColumns().add(priceColumn);
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noItems", Res.get("shared.multipleOffers")));
placeholder.setWrapText(true);
tableView.setPlaceholder(placeholder);
Label titleLabel = new AutoTooltipLabel();
titleLabel.getStyleClass().add("table-title");
UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));
boolean isSellOffer = direction == OfferPayload.Direction.SELL;
Button button = new AutoTooltipButton();
ImageView iconView = new ImageView();
iconView.setId(isSellOffer ? "image-buy-white" : "image-sell-white");
button.setGraphic(iconView);
button.setGraphicTextGap(10);
button.setText(isSellOffer ? Res.get("market.offerBook.buy") : Res.get("market.offerBook.sell"));
button.setMinHeight(40);
button.setId(isSellOffer ? "buy-button-big" : "sell-button-big");
button.setOnAction(e -> {
if (isSellOffer) {
model.preferences.setBuyScreenCurrencyCode(model.getCurrencyCode());
// noinspection unchecked
navigation.navigateTo(MainView.class, BuyOfferView.class);
} else {
model.preferences.setSellScreenCurrencyCode(model.getCurrencyCode());
// noinspection unchecked
navigation.navigateTo(MainView.class, SellOfferView.class);
}
});
VBox vBox = new VBox();
vBox.setSpacing(10);
vBox.setFillWidth(true);
vBox.setMinHeight(190);
vBox.setVgrow(tableView, Priority.ALWAYS);
vBox.getChildren().addAll(titleLabel, tableView, button);
button.prefWidthProperty().bind(vBox.widthProperty());
return new Tuple4<>(tableView, vBox, button, titleLabel);
}
Aggregations