added invert icon again

This commit is contained in:
Manfred Karrer 2016-06-26 19:39:00 +02:00
parent aad658334e
commit 575bd7d183
6 changed files with 88 additions and 29 deletions

View File

@ -13,10 +13,21 @@ public class MarketPrice {
private final double last;
public MarketPrice(String currencyCode, String ask, String bid, String last) {
this(currencyCode, ask, bid, last, false);
}
public MarketPrice(String currencyCode, String ask, String bid, String last, boolean invert) {
this.currencyCode = currencyCode;
this.ask = parseDouble(ask);
this.bid = parseDouble(bid);
this.last = parseDouble(last);
if (invert) {
this.ask = 1d / parseDouble(ask);
this.bid = 1d / parseDouble(bid);
this.last = 1d / parseDouble(last);
} else {
this.ask = parseDouble(ask);
this.bid = parseDouble(bid);
this.last = parseDouble(last);
}
}
public double getPrice(PriceFeed.Type type) {

View File

@ -50,7 +50,7 @@ public class PoloniexPriceProvider implements PriceProvider {
temp.clear();
treeMap2.entrySet().stream().forEach(e2 -> temp.put(e2.getKey(), e2.getValue().toString()));
marketPriceMap.put(otherCurrency,
new MarketPrice(otherCurrency, temp.get("lowestAsk"), temp.get("highestBid"), temp.get("last")));
new MarketPrice(otherCurrency, temp.get("lowestAsk"), temp.get("highestBid"), temp.get("last"), true));
}
}
}

View File

@ -117,12 +117,7 @@ public final class Preferences implements Persistable {
private TradeCurrency preferredTradeCurrency;
private long nonTradeTxFeePerKB = FeePolicy.getNonTradeFeePerKb().value;
private double maxPriceDistanceInPercent;
// Need to keep it for backward compatibility. Not used anymore from v0.4.9 on.
// TODO Can be removed once we don't support old versions anymore.
@Deprecated
private boolean useInvertedMarketPrice;
private String marketScreenCurrencyCode = CurrencyUtil.getDefaultTradeCurrency().getCode();
private String buyScreenCurrencyCode = CurrencyUtil.getDefaultTradeCurrency().getCode();
private String sellScreenCurrencyCode = CurrencyUtil.getDefaultTradeCurrency().getCode();
@ -138,7 +133,7 @@ public final class Preferences implements Persistable {
transient private final ObservableList<FiatCurrency> fiatCurrenciesAsObservable = FXCollections.observableArrayList();
transient private final ObservableList<CryptoCurrency> cryptoCurrenciesAsObservable = FXCollections.observableArrayList();
transient private final ObservableList<TradeCurrency> tradeCurrenciesAsObservable = FXCollections.observableArrayList();
transient private final BooleanProperty useInvertedMarketPriceProperty = new SimpleBooleanProperty(useInvertedMarketPrice);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
@ -155,7 +150,8 @@ public final class Preferences implements Persistable {
if (persisted != null) {
setBtcDenomination(persisted.btcDenomination);
setUseAnimations(persisted.useAnimations);
setUseInvertedMarketPrice(persisted.useInvertedMarketPrice);
setFiatCurrencies(persisted.fiatCurrencies);
fiatCurrencies = new ArrayList<>(fiatCurrenciesAsObservable);
@ -231,6 +227,10 @@ public final class Preferences implements Persistable {
staticUseAnimations = useAnimations;
storage.queueUpForSave(2000);
});
useInvertedMarketPriceProperty.addListener((ov) -> {
useInvertedMarketPrice = useInvertedMarketPriceProperty.get();
storage.queueUpForSave(2000);
});
fiatCurrenciesAsObservable.addListener((Observable ov) -> {
fiatCurrencies.clear();
fiatCurrencies.addAll(fiatCurrenciesAsObservable);
@ -271,6 +271,10 @@ public final class Preferences implements Persistable {
this.useAnimationsProperty.set(useAnimations);
}
public void setUseInvertedMarketPrice(boolean useInvertedMarketPrice) {
this.useInvertedMarketPriceProperty.set(useInvertedMarketPrice);
}
public void setBitcoinNetwork(BitcoinNetwork bitcoinNetwork) {
if (this.bitcoinNetwork != bitcoinNetwork)
bitsquareEnvironment.saveBitcoinNetwork(bitcoinNetwork);
@ -377,6 +381,11 @@ public final class Preferences implements Persistable {
storage.queueUpForSave();
}
public boolean flipUseInvertedMarketPrice() {
setUseInvertedMarketPrice(!getUseInvertedMarketPrice());
return getUseInvertedMarketPrice();
}
public void setUseStickyMarketPrice(boolean useStickyMarketPrice) {
this.useStickyMarketPrice = useStickyMarketPrice;
storage.queueUpForSave();
@ -447,6 +456,14 @@ public final class Preferences implements Persistable {
return staticUseAnimations;
}
public boolean getUseInvertedMarketPrice() {
return useInvertedMarketPriceProperty.get();
}
public BooleanProperty useInvertedMarketPriceProperty() {
return useInvertedMarketPriceProperty;
}
public BitcoinNetwork getBitcoinNetwork() {
return bitcoinNetwork;
}

View File

@ -163,7 +163,7 @@ public class BitsquareApp extends Application {
mainView.setPersistedFilesCorrupted(corruptedDatabaseFiles);
});*/
scene = new Scene(mainView.getRoot(), 1190, 740);
scene = new Scene(mainView.getRoot(), 1200, 740);
Font.loadFont(getClass().getResource("/fonts/Verdana.ttf").toExternalForm(), 13);
Font.loadFont(getClass().getResource("/fonts/VerdanaBold.ttf").toExternalForm(), 13);
@ -200,7 +200,7 @@ public class BitsquareApp extends Application {
// configure the primary stage
primaryStage.setTitle(env.getRequiredProperty(APP_NAME_KEY));
primaryStage.setScene(scene);
primaryStage.setMinWidth(1170);
primaryStage.setMinWidth(1190);
primaryStage.setMinHeight(620);
// on windows the title icon is also used as task bar icon in a larger size

View File

@ -159,7 +159,7 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
return type != null ? "Market price (" + type.name + ")" : "";
},
model.marketPriceCurrencyCode, model.typeProperty));
HBox.setMargin(marketPriceBox.third, new Insets(0, 15, 0, 0));
HBox.setMargin(marketPriceBox.third, new Insets(0, 0, 0, 0));
Tuple2<TextField, VBox> availableBalanceBox = getBalanceBox("Available balance");
@ -284,8 +284,8 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
private Tuple3<ComboBox<PriceFeedComboBoxItem>, Label, VBox> getMarketPriceBox(String text) {
ComboBox<PriceFeedComboBoxItem> priceComboBox = new ComboBox<>();
priceComboBox.setVisibleRowCount(40);
priceComboBox.setMaxWidth(210);
priceComboBox.setMinWidth(210);
priceComboBox.setMaxWidth(220);
priceComboBox.setMinWidth(220);
priceComboBox.setFocusTraversable(false);
priceComboBox.setId("price-feed-combo");
priceComboBox.setCellFactory(p -> getPriceFeedComboBoxListCell());
@ -293,10 +293,22 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
buttonCell.setId("price-feed-combo");
priceComboBox.setButtonCell(buttonCell);
final ImageView invertIcon = new ImageView();
invertIcon.setId("invert");
final Button invertIconButton = new Button("", invertIcon);
invertIconButton.setPadding(new Insets(0, 0, 0, 0));
invertIconButton.setFocusTraversable(false);
invertIconButton.setStyle("-fx-background-color: transparent;");
HBox.setMargin(invertIconButton, new Insets(2, 0, 0, 0));
invertIconButton.setOnAction(e -> model.preferences.flipUseInvertedMarketPrice());
HBox hBox1 = new HBox();
hBox1.getChildren().setAll(priceComboBox, invertIconButton);
Label label = new Label(text);
label.setId("nav-balance-label");
label.setTextAlignment(TextAlignment.CENTER);
label.setPadding(new Insets(0, 5, 0, 6));
label.setPadding(new Insets(0, 25, 0, 0));
final ImageView btcAverageIcon = new ImageView();
btcAverageIcon.setId("btcaverage");
@ -304,7 +316,7 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
btcAverageIconButton.setPadding(new Insets(-1, 0, -1, 0));
btcAverageIconButton.setFocusTraversable(false);
btcAverageIconButton.setStyle("-fx-background-color: transparent;");
HBox.setMargin(btcAverageIconButton, new Insets(0, 7, 0, 0));
HBox.setMargin(btcAverageIconButton, new Insets(0, 27, 0, 0));
btcAverageIconButton.setOnAction(e -> Utilities.openWebPage("https://bitcoinaverage.com"));
btcAverageIconButton.visibleProperty().bind(model.isFiatCurrencyPriceFeedSelected);
btcAverageIconButton.managedProperty().bind(model.isFiatCurrencyPriceFeedSelected);
@ -316,7 +328,7 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
poloniexIconButton.setPadding(new Insets(-3, 0, -3, 0));
poloniexIconButton.setFocusTraversable(false);
poloniexIconButton.setStyle("-fx-background-color: transparent;");
HBox.setMargin(poloniexIconButton, new Insets(1, 7, 0, 0));
HBox.setMargin(poloniexIconButton, new Insets(1, 27, 0, 0));
poloniexIconButton.setOnAction(e -> Utilities.openWebPage("https://poloniex.com"));
poloniexIconButton.visibleProperty().bind(model.isCryptoCurrencyPriceFeedSelected);
poloniexIconButton.managedProperty().bind(model.isCryptoCurrencyPriceFeedSelected);
@ -327,12 +339,11 @@ public class MainView extends InitializableView<StackPane, MainViewModel> {
HBox hBox2 = new HBox();
hBox2.getChildren().setAll(label, spacer, btcAverageIconButton, poloniexIconButton);
hBox2.prefWidthProperty().bind(priceComboBox.widthProperty());
VBox vBox = new VBox();
vBox.setSpacing(3);
vBox.setPadding(new Insets(11, 0, 0, 0));
vBox.getChildren().addAll(priceComboBox, hBox2);
vBox.getChildren().addAll(hBox1, hBox2);
return new Tuple3<>(priceComboBox, label, vBox);
}

View File

@ -124,6 +124,9 @@ public class MainViewModel implements ViewModel {
final StringProperty lockedBalance = new SimpleStringProperty();
private MonadicBinding<String> btcInfoBinding;
final StringProperty marketPrice = new SimpleStringProperty("N/A");
final StringProperty marketPriceInverted = new SimpleStringProperty("N/A");
// P2P network
final StringProperty p2PNetworkInfo = new SimpleStringProperty();
private MonadicBinding<String> p2PNetworkInfoBinding;
@ -709,9 +712,6 @@ public class MainViewModel implements ViewModel {
walletServiceErrorMsg.set("You lost the connection to all bitcoin network peers.\n" +
"Maybe you lost your internet connection or your computer was in standby mode.");
} else {
//TODO remove after testing
log.warn("INFO: we got again btc network peers");
walletServiceErrorMsg.set(null);
}
}, 5);
@ -724,19 +724,20 @@ public class MainViewModel implements ViewModel {
}
private void setupMarketPriceFeed() {
if (priceFeed.getCurrencyCode() == null)
final String currencyCode = priceFeed.getCurrencyCode();
if (currencyCode == null)
priceFeed.setCurrencyCode(preferences.getPreferredTradeCurrency().getCode());
if (priceFeed.getType() == null)
priceFeed.setType(PriceFeed.Type.LAST);
DoubleProperty marketPriceProperty = new SimpleDoubleProperty(0);
priceFeed.init(marketPriceProperty::set,
(errorMessage, throwable) -> marketPriceProperty.set(0));
/* priceFeed.init(marketPriceProperty::set,
(errorMessage, throwable) -> marketPriceProperty.set(0));*/
marketPriceCurrencyCode.bind(priceFeed.currencyCodeProperty());
typeProperty.bind(priceFeed.typeProperty());
marketPriceBinding = EasyBind.combine(
/* marketPriceBinding = EasyBind.combine(
marketPriceCurrencyCode, marketPriceProperty,
(code, marketPrice) -> {
double marketPriceAsDouble = (double) marketPrice;
@ -745,8 +746,25 @@ public class MainViewModel implements ViewModel {
} else {
return "N/A";
}
});*/
//TODO icon
priceFeed.init(price -> {
marketPrice.set(formatter.formatMarketPrice(price, currencyCode));
marketPriceInverted.set(price != 0 ? formatter.formatMarketPrice(1 / price, currencyCode) : "");
},
(errorMessage, throwable) -> {
marketPrice.set("N/A");
marketPriceInverted.set("N/A");
});
marketPriceBinding = EasyBind.combine(
marketPriceCurrencyCode, marketPrice, marketPriceInverted, preferences.useInvertedMarketPriceProperty(),
(code, marketPrice, marketPriceInverted, useInvertedMarketPrice) ->
(useInvertedMarketPrice ? marketPriceInverted : marketPrice) + " " + formatter.getCurrencyPair(code));
marketPriceBinding.subscribe((observable, oldValue, newValue) -> {
if (newValue != null && !newValue.equals(oldValue)) {
setMarketPriceInItems();
@ -794,11 +812,13 @@ public class MainViewModel implements ViewModel {
priceFeedComboBoxItems.stream().forEach(item -> {
String code = item.currencyCode;
MarketPrice marketPrice = priceFeed.getMarketPrice(code);
boolean useInvertedMarketPrice = preferences.getUseInvertedMarketPrice();
String priceString;
if (marketPrice != null) {
double price = marketPrice.getPrice(priceFeed.getType());
if (price != 0) {
priceString = formatter.formatMarketPrice(price, code);
double priceInverted = 1 / price;
priceString = useInvertedMarketPrice ? formatter.formatMarketPrice(priceInverted, code) : formatter.formatMarketPrice(price, code);
item.setIsPriceAvailable(true);
} else {
priceString = "N/A";