javafx.fxml.JavaFXBuilderFactory Java Examples

The following examples show how to use javafx.fxml.JavaFXBuilderFactory. 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: GameView.java    From CrazyAlpha with GNU General Public License v2.0 6 votes vote down vote up
public static Initializable getInitializable(String viewName) throws IOException {
    FXMLLoader loader = new FXMLLoader();    // 创建对象

    loader.setBuilderFactory(new JavaFXBuilderFactory());    // 设置BuilderFactory
    loader.setLocation(GameView.class.getResource(viewName + ".fxml"));    // 设置路径基准

    try {
        InputStream in = GameView.class.getResourceAsStream(viewName + ".fxml");
        AnchorPane page = (AnchorPane) loader.load(in); // 对象方法的参数是InputStream,返回值是Object

        Scene scene = new Scene(page, 800, 600);
        Stage stage = new Stage();
        stage.setScene(scene);
        stage.sizeToScene();

        return (Initializable) loader.getController();    // 可以得到Controller

    } finally {
        in.close();
        return null;
    }
}
 
Example #2
Source File: WizardMain.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

	final Injector injector = Guice.createInjector( new WizardModule() );

	final Parent p = FXMLLoader.load( WizardMain.class.getResource("/wizard-fxml/Wizard.fxml"),
									  null,
									  new JavaFXBuilderFactory(),
									  (clazz) -> injector.getInstance(clazz)
	);
	
	final Scene scene = new Scene(p);
	
	primaryStage.setScene( scene );
	primaryStage.setWidth( 800 );
	primaryStage.setHeight( 600 );
	primaryStage.setTitle("Wizard");
	
	primaryStage.show();
}
 
Example #3
Source File: OldScoresModule.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {

    String mathRecenteredJSONFile = MATH_RECENTERED_JSON_FILE;
    String verbalRecenteredJSONFile = VERBAL_RECENTERED_JSON_FILE;
    String settingsFileName = SETTINGS_FILE_NAME;

    bind(BuilderFactory.class).to(JavaFXBuilderFactory.class);

    bind(String.class).annotatedWith(Names.named("mathRecenteredJSONFile")).toInstance(mathRecenteredJSONFile);
    bind(String.class).annotatedWith(Names.named("verbalRecenteredJSONFile")).toInstance(verbalRecenteredJSONFile);
    bind(String.class).annotatedWith(Names.named("settingsFileName")).toInstance(settingsFileName);

    bind(SettingsDAO.class).to(SettingsDAOImpl.class).asEagerSingleton();
    bind(RecenteredDAO.class).to(RecenteredDAOImpl.class).asEagerSingleton();

    bindInterceptor(Matchers.subclassesOf(ManagedDataSource.class), Matchers.any(), new ManagedDataSourceInterceptor());
}
 
Example #4
Source File: OldScoresModule.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {

    String mathRecenteredJSONFile = MATH_RECENTERED_JSON_FILE;
    String verbalRecenteredJSONFile = VERBAL_RECENTERED_JSON_FILE;
    String settingsFileName = SETTINGS_FILE_NAME;

    bind(BuilderFactory.class).to(JavaFXBuilderFactory.class);

    bind(String.class).annotatedWith(Names.named("mathRecenteredJSONFile")).toInstance(mathRecenteredJSONFile);
    bind(String.class).annotatedWith(Names.named("verbalRecenteredJSONFile")).toInstance(verbalRecenteredJSONFile);
    bind(String.class).annotatedWith(Names.named("settingsFileName")).toInstance(settingsFileName);

    bind(SettingsDAO.class).to(SettingsDAOImpl.class).asEagerSingleton();
    bind(RecenteredDAO.class).to(RecenteredDAOImpl.class).asEagerSingleton();
}
 
Example #5
Source File: OldScoresModule.java    From examples-javafx-repos1 with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {

    String mathRecenteredJSONFile = MATH_RECENTERED_JSON_FILE;
    String verbalRecenteredJSONFile = VERBAL_RECENTERED_JSON_FILE;
    String settingsFileName = SETTINGS_FILE_NAME;

    bind(BuilderFactory.class).to(JavaFXBuilderFactory.class);

    bind(String.class).annotatedWith(Names.named("mathRecenteredJSONFile")).toInstance(mathRecenteredJSONFile);
    bind(String.class).annotatedWith(Names.named("verbalRecenteredJSONFile")).toInstance(verbalRecenteredJSONFile);
    bind(String.class).annotatedWith(Names.named("settingsFileName")).toInstance(settingsFileName);

    bind(SettingsDAO.class).to(SettingsDAOImpl.class).asEagerSingleton();
    bind(RecenteredDAO.class).to(RecenteredDAOImpl.class).asEagerSingleton();

    bindInterceptor(Matchers.subclassesOf(ManagedDataSource.class), Matchers.any(), new ManagedDataSourceInterceptor());
}
 
Example #6
Source File: UpdateController.java    From updatefx with MIT License 6 votes vote down vote up
public static void performUpdate(Release release, URL css) {
	try {
		ResourceBundle i18nBundle = ResourceBundle.getBundle("com.briksoftware.updatefx.gui.i18n.UpdateProgressDialog");

		FXMLLoader loader = new FXMLLoader(UpdateController.class.getResource("UpdateProgressDialog.fxml"), i18nBundle);
		loader.setBuilderFactory(new JavaFXBuilderFactory());
		Parent page = loader.load();
		UpdateController controller = loader.getController();
		controller.release = release;
		controller.initialize();

		Scene scene = new Scene(page);
		if (css != null) {
			scene.getStylesheets().add(css.toExternalForm());
		}
		
		final Stage stage = new Stage();
		stage.setScene(scene);
		stage.show();
		stage.toFront();

	} catch (Throwable ex) {
		ex.printStackTrace();
	}
}
 
Example #7
Source File: TableApp.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {

	FXMLLoader fxmlLoader = new FXMLLoader(
			TableApp.class.getResource("/Persons.fxml"),
			null,
			new JavaFXBuilderFactory(),
			new Callback<Class<?>, Object>() {
				@Override
	    		public Object call(Class<?> clazz) {
					return injector.getInstance(clazz);
				}
			});
	
    Parent p = fxmlLoader.load();
    
    PersonsController pc = fxmlLoader.getController();
    
    Scene scene = new Scene(p);
    
    scene.addEventFilter(KeyEvent.KEY_PRESSED, (evt) -> {
    	if( evt.getCode() == KeyCode.DELETE ) {
    		pc.deletePersons();
    	} else if( evt.getCode() == KeyCode.INSERT ) {
    		pc.addPerson();
    	}        	
    });
    
    primaryStage.setTitle( "Person Table App");
    primaryStage.setScene( scene );
    primaryStage.show();
}
 
Example #8
Source File: WizardController.java    From examples-javafx-repos1 with Apache License 2.0 5 votes vote down vote up
private void buildSteps() throws java.io.IOException {

		final JavaFXBuilderFactory bf = new JavaFXBuilderFactory();

		final Callback<Class<?>, Object> cb = (clazz) -> injector.getInstance(clazz);

		FXMLLoader fxmlLoaderStep1 = new FXMLLoader( WizardController.class.getResource("/wizard-fxml/Step1.fxml"), null, bf, cb);
		Parent step1 = fxmlLoaderStep1.load( );
		step1.getProperties().put( CONTROLLER_KEY, fxmlLoaderStep1.getController() );

		FXMLLoader fxmlLoaderStep2 = new FXMLLoader( WizardController.class.getResource("/wizard-fxml/Step2.fxml"), null, bf, cb );
		Parent step2 = fxmlLoaderStep2.load();
		step2.getProperties().put( CONTROLLER_KEY, fxmlLoaderStep2.getController() );

		FXMLLoader fxmlLoaderStep3 = new FXMLLoader(WizardController.class.getResource("/wizard-fxml/Step3.fxml"), null, bf, cb );
		Parent step3 = fxmlLoaderStep3.load( );
		step3.getProperties().put( CONTROLLER_KEY, fxmlLoaderStep3.getController() );

		FXMLLoader fxmlLoaderConfirm = new FXMLLoader(WizardController.class.getResource("/wizard-fxml/Confirm.fxml"), null, bf, cb);
		Parent confirm = fxmlLoaderConfirm.load(  );
		confirm.getProperties().put( CONTROLLER_KEY, fxmlLoaderConfirm.getController() );

		FXMLLoader fxmlLoaderCompleted = new FXMLLoader( WizardController.class.getResource("/wizard-fxml/Completed.fxml"), null, bf, cb);
		Parent completed = fxmlLoaderCompleted.load();
		completed.getProperties().put( CONTROLLER_KEY, fxmlLoaderCompleted.getController() );

		steps.addAll( Arrays.asList(
				step1, step2, step3, confirm, completed
					));
	}
 
Example #9
Source File: UpdateDialogController.java    From updatefx with MIT License 5 votes vote down vote up
public static void showUpdateDialog(Release release, int currentReleaseID, String currentVersion, int currentLicenseVersion, URL css) {
	try {
		ResourceBundle i18nBundle = ResourceBundle.getBundle("com.briksoftware.updatefx.gui.i18n.UpdateDialog");
		
		FXMLLoader loader = new FXMLLoader(UpdateDialogController.class.getResource("UpdateDialog.fxml"), i18nBundle);
		loader.setBuilderFactory(new JavaFXBuilderFactory());
		Parent page = loader.load();
		UpdateDialogController controller = loader.getController();
		controller.release = release;
		controller.currentReleaseID = currentReleaseID;
		controller.currentVersion = currentVersion;
		controller.currentLicenseVersion = currentLicenseVersion;
		controller.css = css;
		controller.initialize();
		
		Scene scene = new Scene(page);
		if (css != null) {
			scene.getStylesheets().add(css.toExternalForm());
		}
		
		final Stage stage = new Stage();
		stage.setScene(scene);
		stage.show();
		stage.toFront();
		
	} catch (Throwable ex) {
		ex.printStackTrace();
	}		
}
 
Example #10
Source File: HomeScreenController.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
public void initializeHome(List<Path> subappJars, String startupCommandsFileName) {
    CoreModule module = new CoreModule(subappJars, startupCommandsFileName);
    injector = Guice.createInjector(module);
    builderFactory = new JavaFXBuilderFactory();
}
 
Example #11
Source File: LatexdrawBuilderFactory.java    From latexdraw with GNU General Public License v3.0 4 votes vote down vote up
public LatexdrawBuilderFactory(final Injector inj) {
	super();
	injector = inj;
	defaultFactory = new JavaFXBuilderFactory();
}