Extract ViewLoader interface and introduce FxmlViewLoader

This commit is contained in:
Chris Beams 2014-11-24 08:15:20 +01:00
parent 2705e80ef1
commit a2c98d9ea3
No known key found for this signature in database
GPG Key ID: 3D214F8F5BC5ED73
18 changed files with 56 additions and 31 deletions

View File

@ -39,7 +39,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
import viewfx.view.support.guice.GuiceViewFactory;
import javafx.application.Application;
@ -95,7 +95,7 @@ public class BitsquareApp extends Application {
// load the main view and create the main scene
ViewLoader viewLoader = injector.getInstance(ViewLoader.class);
FxmlViewLoader viewLoader = injector.getInstance(FxmlViewLoader.class);
View view = viewLoader.load(Navigation.Item.MAIN.getFxmlUrl(), false);
Scene scene = new Scene((Parent) view.getRoot(), 1000, 600);

View File

@ -36,7 +36,8 @@ import com.google.inject.name.Names;
import java.util.ResourceBundle;
import viewfx.view.ViewFactory;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
import viewfx.view.support.guice.GuiceViewFactory;
import javafx.stage.Stage;
@ -58,7 +59,7 @@ public class GuiModule extends BitsquareModule {
bind(ViewFactory.class).to(GuiceViewFactory.class);
bind(ResourceBundle.class).toInstance(BSResources.getResourceBundle());
bind(ViewLoader.class).asEagerSingleton();
bind(ViewLoader.class).to(FxmlViewLoader.class).asEagerSingleton();
bind(OfferBook.class).asEagerSingleton();
bind(Navigation.class).asEagerSingleton();

View File

@ -29,7 +29,7 @@ import javax.inject.Inject;
import javax.inject.Named;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.support.ActivatableView;
import javafx.application.Platform;

View File

@ -22,7 +22,7 @@ import io.bitsquare.gui.Navigation;
import javax.inject.Inject;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.support.ActivatableView;
import javafx.beans.value.ChangeListener;

View File

@ -23,7 +23,7 @@ import io.bitsquare.gui.main.account.arbitrator.registration.ArbitratorRegistrat
import javax.inject.Inject;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
import viewfx.view.support.AbstractView;
import javafx.fxml.FXML;
@ -36,12 +36,12 @@ class ArbitratorSettingsView extends AbstractView {
private ArbitratorRegistrationView arbitratorRegistrationView;
private final ViewLoader viewLoader;
private final FxmlViewLoader viewLoader;
private final Navigation navigation;
private final Stage primaryStage;
@Inject
private ArbitratorSettingsView(ViewLoader viewLoader, Navigation navigation, Stage primaryStage) {
private ArbitratorSettingsView(FxmlViewLoader viewLoader, Navigation navigation, Stage primaryStage) {
this.viewLoader = viewLoader;
this.navigation = navigation;
this.primaryStage = primaryStage;

View File

@ -32,7 +32,7 @@ import java.util.List;
import javax.inject.Inject;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.support.ActivatableView;
import javafx.fxml.FXML;

View File

@ -30,7 +30,7 @@ import java.util.Locale;
import javax.inject.Inject;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
import viewfx.view.Wizard;
import viewfx.view.support.ActivatableViewAndModel;
@ -56,11 +56,11 @@ public class RestrictionsView extends ActivatableViewAndModel<GridPane, Restrict
private Wizard parent;
private final ViewLoader viewLoader;
private final FxmlViewLoader viewLoader;
private final Stage primaryStage;
@Inject
private RestrictionsView(RestrictionsViewModel model, ViewLoader viewLoader, Stage primaryStage) {
private RestrictionsView(RestrictionsViewModel model, FxmlViewLoader viewLoader, Stage primaryStage) {
super(model);
this.viewLoader = viewLoader;
this.primaryStage = primaryStage;

View File

@ -23,7 +23,7 @@ import io.bitsquare.gui.util.Colors;
import javax.inject.Inject;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.Wizard;
import viewfx.view.support.ActivatableViewAndModel;

View File

@ -27,7 +27,7 @@ import io.bitsquare.gui.main.account.content.seedwords.SeedWordsView;
import javax.inject.Inject;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.Wizard;
import viewfx.view.support.ActivatableView;

View File

@ -23,7 +23,7 @@ import javax.inject.Inject;
import viewfx.model.Activatable;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.support.ActivatableViewAndModel;
import javafx.beans.value.ChangeListener;

View File

@ -24,7 +24,7 @@ import javax.inject.Inject;
import viewfx.model.Activatable;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.support.ActivatableViewAndModel;
import javafx.beans.value.ChangeListener;

View File

@ -24,7 +24,7 @@ import javax.inject.Inject;
import viewfx.model.Activatable;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.ViewLoader;
import viewfx.view.support.ActivatableViewAndModel;
import javafx.beans.value.ChangeListener;

View File

@ -21,12 +21,12 @@ import io.bitsquare.gui.Navigation;
import javax.inject.Inject;
import viewfx.view.support.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
class BuyView extends TradeView {
@Inject
public BuyView(ViewLoader viewLoader, Navigation navigation) {
public BuyView(FxmlViewLoader viewLoader, Navigation navigation) {
super(viewLoader, navigation);
}
}

View File

@ -21,12 +21,12 @@ import io.bitsquare.gui.Navigation;
import javax.inject.Inject;
import viewfx.view.support.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
class SellView extends TradeView {
@Inject
public SellView(ViewLoader viewLoader, Navigation navigation) {
public SellView(FxmlViewLoader viewLoader, Navigation navigation) {
super(viewLoader, navigation);
}
}

View File

@ -31,7 +31,7 @@ import org.bitcoinj.utils.Fiat;
import java.util.List;
import viewfx.view.View;
import viewfx.view.support.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
import viewfx.view.support.ActivatableView;
import javafx.application.Platform;
@ -53,10 +53,10 @@ public class TradeView extends ActivatableView<TabPane, Void> {
private Fiat price;
private Offer offer;
private final ViewLoader viewLoader;
private final FxmlViewLoader viewLoader;
private final Navigation navigation;
protected TradeView(ViewLoader viewLoader, Navigation navigation) {
protected TradeView(FxmlViewLoader viewLoader, Navigation navigation) {
this.viewLoader = viewLoader;
this.navigation = navigation;
}

View File

@ -0,0 +1,22 @@
/*
* 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 viewfx.view;
public interface ViewLoader<Location> {
View load(Location location);
}

View File

@ -15,7 +15,7 @@
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package viewfx.view.support;
package viewfx.view.fxml;
import java.io.IOException;
@ -29,21 +29,23 @@ import javax.inject.Inject;
import viewfx.view.View;
import viewfx.view.ViewFactory;
import viewfx.view.ViewLoader;
import javafx.fxml.FXMLLoader;
public class ViewLoader {
public class FxmlViewLoader implements ViewLoader<URL> {
private final Map<URL, View> cache = new HashMap<>();
private final ViewFactory viewFactory;
private final ResourceBundle resourceBundle;
@Inject
public ViewLoader(ViewFactory viewFactory, ResourceBundle resourceBundle) {
public FxmlViewLoader(ViewFactory viewFactory, ResourceBundle resourceBundle) {
this.viewFactory = viewFactory;
this.resourceBundle = resourceBundle;
}
@Override
public View load(URL url) {
return load(url, true);
}

View File

@ -29,7 +29,7 @@ import java.net.MalformedURLException;
import java.util.ResourceBundle;
import viewfx.view.support.ViewLoader;
import viewfx.view.fxml.FxmlViewLoader;
import viewfx.view.support.guice.GuiceViewFactory;
import javafx.application.Application;
@ -81,11 +81,11 @@ public class ViewLoaderTests {
@Test(expected = BitsquareException.class)
public void loadingBogusFxmlResourceShouldThrow() throws MalformedURLException {
new ViewLoader(viewFactory, resourceBundle).load(Navigation.Item.BOGUS.getFxmlUrl(), false);
new FxmlViewLoader(viewFactory, resourceBundle).load(Navigation.Item.BOGUS.getFxmlUrl(), false);
}
@Test
public void loadingValidFxmlResourceShouldNotThrow() {
new ViewLoader(viewFactory, resourceBundle).load(Navigation.Item.ACCOUNT.getFxmlUrl(), false);
new FxmlViewLoader(viewFactory, resourceBundle).load(Navigation.Item.ACCOUNT.getFxmlUrl(), false);
}
}