diff --git a/src/main/java/io/bitsquare/di/BitSquareModule.java b/src/main/java/io/bitsquare/di/BitSquareModule.java index 6cb0ffc070..0a35b1c04d 100644 --- a/src/main/java/io/bitsquare/di/BitSquareModule.java +++ b/src/main/java/io/bitsquare/di/BitSquareModule.java @@ -22,6 +22,7 @@ import io.bitsquare.btc.BlockChainFacade; import io.bitsquare.btc.FeePolicy; import io.bitsquare.btc.WalletFacade; import io.bitsquare.crypto.CryptoFacade; +import io.bitsquare.gui.view.MainViewCB; import io.bitsquare.msg.BootstrappedPeerFactory; import io.bitsquare.msg.MessageFacade; import io.bitsquare.msg.P2PNode; @@ -63,6 +64,7 @@ public class BitSquareModule extends AbstractModule { bind(BootstrappedPeerFactory.class).asEagerSingleton(); bind(TradeManager.class).asEagerSingleton(); + bind(MainViewCB.class).asEagerSingleton(); //bind(String.class).annotatedWith(Names.named("networkType")).toInstance(WalletFacade.MAIN_NET); diff --git a/src/main/java/io/bitsquare/gui/NavigationItem.java b/src/main/java/io/bitsquare/gui/NavigationItem.java index 114e4313bc..43c6dba532 100644 --- a/src/main/java/io/bitsquare/gui/NavigationItem.java +++ b/src/main/java/io/bitsquare/gui/NavigationItem.java @@ -22,7 +22,7 @@ import io.bitsquare.gui.util.ImageUtil; public enum NavigationItem { // app - MAIN("/io/bitsquare/gui/MainView.fxml"), + MAIN("/io/bitsquare/gui/view/MainView.fxml"), // main menu screens HOME("/io/bitsquare/gui/home/HomeView.fxml", ImageUtil.HOME, ImageUtil.HOME_ACTIVE), diff --git a/src/main/java/io/bitsquare/gui/components/Popups.java b/src/main/java/io/bitsquare/gui/components/Popups.java index b2cdf3a4b8..c2e0ce639f 100644 --- a/src/main/java/io/bitsquare/gui/components/Popups.java +++ b/src/main/java/io/bitsquare/gui/components/Popups.java @@ -18,7 +18,7 @@ package io.bitsquare.gui.components; import io.bitsquare.BitSquare; -import io.bitsquare.gui.MainController; +import io.bitsquare.gui.view.MainViewCB; import io.bitsquare.locale.BSResources; import com.google.bitcoin.store.BlockStoreException; @@ -56,7 +56,7 @@ public class Popups { // Supports blurring the content background public static void openInfo(String message, String masthead) { - MainController.GET_INSTANCE().blurContentScreen(); + MainViewCB.getInstance().blurContentScreen(); List actions = new ArrayList<>(); // Dialogs are a bit limited. There is no callback for the InformationDialog button click, so we added @@ -65,7 +65,7 @@ public class Popups { @Override public void handle(ActionEvent actionEvent) { Dialog.Actions.CLOSE.handle(actionEvent); - MainController.GET_INSTANCE().removeContentScreenBlur(); + MainViewCB.getInstance().removeContentScreenBlur(); } }); openInfo(message, masthead, actions); diff --git a/src/main/java/io/bitsquare/gui/components/btc/AddressTextField.java b/src/main/java/io/bitsquare/gui/components/btc/AddressTextField.java index 5b28adbd1c..72ac783730 100644 --- a/src/main/java/io/bitsquare/gui/components/btc/AddressTextField.java +++ b/src/main/java/io/bitsquare/gui/components/btc/AddressTextField.java @@ -17,8 +17,8 @@ package io.bitsquare.gui.components.btc; -import io.bitsquare.gui.MainController; import io.bitsquare.gui.components.Popups; +import io.bitsquare.gui.view.MainViewCB; import com.google.bitcoin.core.Coin; import com.google.bitcoin.uri.BitcoinURI; @@ -124,13 +124,13 @@ public class AddressTextField extends AnchorPane { PopOver popOver = new PopOver(pane); popOver.setDetachedTitle("Scan QR code for this address"); popOver.setDetached(true); - popOver.setOnHiding(windowEvent -> MainController.GET_INSTANCE().removeContentScreenBlur()); + popOver.setOnHiding(windowEvent -> MainViewCB.getInstance().removeContentScreenBlur()); Window window = getScene().getWindow(); double x = Math.round(window.getX() + (window.getWidth() - 320) / 2); double y = Math.round(window.getY() + (window.getHeight() - 240) / 2); popOver.show(getScene().getWindow(), x, y); - MainController.GET_INSTANCE().blurContentScreen(); + MainViewCB.getInstance().blurContentScreen(); } }); diff --git a/src/main/java/io/bitsquare/gui/model/MainModel.java b/src/main/java/io/bitsquare/gui/model/MainModel.java new file mode 100644 index 0000000000..bbdc4bbefe --- /dev/null +++ b/src/main/java/io/bitsquare/gui/model/MainModel.java @@ -0,0 +1,210 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare 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. + * + * Bitsquare 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 Bitsquare. If not, see . + */ + +package io.bitsquare.gui.model; + +import io.bitsquare.bank.BankAccount; +import io.bitsquare.btc.WalletFacade; +import io.bitsquare.btc.listeners.BalanceListener; +import io.bitsquare.gui.NavigationItem; +import io.bitsquare.gui.UIModel; +import io.bitsquare.gui.util.Profiler; +import io.bitsquare.msg.MessageFacade; +import io.bitsquare.msg.listeners.BootstrapListener; +import io.bitsquare.persistence.Persistence; +import io.bitsquare.trade.TradeManager; +import io.bitsquare.user.User; + +import com.google.bitcoin.core.Coin; + +import com.google.inject.Inject; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleDoubleProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.collections.ObservableList; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MainModel extends UIModel { + private static final Logger log = LoggerFactory.getLogger(MainModel.class); + + private final User user; + private final WalletFacade walletFacade; + private final MessageFacade messageFacade; + private final TradeManager tradeManager; + private final Persistence persistence; + + private boolean messageFacadeInited; + private boolean walletFacadeInited; + + public final BooleanProperty backendInited = new SimpleBooleanProperty(); + public final DoubleProperty networkSyncProgress = new SimpleDoubleProperty(); + public final BooleanProperty networkSyncComplete = new SimpleBooleanProperty(); + public final BooleanProperty takeOfferRequested = new SimpleBooleanProperty(); + public final ObjectProperty balance = new SimpleObjectProperty<>(); + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + private MainModel(User user, WalletFacade walletFacade, MessageFacade messageFacade, + TradeManager tradeManager, Persistence persistence) { + this.user = user; + this.walletFacade = walletFacade; + this.messageFacade = messageFacade; + this.tradeManager = tradeManager; + this.persistence = persistence; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Lifecycle + /////////////////////////////////////////////////////////////////////////////////////////// + + @SuppressWarnings("EmptyMethod") + @Override + public void initialized() { + super.initialized(); + } + + @Override + public void activate() { + super.activate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void deactivate() { + super.deactivate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void terminate() { + super.terminate(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Public + /////////////////////////////////////////////////////////////////////////////////////////// + + public void initBackend() { + Profiler.printMsgWithTime("MainModel.initFacades"); + messageFacade.init(new BootstrapListener() { + @Override + public void onCompleted() { + messageFacadeInited = true; + if (walletFacadeInited) onFacadesInitialised(); + } + + @Override + public void onFailed(Throwable throwable) { + log.error(throwable.toString()); + } + }); + + walletFacade.initialize(() -> { + walletFacadeInited = true; + if (messageFacadeInited) + onFacadesInitialised(); + + + walletFacade.addBalanceListener(new BalanceListener() { + @Override + public void onBalanceChanged(Coin balance) { + updateBalance(balance); + } + }); + updateBalance(walletFacade.getWalletBalance()); + }); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////////////////////////////////// + + public void setSelectedNavigationItem(NavigationItem navigationItem) { + persistence.write(this, "selectedNavigationItem", navigationItem); + } + + public void setCurrentBankAccount(BankAccount bankAccount) { + user.setCurrentBankAccount(bankAccount); + } + + /////////////////////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////////////////////// + + public ObservableList getBankAccounts() { + return user.getBankAccounts(); + } + + public ObjectProperty currentBankAccountProperty() { + return user.currentBankAccountProperty(); + } + + public NavigationItem getSelectedNavigationItem() { + NavigationItem selectedNavigationItem = (NavigationItem) persistence.read(this, "selectedNavigationItem"); + // Set default + // TODO set HOME later + if (selectedNavigationItem == null) + selectedNavigationItem = NavigationItem.BUY; + + return selectedNavigationItem; + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private + /////////////////////////////////////////////////////////////////////////////////////////// + + private void onFacadesInitialised() { + Profiler.printMsgWithTime("MainModel.onFacadesInitialised"); + + // TODO Check this: never called on regtest + // Consider to use version from Mike Hearn + walletFacade.addDownloadListener(new WalletFacade.DownloadListener() { + @Override + public void progress(double percent) { + networkSyncProgress.set(percent); + } + + @Override + public void downloadComplete() { + networkSyncComplete.set(true); + } + }); + + tradeManager.addTakeOfferRequestListener((offerId, sender) -> takeOfferRequested.set(true)); + + backendInited.set(true); + } + + + private void updateBalance(Coin balance) { + this.balance.set(balance); + } +} diff --git a/src/main/java/io/bitsquare/gui/pm/MainPM.java b/src/main/java/io/bitsquare/gui/pm/MainPM.java new file mode 100644 index 0000000000..50c5aa7931 --- /dev/null +++ b/src/main/java/io/bitsquare/gui/pm/MainPM.java @@ -0,0 +1,166 @@ +/* + * This file is part of Bitsquare. + * + * Bitsquare 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. + * + * Bitsquare 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 Bitsquare. If not, see . + */ + +package io.bitsquare.gui.pm; + +import io.bitsquare.bank.BankAccount; +import io.bitsquare.gui.NavigationItem; +import io.bitsquare.gui.PresentationModel; +import io.bitsquare.gui.model.MainModel; +import io.bitsquare.gui.util.BSFormatter; + +import com.google.inject.Inject; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.ListChangeListener; +import javafx.collections.ObservableList; +import javafx.util.StringConverter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class MainPM extends PresentationModel { + private static final Logger log = LoggerFactory.getLogger(MainPM.class); + + public final BooleanProperty backendInited = new SimpleBooleanProperty(); + public final StringProperty balance = new SimpleStringProperty(); + public final StringProperty bankAccountsComboBoxPrompt = new SimpleStringProperty(); + public final BooleanProperty bankAccountsComboBoxDisable = new SimpleBooleanProperty(); + public final StringProperty splashScreenInfoText = new SimpleStringProperty(); + public final BooleanProperty networkSyncComplete = new SimpleBooleanProperty(); + public final BooleanProperty takeOfferRequested = new SimpleBooleanProperty(); + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + private MainPM(MainModel model) { + super(model); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Lifecycle + /////////////////////////////////////////////////////////////////////////////////////////// + + @SuppressWarnings("EmptyMethod") + @Override + public void initialized() { + super.initialized(); + + backendInited.bind(model.backendInited); + networkSyncComplete.bind(model.networkSyncComplete); + takeOfferRequested.bind(model.takeOfferRequested); + + model.networkSyncProgress.addListener((ov, oldValue, newValue) -> { + if ((double) newValue > 0) + splashScreenInfoText.set("Synchronise with network " + BSFormatter.formatToPercent((double) newValue)); + else if ((double) newValue == 1) + splashScreenInfoText.set("Synchronise with network completed."); + else + splashScreenInfoText.set("Synchronise with network..."); + + }); + + model.balance.addListener((ov, oldValue, newValue) -> balance.set(BSFormatter.formatCoinWithCode + (newValue))); + + model.getBankAccounts().addListener((ListChangeListener) change -> { + bankAccountsComboBoxDisable.set(change.getList().isEmpty()); + bankAccountsComboBoxPrompt.set(change.getList().isEmpty() ? "No accounts" : ""); + }); + bankAccountsComboBoxDisable.set(model.getBankAccounts().isEmpty()); + bankAccountsComboBoxPrompt.set(model.getBankAccounts().isEmpty() ? "No accounts" : ""); + } + + @Override + public void activate() { + super.activate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void deactivate() { + super.deactivate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void terminate() { + super.terminate(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Public + /////////////////////////////////////////////////////////////////////////////////////////// + + public void initBackend() { + model.initBackend(); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////////////////////////////////// + + public void setSelectedNavigationItem(NavigationItem navigationItem) { + model.setSelectedNavigationItem(navigationItem); + } + + public void setCurrentBankAccount(BankAccount bankAccount) { + model.setCurrentBankAccount(bankAccount); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////////////////////// + + public NavigationItem getSelectedNavigationItem() { + return model.getSelectedNavigationItem(); + } + + public ObservableList getBankAccounts() { + return model.getBankAccounts(); + } + + public ObjectProperty currentBankAccountProperty() { + return model.currentBankAccountProperty(); + } + + public StringConverter getBankAccountsConverter() { + return new StringConverter() { + @Override + public String toString(BankAccount bankAccount) { + return bankAccount.getAccountTitle(); + } + + @Override + public BankAccount fromString(String s) { + return null; + } + }; + } + +} diff --git a/src/main/java/io/bitsquare/gui/trade/TradeController.java b/src/main/java/io/bitsquare/gui/trade/TradeController.java index 57af403a5f..c9ce548ec7 100644 --- a/src/main/java/io/bitsquare/gui/trade/TradeController.java +++ b/src/main/java/io/bitsquare/gui/trade/TradeController.java @@ -22,7 +22,7 @@ import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.components.InputTextField; import io.bitsquare.gui.trade.orderbook.OrderBookController; import io.bitsquare.gui.trade.takeoffer.TakeOfferController; -import io.bitsquare.gui.view.trade.CreateOfferCB; +import io.bitsquare.gui.view.trade.CreateOfferViewCB; import io.bitsquare.trade.Direction; import io.bitsquare.util.BSFXMLLoader; @@ -47,7 +47,7 @@ public class TradeController extends CachedViewController { private static final Logger log = LoggerFactory.getLogger(TradeController.class); protected OrderBookController orderBookController; - protected CreateOfferCB createOfferCodeBehind; + protected CreateOfferViewCB createOfferCodeBehind; protected TakeOfferController takeOfferController; protected BSFXMLLoader orderBookLoader; private Node createOfferView; 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 195d71aaeb..3e8972c247 100644 --- a/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java +++ b/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java @@ -21,14 +21,14 @@ import io.bitsquare.bank.BankAccountType; import io.bitsquare.btc.WalletFacade; import io.bitsquare.gui.CachedViewController; import io.bitsquare.gui.CodeBehind; -import io.bitsquare.gui.MainController; import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.ViewController; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.trade.takeoffer.TakeOfferController; import io.bitsquare.gui.util.BSFormatter; import io.bitsquare.gui.util.ImageUtil; -import io.bitsquare.gui.view.trade.CreateOfferCB; +import io.bitsquare.gui.view.MainViewCB; +import io.bitsquare.gui.view.trade.CreateOfferViewCB; import io.bitsquare.locale.BSResources; import io.bitsquare.locale.Country; import io.bitsquare.locale.CurrencyUtil; @@ -245,7 +245,7 @@ public class OrderBookController extends CachedViewController { } if (nextController != null) - ((CreateOfferCB) nextController).setOrderBookFilter(orderBookFilter); + ((CreateOfferViewCB) nextController).setOrderBookFilter(orderBookFilter); } else { openSetupScreen(); @@ -270,16 +270,16 @@ public class OrderBookController extends CachedViewController { private void openSetupScreen() { - MainController.GET_INSTANCE().blurContentScreen(); + MainViewCB.getInstance().blurContentScreen(); List actions = new ArrayList<>(); actions.add(new AbstractAction(BSResources.get("shared.ok")) { @Override public void handle(ActionEvent actionEvent) { Dialog.Actions.OK.handle(actionEvent); - MainController.GET_INSTANCE().removeContentScreenBlur(); + MainViewCB.getInstance().removeContentScreenBlur(); - MainController.GET_INSTANCE().loadViewAndGetChildController(NavigationItem.ACCOUNT); - MainController.GET_INSTANCE() + MainViewCB.getInstance().triggerMainMenuButton(NavigationItem.ACCOUNT); + MainViewCB.getInstance() .setPreviousNavigationItem((orderBookFilter.getDirection() == Direction.BUY) ? NavigationItem.BUY : NavigationItem.SELL); } diff --git a/src/main/java/io/bitsquare/gui/util/BSFormatter.java b/src/main/java/io/bitsquare/gui/util/BSFormatter.java index 3d6f693bf3..55d4d03f4c 100644 --- a/src/main/java/io/bitsquare/gui/util/BSFormatter.java +++ b/src/main/java/io/bitsquare/gui/util/BSFormatter.java @@ -291,6 +291,14 @@ public class BSFormatter { return decimalFormat.format(collateral / 10) + " %"; } + public static String formatToPercent(double value) { + DecimalFormat decimalFormat = (DecimalFormat) DecimalFormat.getInstance(locale); + decimalFormat.setMinimumFractionDigits(1); + decimalFormat.setMaximumFractionDigits(1); + decimalFormat.setGroupingUsed(false); + return decimalFormat.format(value / 100) + " %"; + } + public static String formatVolumeWithMinVolume(Fiat volume, Fiat minVolume) { return formatFiat(volume) + " (" + formatFiat(minVolume) + ")"; } diff --git a/src/main/java/io/bitsquare/gui/view/AccountView.fxml b/src/main/java/io/bitsquare/gui/view/AccountView.fxml index f425f6af7a..9966dc3c12 100644 --- a/src/main/java/io/bitsquare/gui/view/AccountView.fxml +++ b/src/main/java/io/bitsquare/gui/view/AccountView.fxml @@ -19,7 +19,7 @@ - { +public class AccountViewCB extends CachedCodeBehind { - private static final Logger log = LoggerFactory.getLogger(AccountCB.class); + private static final Logger log = LoggerFactory.getLogger(AccountViewCB.class); public Tab tab; @@ -52,7 +51,7 @@ public class AccountCB extends CachedCodeBehind { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private AccountCB(AccountPM presentationModel) { + private AccountViewCB(AccountPM presentationModel) { super(presentationModel); } @@ -111,8 +110,8 @@ public class AccountCB extends CachedCodeBehind { Initializable childController = loader.getController(); ((CodeBehind) childController).setParentController(this); - if (childController instanceof AccountSetupCB) - ((AccountSetupCB) childController).setRemoveCallBack(() -> { + if (childController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) childController).setRemoveCallBack(() -> { removeSetup(); return null; }); @@ -132,11 +131,11 @@ public class AccountCB extends CachedCodeBehind { private void removeSetup() { childController = null; - NavigationItem previousItem = MainController.GET_INSTANCE().getPreviousNavigationItem(); + NavigationItem previousItem = MainViewCB.getInstance().getPreviousNavigationItem(); if (previousItem == null) previousItem = NavigationItem.HOME; - MainController.GET_INSTANCE().loadViewAndGetChildController(previousItem); + MainViewCB.getInstance().triggerMainMenuButton(previousItem); } } diff --git a/src/main/java/io/bitsquare/gui/MainView.fxml b/src/main/java/io/bitsquare/gui/view/MainView.fxml similarity index 92% rename from src/main/java/io/bitsquare/gui/MainView.fxml rename to src/main/java/io/bitsquare/gui/view/MainView.fxml index c2eb22c969..5de676b874 100644 --- a/src/main/java/io/bitsquare/gui/MainView.fxml +++ b/src/main/java/io/bitsquare/gui/view/MainView.fxml @@ -17,7 +17,7 @@ --> - \ No newline at end of file diff --git a/src/main/java/io/bitsquare/gui/MainController.java b/src/main/java/io/bitsquare/gui/view/MainViewCB.java similarity index 52% rename from src/main/java/io/bitsquare/gui/MainController.java rename to src/main/java/io/bitsquare/gui/view/MainViewCB.java index 01470c519a..15aab57ea4 100644 --- a/src/main/java/io/bitsquare/gui/MainController.java +++ b/src/main/java/io/bitsquare/gui/view/MainViewCB.java @@ -15,27 +15,21 @@ * along with Bitsquare. If not, see . */ -package io.bitsquare.gui; +package io.bitsquare.gui.view; import io.bitsquare.bank.BankAccount; -import io.bitsquare.btc.WalletFacade; -import io.bitsquare.btc.listeners.BalanceListener; +import io.bitsquare.gui.CachedCodeBehind; +import io.bitsquare.gui.CodeBehind; +import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.components.NetworkSyncPane; import io.bitsquare.gui.orders.OrdersController; -import io.bitsquare.gui.util.BSFormatter; +import io.bitsquare.gui.pm.MainPM; import io.bitsquare.gui.util.ImageUtil; import io.bitsquare.gui.util.Profiler; import io.bitsquare.gui.util.Transitions; -import io.bitsquare.msg.MessageFacade; -import io.bitsquare.msg.listeners.BootstrapListener; -import io.bitsquare.persistence.Persistence; -import io.bitsquare.trade.TradeManager; -import io.bitsquare.user.User; import io.bitsquare.util.AWTSystemTray; import io.bitsquare.util.BSFXMLLoader; -import com.google.bitcoin.core.Coin; - import java.io.IOException; import java.net.URL; @@ -45,9 +39,6 @@ import java.util.ResourceBundle; import javax.inject.Inject; import javafx.application.Platform; -import javafx.beans.Observable; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; import javafx.fxml.Initializable; import javafx.geometry.Insets; import javafx.geometry.Pos; @@ -55,9 +46,6 @@ import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.image.*; import javafx.scene.layout.*; -import javafx.util.StringConverter; - -import net.tomp2p.peers.PeerAddress; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,32 +56,35 @@ import org.slf4j.LoggerFactory; * frozen for too long. Pre-loading of views is not implemented yet, and after a quick test it seemed that it does not * give much improvements. */ -public class MainController extends ViewController { - private static final Logger log = LoggerFactory.getLogger(MainController.class); - private static MainController INSTANCE; +public class MainViewCB extends CachedCodeBehind { + private static final Logger log = LoggerFactory.getLogger(MainViewCB.class); + //TODO + private static MainViewCB instance; - private final User user; - private final WalletFacade walletFacade; - private final MessageFacade messageFacade; - private final TradeManager tradeManager; - private final Persistence persistence; - private final ViewBuilder viewBuilder; + private boolean showNetworkSyncPaneRequested; + private VBox baseOverlayContainer; private final ToggleGroup navButtonsGroup = new ToggleGroup(); + private NavigationItem previousNavigationItem; + private AnchorPane contentPane; + private HBox leftNavPane, rightNavPane; + private NetworkSyncPane networkSyncPane; + private BorderPane baseContentContainer; + private AnchorPane contentScreen; + private MenuBar menuBar; + private Label loadingLabel; private ToggleButton buyButton, sellButton, homeButton, msgButton, ordersButton, fundsButton, settingsButton, accountButton; - private Pane ordersButtonButtonHolder; - private boolean messageFacadeInited; - private boolean walletFacadeInited; - private NavigationItem previousNavigationItem; + private Pane ordersButtonButtonPane; /////////////////////////////////////////////////////////////////////////////////////////// // Static /////////////////////////////////////////////////////////////////////////////////////////// - public static MainController GET_INSTANCE() { - return INSTANCE; + //TODO + public static MainViewCB getInstance() { + return instance; } @@ -102,17 +93,11 @@ public class MainController extends ViewController { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private MainController(User user, WalletFacade walletFacade, MessageFacade messageFacade, - TradeManager tradeManager, Persistence persistence) { - this.user = user; - this.walletFacade = walletFacade; - this.messageFacade = messageFacade; - this.tradeManager = tradeManager; - this.persistence = persistence; + private MainViewCB(MainPM presentationModel) { + super(presentationModel); - viewBuilder = new ViewBuilder(); - - MainController.INSTANCE = this; + //TODO + MainViewCB.instance = this; } @@ -120,14 +105,27 @@ public class MainController extends ViewController { // Lifecycle /////////////////////////////////////////////////////////////////////////////////////////// + @SuppressWarnings("EmptyMethod") @Override public void initialize(URL url, ResourceBundle rb) { super.initialize(url, rb); Profiler.printMsgWithTime("MainController.initialize"); - Platform.runLater(() -> viewBuilder.buildSplashScreen((StackPane) root, this)); + startup(); } + @Override + public void activate() { + super.activate(); + } + + @SuppressWarnings("EmptyMethod") + @Override + public void deactivate() { + super.deactivate(); + } + + @SuppressWarnings("EmptyMethod") @Override public void terminate() { super.terminate(); @@ -138,8 +136,7 @@ public class MainController extends ViewController { // Navigation /////////////////////////////////////////////////////////////////////////////////////////// - @Override - public Initializable loadViewAndGetChildController(NavigationItem navigationItem) { + public Initializable triggerMainMenuButton(NavigationItem navigationItem) { switch (navigationItem) { case HOME: homeButton.fire(); @@ -169,176 +166,256 @@ public class MainController extends ViewController { return childController; } + @Override + public Initializable loadView(NavigationItem navigationItem) { + super.loadView((navigationItem)); + + final BSFXMLLoader loader = new BSFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl())); + try { + final Node view = loader.load(); + contentPane.getChildren().setAll(view); + childController = loader.getController(); + + if (childController instanceof CodeBehind) + ((CodeBehind) childController).setParentController(this); + + presentationModel.setSelectedNavigationItem(navigationItem); + return childController; + } catch (IOException e) { + e.getStackTrace(); + log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl()); + } + return null; + } + + public void setPreviousNavigationItem(NavigationItem previousNavigationItem) { + this.previousNavigationItem = previousNavigationItem; + } + + public NavigationItem getPreviousNavigationItem() { + return previousNavigationItem; + } + /////////////////////////////////////////////////////////////////////////////////////////// - // Blur effect + // Blur /////////////////////////////////////////////////////////////////////////////////////////// public void removeContentScreenBlur() { - Transitions.removeBlur(viewBuilder.baseContentContainer); + Transitions.removeBlur(baseContentContainer); } public void blurContentScreen() { - Transitions.blur(viewBuilder.baseContentContainer); + Transitions.blur(baseContentContainer); } /////////////////////////////////////////////////////////////////////////////////////////// - // Startup Handlers + // Private Methods: Startup /////////////////////////////////////////////////////////////////////////////////////////// - void onViewInitialized() { - Profiler.printMsgWithTime("MainController.onViewInitialized"); - Platform.runLater(this::initFacades); + private void startup() { + buildBaseContainers(); } - private void onFacadesInitialised() { - Profiler.printMsgWithTime("MainController.onFacadesInitialised"); - // never called on regtest - walletFacade.addDownloadListener(new WalletFacade.DownloadListener() { - @Override - public void progress(double percent) { - viewBuilder.loadingLabel.setText("Synchronise with network..."); - if (viewBuilder.networkSyncPane == null) - viewBuilder.setShowNetworkSyncPane(); - } + private void buildBaseContainers() { + Profiler.printMsgWithTime("MainController.ViewBuilder.buildBaseContainers"); - @Override - public void downloadComplete() { - viewBuilder.loadingLabel.setText("Synchronise with network done."); - if (viewBuilder.networkSyncPane != null) - viewBuilder.networkSyncPane.downloadComplete(); - } + baseContentContainer = getBaseContentContainer(); + baseContentContainer.setOpacity(0); + baseOverlayContainer = getSplashScreen(); + ((StackPane) root).getChildren().addAll(baseContentContainer, baseOverlayContainer); + + Platform.runLater(this::buildContentView); + } + + private void buildContentView() { + Profiler.printMsgWithTime("MainController.ViewBuilder.buildContentView"); + + menuBar = getMenuBar(); + contentScreen = getContentScreen(); + + + if (showNetworkSyncPaneRequested) + addNetworkSyncPane(); + + baseContentContainer.setTop(menuBar); + baseContentContainer.setCenter(contentScreen); + + Platform.runLater(this::onBaseContainersCreated); + } + + // We need to wait until the backend is initialized as we need it for menu items like the balance field + private void onBaseContainersCreated() { + Profiler.printMsgWithTime("MainController.onBaseContainersCreated"); + + presentationModel.backendInited.addListener((ov, oldValue, newValue) -> { + if (newValue) + onBackendInited(); }); - tradeManager.addTakeOfferRequestListener(this::onTakeOfferRequested); - Platform.runLater(this::addNavigation); + presentationModel.initBackend(); } - private void onNavigationAdded() { - Profiler.printMsgWithTime("MainController.onNavigationAdded"); - Platform.runLater(this::loadContentView); + private void onBackendInited() { + Profiler.printMsgWithTime("MainController.onBackendInited"); + addMainNavigation(); } - private void onContentViewLoaded() { - Profiler.printMsgWithTime("MainController.onContentViewLoaded"); + private void onMainNavigationAdded() { + Profiler.printMsgWithTime("MainController.ondMainNavigationAdded"); + triggerMainMenuButton(presentationModel.getSelectedNavigationItem()); + Platform.runLater(this::onContentAdded); + } + + private void onContentAdded() { + Profiler.printMsgWithTime("MainController.onContentAdded"); + + presentationModel.takeOfferRequested.addListener((ov, olaValue, newValue) -> { + final Button alertButton = new Button("", ImageUtil.getIconImageView(ImageUtil.MSG_ALERT)); + alertButton.setId("nav-alert-button"); + alertButton.relocate(36, 19); + alertButton.setOnAction((e) -> { + ordersButton.fire(); + //TODO + OrdersController.GET_INSTANCE().setSelectedTabIndex(1); + }); + Tooltip.install(alertButton, new Tooltip("Your offer has been accepted")); + ordersButtonButtonPane.getChildren().add(alertButton); + + AWTSystemTray.setAlert(); + }); + Platform.runLater(this::fadeOutSplash); } private void fadeOutSplash() { Profiler.printMsgWithTime("MainController.fadeOutSplash"); - Transitions.blur(viewBuilder.splashVBox, 700, false, true); - Transitions.fadeIn(viewBuilder.menuBar); - Transitions.fadeIn(viewBuilder.contentScreen); + Transitions.blur(baseOverlayContainer, 700, false, true); + Transitions.fadeIn(baseContentContainer); } /////////////////////////////////////////////////////////////////////////////////////////// - // Handlers + // Private /////////////////////////////////////////////////////////////////////////////////////////// - //TODO make ordersButton also reacting to jump to pending tab - private void onTakeOfferRequested(String offerId, PeerAddress sender) { - final Button alertButton = new Button("", ImageUtil.getIconImageView(ImageUtil.MSG_ALERT)); - alertButton.setId("nav-alert-button"); - alertButton.relocate(36, 19); - alertButton.setOnAction((e) -> { - ordersButton.fire(); - OrdersController.GET_INSTANCE().setSelectedTabIndex(1); - }); - Tooltip.install(alertButton, new Tooltip("Someone accepted your offer")); - ordersButtonButtonHolder.getChildren().add(alertButton); - - AWTSystemTray.setAlert(); + private BorderPane getBaseContentContainer() { + BorderPane borderPane = new BorderPane(); + borderPane.setId("base-content-container"); + return borderPane; } + private VBox getSplashScreen() { + VBox vBox = new VBox(); + vBox.setAlignment(Pos.CENTER); + vBox.setSpacing(10); + vBox.setId("splash"); - /////////////////////////////////////////////////////////////////////////////////////////// - // Private startup methods - /////////////////////////////////////////////////////////////////////////////////////////// + ImageView logo = ImageUtil.getIconImageView(ImageUtil.SPLASH_LOGO); + logo.setFitWidth(300); + logo.setFitHeight(300); - private void initFacades() { - Profiler.printMsgWithTime("MainController.initFacades"); - messageFacade.init(new BootstrapListener() { - @Override - public void onCompleted() { - messageFacadeInited = true; - if (walletFacadeInited) onFacadesInitialised(); - } + Label subTitle = new Label("The decentralized Bitcoin exchange"); + subTitle.setAlignment(Pos.CENTER); + subTitle.setId("logo-sub-title-label"); - @Override - public void onFailed(Throwable throwable) { - log.error(throwable.toString()); - } - }); + loadingLabel = new Label(); + loadingLabel.setAlignment(Pos.CENTER); + loadingLabel.setPadding(new Insets(80, 0, 0, 0)); + loadingLabel.textProperty().bind(presentationModel.splashScreenInfoText); - walletFacade.initialize(() -> { - walletFacadeInited = true; - if (messageFacadeInited) onFacadesInitialised(); - }); + vBox.getChildren().addAll(logo, subTitle, loadingLabel); + return vBox; } - private void addNavigation() { - Profiler.printMsgWithTime("MainController.addNavigation"); + private MenuBar getMenuBar() { + MenuBar menuBar = new MenuBar(); + menuBar.setUseSystemMenuBar(false); - homeButton = addNavButton(viewBuilder.leftNavPane, "Overview", NavigationItem.HOME); - buyButton = addNavButton(viewBuilder.leftNavPane, "Buy BTC", NavigationItem.BUY); - sellButton = addNavButton(viewBuilder.leftNavPane, "Sell BTC", NavigationItem.SELL); + Menu fileMenu = new Menu("_File"); + fileMenu.setMnemonicParsing(true); + MenuItem backupMenuItem = new MenuItem("Backup wallet"); + fileMenu.getItems().addAll(backupMenuItem); - ordersButtonButtonHolder = new Pane(); - ordersButton = addNavButton(ordersButtonButtonHolder, "Orders", NavigationItem.ORDERS); - viewBuilder.leftNavPane.getChildren().add(ordersButtonButtonHolder); + Menu settingsMenu = new Menu("_Settings"); + settingsMenu.setMnemonicParsing(true); + MenuItem changePwMenuItem = new MenuItem("Change password"); + settingsMenu.getItems().addAll(changePwMenuItem); - fundsButton = addNavButton(viewBuilder.leftNavPane, "Funds", NavigationItem.FUNDS); + Menu helpMenu = new Menu("_Help"); + helpMenu.setMnemonicParsing(true); + MenuItem faqMenuItem = new MenuItem("FAQ"); + MenuItem forumMenuItem = new MenuItem("Forum"); + helpMenu.getItems().addAll(faqMenuItem, forumMenuItem); + + menuBar.getMenus().setAll(fileMenu, settingsMenu, helpMenu); + return menuBar; + } + + private AnchorPane getContentScreen() { + AnchorPane anchorPane = new AnchorPane(); + anchorPane.setId("content-pane"); + + leftNavPane = new HBox(); + leftNavPane.setSpacing(10); + AnchorPane.setLeftAnchor(leftNavPane, 10d); + AnchorPane.setTopAnchor(leftNavPane, 0d); + + rightNavPane = new HBox(); + rightNavPane.setSpacing(10); + AnchorPane.setRightAnchor(rightNavPane, 10d); + AnchorPane.setTopAnchor(rightNavPane, 0d); + + contentPane = new AnchorPane(); + contentPane.setId("content-pane"); + AnchorPane.setLeftAnchor(contentPane, 0d); + AnchorPane.setRightAnchor(contentPane, 0d); + AnchorPane.setTopAnchor(contentPane, 60d); + AnchorPane.setBottomAnchor(contentPane, 20d); + + anchorPane.getChildren().addAll(leftNavPane, rightNavPane, contentPane); + return anchorPane; + } + + private void addNetworkSyncPane() { + networkSyncPane = new NetworkSyncPane(); + networkSyncPane.setSpacing(10); + networkSyncPane.setPrefHeight(20); + AnchorPane.setLeftAnchor(networkSyncPane, 0d); + AnchorPane.setBottomAnchor(networkSyncPane, 5d); + + presentationModel.networkSyncComplete.addListener((ov, old, newValue) -> { + if (newValue) + networkSyncPane.downloadComplete(); + }); + + contentScreen.getChildren().addAll(networkSyncPane); + } + + private void addMainNavigation() { + homeButton = addNavButton(leftNavPane, "Overview", NavigationItem.HOME); + buyButton = addNavButton(leftNavPane, "Buy BTC", NavigationItem.BUY); + sellButton = addNavButton(leftNavPane, "Sell BTC", NavigationItem.SELL); + + ordersButtonButtonPane = new Pane(); + ordersButton = addNavButton(ordersButtonButtonPane, "Orders", NavigationItem.ORDERS); + leftNavPane.getChildren().add(ordersButtonButtonPane); + + fundsButton = addNavButton(leftNavPane, "Funds", NavigationItem.FUNDS); final Pane msgButtonHolder = new Pane(); msgButton = addNavButton(msgButtonHolder, "Message", NavigationItem.MSG); - viewBuilder.leftNavPane.getChildren().add(msgButtonHolder); + leftNavPane.getChildren().add(msgButtonHolder); - addBalanceInfo(viewBuilder.rightNavPane); + addBalanceInfo(rightNavPane); - addAccountComboBox(viewBuilder.rightNavPane); + addBankAccountComboBox(rightNavPane); - settingsButton = addNavButton(viewBuilder.rightNavPane, "Settings", NavigationItem.SETTINGS); - accountButton = addNavButton(viewBuilder.rightNavPane, "Account", NavigationItem.ACCOUNT); + settingsButton = addNavButton(rightNavPane, "Settings", NavigationItem.SETTINGS); + accountButton = addNavButton(rightNavPane, "Account", NavigationItem.ACCOUNT); - Platform.runLater(this::onNavigationAdded); - } - - private void loadContentView() { - Profiler.printMsgWithTime("MainController.loadContentView"); - NavigationItem selectedNavigationItem = (NavigationItem) persistence.read(this, "selectedNavigationItem"); - if (selectedNavigationItem == null) - selectedNavigationItem = NavigationItem.BUY; - - loadViewAndGetChildController(selectedNavigationItem); - - Platform.runLater(this::onContentViewLoaded); - } - - - /////////////////////////////////////////////////////////////////////////////////////////// - // Private methods - /////////////////////////////////////////////////////////////////////////////////////////// - - private void loadView(NavigationItem navigationItem) { - final BSFXMLLoader loader = new BSFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl())); - try { - final Node view = loader.load(); - viewBuilder.contentPane.getChildren().setAll(view); - childController = loader.getController(); - - //TODO Remove that when all UIs are converted to CodeBehind - if (childController instanceof ViewController) - ((ViewController) childController).setParentController(this); - else if (childController instanceof CodeBehind) - ((CodeBehind) childController).setParentController(this); - - persistence.write(this, "selectedNavigationItem", navigationItem); - } catch (IOException e) { - log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl()); - e.getStackTrace(); - } + onMainNavigationAdded(); } private ToggleButton addNavButton(Pane parent, String title, NavigationItem navigationItem) { @@ -380,13 +457,8 @@ public class MainController extends ViewController { balanceTextField.setEditable(false); balanceTextField.setPrefWidth(110); balanceTextField.setId("nav-balance-label"); - balanceTextField.setText(BSFormatter.formatCoinWithCode(walletFacade.getWalletBalance())); - walletFacade.addBalanceListener(new BalanceListener() { - @Override - public void onBalanceChanged(Coin balance) { - balanceTextField.setText(BSFormatter.formatCoinWithCode(walletFacade.getWalletBalance())); - } - }); + balanceTextField.textProperty().bind(presentationModel.balance); + final Label titleLabel = new Label("Balance"); titleLabel.setMouseTransparent(true); @@ -402,37 +474,22 @@ public class MainController extends ViewController { parent.getChildren().add(vBox); } - private void addAccountComboBox(Pane parent) { - final ObservableList accounts = user.getBankAccounts(); - final ComboBox comboBox = - new ComboBox<>(FXCollections.observableArrayList(accounts)); + private void addBankAccountComboBox(Pane parent) { + final ComboBox comboBox = new ComboBox<>(presentationModel.getBankAccounts()); comboBox.setLayoutY(12); comboBox.setVisibleRowCount(5); - comboBox.setConverter(new StringConverter() { - @Override - public String toString(BankAccount bankAccount) { - return bankAccount.getAccountTitle(); - } + comboBox.setConverter(presentationModel.getBankAccountsConverter()); - @Override - public BankAccount fromString(String s) { - return null; - } - }); + comboBox.valueProperty().addListener((ov, oldValue, newValue) -> + presentationModel.setCurrentBankAccount(newValue)); - comboBox.setItems(accounts); - comboBox.valueProperty().addListener((ov, oldValue, newValue) -> user.setCurrentBankAccount(newValue)); - accounts.addListener((Observable observable) -> { - comboBox.setPromptText((accounts.size() == 0) ? "No accounts" : ""); - comboBox.setDisable((accounts.isEmpty())); - }); - comboBox.setPromptText((accounts.isEmpty()) ? "No accounts" : ""); - comboBox.setDisable((accounts.isEmpty())); - user.currentBankAccountProperty().addListener((ov, oldValue, newValue) -> { - if (newValue != null) - comboBox.getSelectionModel().select(newValue); - }); - comboBox.getSelectionModel().select(user.getCurrentBankAccount()); + comboBox.disableProperty().bind(presentationModel.bankAccountsComboBoxDisable); + comboBox.promptTextProperty().bind(presentationModel.bankAccountsComboBoxPrompt); + + presentationModel.currentBankAccountProperty().addListener((ov, oldValue, newValue) -> + comboBox.getSelectionModel().select(newValue)); + + comboBox.getSelectionModel().select(presentationModel.currentBankAccountProperty().get()); final Label titleLabel = new Label("Bank account"); titleLabel.setMouseTransparent(true); @@ -448,149 +505,5 @@ public class MainController extends ViewController { parent.getChildren().add(vBox); } - public void setPreviousNavigationItem(NavigationItem previousNavigationItem) { - this.previousNavigationItem = previousNavigationItem; - } - public NavigationItem getPreviousNavigationItem() { - return previousNavigationItem; - } -} - - -class ViewBuilder { - HBox leftNavPane, rightNavPane; - AnchorPane contentPane; - NetworkSyncPane networkSyncPane; - BorderPane baseContentContainer; - AnchorPane contentScreen; - VBox splashVBox; - MenuBar menuBar; - StackPane root; - Label loadingLabel; - boolean showNetworkSyncPane; - - void buildSplashScreen(StackPane root, MainController controller) { - Profiler.printMsgWithTime("MainController.ViewBuilder.buildSplashScreen"); - - this.root = root; - - baseContentContainer = new BorderPane(); - baseContentContainer.setId("base-content-container"); - splashVBox = getSplashScreen(); - - root.getChildren().addAll(baseContentContainer, splashVBox); - - Platform.runLater(() -> buildContentView(controller)); - } - - void buildContentView(MainController controller) { - Profiler.printMsgWithTime("MainController.ViewBuilder.buildContentView"); - - menuBar = getMenuBar(); - baseContentContainer.setTop(menuBar); - - contentScreen = getContentScreen(); - baseContentContainer.setCenter(contentScreen); - - Platform.runLater(controller::onViewInitialized); - } - - AnchorPane getContentScreen() { - AnchorPane anchorPane = new AnchorPane(); - anchorPane.setId("content-pane"); - - leftNavPane = new HBox(); - // leftNavPane.setAlignment(Pos.CENTER); - leftNavPane.setSpacing(10); - AnchorPane.setLeftAnchor(leftNavPane, 10d); - AnchorPane.setTopAnchor(leftNavPane, 0d); - - rightNavPane = new HBox(); - // rightNavPane.setAlignment(Pos.CENTER); - rightNavPane.setSpacing(10); - AnchorPane.setRightAnchor(rightNavPane, 10d); - AnchorPane.setTopAnchor(rightNavPane, 0d); - - contentPane = new AnchorPane(); - contentPane.setId("content-pane"); - AnchorPane.setLeftAnchor(contentPane, 0d); - AnchorPane.setRightAnchor(contentPane, 0d); - AnchorPane.setTopAnchor(contentPane, 60d); - AnchorPane.setBottomAnchor(contentPane, 20d); - - anchorPane.getChildren().addAll(leftNavPane, rightNavPane, contentPane); - anchorPane.setOpacity(0); - - if (showNetworkSyncPane) - addNetworkSyncPane(); - - return anchorPane; - } - - void setShowNetworkSyncPane() { - showNetworkSyncPane = true; - - if (contentScreen != null) - addNetworkSyncPane(); - } - - private void addNetworkSyncPane() { - networkSyncPane = new NetworkSyncPane(); - networkSyncPane.setSpacing(10); - networkSyncPane.setPrefHeight(20); - AnchorPane.setLeftAnchor(networkSyncPane, 0d); - AnchorPane.setBottomAnchor(networkSyncPane, 5d); - - contentScreen.getChildren().addAll(networkSyncPane); - } - - VBox getSplashScreen() { - VBox splashVBox = new VBox(); - splashVBox.setAlignment(Pos.CENTER); - splashVBox.setSpacing(10); - splashVBox.setId("splash"); - - ImageView logo = ImageUtil.getIconImageView(ImageUtil.SPLASH_LOGO); - logo.setFitWidth(300); - logo.setFitHeight(300); - - Label subTitle = new Label("The decentralized Bitcoin exchange"); - subTitle.setAlignment(Pos.CENTER); - subTitle.setId("logo-sub-title-label"); - - loadingLabel = new Label("Initializing..."); - loadingLabel.setAlignment(Pos.CENTER); - loadingLabel.setPadding(new Insets(80, 0, 0, 0)); - - splashVBox.getChildren().addAll(logo, subTitle, loadingLabel); - return splashVBox; - } - - MenuBar getMenuBar() { - MenuBar menuBar = new MenuBar(); - // on mac we could place menu bar in the systems menu - // menuBar.setUseSystemMenuBar(true); - menuBar.setUseSystemMenuBar(false); - - Menu fileMenu = new Menu("_File"); - fileMenu.setMnemonicParsing(true); - MenuItem backupMenuItem = new MenuItem("Backup wallet"); - fileMenu.getItems().addAll(backupMenuItem); - - Menu settingsMenu = new Menu("_Settings"); - settingsMenu.setMnemonicParsing(true); - MenuItem changePwMenuItem = new MenuItem("Change password"); - settingsMenu.getItems().addAll(changePwMenuItem); - - Menu helpMenu = new Menu("_Help"); - helpMenu.setMnemonicParsing(true); - MenuItem faqMenuItem = new MenuItem("FAQ"); - MenuItem forumMenuItem = new MenuItem("Forum"); - helpMenu.getItems().addAll(faqMenuItem, forumMenuItem); - - menuBar.getMenus().setAll(fileMenu, settingsMenu, helpMenu); - menuBar.setOpacity(0); - return menuBar; - } } diff --git a/src/main/java/io/bitsquare/gui/view/account/AccountSettingsView.fxml b/src/main/java/io/bitsquare/gui/view/account/AccountSettingsView.fxml index 45f0167e3d..e2d022d48d 100644 --- a/src/main/java/io/bitsquare/gui/view/account/AccountSettingsView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/AccountSettingsView.fxml @@ -19,7 +19,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/account/AccountSettingsCB.java b/src/main/java/io/bitsquare/gui/view/account/AccountSettingsViewCB.java similarity index 93% rename from src/main/java/io/bitsquare/gui/view/account/AccountSettingsCB.java rename to src/main/java/io/bitsquare/gui/view/account/AccountSettingsViewCB.java index d6ccfc33c6..58673aed35 100644 --- a/src/main/java/io/bitsquare/gui/view/account/AccountSettingsCB.java +++ b/src/main/java/io/bitsquare/gui/view/account/AccountSettingsViewCB.java @@ -22,7 +22,7 @@ import io.bitsquare.gui.CodeBehind; import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.PresentationModel; import io.bitsquare.gui.pm.account.AccountSettingsPM; -import io.bitsquare.gui.view.account.content.AdjustableAccountContent; +import io.bitsquare.gui.view.account.content.ContextAware; import io.bitsquare.util.BSFXMLLoader; import java.io.IOException; @@ -45,9 +45,9 @@ import de.jensd.fx.fontawesome.AwesomeIcon; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class AccountSettingsCB extends CachedCodeBehind { +public class AccountSettingsViewCB extends CachedCodeBehind { - private static final Logger log = LoggerFactory.getLogger(AccountSettingsCB.class); + private static final Logger log = LoggerFactory.getLogger(AccountSettingsViewCB.class); public VBox leftVBox; public AnchorPane content; @@ -56,7 +56,7 @@ public class AccountSettingsCB extends CachedCodeBehind { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private AccountSettingsCB(AccountSettingsPM presentationModel) { + private AccountSettingsViewCB(AccountSettingsPM presentationModel) { super(presentationModel); } @@ -133,11 +133,11 @@ class MenuItem extends ToggleButton { private CodeBehind childController; - private final AccountSettingsCB parentCB; + private final AccountSettingsViewCB parentCB; private final Parent content; private final NavigationItem navigationItem; - MenuItem(AccountSettingsCB parentCB, Parent content, String title, NavigationItem navigationItem, + MenuItem(AccountSettingsViewCB parentCB, Parent content, String title, NavigationItem navigationItem, ToggleGroup toggleGroup) { this.parentCB = parentCB; this.content = content; @@ -193,7 +193,7 @@ class MenuItem extends ToggleButton { ((AnchorPane) content).getChildren().setAll(view); childController = loader.getController(); childController.setParentController(parentCB); - ((AdjustableAccountContent) childController).isSettingsMode(true); + ((ContextAware) childController).useSettingsContext(true); } catch (IOException e) { log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl()); e.getStackTrace(); diff --git a/src/main/java/io/bitsquare/gui/view/account/AccountSetupView.fxml b/src/main/java/io/bitsquare/gui/view/account/AccountSetupView.fxml index 5734ba16a1..7a081bc336 100644 --- a/src/main/java/io/bitsquare/gui/view/account/AccountSetupView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/AccountSetupView.fxml @@ -19,7 +19,7 @@ - { +public class AccountSetupViewCB extends CachedCodeBehind { - private static final Logger log = LoggerFactory.getLogger(AccountSetupCB.class); + private static final Logger log = LoggerFactory.getLogger(AccountSetupViewCB.class); private WizardItem seedWords, password, fiatAccount, restrictions, registration; private Callable requestCloseCallable; @@ -66,7 +66,7 @@ public class AccountSetupCB extends CachedCodeBehind { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private AccountSetupCB(AccountSetupPM presentationModel) { + private AccountSetupViewCB(AccountSetupPM presentationModel) { super(presentationModel); } @@ -122,23 +122,23 @@ public class AccountSetupCB extends CachedCodeBehind { /////////////////////////////////////////////////////////////////////////////////////////// public void onCompleted(CodeBehind childView) { - if (childView instanceof SeedWordsCB) { + if (childView instanceof SeedWordsViewCB) { seedWords.onCompleted(); childController = password.show(); } - else if (childView instanceof PasswordCB) { + else if (childView instanceof PasswordViewCB) { password.onCompleted(); childController = restrictions.show(); } - else if (childView instanceof RestrictionsCB) { + else if (childView instanceof RestrictionsViewCB) { restrictions.onCompleted(); childController = fiatAccount.show(); } - else if (childView instanceof FiatAccountCB) { + else if (childView instanceof FiatAccountViewCB) { fiatAccount.onCompleted(); childController = registration.show(); } - else if (childView instanceof RegistrationCB) { + else if (childView instanceof RegistrationViewCB) { registration.onCompleted(); childController = null; @@ -171,11 +171,12 @@ class WizardItem extends HBox { private final ImageView imageView; private final Label titleLabel; private final Label subTitleLabel; - private final AccountSetupCB parentCB; + private final AccountSetupViewCB parentCB; private final Parent content; private final NavigationItem navigationItem; - WizardItem(AccountSetupCB parentCB, Parent content, String title, String subTitle, NavigationItem navigationItem) { + WizardItem(AccountSetupViewCB parentCB, Parent content, String title, String subTitle, + NavigationItem navigationItem) { this.parentCB = parentCB; this.content = content; this.navigationItem = navigationItem; @@ -236,7 +237,7 @@ class WizardItem extends HBox { ((AnchorPane) content).getChildren().setAll(view); childController = loader.getController(); childController.setParentController(parentCB); - ((AdjustableAccountContent) childController).isSettingsMode(false); + ((ContextAware) childController).useSettingsContext(false); } catch (IOException e) { log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl()); e.getStackTrace(); diff --git a/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordView.fxml b/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordView.fxml index cebe7ecad6..f11978bb7a 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordView.fxml @@ -21,7 +21,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordCB.java b/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordViewCB.java similarity index 85% rename from src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordCB.java rename to src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordViewCB.java index 0810837ba7..7ec4fd62d0 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordCB.java +++ b/src/main/java/io/bitsquare/gui/view/account/content/ChangePasswordViewCB.java @@ -21,7 +21,7 @@ import io.bitsquare.gui.CachedCodeBehind; import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; import io.bitsquare.gui.pm.account.content.ChangePasswordPM; -import io.bitsquare.gui.view.account.AccountSetupCB; +import io.bitsquare.gui.view.account.AccountSetupViewCB; import java.net.URL; @@ -36,9 +36,9 @@ import javafx.scene.layout.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class ChangePasswordCB extends CachedCodeBehind implements AdjustableAccountContent { +public class ChangePasswordViewCB extends CachedCodeBehind implements ContextAware { - private static final Logger log = LoggerFactory.getLogger(ChangePasswordCB.class); + private static final Logger log = LoggerFactory.getLogger(ChangePasswordViewCB.class); @FXML private HBox buttonsHBox; @FXML private Button saveButton, skipButton; @@ -50,7 +50,7 @@ public class ChangePasswordCB extends CachedCodeBehind impleme /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private ChangePasswordCB(ChangePasswordPM presentationModel) { + private ChangePasswordViewCB(ChangePasswordPM presentationModel) { super(presentationModel); } @@ -93,8 +93,8 @@ public class ChangePasswordCB extends CachedCodeBehind impleme /////////////////////////////////////////////////////////////////////////////////////////// @Override - public void isSettingsMode(boolean isSettingsMode) { - if (isSettingsMode) + public void useSettingsContext(boolean useSettingsContext) { + if (useSettingsContext) buttonsHBox.getChildren().remove(skipButton); } @@ -107,8 +107,8 @@ public class ChangePasswordCB extends CachedCodeBehind impleme private void onSaved() { boolean result = presentationModel.requestSavePassword(); if (result) { - if (parentController instanceof AccountSetupCB) - ((AccountSetupCB) parentController).onCompleted(this); + if (parentController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) parentController).onCompleted(this); } else { log.debug(presentationModel.getErrorMessage()); // TODO use validating TF @@ -122,8 +122,8 @@ public class ChangePasswordCB extends CachedCodeBehind impleme @FXML private void onSkipped() { - if (parentController instanceof AccountSetupCB) - ((AccountSetupCB) parentController).onCompleted(this); + if (parentController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) parentController).onCompleted(this); } } diff --git a/src/main/java/io/bitsquare/gui/view/account/content/AdjustableAccountContent.java b/src/main/java/io/bitsquare/gui/view/account/content/ContextAware.java similarity index 88% rename from src/main/java/io/bitsquare/gui/view/account/content/AdjustableAccountContent.java rename to src/main/java/io/bitsquare/gui/view/account/content/ContextAware.java index 135f7a6b76..bacb45ed86 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/AdjustableAccountContent.java +++ b/src/main/java/io/bitsquare/gui/view/account/content/ContextAware.java @@ -17,6 +17,6 @@ package io.bitsquare.gui.view.account.content; -public interface AdjustableAccountContent { - void isSettingsMode(boolean isSettingsMode); +public interface ContextAware { + void useSettingsContext(boolean useSettingsContext); } diff --git a/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountView.fxml b/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountView.fxml index 73ea682fa9..17f914fc47 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountView.fxml @@ -23,7 +23,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountCB.java b/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountViewCB.java similarity index 96% rename from src/main/java/io/bitsquare/gui/view/account/content/FiatAccountCB.java rename to src/main/java/io/bitsquare/gui/view/account/content/FiatAccountViewCB.java index f6e3ba043b..eb1e816fee 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountCB.java +++ b/src/main/java/io/bitsquare/gui/view/account/content/FiatAccountViewCB.java @@ -26,7 +26,7 @@ import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; import io.bitsquare.gui.pm.account.content.FiatAccountPm; import io.bitsquare.gui.util.validation.InputValidator; -import io.bitsquare.gui.view.account.AccountSetupCB; +import io.bitsquare.gui.view.account.AccountSetupViewCB; import io.bitsquare.locale.Country; import io.bitsquare.locale.Region; @@ -52,9 +52,9 @@ import org.slf4j.LoggerFactory; import static javafx.beans.binding.Bindings.createBooleanBinding; -public class FiatAccountCB extends CachedCodeBehind implements AdjustableAccountContent { +public class FiatAccountViewCB extends CachedCodeBehind implements ContextAware { - private static final Logger log = LoggerFactory.getLogger(FiatAccountCB.class); + private static final Logger log = LoggerFactory.getLogger(FiatAccountViewCB.class); @FXML private HBox buttonsHBox; @FXML private ComboBox regionComboBox; @@ -71,7 +71,7 @@ public class FiatAccountCB extends CachedCodeBehind implements Ad /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private FiatAccountCB(FiatAccountPm presentationModel) { + private FiatAccountViewCB(FiatAccountPm presentationModel) { super(presentationModel); } @@ -126,8 +126,8 @@ public class FiatAccountCB extends CachedCodeBehind implements Ad /////////////////////////////////////////////////////////////////////////////////////////// @Override - public void isSettingsMode(boolean isSettingsMode) { - if (isSettingsMode) + public void useSettingsContext(boolean useSettingsContext) { + if (useSettingsContext) buttonsHBox.getChildren().remove(completedButton); } @@ -177,7 +177,7 @@ public class FiatAccountCB extends CachedCodeBehind implements Ad @FXML private void onCompleted() { if (parentController != null) - ((AccountSetupCB) parentController).onCompleted(this); + ((AccountSetupViewCB) parentController).onCompleted(this); } @FXML diff --git a/src/main/java/io/bitsquare/gui/view/account/content/PasswordView.fxml b/src/main/java/io/bitsquare/gui/view/account/content/PasswordView.fxml index a9a99e3099..976f31ec1f 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/PasswordView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/content/PasswordView.fxml @@ -21,7 +21,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/account/content/PasswordCB.java b/src/main/java/io/bitsquare/gui/view/account/content/PasswordViewCB.java similarity index 85% rename from src/main/java/io/bitsquare/gui/view/account/content/PasswordCB.java rename to src/main/java/io/bitsquare/gui/view/account/content/PasswordViewCB.java index bdadadc6a0..de5f373493 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/PasswordCB.java +++ b/src/main/java/io/bitsquare/gui/view/account/content/PasswordViewCB.java @@ -21,7 +21,7 @@ import io.bitsquare.gui.CachedCodeBehind; import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; import io.bitsquare.gui.pm.account.content.PasswordPM; -import io.bitsquare.gui.view.account.AccountSetupCB; +import io.bitsquare.gui.view.account.AccountSetupViewCB; import java.net.URL; @@ -36,9 +36,9 @@ import javafx.scene.layout.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class PasswordCB extends CachedCodeBehind implements AdjustableAccountContent { +public class PasswordViewCB extends CachedCodeBehind implements ContextAware { - private static final Logger log = LoggerFactory.getLogger(PasswordCB.class); + private static final Logger log = LoggerFactory.getLogger(PasswordViewCB.class); @FXML private HBox buttonsHBox; @FXML private Button saveButton, skipButton; @@ -50,7 +50,7 @@ public class PasswordCB extends CachedCodeBehind implements Adjustab /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private PasswordCB(PasswordPM presentationModel) { + private PasswordViewCB(PasswordPM presentationModel) { super(presentationModel); } @@ -93,8 +93,8 @@ public class PasswordCB extends CachedCodeBehind implements Adjustab /////////////////////////////////////////////////////////////////////////////////////////// @Override - public void isSettingsMode(boolean isSettingsMode) { - if (isSettingsMode) + public void useSettingsContext(boolean useSettingsContext) { + if (useSettingsContext) buttonsHBox.getChildren().remove(skipButton); } @@ -107,8 +107,8 @@ public class PasswordCB extends CachedCodeBehind implements Adjustab private void onSaved() { boolean result = presentationModel.requestSavePassword(); if (result) { - if (parentController instanceof AccountSetupCB) - ((AccountSetupCB) parentController).onCompleted(this); + if (parentController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) parentController).onCompleted(this); } else { // TODO use validating passwordTF @@ -118,8 +118,8 @@ public class PasswordCB extends CachedCodeBehind implements Adjustab @FXML private void onSkipped() { - if (parentController instanceof AccountSetupCB) - ((AccountSetupCB) parentController).onCompleted(this); + if (parentController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) parentController).onCompleted(this); } @FXML diff --git a/src/main/java/io/bitsquare/gui/view/account/content/RegistrationView.fxml b/src/main/java/io/bitsquare/gui/view/account/content/RegistrationView.fxml index c220fe549d..4851af9885 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/RegistrationView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/content/RegistrationView.fxml @@ -23,7 +23,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/account/content/RegistrationCB.java b/src/main/java/io/bitsquare/gui/view/account/content/RegistrationViewCB.java similarity index 90% rename from src/main/java/io/bitsquare/gui/view/account/content/RegistrationCB.java rename to src/main/java/io/bitsquare/gui/view/account/content/RegistrationViewCB.java index ac7558882f..96f95314af 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/RegistrationCB.java +++ b/src/main/java/io/bitsquare/gui/view/account/content/RegistrationViewCB.java @@ -18,14 +18,14 @@ package io.bitsquare.gui.view.account.content; import io.bitsquare.gui.CachedCodeBehind; -import io.bitsquare.gui.MainController; import io.bitsquare.gui.components.Popups; import io.bitsquare.gui.components.btc.AddressTextField; import io.bitsquare.gui.components.btc.BalanceTextField; import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; import io.bitsquare.gui.pm.account.content.RegistrationPM; -import io.bitsquare.gui.view.account.AccountSetupCB; +import io.bitsquare.gui.view.MainViewCB; +import io.bitsquare.gui.view.account.AccountSetupViewCB; import io.bitsquare.locale.BSResources; import java.net.URL; @@ -48,9 +48,9 @@ import org.controlsfx.dialog.Dialog; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RegistrationCB extends CachedCodeBehind implements AdjustableAccountContent { +public class RegistrationViewCB extends CachedCodeBehind implements ContextAware { - private static final Logger log = LoggerFactory.getLogger(RegistrationCB.class); + private static final Logger log = LoggerFactory.getLogger(RegistrationViewCB.class); @FXML private TextField feeTextField; @@ -64,7 +64,7 @@ public class RegistrationCB extends CachedCodeBehind implements /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private RegistrationCB(RegistrationPM presentationModel) { + private RegistrationViewCB(RegistrationPM presentationModel) { super(presentationModel); } @@ -95,7 +95,7 @@ public class RegistrationCB extends CachedCodeBehind implements presentationModel.showTransactionPublishedScreen.addListener((o, oldValue, newValue) -> { if (newValue) { - MainController.GET_INSTANCE().blurContentScreen(); + MainViewCB.getInstance().blurContentScreen(); List actions = new ArrayList<>(); actions.add(new AbstractAction(BSResources.get("shared.copyTxId")) { @@ -111,13 +111,13 @@ public class RegistrationCB extends CachedCodeBehind implements @Override public void handle(ActionEvent actionEvent) { try { - if (parentController instanceof AccountSetupCB) - ((AccountSetupCB) parentController).onCompleted(RegistrationCB.this); + if (parentController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) parentController).onCompleted(RegistrationViewCB.this); } catch (Exception e) { e.printStackTrace(); } Dialog.Actions.CLOSE.handle(actionEvent); - MainController.GET_INSTANCE().removeContentScreenBlur(); + MainViewCB.getInstance().removeContentScreenBlur(); } }); @@ -155,8 +155,8 @@ public class RegistrationCB extends CachedCodeBehind implements /////////////////////////////////////////////////////////////////////////////////////////// @Override - public void isSettingsMode(boolean isSettingsMode) { - if (isSettingsMode) { + public void useSettingsContext(boolean useSettingsContext) { + if (useSettingsContext) { // TODO } } diff --git a/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsView.fxml b/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsView.fxml index 4948822510..0908924b55 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsView.fxml @@ -20,7 +20,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsCB.java b/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsViewCB.java similarity index 96% rename from src/main/java/io/bitsquare/gui/view/account/content/RestrictionsCB.java rename to src/main/java/io/bitsquare/gui/view/account/content/RestrictionsViewCB.java index af7993bc7d..95351e451a 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsCB.java +++ b/src/main/java/io/bitsquare/gui/view/account/content/RestrictionsViewCB.java @@ -25,7 +25,7 @@ import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; import io.bitsquare.gui.pm.account.content.RestrictionsPM; import io.bitsquare.gui.util.ImageUtil; -import io.bitsquare.gui.view.account.AccountSetupCB; +import io.bitsquare.gui.view.account.AccountSetupViewCB; import io.bitsquare.locale.Country; import io.bitsquare.locale.Region; import io.bitsquare.util.BSFXMLLoader; @@ -53,9 +53,9 @@ import javafx.util.StringConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class RestrictionsCB extends CachedCodeBehind implements AdjustableAccountContent { +public class RestrictionsViewCB extends CachedCodeBehind implements ContextAware { - private static final Logger log = LoggerFactory.getLogger(RestrictionsCB.class); + private static final Logger log = LoggerFactory.getLogger(RestrictionsViewCB.class); @FXML private ListView languagesListView, countriesListView, arbitratorsListView; @FXML private ComboBox languageComboBox; @@ -69,7 +69,7 @@ public class RestrictionsCB extends CachedCodeBehind implements /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private RestrictionsCB(RestrictionsPM presentationModel) { + private RestrictionsViewCB(RestrictionsPM presentationModel) { super(presentationModel); } @@ -116,8 +116,8 @@ public class RestrictionsCB extends CachedCodeBehind implements /////////////////////////////////////////////////////////////////////////////////////////// @Override - public void isSettingsMode(boolean isSettingsMode) { - if (isSettingsMode) + public void useSettingsContext(boolean useSettingsContext) { + if (useSettingsContext) ((GridPane) root).getChildren().remove(completedButton); } @@ -160,8 +160,8 @@ public class RestrictionsCB extends CachedCodeBehind implements @FXML private void onCompleted() { - if (parentController instanceof AccountSetupCB) - ((AccountSetupCB) parentController).onCompleted(this); + if (parentController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) parentController).onCompleted(this); } @FXML diff --git a/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsView.fxml b/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsView.fxml index 755c1a823a..293237e4f2 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsView.fxml +++ b/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsView.fxml @@ -22,7 +22,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsCB.java b/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsViewCB.java similarity index 86% rename from src/main/java/io/bitsquare/gui/view/account/content/SeedWordsCB.java rename to src/main/java/io/bitsquare/gui/view/account/content/SeedWordsViewCB.java index 0311640784..800bca6e0c 100644 --- a/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsCB.java +++ b/src/main/java/io/bitsquare/gui/view/account/content/SeedWordsViewCB.java @@ -21,7 +21,7 @@ import io.bitsquare.gui.CachedCodeBehind; import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; import io.bitsquare.gui.pm.account.content.SeedWordsPM; -import io.bitsquare.gui.view.account.AccountSetupCB; +import io.bitsquare.gui.view.account.AccountSetupViewCB; import java.net.URL; @@ -36,9 +36,9 @@ import javafx.scene.layout.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SeedWordsCB extends CachedCodeBehind implements AdjustableAccountContent { +public class SeedWordsViewCB extends CachedCodeBehind implements ContextAware { - private static final Logger log = LoggerFactory.getLogger(SeedWordsCB.class); + private static final Logger log = LoggerFactory.getLogger(SeedWordsViewCB.class); @FXML private Button completedButton; @FXML private TextArea seedWordsTextArea; @@ -49,7 +49,7 @@ public class SeedWordsCB extends CachedCodeBehind implements Adjust /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private SeedWordsCB(SeedWordsPM presentationModel) { + private SeedWordsViewCB(SeedWordsPM presentationModel) { super(presentationModel); } @@ -89,8 +89,8 @@ public class SeedWordsCB extends CachedCodeBehind implements Adjust /////////////////////////////////////////////////////////////////////////////////////////// @Override - public void isSettingsMode(boolean isSettingsMode) { - if (isSettingsMode) + public void useSettingsContext(boolean useSettingsContext) { + if (useSettingsContext) ((GridPane) root).getChildren().remove(completedButton); } @@ -101,8 +101,8 @@ public class SeedWordsCB extends CachedCodeBehind implements Adjust @FXML private void onCompleted() { - if (parentController instanceof AccountSetupCB) - ((AccountSetupCB) parentController).onCompleted(this); + if (parentController instanceof AccountSetupViewCB) + ((AccountSetupViewCB) parentController).onCompleted(this); } @FXML diff --git a/src/main/java/io/bitsquare/gui/view/trade/CreateOfferView.fxml b/src/main/java/io/bitsquare/gui/view/trade/CreateOfferView.fxml index 8b53a9fa36..8e5fb15801 100644 --- a/src/main/java/io/bitsquare/gui/view/trade/CreateOfferView.fxml +++ b/src/main/java/io/bitsquare/gui/view/trade/CreateOfferView.fxml @@ -26,7 +26,7 @@ - diff --git a/src/main/java/io/bitsquare/gui/view/trade/CreateOfferCB.java b/src/main/java/io/bitsquare/gui/view/trade/CreateOfferViewCB.java similarity index 98% rename from src/main/java/io/bitsquare/gui/view/trade/CreateOfferCB.java rename to src/main/java/io/bitsquare/gui/view/trade/CreateOfferViewCB.java index 26bbeda425..9af531cbd7 100644 --- a/src/main/java/io/bitsquare/gui/view/trade/CreateOfferCB.java +++ b/src/main/java/io/bitsquare/gui/view/trade/CreateOfferViewCB.java @@ -18,7 +18,6 @@ package io.bitsquare.gui.view.trade; import io.bitsquare.gui.CachedCodeBehind; -import io.bitsquare.gui.MainController; import io.bitsquare.gui.NavigationItem; import io.bitsquare.gui.components.InfoDisplay; import io.bitsquare.gui.components.InputTextField; @@ -29,6 +28,7 @@ import io.bitsquare.gui.help.Help; import io.bitsquare.gui.help.HelpId; import io.bitsquare.gui.pm.trade.CreateOfferPM; import io.bitsquare.gui.util.ImageUtil; +import io.bitsquare.gui.view.MainViewCB; import io.bitsquare.locale.BSResources; import io.bitsquare.trade.orderbook.OrderBookFilter; @@ -70,8 +70,8 @@ import static javafx.beans.binding.Bindings.createStringBinding; // TODO Implement other positioning method in InoutTextField to display it over the field instead of right side // priceAmountHBox is too large after redesign as to be used as layoutReference. -public class CreateOfferCB extends CachedCodeBehind { - private static final Logger log = LoggerFactory.getLogger(CreateOfferCB.class); +public class CreateOfferViewCB extends CachedCodeBehind { + private static final Logger log = LoggerFactory.getLogger(CreateOfferViewCB.class); private boolean detailsVisible; private boolean advancedScreenInited; @@ -105,7 +105,7 @@ public class CreateOfferCB extends CachedCodeBehind { /////////////////////////////////////////////////////////////////////////////////////////// @Inject - private CreateOfferCB(CreateOfferPM presentationModel) { + private CreateOfferViewCB(CreateOfferPM presentationModel) { super(presentationModel); } @@ -234,7 +234,7 @@ public class CreateOfferCB extends CachedCodeBehind { /////////////////////////////////////////////////////////////////////////////////////////// private void openAccountSettings() { - MainController.GET_INSTANCE().loadViewAndGetChildController(NavigationItem.ACCOUNT); + MainViewCB.getInstance().triggerMainMenuButton(NavigationItem.ACCOUNT); } private void close() { @@ -306,7 +306,7 @@ public class CreateOfferCB extends CachedCodeBehind { presentationModel.showTransactionPublishedScreen.addListener((o, oldValue, newValue) -> { if (newValue) { - MainController.GET_INSTANCE().blurContentScreen(); + MainViewCB.getInstance().blurContentScreen(); // Dialogs are a bit limited. There is no callback for the InformationDialog button click, so we added // our own actions. @@ -329,7 +329,7 @@ public class CreateOfferCB extends CachedCodeBehind { e.printStackTrace(); } Dialog.Actions.CLOSE.handle(actionEvent); - MainController.GET_INSTANCE().removeContentScreenBlur(); + MainViewCB.getInstance().removeContentScreenBlur(); } });