From 4e2f977ff094c72d2c86f86ffb12516ab9213a19 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 24 Aug 2014 17:53:43 +0200 Subject: [PATCH] adjust bank account combobox and balance label --- README.md | 2 +- .../java/io/bitsquare/btc/WalletFacade.java | 4 - .../java/io/bitsquare/gui/MainController.java | 84 +++++++++++-------- src/main/java/io/bitsquare/gui/bitsquare.css | 8 +- .../gui/settings/SettingsController.java | 23 ++--- .../trade/orderbook/OrderBookController.java | 13 +-- src/main/java/io/bitsquare/user/User.java | 50 ++++++++--- 7 files changed, 103 insertions(+), 81 deletions(-) diff --git a/README.md b/README.md index a3c816b2e0..d04de776bb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ## About Bitsquare Bitsquare is a **P2P Fiat-BTC Exchange**. -It allows to trade fiat money (USD, EURO, ...) for Bitcoins without relying on a centralized exchange like MtGox. +It allows to trade fiat money (USD, EURO, ...) for Bitcoins without relying on a centralized exchange like Coinbase or BitStamp. Instead, all participants form a peer to peer market. ## Dependencies diff --git a/src/main/java/io/bitsquare/btc/WalletFacade.java b/src/main/java/io/bitsquare/btc/WalletFacade.java index 83a3be1fc2..3da4f62493 100644 --- a/src/main/java/io/bitsquare/btc/WalletFacade.java +++ b/src/main/java/io/bitsquare/btc/WalletFacade.java @@ -473,13 +473,9 @@ public class WalletFacade { Coin balance; if (balanceListener.getAddress() != null) - { balance = getBalanceForAddress(balanceListener.getAddress()); - } else - { balance = getWalletBalance(); - } balanceListener.onBalanceChanged(balance); } diff --git a/src/main/java/io/bitsquare/gui/MainController.java b/src/main/java/io/bitsquare/gui/MainController.java index 47b22ff5db..8ab04355f6 100644 --- a/src/main/java/io/bitsquare/gui/MainController.java +++ b/src/main/java/io/bitsquare/gui/MainController.java @@ -7,6 +7,7 @@ import io.bitsquare.btc.listeners.BalanceListener; import io.bitsquare.di.GuiceFXMLLoader; import io.bitsquare.gui.components.NetworkSyncPane; import io.bitsquare.gui.orders.OrdersController; +import io.bitsquare.gui.util.BitSquareFormatter; import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.Profiler; import io.bitsquare.gui.util.Transitions; @@ -59,6 +60,7 @@ public class MainController extends ViewController private Pane ordersButtonButtonHolder; private boolean messageFacadeInited; private boolean walletFacadeInited; + private VBox accountComboBoxHolder; /////////////////////////////////////////////////////////////////////////////////////////// @@ -272,8 +274,16 @@ public class MainController extends ViewController viewBuilder.leftNavPane.getChildren().add(msgButtonHolder); addBalanceInfo(viewBuilder.rightNavPane); + addAccountComboBox(viewBuilder.rightNavPane); + user.getBankAccountsSizeProperty().addListener((observableValue, oldValue, newValue) -> { + if ((int) newValue == 2) + viewBuilder.rightNavPane.getChildren().add(1, accountComboBoxHolder);// accountComboBoxHolder.setVisible(true); + else if ((int) newValue < 2) + viewBuilder.rightNavPane.getChildren().remove(accountComboBoxHolder);//accountComboBoxHolder.setVisible(false); + }); + settingsButton = addNavButton(viewBuilder.rightNavPane, "Settings", NavigationItem.SETTINGS); Platform.runLater(this::onNavigationAdded); @@ -358,71 +368,71 @@ public class MainController extends ViewController balanceTextField.setEditable(false); balanceTextField.setPrefWidth(110); balanceTextField.setId("nav-balance-label"); - balanceTextField.setText(walletFacade.getWalletBalance().toFriendlyString()); + balanceTextField.setText(BitSquareFormatter.formatCoinWithCode(walletFacade.getWalletBalance())); walletFacade.addBalanceListener(new BalanceListener() { @Override public void onBalanceChanged(Coin balance) { - balanceTextField.setText(balance.toFriendlyString()); + balanceTextField.setText(BitSquareFormatter.formatCoinWithCode(walletFacade.getWalletBalance())); } }); - final HBox hBox = new HBox(); - hBox.setSpacing(2); - hBox.getChildren().setAll(balanceTextField); - final Label titleLabel = new Label("Balance"); + titleLabel.prefWidthProperty().bind(balanceTextField.widthProperty()); titleLabel.setMouseTransparent(true); - titleLabel.setPrefWidth(90); titleLabel.setId("nav-button-label"); final VBox vBox = new VBox(); vBox.setPadding(new Insets(12, 0, 0, 0)); vBox.setSpacing(2); - vBox.getChildren().setAll(hBox, titleLabel); + vBox.getChildren().setAll(balanceTextField, titleLabel); parent.getChildren().add(vBox); } private void addAccountComboBox(Pane parent) { - if (user.getBankAccounts().size() > 1) + final ComboBox accountComboBox = new ComboBox<>(FXCollections.observableArrayList(user.getBankAccounts())); + accountComboBox.setId("nav-account-combo-box"); + accountComboBox.setLayoutY(12); + if (user.getCurrentBankAccount() != null) + accountComboBox.getSelectionModel().select(user.getCurrentBankAccount()); + accountComboBox.valueProperty().addListener((ov, oldValue, newValue) -> user.setCurrentBankAccount(newValue)); + accountComboBox.setConverter(new StringConverter() { - final ComboBox accountComboBox = new ComboBox<>(FXCollections.observableArrayList(user.getBankAccounts())); - accountComboBox.setLayoutY(12); - accountComboBox.setValue(user.getCurrentBankAccount()); - accountComboBox.valueProperty().addListener((ov, oldValue, newValue) -> user.setCurrentBankAccount(newValue)); - accountComboBox.setConverter(new StringConverter() + @Override + public String toString(BankAccount bankAccount) { + return bankAccount.getAccountTitle(); + } - @Override - public String toString(BankAccount bankAccount) - { - return bankAccount.getAccountTitle(); - } + @Override + public BankAccount fromString(String s) + { + return null; + } + }); + user.getSelectedBankAccountIndexProperty().addListener(observable -> accountComboBox.getSelectionModel().select(user.getCurrentBankAccount())); + user.getBankAccountsSizeProperty().addListener(observable -> { + accountComboBox.setItems(FXCollections.observableArrayList(user.getBankAccounts())); + // need to delay it a bit otherwise it will not be set + Platform.runLater(() -> accountComboBox.getSelectionModel().select(user.getCurrentBankAccount())); + }); - @Override - public BankAccount fromString(String s) - { - return null; - } - }); + final Label titleLabel = new Label("Bank account"); + titleLabel.prefWidthProperty().bind(accountComboBox.widthProperty()); + titleLabel.setMouseTransparent(true); + titleLabel.setId("nav-button-label"); + accountComboBoxHolder = new VBox(); + accountComboBoxHolder.setPadding(new Insets(12, 0, 0, 0)); + accountComboBoxHolder.setSpacing(2); + accountComboBoxHolder.getChildren().setAll(accountComboBox, titleLabel); - final Label titleLabel = new Label("Bank account"); - titleLabel.setMouseTransparent(true); - titleLabel.setPrefWidth(90); - titleLabel.setId("nav-button-label"); - - final VBox vBox = new VBox(); - vBox.setPadding(new Insets(12, 0, 0, 0)); - vBox.setSpacing(2); - vBox.getChildren().setAll(accountComboBox, titleLabel); - parent.getChildren().add(vBox); - } + if (user.getBankAccounts().size() > 1) + parent.getChildren().add(accountComboBoxHolder); } - } diff --git a/src/main/java/io/bitsquare/gui/bitsquare.css b/src/main/java/io/bitsquare/gui/bitsquare.css index 40daab6670..136a5647fa 100644 --- a/src/main/java/io/bitsquare/gui/bitsquare.css +++ b/src/main/java/io/bitsquare/gui/bitsquare.css @@ -47,17 +47,15 @@ #nav-button-label { -fx-font-size: 10; - -fx-text-alignment: center; -fx-alignment: center; } #nav-balance-label { -fx-font-weight: bold; - -fx-text-alignment: right; + -fx-alignment: center; } - -#nav-balance-currency-label { - -fx-text-alignment: left; +#nav-account-combo-box .list-cell{ + -fx-alignment: center; } .text-field:readonly { diff --git a/src/main/java/io/bitsquare/gui/settings/SettingsController.java b/src/main/java/io/bitsquare/gui/settings/SettingsController.java index e83d1df324..ff5a4d6203 100644 --- a/src/main/java/io/bitsquare/gui/settings/SettingsController.java +++ b/src/main/java/io/bitsquare/gui/settings/SettingsController.java @@ -229,7 +229,7 @@ public class SettingsController extends CachedViewController { user.setCurrentBankAccount(bankAccount); persistence.write(user); - initBankAccountScreen(); + fillWithCurrentBankAccount(); } } @@ -539,13 +539,8 @@ public class SettingsController extends CachedViewController // Bank Account Settings - private void initBankAccountScreen() + private void fillWithCurrentBankAccount() { - initBankAccountComboBox(); - initBankAccountTypesComboBox(); - initBankAccountCurrencyComboBox(); - initBankAccountCountryComboBox(); - BankAccount currentBankAccount = user.getCurrentBankAccount(); if (currentBankAccount != null) { @@ -560,6 +555,16 @@ public class SettingsController extends CachedViewController { resetBankAccountInput(); } + } + + private void initBankAccountScreen() + { + initBankAccountComboBox(); + initBankAccountTypesComboBox(); + initBankAccountCurrencyComboBox(); + initBankAccountCountryComboBox(); + + fillWithCurrentBankAccount(); //TODO if (BitSquare.fillFormsWithDummyData) @@ -751,8 +756,6 @@ public class SettingsController extends CachedViewController saveUser(); - initBankAccountScreen(); - if (!settings.getAcceptedCountries().contains(bankAccount.getCountry())) { List actions = new ArrayList<>(); @@ -775,7 +778,7 @@ public class SettingsController extends CachedViewController saveUser(); saveSettings(); - initBankAccountScreen(); + fillWithCurrentBankAccount(); } private boolean verifyBankAccountData() diff --git a/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java b/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java index 8af8d3b51c..e04becbe9b 100644 --- a/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java +++ b/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java @@ -179,9 +179,9 @@ public class OrderBookController extends CachedViewController updateVolume(); }); - orderBookFilter.getDirectionChangedProperty().addListener((observable, oldValue, newValue) -> applyOffers()); + orderBookFilter.getDirectionChangedProperty().addListener((observable) -> applyOffers()); - user.getBankAccountChangedProperty().addListener((observable, oldValue, newValue) -> orderBook.loadOffers()); + user.getSelectedBankAccountIndexProperty().addListener((observable) -> orderBook.loadOffers()); createOfferButton.setOnAction(e -> createOffer()); @@ -213,18 +213,9 @@ public class OrderBookController extends CachedViewController if (isRegistered()) { createOfferButton.setDisable(true); - /* if (walletFacade.isUnusedTradeAddressBalanceAboveCreationFee()) - { */ ViewController nextController = parentController.loadViewAndGetChildController(NavigationItem.CREATE_OFFER); if (nextController != null) ((CreateOfferController) nextController).setOrderBookFilter(orderBookFilter); - /* } - else - { - Action response = Popups.openErrorPopup("No funds for a trade", "You have to add some funds before you create a new offer."); - if (response == Dialog.Actions.OK) - MainController.GET_INSTANCE().navigateToView(NavigationItem.FUNDS); - } */ } else { diff --git a/src/main/java/io/bitsquare/user/User.java b/src/main/java/io/bitsquare/user/User.java index 0c9c815315..a657910a4b 100644 --- a/src/main/java/io/bitsquare/user/User.java +++ b/src/main/java/io/bitsquare/user/User.java @@ -7,7 +7,9 @@ import java.security.KeyPair; import java.security.PublicKey; import java.util.ArrayList; import java.util.List; -import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,7 +21,8 @@ public class User implements Serializable private static final Logger log = LoggerFactory.getLogger(User.class); private static final long serialVersionUID = 7409078808248518638L; - transient private final SimpleBooleanProperty bankAccountChangedProperty = new SimpleBooleanProperty(); + transient private final IntegerProperty selectedBankAccountIndexProperty = new SimpleIntegerProperty(); + transient private final IntegerProperty bankAccountsSizeProperty = new SimpleIntegerProperty(); private KeyPair messageKeyPair; private String accountID; @@ -42,7 +45,6 @@ public class User implements Serializable { bankAccounts = persistedUser.getBankAccounts(); messageKeyPair = persistedUser.getMessageKeyPair(); - accountID = persistedUser.getAccountId(); setCurrentBankAccount(persistedUser.getCurrentBankAccount()); } @@ -52,22 +54,33 @@ public class User implements Serializable bankAccounts = new ArrayList<>(); messageKeyPair = DSAKeyUtil.generateKeyPair(); // DSAKeyUtil.getKeyPair() runs in same thread now } - DSAKeyUtil.generateKeyPair(); + + bankAccountsSizeProperty.set(bankAccounts.size()); } public void addBankAccount(BankAccount bankAccount) { - if (!bankAccounts.contains(bankAccount)) bankAccounts.add(bankAccount); + if (!bankAccounts.contains(bankAccount)) + { + bankAccounts.add(bankAccount); + bankAccountsSizeProperty.set(bankAccounts.size()); + } setCurrentBankAccount(bankAccount); } public void removeCurrentBankAccount() { - if (currentBankAccount != null) bankAccounts.remove(currentBankAccount); + if (currentBankAccount != null) + { + bankAccounts.remove(currentBankAccount); + bankAccountsSizeProperty.set(bankAccounts.size()); + } - if (bankAccounts.isEmpty()) currentBankAccount = null; - else setCurrentBankAccount(bankAccounts.get(0)); + if (bankAccounts.isEmpty()) + setCurrentBankAccount(null); + else + setCurrentBankAccount(bankAccounts.get(0)); } @@ -82,10 +95,16 @@ public class User implements Serializable this.accountID = accountID; } - public void setCurrentBankAccount(BankAccount bankAccount) + public void setCurrentBankAccount(@Nullable BankAccount bankAccount) { - this.currentBankAccount = bankAccount; - bankAccountChangedProperty.set(!bankAccountChangedProperty.get()); + currentBankAccount = bankAccount; + int index = -1; + for (index = 0; index < bankAccounts.size(); index++) + { + if (currentBankAccount != null && currentBankAccount.equals(bankAccounts.get(index))) + break; + } + selectedBankAccountIndexProperty.set(index); } @@ -137,9 +156,9 @@ public class User implements Serializable return null; } - public SimpleBooleanProperty getBankAccountChangedProperty() + public IntegerProperty getSelectedBankAccountIndexProperty() { - return bankAccountChangedProperty; + return selectedBankAccountIndexProperty; } public KeyPair getMessageKeyPair() @@ -156,4 +175,9 @@ public class User implements Serializable { return DSAKeyUtil.getHexStringFromPublicKey(getMessagePublicKey()); } + + public IntegerProperty getBankAccountsSizeProperty() + { + return bankAccountsSizeProperty; + } }