Search in sources :

Example 1 with JavaFXBuilderFactory

use of javafx.fxml.JavaFXBuilderFactory in project Gargoyle by callakrsos.

the class FXMLPreviewLoader method start.

/**
	 * @inheritDoc
	 */
@Override
public void start(Stage primaryStage) throws Exception {
    BorderPane borderPane = new BorderPane();
    FXMLLoader loader = new FXMLLoader() {
    };
    // InputStream resourceAsStream =
    // FXMLPreviewLoader.class.getResourceAsStream("lang_ko.properties");
    //
    // loader.setResources(new PropertyResourceBundle(new
    // InputStreamReader(resourceAsStream, "UTF-8")) {
    // /*
    // * @inheritDoc
    // */
    // @Override
    // public boolean containsKey(String key) {
    // return true;
    // }
    //
    // /*
    // * @inheritDoc
    // */
    // @Override
    // public Object handleGetObject(String key) {
    // if (key == null) {
    // return "";
    // }
    //
    // Object result = null;
    //
    // try {
    // result = super.handleGetObject(key);
    // } catch (Exception e) {
    // ;
    // }
    //
    // return (result == null) ? key : result;
    // }
    // });
    // loader.setLocation(/*FXMLPreviewLoader.class.getResource("ColumnExam3.fxml")*/url);
    loader.setBuilderFactory(new BuilderFactory() {

        @Override
        public Builder<?> getBuilder(Class<?> param) {
            return new JavaFXBuilderFactory().getBuilder(param);
        }
    });
    loader.setControllerFactory(new Callback<Class<?>, Object>() {

        @Override
        public Object call(Class<?> param) {
            return null;
        }
    });
    FileInputStream inputStream = new FileInputStream(file);
    InputStream is = null;
    try {
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        FXMLSaxHandler handler = new FXMLSaxHandler(out);
        sp.parse(inputStream, handler);
        String string = out.toString("UTF-8");
        string = ValueUtil.regexReplaceMatchs("<!\\[CDATA\\[[?<a-zA-Z. *?>]+]]>", string, str -> {
            return ValueUtil.regexMatch("<\\?import [a-zA-Z.*?]+>", str);
        });
        System.out.println(string);
        byte[] bytes = string.getBytes();
        is = new ByteArrayInputStream(bytes);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // FileInputStream inputStream = new FileInputStream(file);
    borderPane.setCenter(loader.load(is));
    Scene scene = new Scene(borderPane);
    primaryStage.setScene(scene);
    primaryStage.show();
}
Also used : JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) FXMLSaxHandler(com.kyj.fx.voeditor.visual.framework.parser.FXMLSaxHandler) FXMLSaxHandler(com.kyj.fx.voeditor.visual.framework.parser.FXMLSaxHandler) Scene(javafx.scene.Scene) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) SAXParserFactory(javax.xml.parsers.SAXParserFactory) ValueUtil(com.kyj.fx.voeditor.visual.util.ValueUtil) FileInputStream(java.io.FileInputStream) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Application(javafx.application.Application) Matcher(java.util.regex.Matcher) ByteArrayInputStream(java.io.ByteArrayInputStream) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) SAXParser(javax.xml.parsers.SAXParser) Pattern(java.util.regex.Pattern) BorderPane(javafx.scene.layout.BorderPane) BuilderFactory(javafx.util.BuilderFactory) Callback(javafx.util.Callback) Builder(javafx.util.Builder) InputStream(java.io.InputStream) BorderPane(javafx.scene.layout.BorderPane) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Builder(javafx.util.Builder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) BuilderFactory(javafx.util.BuilderFactory) FileInputStream(java.io.FileInputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 2 with JavaFXBuilderFactory

use of javafx.fxml.JavaFXBuilderFactory in project loinc2hpo by monarch-initiative.

the class Main method init.

@Override
public void init() throws IOException {
    final Injector injector = Guice.createInjector(new DepInjectionModule());
    final Callback<Class<?>, Object> guiceFactory = clazz -> injector.getInstance(clazz);
    rootNode = FXMLLoader.load(getClass().getResource("/fxml/main.fxml"), // The resource bundle, useful to internationalised apps. Null here.
    null, new JavaFXBuilderFactory(), // this Guice factory will manage the instantiation of the controllers and their dependency injections.
    guiceFactory);
    // the following two lines both works; not sure what the first line is
    // mainController = injector.getInstance(Key.get(MainController.class));
    mainController = injector.getInstance(MainController.class);
}
Also used : Scene(javafx.scene.Scene) JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) Loinc2HpoPlatform(org.monarchinitiative.loinc2hpo.io.Loinc2HpoPlatform) MainController(org.monarchinitiative.loinc2hpo.controller.MainController) URL(java.net.URL) Inject(com.google.inject.Inject) Key(com.google.inject.Key) IOException(java.io.IOException) Injector(com.google.inject.Injector) Application(javafx.application.Application) Platform(javafx.application.Platform) Parent(javafx.scene.Parent) Logger(org.apache.logging.log4j.Logger) Stage(javafx.stage.Stage) FXMLLoader(javafx.fxml.FXMLLoader) Guice(com.google.inject.Guice) Optional(java.util.Optional) Callback(javafx.util.Callback) Image(javafx.scene.image.Image) LogManager(org.apache.logging.log4j.LogManager) javax.swing(javax.swing) JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) Injector(com.google.inject.Injector) MainController(org.monarchinitiative.loinc2hpo.controller.MainController)

Example 3 with JavaFXBuilderFactory

use of javafx.fxml.JavaFXBuilderFactory in project latexdraw by arnobl.

the class CodeInserter method getInsertCodeDialogue.

/**
 * @return The created latexdraw dialogue box.
 */
protected Optional<Stage> getInsertCodeDialogue() {
    if (codeInserterDialogue == null) {
        try {
            // The FXML file only loaded only when this method is called: this JFX controller is created by
            // the app injector and lives as a singleton. A call to this function loads the FXML.
            final Parent root = // NON-NLS
            FXMLLoader.load(// NON-NLS
            getClass().getResource("/fxml/InsertCode.fxml"), // NON-NLS
            LangTool.INSTANCE.getBundle(), new JavaFXBuilderFactory(), LaTeXDraw.getInstance().getInstanceCallBack());
            final Scene scene = new Scene(root);
            codeInserterDialogue = new Stage(StageStyle.UTILITY);
            codeInserterDialogue.setTitle(LangTool.INSTANCE.getBundle().getString("InsertPSTricksCodeFrame.0"));
            codeInserterDialogue.setScene(scene);
            codeInserterDialogue.setOnHiding(evt -> setActivated(false));
        } catch (final Exception ex) {
            BadaboomCollector.INSTANCE.add(ex);
        }
    }
    return Optional.ofNullable(codeInserterDialogue);
}
Also used : JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) Parent(javafx.scene.Parent) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene) RecognitionException(org.antlr.v4.runtime.RecognitionException)

Example 4 with JavaFXBuilderFactory

use of javafx.fxml.JavaFXBuilderFactory in project drbookings by DrBookings.

the class SamplePart method createScene.

protected void createScene(final Composite parent) {
    if (logger.isInfoEnabled()) {
        logger.info("Initializing FX");
    }
    try {
        final URL location = getClass().getResource("/fxml/FXML.fxml");
        final FXMLLoader fXMLLoader = new FXMLLoader();
        fXMLLoader.setLocation(location);
        fXMLLoader.setBuilderFactory(new JavaFXBuilderFactory());
        final Parent root = fXMLLoader.load(location.openStream());
        fxmlController = fXMLLoader.getController();
        // fxmlController.getZoomManager().start();
        final Scene scene = new Scene(root);
        fxCanvas.setScene(scene);
        if (logger.isInfoEnabled()) {
            logger.info("Initializing FX successful");
        }
    } catch (final Exception e) {
        if (logger.isErrorEnabled()) {
            logger.error(e.getLocalizedMessage(), e);
        }
    }
    fxmlController.getTable().setItems(manager.getBookings());
}
Also used : JavaFXBuilderFactory(javafx.fxml.JavaFXBuilderFactory) Parent(javafx.scene.Parent) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) URL(java.net.URL)

Aggregations

JavaFXBuilderFactory (javafx.fxml.JavaFXBuilderFactory)4 Scene (javafx.scene.Scene)4 FXMLLoader (javafx.fxml.FXMLLoader)3 Parent (javafx.scene.Parent)3 Stage (javafx.stage.Stage)3 URL (java.net.URL)2 Application (javafx.application.Application)2 Callback (javafx.util.Callback)2 Guice (com.google.inject.Guice)1 Inject (com.google.inject.Inject)1 Injector (com.google.inject.Injector)1 Key (com.google.inject.Key)1 FXMLSaxHandler (com.kyj.fx.voeditor.visual.framework.parser.FXMLSaxHandler)1 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1