From 3fcd3d8c9b12fea1da72f087fc78ba07ea58ccfa Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Thu, 4 Sep 2014 16:59:45 +0200 Subject: [PATCH] Make setup visible --- .../java/io/bitsquare/gui/MainController.java | 49 ++++++++++++-- .../java/io/bitsquare/gui/ViewController.java | 13 +++- .../registration/RegistrationController.java | 4 -- .../{SetupController.java => SetupCB.java} | 12 ++-- .../io/bitsquare/gui/setup/SetupModel.java | 65 +++++++++++++++++++ .../java/io/bitsquare/gui/setup/SetupPm.java | 65 +++++++++++++++++++ .../io/bitsquare/gui/setup/SetupView.fxml | 10 ++- .../trade/orderbook/OrderBookController.java | 29 ++++++++- .../resources/i18n/displayStrings.properties | 4 +- 9 files changed, 223 insertions(+), 28 deletions(-) rename src/main/java/io/bitsquare/gui/setup/{SetupController.java => SetupCB.java} (87%) create mode 100644 src/main/java/io/bitsquare/gui/setup/SetupModel.java create mode 100644 src/main/java/io/bitsquare/gui/setup/SetupPm.java diff --git a/src/main/java/io/bitsquare/gui/MainController.java b/src/main/java/io/bitsquare/gui/MainController.java index 0f7252681f..4102eaa943 100644 --- a/src/main/java/io/bitsquare/gui/MainController.java +++ b/src/main/java/io/bitsquare/gui/MainController.java @@ -200,7 +200,35 @@ public class MainController extends ViewController { private void onNavigationAdded() { Profiler.printMsgWithTime("MainController.onNavigationAdded"); - Platform.runLater(this::loadContentView); + // Platform.runLater(this::loadContentView); + // TODO for dev testing + Platform.runLater(this::loadSetup); + } + + //TODO for dev testing + private void loadSetup() { + Profiler.printMsgWithTime("MainController.loadSetup"); + + final GuiceFXMLLoader loader = new GuiceFXMLLoader(getClass().getResource(NavigationItem.SETUP.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); + + } catch (IOException e) { + log.error("Loading view failed. FxmlUrl = " + NavigationItem.SETUP.getFxmlUrl()); + log.error(e.getCause().toString()); + log.error(e.getMessage()); + log.error(e.getStackTrace().toString()); + } + + Platform.runLater(this::onContentViewLoaded); } private void onContentViewLoaded() { @@ -310,15 +338,24 @@ public class MainController extends ViewController { // Private methods /////////////////////////////////////////////////////////////////////////////////////////// - private void loadViewFromNavButton(NavigationItem navigationItem) { + private void loadView(NavigationItem navigationItem) { final GuiceFXMLLoader loader = new GuiceFXMLLoader(getClass().getResource(navigationItem.getFxmlUrl())); try { final Node view = loader.load(); viewBuilder.contentPane.getChildren().setAll(view); childController = loader.getController(); - childController.setParentController(this); + + //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); + } catch (IOException e) { - log.error("Loading view failed. " + navigationItem.getFxmlUrl()); + log.error("Loading view failed. FxmlUrl = " + navigationItem.getFxmlUrl()); + log.error(e.getCause().toString()); + log.error(e.getMessage()); + log.error(e.getStackTrace().toString()); } } @@ -336,7 +373,7 @@ public class MainController extends ViewController { prevToggleButtonIcon = ((ImageView) (toggleButton.getGraphic())).getImage(); ((ImageView) (toggleButton.getGraphic())).setImage(ImageUtil.getIconImage(navigationItem.getActiveIcon())); - loadViewFromNavButton(navigationItem); + loadView(navigationItem); persistence.write(this, "selectedNavigationItem", navigationItem); @@ -517,7 +554,7 @@ class ViewBuilder { logo.setFitWidth(300); logo.setFitHeight(300); - Label subTitle = new Label("The P2P Fiat-Bitcoin Exchange"); + Label subTitle = new Label("The decentralized Bitcoin exchange"); subTitle.setAlignment(Pos.CENTER); subTitle.setId("logo-sub-title-label"); diff --git a/src/main/java/io/bitsquare/gui/ViewController.java b/src/main/java/io/bitsquare/gui/ViewController.java index 07cac08bef..27ed4d019c 100644 --- a/src/main/java/io/bitsquare/gui/ViewController.java +++ b/src/main/java/io/bitsquare/gui/ViewController.java @@ -36,8 +36,8 @@ import org.slf4j.LoggerFactory; public abstract class ViewController implements Initializable { private static final Logger log = LoggerFactory.getLogger(ViewController.class); - protected ViewController childController; - protected ViewController parentController; + protected Initializable childController; + protected Initializable parentController; @FXML protected Parent root; @@ -63,7 +63,14 @@ public abstract class ViewController implements Initializable { */ public void terminate() { log.trace("Lifecycle: terminate " + this.getClass().getSimpleName()); - if (childController != null) childController.terminate(); + + if (childController != null) { + if (childController instanceof ViewController) + ((ViewController) childController).terminate(); + else if (childController instanceof CodeBehind) + ((CodeBehind) childController).terminate(); + } + } /** diff --git a/src/main/java/io/bitsquare/gui/registration/RegistrationController.java b/src/main/java/io/bitsquare/gui/registration/RegistrationController.java index ca77cf374a..5bfea64cc0 100644 --- a/src/main/java/io/bitsquare/gui/registration/RegistrationController.java +++ b/src/main/java/io/bitsquare/gui/registration/RegistrationController.java @@ -18,7 +18,6 @@ package io.bitsquare.gui.registration; import io.bitsquare.gui.CodeBehind; -import io.bitsquare.gui.trade.TradeController; import java.net.URL; @@ -54,9 +53,6 @@ public class RegistrationController extends CodeBehind { @Override public void terminate() { super.terminate(); - - // Used to reset disable state of createOfferButton in OrderBookController - if (parentController != null) ((TradeController) parentController).onCreateOfferViewRemoved(); } diff --git a/src/main/java/io/bitsquare/gui/setup/SetupController.java b/src/main/java/io/bitsquare/gui/setup/SetupCB.java similarity index 87% rename from src/main/java/io/bitsquare/gui/setup/SetupController.java rename to src/main/java/io/bitsquare/gui/setup/SetupCB.java index 2b9749260b..6f6c6e1a04 100644 --- a/src/main/java/io/bitsquare/gui/setup/SetupController.java +++ b/src/main/java/io/bitsquare/gui/setup/SetupCB.java @@ -18,7 +18,6 @@ package io.bitsquare.gui.setup; import io.bitsquare.gui.CodeBehind; -import io.bitsquare.gui.trade.TradeController; import java.net.URL; @@ -29,18 +28,20 @@ import javax.inject.Inject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SetupController extends CodeBehind { +public class SetupCB extends CodeBehind { - private static final Logger log = LoggerFactory.getLogger(SetupController.class); + private static final Logger log = LoggerFactory.getLogger(SetupCB.class); /////////////////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////////////////// @Inject - public SetupController() { + public SetupCB(SetupPm presentationModel) { + super(presentationModel); } + /////////////////////////////////////////////////////////////////////////////////////////// // Lifecycle /////////////////////////////////////////////////////////////////////////////////////////// @@ -54,9 +55,6 @@ public class SetupController extends CodeBehind { @Override public void terminate() { super.terminate(); - - // Used to reset disable state of createOfferButton in OrderBookController - if (parentController != null) ((TradeController) parentController).onCreateOfferViewRemoved(); } diff --git a/src/main/java/io/bitsquare/gui/setup/SetupModel.java b/src/main/java/io/bitsquare/gui/setup/SetupModel.java new file mode 100644 index 0000000000..e557a749af --- /dev/null +++ b/src/main/java/io/bitsquare/gui/setup/SetupModel.java @@ -0,0 +1,65 @@ +/* + * 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.setup; + +import io.bitsquare.gui.UIModel; + +import com.google.inject.Inject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SetupModel extends UIModel { + private static final Logger log = LoggerFactory.getLogger(SetupModel.class); + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + public SetupModel() { + + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Public methods + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Interface implementation: Initializable + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////////////////////////////////// + + +} diff --git a/src/main/java/io/bitsquare/gui/setup/SetupPm.java b/src/main/java/io/bitsquare/gui/setup/SetupPm.java new file mode 100644 index 0000000000..e474ee1d23 --- /dev/null +++ b/src/main/java/io/bitsquare/gui/setup/SetupPm.java @@ -0,0 +1,65 @@ +/* + * 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.setup; + +import io.bitsquare.gui.PresentationModel; + +import com.google.inject.Inject; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SetupPm extends PresentationModel { + private static final Logger log = LoggerFactory.getLogger(SetupPm.class); + + /////////////////////////////////////////////////////////////////////////////////////////// + // Constructor + /////////////////////////////////////////////////////////////////////////////////////////// + + @Inject + public SetupPm(SetupModel model) { + super(model); + } + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Public methods + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Interface implementation: Initializable + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Getters + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Setters + /////////////////////////////////////////////////////////////////////////////////////////// + + + /////////////////////////////////////////////////////////////////////////////////////////// + // Private methods + /////////////////////////////////////////////////////////////////////////////////////////// + + +} diff --git a/src/main/java/io/bitsquare/gui/setup/SetupView.fxml b/src/main/java/io/bitsquare/gui/setup/SetupView.fxml index a013e6124f..39a6231305 100644 --- a/src/main/java/io/bitsquare/gui/setup/SetupView.fxml +++ b/src/main/java/io/bitsquare/gui/setup/SetupView.fxml @@ -17,15 +17,19 @@ ~ along with Bitsquare. If not, see . --> - + - - 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 e5e3e764cb..501f963006 100644 --- a/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java +++ b/src/main/java/io/bitsquare/gui/trade/orderbook/OrderBookController.java @@ -21,6 +21,7 @@ import io.bitsquare.bank.BankAccountType; import io.bitsquare.btc.FeePolicy; 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; @@ -229,7 +230,18 @@ public class OrderBookController extends CachedViewController { public void createOffer() { if (isRegistered()) { createOfferButton.setDisable(true); - Initializable nextController = parentController.loadViewAndGetChildController(NavigationItem.CREATE_OFFER); + + //TODO Remove that when all UIs are converted to CodeBehind + Initializable nextController = null; + if (parentController != null) { + if (parentController instanceof ViewController) + nextController = ((ViewController) parentController).loadViewAndGetChildController(NavigationItem + .CREATE_OFFER); + else if (parentController instanceof CodeBehind) + nextController = ((CodeBehind) parentController).loadViewAndGetChildController(NavigationItem + .CREATE_OFFER); + } + if (nextController != null) ((CreateOfferCB) nextController).setOrderBookFilter(orderBookFilter); } @@ -345,8 +357,19 @@ public class OrderBookController extends CachedViewController { private void takeOffer(Offer offer) { if (isRegistered()) { - TakeOfferController takeOfferController = - (TakeOfferController) parentController.loadViewAndGetChildController(NavigationItem.TAKE_OFFER); + + //TODO Remove that when all UIs are converted to CodeBehind + TakeOfferController takeOfferController = null; + if (parentController != null) { + if (parentController instanceof ViewController) + takeOfferController = (TakeOfferController) ((ViewController) parentController) + .loadViewAndGetChildController(NavigationItem + .TAKE_OFFER); + else if (parentController instanceof CodeBehind) + takeOfferController = (TakeOfferController) ((CodeBehind) parentController) + .loadViewAndGetChildController(NavigationItem + .TAKE_OFFER); + } Coin requestedAmount; if (!"".equals(amount.getText())) { diff --git a/src/main/resources/i18n/displayStrings.properties b/src/main/resources/i18n/displayStrings.properties index 249c2c9d4f..7a21926d94 100644 --- a/src/main/resources/i18n/displayStrings.properties +++ b/src/main/resources/i18n/displayStrings.properties @@ -32,7 +32,7 @@ createOffer.amountPriceBox.amountDescr=Amount of Bitcoin to buy createOffer.amountPriceBox.priceDescr=Price per Bitcoin in {0} createOffer.amountPriceBox.volumeDescr=Amount in {0} to spend createOffer.amountPriceBox.minAmountDescr=Minimum amount of Bitcoin -createOffer.amountPriceBox.info=With the minimum amount you can attract more potential traders with giving them more flexibility. But note that there is no automatic creation of a new offer for the remaining amount in the case that a trader takes your offer with a lower amount as defined in the amount field. Your offer will be removed from the orderbook once a trader has taken your offer. +createOffer.amountPriceBox.info=Define a price for which you want to byu Bitcoin and either enter the amount or the trade volume. With the minimum amount you can attract more potential traders with giving them more flexibility. But note that there is no automatic creation of a new offer for the remaining amount in the case that a trader takes your offer with a lower amount as defined in the amount field. Your offer will be removed from the orderbook once a trader has taken your offer. createOffer.amountPriceBox.next=Next step createOffer.amountPriceBox.warning.invalidBtcDecimalPlaces=The amount you have entered exceeds the number of allowed decimal places.\nThe amount has been adjusted to 4 decimal places. createOffer.amountPriceBox.warning.invalidFiatDecimalPlaces=The amount you have entered exceeds the number of allowed decimal places. The amount has been adjusted to 2 decimal places. @@ -46,7 +46,7 @@ createOffer.fundsBox.totalsNeeded=Funds needed for that trade: createOffer.fundsBox.address=Trade wallet address: createOffer.fundsBox.balance=Trade wallet balance: createOffer.fundsBox.info=For every offer there is a dedicated trade wallet. You need to fund that trade wallet with the necessary Bitcoin amount. Those funds are reserved and will be used in the case that your offer gets executed. If you cancel your offer you can withdraw your funds from that trading wallet. The only payment which will be done now when placing the offer is the offer fee payment. -createOffer.fundsBox.collateral=Collateral ({0}): +createOffer.fundsBox.collateral=Refundable collateral ({0}): createOffer.fundsBox.offerFee=Offer fee: createOffer.fundsBox.networkFee=Bitcoin network fee: createOffer.fundsBox.total=Total: