mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-20 23:56:30 -04:00
Make market price display invertable by click on field
This commit is contained in:
parent
4010f5a727
commit
b2552b968c
@ -153,7 +153,7 @@ public class BitsquareApp extends Application {
|
||||
mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
|
||||
});*/
|
||||
|
||||
scene = new Scene(mainView.getRoot(), 1060, 740);
|
||||
scene = new Scene(mainView.getRoot(), 1100, 740);
|
||||
scene.getStylesheets().setAll(
|
||||
"/io/bitsquare/gui/bitsquare.css",
|
||||
"/io/bitsquare/gui/images.css");
|
||||
|
@ -992,4 +992,11 @@ textfield */
|
||||
|
||||
.popup-icon-warning {
|
||||
-fx-text-fill: #dd6900;
|
||||
}
|
||||
}
|
||||
|
||||
#price-feed-text-field {
|
||||
-fx-alignment: center;
|
||||
-fx-background-color: #555;
|
||||
-fx-text-fill: white;
|
||||
-fx-cursor: hand;
|
||||
}
|
||||
|
@ -36,6 +36,8 @@ import io.bitsquare.gui.main.overlays.popups.Popup;
|
||||
import io.bitsquare.gui.main.portfolio.PortfolioView;
|
||||
import io.bitsquare.gui.main.settings.SettingsView;
|
||||
import io.bitsquare.gui.util.Transitions;
|
||||
import javafx.beans.property.BooleanProperty;
|
||||
import javafx.beans.property.SimpleBooleanProperty;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.geometry.Pos;
|
||||
@ -134,12 +136,17 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
|
||||
}};
|
||||
|
||||
Tuple3<TextField, Label, VBox> marketPriceBox = getMarketPriceBox("Market price");
|
||||
final BooleanProperty priceInverted = new SimpleBooleanProperty(false);
|
||||
marketPriceBox.first.setOnMouseClicked(e -> priceInverted.setValue(!priceInverted.get()));
|
||||
marketPriceBox.first.textProperty().bind(createStringBinding(
|
||||
() -> {
|
||||
return model.marketPrice.get() + " " +
|
||||
model.marketPriceCurrency.get() + "/BTC";
|
||||
},
|
||||
model.marketPriceCurrency, model.marketPrice));
|
||||
() -> (priceInverted.get() ?
|
||||
model.marketPriceInverted.get() :
|
||||
model.marketPrice.get()) +
|
||||
(priceInverted.get() ?
|
||||
" BTC/" + model.marketPriceCurrency.get() :
|
||||
" " + model.marketPriceCurrency.get() + "/BTC"),
|
||||
model.marketPriceCurrency, model.marketPrice, priceInverted));
|
||||
|
||||
marketPriceBox.second.textProperty().bind(createStringBinding(
|
||||
() -> {
|
||||
PriceFeed.Type type = model.typeProperty.get();
|
||||
@ -256,10 +263,9 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
|
||||
private Tuple3<TextField, Label, VBox> getMarketPriceBox(String text) {
|
||||
TextField textField = new TextField();
|
||||
textField.setEditable(false);
|
||||
textField.setPrefWidth(150);
|
||||
textField.setMouseTransparent(true);
|
||||
textField.setPrefWidth(180);
|
||||
textField.setFocusTraversable(false);
|
||||
textField.setStyle("-fx-alignment: center; -fx-background-color: -bs-bg-grey;");
|
||||
textField.setId("price-feed-text-field");
|
||||
|
||||
Label label = new Label(text);
|
||||
label.setId("nav-balance-label");
|
||||
@ -497,11 +503,6 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
|
||||
notification.getChildren().addAll(icon, label);
|
||||
notification.visibleProperty().bind(model.showPendingTradesNotification);
|
||||
buttonHolder.getChildren().add(notification);
|
||||
|
||||
/* model.showPendingTradesNotification.addListener((ov, oldValue, newValue) -> {
|
||||
if (newValue)
|
||||
SystemNotification.openInfoNotification(title, "You received a new trade message.");
|
||||
});*/
|
||||
}
|
||||
|
||||
private void setupDisputesIcon(Pane buttonHolder) {
|
||||
@ -521,11 +522,6 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
|
||||
notification.getChildren().addAll(icon, label);
|
||||
notification.visibleProperty().bind(model.showOpenDisputesNotification);
|
||||
buttonHolder.getChildren().add(notification);
|
||||
|
||||
/* model.showOpenDisputesNotification.addListener((ov, oldValue, newValue) -> {
|
||||
if (newValue)
|
||||
SystemNotification.openInfoNotification(title, "You received a dispute message.");
|
||||
});*/
|
||||
}
|
||||
|
||||
private class NavButton extends ToggleButton {
|
||||
|
@ -101,6 +101,7 @@ public class MainViewModel implements ViewModel {
|
||||
final StringProperty walletServiceErrorMsg = new SimpleStringProperty();
|
||||
final StringProperty btcSplashSyncIconId = new SimpleStringProperty();
|
||||
final StringProperty marketPrice = new SimpleStringProperty("N/A");
|
||||
final StringProperty marketPriceInverted = new SimpleStringProperty("N/A");
|
||||
final StringProperty marketPriceCurrency = new SimpleStringProperty("");
|
||||
final ObjectProperty<PriceFeed.Type> typeProperty = new SimpleObjectProperty<>(PriceFeed.Type.LAST);
|
||||
final StringProperty availableBalance = new SimpleStringProperty();
|
||||
@ -609,9 +610,11 @@ public class MainViewModel implements ViewModel {
|
||||
priceFeed.setType(PriceFeed.Type.LAST);
|
||||
priceFeed.init(price -> {
|
||||
marketPrice.set(formatter.formatMarketPrice(price));
|
||||
marketPriceInverted.set(formatter.formatMarketPrice(1 / price, 8));
|
||||
},
|
||||
(errorMessage, throwable) -> {
|
||||
marketPrice.set("N/A");
|
||||
marketPriceInverted.set("N/A");
|
||||
});
|
||||
marketPriceCurrency.bind(priceFeed.currencyCodeProperty());
|
||||
typeProperty.bind(priceFeed.typeProperty());
|
||||
|
@ -27,6 +27,8 @@ import io.bitsquare.gui.main.offer.BuyOfferView;
|
||||
import io.bitsquare.gui.main.offer.SellOfferView;
|
||||
import io.bitsquare.gui.main.offer.offerbook.OfferBookListItem;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.locale.CryptoCurrency;
|
||||
import io.bitsquare.locale.FiatCurrency;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
@ -86,7 +88,13 @@ public class MarketsChartsView extends ActivatableViewAndModel<VBox, MarketsChar
|
||||
currencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
|
||||
@Override
|
||||
public String toString(TradeCurrency tradeCurrency) {
|
||||
return tradeCurrency.getNameAndCode();
|
||||
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
|
||||
if (tradeCurrency instanceof FiatCurrency)
|
||||
return "★ " + tradeCurrency.getNameAndCode();
|
||||
else if (tradeCurrency instanceof CryptoCurrency)
|
||||
return "✦ " + tradeCurrency.getNameAndCode();
|
||||
else
|
||||
return "-";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -158,7 +166,7 @@ public class MarketsChartsView extends ActivatableViewAndModel<VBox, MarketsChar
|
||||
tableView.setMinHeight(100);
|
||||
tableView.setMaxHeight(100);
|
||||
tableView.setMinWidth(390);
|
||||
// tableView.setMouseTransparent(true);
|
||||
tableView.setMouseTransparent(true);
|
||||
|
||||
// price
|
||||
TableColumn<Offer, Offer> priceColumn = new TableColumn<>();
|
||||
|
@ -34,6 +34,8 @@ import io.bitsquare.gui.main.overlays.popups.Popup;
|
||||
import io.bitsquare.gui.main.overlays.windows.OfferDetailsWindow;
|
||||
import io.bitsquare.gui.util.Layout;
|
||||
import io.bitsquare.locale.BSResources;
|
||||
import io.bitsquare.locale.CryptoCurrency;
|
||||
import io.bitsquare.locale.FiatCurrency;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
import io.bitsquare.payment.PaymentMethod;
|
||||
import io.bitsquare.trade.offer.Offer;
|
||||
@ -94,12 +96,17 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
@Override
|
||||
public String toString(TradeCurrency tradeCurrency) {
|
||||
String code = tradeCurrency.getCode();
|
||||
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
|
||||
if (code.equals(OfferBookViewModel.SHOW_ALL_FLAG))
|
||||
return ">> Show all";
|
||||
return "▶ Show all";
|
||||
else if (code.equals(OfferBookViewModel.EDIT_FLAG))
|
||||
return ">> Edit currency list";
|
||||
return "▼ Edit currency list";
|
||||
else if (tradeCurrency instanceof FiatCurrency)
|
||||
return "★ " + tradeCurrency.getNameAndCode();
|
||||
else if (tradeCurrency instanceof CryptoCurrency)
|
||||
return "✦ " + tradeCurrency.getNameAndCode();
|
||||
else
|
||||
return tradeCurrency.getNameAndCode();
|
||||
return "-";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -114,7 +121,12 @@ public class OfferBookView extends ActivatableViewAndModel<GridPane, OfferBookVi
|
||||
@Override
|
||||
public String toString(PaymentMethod paymentMethod) {
|
||||
String id = paymentMethod.getId();
|
||||
return BSResources.get(!id.equals(OfferBookViewModel.SHOW_ALL_FLAG) ? id : ">> Show all");
|
||||
if (id.equals(OfferBookViewModel.SHOW_ALL_FLAG))
|
||||
return "▶ Show all";
|
||||
else if (paymentMethod.equals(PaymentMethod.BLOCK_CHAINS))
|
||||
return "✦ " + BSResources.get(id);
|
||||
else
|
||||
return "★ " + BSResources.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -136,11 +136,17 @@ public class PreferencesView extends ActivatableViewAndModel<GridPane, Activatab
|
||||
preferredTradeCurrencyComboBox.setConverter(new StringConverter<TradeCurrency>() {
|
||||
@Override
|
||||
public String toString(TradeCurrency tradeCurrency) {
|
||||
return tradeCurrency.getNameAndCode();
|
||||
// http://boschista.deviantart.com/journal/Cool-ASCII-Symbols-214218618
|
||||
if (tradeCurrency instanceof FiatCurrency)
|
||||
return "★ " + tradeCurrency.getNameAndCode();
|
||||
else if (tradeCurrency instanceof CryptoCurrency)
|
||||
return "✦ " + tradeCurrency.getNameAndCode();
|
||||
else
|
||||
return "-";
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeCurrency fromString(String string) {
|
||||
public TradeCurrency fromString(String s) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
@ -263,20 +263,13 @@ public class BSFormatter {
|
||||
}
|
||||
|
||||
public String formatMarketPrice(double price) {
|
||||
if (price > 0) {
|
||||
String str = String.valueOf(price);
|
||||
int decPoint = str.indexOf(".");
|
||||
if (decPoint > 0) {
|
||||
while (str.length() < decPoint + 3) {
|
||||
str += "0";
|
||||
}
|
||||
return str.substring(0, decPoint + 3);
|
||||
} else {
|
||||
return str;
|
||||
}
|
||||
} else {
|
||||
return "N/A";
|
||||
}
|
||||
return formatMarketPrice(price, 3);
|
||||
}
|
||||
|
||||
public String formatMarketPrice(double price, int decimals) {
|
||||
DecimalFormat df = new DecimalFormat("#.#");
|
||||
df.setMaximumFractionDigits(decimals);
|
||||
return df.format(price);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user