com.airhacks.afterburner.injection.Injector Java Examples

The following examples show how to use com.airhacks.afterburner.injection.Injector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppViewManager.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
static void buildDrawer(MobileApplication app, NavigationDrawer.Header header, Collection<AppView> views) {
    final NavigationDrawer drawer = app.getDrawer();
    Utils.buildDrawer(drawer, header, views);

    final Service service = Injector.instantiateModelOrService(Service.class);
    
    for (Node item : drawer.getItems()) {
        if (item instanceof NavigationDrawer.ViewItem && 
                ((NavigationDrawer.ViewItem) item).getViewName().equals(EDITION_VIEW.getId())) {
            item.disableProperty().bind(service.userProperty().isNull());
            break;
        }
    }
    
    service.userProperty().addListener((obs, ov, nv) -> avatar.setImage(getAvatarImage(service)));
    avatar.setImage(getAvatarImage(service));
}
 
Example #2
Source File: Mokka7App.java    From mokka7 with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {

    String version = Mokka7App.class.getPackage().getImplementationVersion();

    stage.setTitle(String.format("Mokka7 client v.%s", version != null ? version : "DEV"));
    stage.setResizable(true);

    Injector.setLogger((t) -> logger.trace(t));

    Injector.setModelOrService(MonitoredS7Client.class, new MonitoredS7Client());

    SessionManager session = Injector.instantiateModelOrService(SessionManager.class);
    session.setSession(getClass().getName().toLowerCase());
    session.loadSession();

    session.bind(sceneWidthProperty, "scene.width");
    session.bind(sceneHeightProperty, "scene.height");

    MainView main = new MainView();

    final Scene scene = new Scene(main.getView(), sceneWidthProperty.get(), sceneHeightProperty.get());
    stage.setOnCloseRequest((e) -> {
        sceneWidthProperty.set(scene.getWidth());
        sceneHeightProperty.set(scene.getHeight());
        Injector.forgetAll();
        System.exit(0);
    });
    stage.setScene(scene);
    Image icon16 = new Image(getClass().getResourceAsStream("icon-16x16.png"));
    Image icon32 = new Image(getClass().getResourceAsStream("icon-32x32.png"));
    Image icon48 = new Image(getClass().getResourceAsStream("icon-48x48.png"));

    stage.getIcons().addAll(icon16, icon32, icon48);

    stage.show();

}
 
Example #3
Source File: VncClientApp.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
private void restart() {
  stageRef.close();
  try {
    sceneWidthProperty.set(stageRef.getScene().getWidth());
    sceneHeightProperty.set(stageRef.getScene().getHeight());
    Injector.forgetAll();
    start(new Stage());
  } catch (Exception e) {
    throw new RuntimeException("Failed to restart " + getClass().getName(), e);
  }
}
 
Example #4
Source File: AboutViewTest.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void init() {
  Injector.setLogger((t) -> logger.info(t));
  // AboutView view = new AboutView();
  // stage = new Stage(StageStyle.UNDECORATED);
  // stage.setScene(new Scene(view.getView()));
  // stage.show();
}
 
Example #5
Source File: Main.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void stop() throws Exception {
    Injector.forgetAll();
}
 
Example #6
Source File: VncClientApp.java    From jfxvnc with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
  stageRef = stage;
  stage.titleProperty().bind(headerExpr);
  stage.setResizable(true);
  offlineImg = new Image(VncClientApp.class.getResourceAsStream("icon.png"));
  onlineImg = new Image(VncClientApp.class.getResourceAsStream("icon_green.png"));

  Injector.setLogger(logger::trace);

  VncRenderService vncService = Injector.instantiateModelOrService(VncRenderService.class);

  vncService.fullSceenProperty().addListener((l, a, b) -> Platform.runLater(() -> stage.setFullScreen(b)));
  vncService.restartProperty().addListener(l -> restart());
  vncService.connectInfoProperty().addListener((l, a, b) -> Platform.runLater(() -> headerProperty.set(b.getServerName())));
  vncService.onlineProperty().addListener((l, a, b) -> Platform.runLater(() -> {
    stage.getIcons().add(b ? onlineImg : offlineImg);
    stage.getIcons().remove(!b ? onlineImg : offlineImg);
  }));

  // update property on exit full screen by key combination
  stage.fullScreenProperty().addListener((l, a, b) -> vncService.fullSceenProperty().set(b));

  SessionContext session = Injector.instantiateModelOrService(SessionContext.class);
  session.setSession("jfxvnc.app");
  session.loadSession();

  session.bind(sceneWidthProperty, "scene.width");
  session.bind(sceneHeightProperty, "scene.height");

  MainView main = new MainView();

  final Scene scene = new Scene(main.getView(), sceneWidthProperty.get(), sceneHeightProperty.get());
  stage.setOnCloseRequest((e) -> {
    sceneWidthProperty.set(scene.getWidth());
    sceneHeightProperty.set(scene.getHeight());
    Injector.forgetAll();
    System.exit(0);
  });
  stage.setScene(scene);
  stage.getIcons().add(offlineImg);
  stage.show();
}
 
Example #7
Source File: AboutViewTest.java    From jfxvnc with Apache License 2.0 4 votes vote down vote up
public static void end() {
  Injector.forgetAll();
  // stage.close();
}
 
Example #8
Source File: AppViewManager.java    From Game2048FX with GNU General Public License v3.0 4 votes vote down vote up
public static void registerViews(MobileApplication app) {
    NavigationDrawer drawer = app.getDrawer();
    for (AppView view : REGISTRY.getViews()) {
        view.registerView(app);
        if (view.isShownInDrawer()) {
            drawer.getItems().add(view.getMenuItem());
        }
    }

    cloud = Injector.instantiateModelOrService(Cloud.class);
    cloud.authenticatedUserProperty().addListener(o ->
            drawer.setHeader(getHeader()));

    drawer.setHeader(getHeader());

    final NavigationDrawer.Item aboutItem = new NavigationDrawer.Item("About 2048FX", MaterialDesignIcon.INFO_OUTLINE.graphic());
    drawer.selectedItemProperty().addListener((obs, ov, nv) -> {
        if (aboutItem.equals(nv)) {
            PauseTransition pause = new PauseTransition(Duration.seconds(0.5));
            pause.setOnFinished(f -> new About());
            pause.play();
            drawer.setSelectedItem(GAME_VIEW.getMenuItem());
        }
    });
    drawer.getItems().add(aboutItem);

    if (Platform.isDesktop()) {
        NavigationDrawer.Item quitItem = new NavigationDrawer.Item("Quit", MaterialDesignIcon.EXIT_TO_APP.graphic());
        quitItem.selectedProperty().addListener((obs, ov, nv) -> {
            if (nv) {
                Services.get(LifecycleService.class).ifPresent(LifecycleService::shutdown);
            }
        });
        drawer.getItems().add(quitItem);
    }

    drawer.skinProperty().addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable observable) {
            ListTile versionTile = new ListTile();
            versionTile.setPrimaryGraphic(new ImageView());
            versionTile.textProperty().addAll("2048FX", "Version " + VERSION + " - " + Year.now().toString());
            HBox hBottom = new HBox(versionTile);
            hBottom.getStyleClass().add("drawer-bottom");
            HBox.setHgrow(versionTile, Priority.ALWAYS);

            ((BorderPane) drawer.getChildrenUnmodifiable().get(0)).setBottom(hBottom);

            drawer.skinProperty().removeListener(this);
        }
    });
}
 
Example #9
Source File: Game2048.java    From Game2048FX with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void postInit(Scene scene) {

    String display = Services.get(DisplayService.class)
            .map(service -> service.isTablet() ? "tablet" : "phone")
            .orElse("phone");
    scene.getStylesheets().add(GameManager.class.getResource(display + ".css").toExternalForm());

    GameModel gameModel = Injector.instantiateModelOrService(GameModel.class);
    scene.getRoot().getStyleClass().add(gameModel.getGameMode().toString().toLowerCase());
    gameModel.gameModeProperty().addListener((obs, m, m1) -> {
        scene.getRoot().getStyleClass().remove(m.toString().toLowerCase());
        scene.getRoot().getStyleClass().add(m1.toString().toLowerCase());
    });
    Stage stage = (Stage) scene.getWindow();

    if (Platform.isDesktop()) {
        Services.get(DisplayService.class)
                .ifPresent(service -> {
                    if (service.isTablet()) {
                        // tablet
                        scene.getWindow().setWidth(600);
                        scene.getWindow().setHeight(800);
                    }
                });

        stage.setTitle("2048FX");
        stage.getIcons()
                .add(new Image(GameManager.class.getResourceAsStream("Icon-60.png")));
    }

    AppViewManager.GAME_VIEW.getPresenter().ifPresent(presenter -> {
        gamePresenter = (GamePresenter) presenter;
        gamePresenter.pauseProperty().bind(pause);
        gamePresenter.stopProperty().bind(stop);
    });

    if (Platform.isDesktop() && isARMDevice()) {
        stage.setFullScreen(true);
        stage.setFullScreenExitHint("");
    }

    if (javafx.application.Platform.isSupported(ConditionalFeature.INPUT_TOUCH)) {
        scene.setCursor(Cursor.NONE);
    }
}
 
Example #10
Source File: Visualizer.java    From HdrHistogramVisualizer with Apache License 2.0 4 votes vote down vote up
@Override
public void stop() {
    Injector.forgetAll();
}
 
Example #11
Source File: AboutViewTest.java    From jfxvnc with Apache License 2.0 3 votes vote down vote up
@Test
public void aboutView() {

  AboutViewPresenter presenter = Injector.instantiatePresenter(AboutViewPresenter.class);
  assertNotNull(presenter);

}