Merge pull request #1482 from ripcurlx/add-info-tooltips-for-offer-table

Add info icons to prices in offer table
This commit is contained in:
Manfred Karrer 2018-03-28 08:35:03 -05:00 committed by GitHub
commit 57d657b6bf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 159 additions and 4 deletions

View file

@ -0,0 +1,87 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop.components;
import bisq.common.UserThread;
import org.controlsfx.control.PopOver;
import javafx.scene.Node;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.text.Text;
import javafx.geometry.Insets;
import java.util.concurrent.TimeUnit;
import static bisq.desktop.util.FormBuilder.getIcon;
import de.jensd.fx.glyphs.GlyphIcons;
public class InfoAutoTooltipLabel extends AutoTooltipLabel {
private Text textIcon;
private Boolean hidePopover;
private PopOver infoPopover;
public InfoAutoTooltipLabel(String text, GlyphIcons icon, ContentDisplay contentDisplay, String info) {
super(text);
textIcon = getIcon(icon);
textIcon.setOpacity(0.4);
textIcon.setOnMouseEntered(e -> {
hidePopover = false;
final Label helpLabel = new Label(info);
helpLabel.setMaxWidth(300);
helpLabel.setWrapText(true);
helpLabel.setPadding(new Insets(10));
showInfoPopOver(helpLabel);
});
textIcon.setOnMouseExited(e -> {
if (infoPopover != null)
infoPopover.hide();
hidePopover = true;
UserThread.runAfter(() -> {
if (hidePopover) {
infoPopover.hide();
hidePopover = false;
}
}, 250, TimeUnit.MILLISECONDS);
});
setGraphic(textIcon);
setContentDisplay(contentDisplay);
}
private void showInfoPopOver(Node node) {
node.getStyleClass().add("default-text");
infoPopover = new PopOver(node);
if (textIcon.getScene() != null) {
infoPopover.setDetachable(false);
infoPopover.setArrowLocation(PopOver.ArrowLocation.LEFT_CENTER);
infoPopover.show(textIcon, -10);
}
}
}

View file

@ -1,3 +1,20 @@
/*
* This file is part of Bisq.
*
* Bisq is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bisq is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/
package bisq.desktop.components;
import bisq.common.UserThread;

View file

@ -25,6 +25,7 @@ import bisq.desktop.components.AutoTooltipLabel;
import bisq.desktop.components.AutoTooltipTableColumn;
import bisq.desktop.components.ColoredDecimalPlacesWithZerosText;
import bisq.desktop.components.HyperlinkWithIcon;
import bisq.desktop.components.InfoAutoTooltipLabel;
import bisq.desktop.components.PeerInfoIcon;
import bisq.desktop.main.MainView;
import bisq.desktop.main.account.AccountView;
@ -67,6 +68,7 @@ import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ContentDisplay;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
@ -98,9 +100,16 @@ import javafx.util.StringConverter;
import java.util.Comparator;
import java.util.Optional;
import org.jetbrains.annotations.NotNull;
import static bisq.desktop.util.FormBuilder.addButton;
import static bisq.desktop.util.FormBuilder.addHBoxLabelComboBox;
import static bisq.desktop.util.FormBuilder.addTitledGroupBg;
import static bisq.desktop.util.FormBuilder.getIcon;
import de.jensd.fx.glyphs.materialdesignicons.MaterialDesignIcon;
@FxmlView
public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookViewModel> {
@ -608,7 +617,7 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
priceChangedListener = null;
}
offerBookListItem = null;
setText("");
setGraphic(null);
getTableView().sceneProperty().removeListener(sceneChangeListener);
sceneChangeListener = null;
}
@ -621,12 +630,12 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
if (priceChangedListener == null) {
priceChangedListener = (observable, oldValue, newValue) -> {
if (offerBookListItem != null && offerBookListItem.getOffer().getPrice() != null) {
setText(model.getPrice(offerBookListItem));
setGraphic(getPriceLabel(model.getPrice(offerBookListItem), offerBookListItem));
}
};
model.priceFeedService.updateCounterProperty().addListener(priceChangedListener);
}
setText(item.getOffer().getPrice() == null ? Res.get("shared.na") : model.getPrice(item));
setGraphic(getPriceLabel(item.getOffer().getPrice() == null ? Res.get("shared.na") : model.getPrice(item), item));
} else {
if (priceChangedListener != null) {
model.priceFeedService.updateCounterProperty().removeListener(priceChangedListener);
@ -637,9 +646,47 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
sceneChangeListener = null;
}
this.offerBookListItem = null;
setText("");
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);
}
};
}
});

View file

@ -364,6 +364,10 @@ class OfferBookViewModel extends ActivatableViewModel {
}
}
String getAbsolutePriceMargin(Offer offer) {
return formatter.formatPercentagePrice(Math.abs(offer.getMarketPriceMargin()));
}
private String formatPrice(Offer offer, boolean decimalAligned) {
return formatter.formatPrice(offer.getPrice(), decimalAligned, maxPlacesForPrice.get());
}