Introduce app.gui.MainModule

This commit is contained in:
Chris Beams 2014-11-06 16:35:03 +01:00
parent 21098afd45
commit 486cd9824e
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
4 changed files with 59 additions and 27 deletions

View File

@ -20,7 +20,6 @@ package io.bitsquare.app;
import io.bitsquare.AbstractBitsquareModule;
import io.bitsquare.btc.BitcoinModule;
import io.bitsquare.crypto.CryptoModule;
import io.bitsquare.gui.GuiModule;
import io.bitsquare.msg.MessageModule;
import io.bitsquare.msg.tomp2p.TomP2PMessageModule;
import io.bitsquare.offer.OfferModule;
@ -29,15 +28,12 @@ import io.bitsquare.persistence.Persistence;
import io.bitsquare.settings.Settings;
import io.bitsquare.trade.TradeModule;
import io.bitsquare.user.User;
import io.bitsquare.util.ConfigLoader;
import com.google.inject.Injector;
import com.google.inject.name.Names;
import java.util.Properties;
import javafx.stage.Stage;
import net.tomp2p.connection.Ports;
import org.slf4j.Logger;
@ -46,19 +42,16 @@ import org.slf4j.LoggerFactory;
import akka.actor.ActorSystem;
import scala.concurrent.duration.Duration;
public class BitsquareModule extends AbstractBitsquareModule {
/**
* Configures all non-UI modules necessary to run a Bitsquare application.
*/
public class AppModule extends AbstractBitsquareModule {
private static final Logger log = LoggerFactory.getLogger(AppModule.class);
private static final Logger log = LoggerFactory.getLogger(BitsquareModule.class);
private final Stage primaryStage;
private final String appName;
public BitsquareModule(Stage primaryStage, String appName) {
this(primaryStage, appName, ConfigLoader.loadConfig());
}
public BitsquareModule(Stage primaryStage, String appName, Properties properties) {
public AppModule(Properties properties, String appName) {
super(properties);
this.primaryStage = primaryStage;
this.appName = appName;
}
@ -73,7 +66,6 @@ public class BitsquareModule extends AbstractBitsquareModule {
install(cryptoModule());
install(tradeModule());
install(offerModule());
install(guiModule());
bindConstant().annotatedWith(Names.named("appName")).to(appName);
bind(ActorSystem.class).toInstance(ActorSystem.create(appName));
@ -100,10 +92,6 @@ public class BitsquareModule extends AbstractBitsquareModule {
protected OfferModule offerModule() { return new TomP2POfferModule(properties); }
protected GuiModule guiModule() {
return new GuiModule(properties, primaryStage);
}
@Override
protected void doClose(Injector injector) {
ActorSystem actorSystem = injector.getInstance(ActorSystem.class);

View File

@ -18,7 +18,6 @@
package io.bitsquare.app.gui;
import io.bitsquare.app.ArgumentParser;
import io.bitsquare.app.BitsquareModule;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.SystemTray;
import io.bitsquare.gui.ViewLoader;
@ -51,7 +50,7 @@ public class Main extends Application {
private static final Logger log = LoggerFactory.getLogger(Main.class);
private static String appName = "Bitsquare";
private BitsquareModule bitsquareModule;
private MainModule mainModule;
private Injector injector;
public static void main(String[] args) {
@ -67,8 +66,8 @@ public class Main extends Application {
@Override
public void start(Stage primaryStage) {
bitsquareModule = new BitsquareModule(primaryStage, appName);
injector = Guice.createInjector(bitsquareModule);
mainModule = new MainModule(appName, primaryStage);
injector = Guice.createInjector(mainModule);
// route uncaught exceptions to a user-facing dialog
@ -138,7 +137,7 @@ public class Main extends Application {
@Override
public void stop() {
bitsquareModule.close(injector);
mainModule.close(injector);
System.exit(0);
}
}

View File

@ -0,0 +1,43 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.app.gui;
import io.bitsquare.AbstractBitsquareModule;
import io.bitsquare.app.AppModule;
import io.bitsquare.gui.GuiModule;
import io.bitsquare.util.ConfigLoader;
import javafx.stage.Stage;
class MainModule extends AbstractBitsquareModule {
private final String appName;
private final Stage primaryStage;
public MainModule(String appName, Stage primaryStage) {
super(ConfigLoader.loadConfig());
this.appName = appName;
this.primaryStage = primaryStage;
}
@Override
protected void configure() {
install(new AppModule(properties, appName));
install(new GuiModule(properties, primaryStage));
}
}

View File

@ -15,9 +15,11 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.gui;
package io.bitsquare.app.gui;
import io.bitsquare.app.BitsquareModule;
import io.bitsquare.gui.FatalException;
import io.bitsquare.gui.Navigation;
import io.bitsquare.gui.ViewLoader;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -30,7 +32,7 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class ViewLoaderTest {
public class ViewLoaderTests {
public static class TestApp extends Application {
static Stage primaryStage;
@ -56,7 +58,7 @@ public class ViewLoaderTest {
@Before
public void setUp() {
Injector injector = Guice.createInjector(new BitsquareModule(TestApp.primaryStage, "testApp"));
Injector injector = Guice.createInjector(new MainModule("testApp", TestApp.primaryStage));
ViewLoader.setInjector(injector);
}