Java 类javafx.fxml.Initializable 实例源码

项目:supernovae    文件:SupernovaeGame.java   
protected Initializable replaceSceneContent(String fxml) throws Exception {
    FXMLLoader loader = new FXMLLoader();
    InputStream in = SupernovaeGame.class.getResourceAsStream(fxml);
    loader.setBuilderFactory(new JavaFXBuilderFactory());
    loader.setLocation(SupernovaeGame.class.getResource(fxml));
    Pane page;
    try {
        page = (Pane) loader.load(in);
    } finally {
        in.close();
    }
    Scene scene = new Scene(page, 800, 600);
    ViewPlatform.JavaFXScene.setValue(scene);
    stage.setScene(scene);
    stage.sizeToScene();
    return (Initializable) loader.getController();
}
项目:mm3Capture    文件:SpringFxmlLoader.java   
public Object load(String url, Class<?> controllerClass) throws IOException {
    InputStream fxmlStream = null;
    try {
        fxmlStream = context.getResource("classpath:" + url).getInputStream();
        Object controller = context.getBean(controllerClass);
        FXMLLoader loader = context.getBean(FXMLLoader.class);
        loader.setController(controller);
        Object fxml =  loader.load(fxmlStream);
        ((Initializable)controller).initialize(null,null);
        return fxml;

    } finally {
        if (fxmlStream != null) {
            fxmlStream.close();
        }
    }
}
项目:fellesprosjekt    文件:CalendarApplication.java   
private Initializable replaceSceneContent(String fxml) {
    FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml));

    Parent root;
    try {
        root = loader.load();
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(1);
        return null;
    }

    // replaceSceneContent can be called from a non-GUI thread, runLater makes it work
    Platform.runLater(() -> {
        Scene scene = new Scene(root, WIDTH, HEIGHT);
        stage.setScene(scene);
        stage.sizeToScene();
    });

    return (Initializable) loader.getController();
}
项目:JavaFxClient    文件:MainFrameworkController.java   
public static Initializable loadUI(Stage primaryStage) {
    FxmlContent fxmlContent = FxmlLoadUtils.loadFxml("/com/hk/main/mainframe.fxml");
    if (fxmlContent == null) {
        return null;
    }
    final UndecoratorScene undecoratorScene = new UndecoratorScene(primaryStage, fxmlContent.getPane());
    undecoratorScene.setFadeInTransition();
    primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent we) {
            undecoratorScene.setFadeOutTransition();
            RabbitConfiguration.destroy();
            RabbitMethodInterceptor.destroy();
            we.consume();   // Do not hide
        }
    });
    primaryStage.setScene(undecoratorScene);
    primaryStage.sizeToScene();
    primaryStage.toFront();
    Undecorator undecorator = undecoratorScene.getUndecorator();
    primaryStage.setMinWidth(undecorator.getMinWidth());
    primaryStage.setMinHeight(undecorator.getMinHeight());
    primaryStage.setMaximized(true);
    primaryStage.show();
    return (Initializable) fxmlContent.getController();
}
项目:Omoikane    文件:SpringAnnotatedConfig.java   
private SceneOverloaded initView(String fxml, final Initializable controller) {
    FXMLLoader fxmlLoader;
    try {
        fxmlLoader = new FXMLLoader(getClass().getResource(fxml));
        fxmlLoader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> aClass) {
                return controller;
            }
        });
        AnchorPane page = (AnchorPane) fxmlLoader.load();
        SceneOverloaded scene = new SceneOverloaded(page, controller);
        return scene;
    } catch(IOException exception) {
        logger.error(exception.getMessage(), exception);
        return null;
    }
}
项目:Omoikane    文件:ArtemisaSpringAnnotatedConfig.java   
private SceneOverloaded initView(String fxml, final Initializable controller) {
    FXMLLoader fxmlLoader;
    try {
        fxmlLoader = new FXMLLoader(getClass().getResource(fxml));
        fxmlLoader.setControllerFactory(new Callback<Class<?>, Object>() {
            @Override
            public Object call(Class<?> aClass) {
                return controller;
            }
        });
        AnchorPane page = (AnchorPane) fxmlLoader.load();
        SceneOverloaded scene = new SceneOverloaded(page, controller);
        return scene;
    } catch(IOException exception) {
        logger.error(exception.getMessage(), exception);
        return null;
    }
}
项目:CSS-Editor-FX    文件:Util.java   
public static <C extends Initializable, P> Pair<C, P> renderFxml(Class<C> controllerClass) throws IOException {
  String clzName = controllerClass.getSimpleName();
  String suffix = "Controller";
  if (!clzName.endsWith(suffix)) {
    throw new IOException("Class must named like \"xxxController\".");
  } else {
    return renderFxml(clzName.substring(0, clzName.length() - suffix.length()));
  }
}
项目:CSS-Editor-FX    文件:Util.java   
public static <C extends Initializable, P> Pair<C, P> renderFxml(Class<C> controllerClass) throws IOException {
  String clzName = controllerClass.getSimpleName();
  String suffix = "Controller";
  if (!clzName.endsWith(suffix)) {
    throw new IOException("Class must named like \"xxxController\".");
  } else {
    return renderFxml(clzName.substring(0, clzName.length() - suffix.length()));
  }
}
项目:Fx2C    文件:FxmlGenerator.java   
private void setupInitializableControllerCode(CodeGenerator codeGenerator, ReflectionResolver resolver) {
    if (OsUtils.isNullOrEmpty(codeGenerator.ControllerType)) {
        return;
    }
    Class<?> controllerClass = resolver.resolve(codeGenerator.ControllerType);
    if (controllerClass == null || !Initializable.class.isAssignableFrom(controllerClass)) {
        return;
    }
    codeGenerator.BuildControlsLines.add("_controller.initialize(null, null);");
}
项目:efiscen    文件:FrameController.java   
/**
 * Loads FXML file and it's controller.
 * @param filename the given fxml file
 * @param controller the given controller for the FXML file
 * @param rb the given resource bundle
 * @return Panel containing elements from fxml file
 */
private Pane loadFXML(String filename,Initializable controller,ResourceBundle rb) {
    FXMLLoader fxmlLoader = new FXMLLoader();
    fxmlLoader.setResources(rb);
    if(controller!=null) fxmlLoader.setController(controller);
    Pane pane = null;
    try {
         pane = (Pane) fxmlLoader.load(this.getClass().getResource(filename).openStream());
    } catch (IOException ex) {
        ex.printStackTrace();
        System.err.println(rb.getString("key.error1"));
        //System.exit(-1);
    }
    return pane;
}
项目:JobHunter    文件:JavaFXUtils.java   
public static Optional<Parent> loadFXML(Initializable clazz, String path, ResourceBundle bundle) {
    FXMLLoader fxmlLoader = new FXMLLoader(clazz.getClass().getResource(path));
    fxmlLoader.setResources(bundle);
    fxmlLoader.setController(clazz);
    try {
        return Optional.of((Parent)fxmlLoader.load());
    } catch (IOException e) {
        l.error("Failed to open file {}", path, e);
    }
    return Optional.empty();
}
项目:SAST    文件:Login.java   
private Initializable replaceSceneContent(String fxml) throws Exception {
    FXMLLoader loader = new FXMLLoader();
    InputStream in = Login.class.getResourceAsStream(fxml);
    loader.setBuilderFactory(new JavaFXBuilderFactory());
    loader.setLocation(Login.class.getResource(fxml));
    AnchorPane page;
    try {
        page = (AnchorPane) loader.load(in);
    } finally {
        in.close();
    }

    // Store the stage width and height in case the user has resized the window
    double stageWidth = stage.getWidth();
    if (!Double.isNaN(stageWidth)) {
        stageWidth -= (stage.getWidth() - stage.getScene().getWidth());
    }

    double stageHeight = stage.getHeight();
    if (!Double.isNaN(stageHeight)) {
        stageHeight -= (stage.getHeight() - stage.getScene().getHeight());
    }

    Scene scene = new Scene(page);
    if (!Double.isNaN(stageWidth)) {
        page.setPrefWidth(stageWidth);
    }
    if (!Double.isNaN(stageHeight)) {
        page.setPrefHeight(stageHeight);
    }

    stage.setScene(scene);
    stage.sizeToScene();
    return (Initializable) loader.getController();
}
项目:auto-shot    文件:Main.java   
/**
 * @param fxml XML scene file to load
 */
private Initializable replaceSceneContent(String fxml) throws Exception {
    FXMLLoader loader = new FXMLLoader();
    loader.setBuilderFactory(new JavaFXBuilderFactory());
    loader.setLocation(Main.class.getResource(fxml));
    GridPane page;
    try (InputStream in = Main.class.getResourceAsStream(fxml)) {
        page = loader.load(in);
    }
    Scene scene = new Scene(page);
    stage.setScene(scene);
    stage.sizeToScene();
    return (Initializable) loader.getController();
}
项目:igtv    文件:Main.java   
/**
 * Replaces one scene with another
 * 
 * @param fxml
 * @return
 * @throws Exception
 */
private Initializable replaceSceneContent(String fxml) throws Exception {

  // Create a loader
  FXMLLoader loader = new FXMLLoader();

  // Stream the fxml resource
  InputStream in = Main.class.getResourceAsStream(fxml);

  // Load the document
  loader.setBuilderFactory(new JavaFXBuilderFactory());
  loader.setLocation(Main.class.getResource(fxml));

  // Page loading
  AnchorPane page;

  // Instantiate the scene
  try {
    page = (AnchorPane) loader.load(in);
  } finally {
    in.close();
  }

  // Setup the scene
  Scene scene = new Scene(page, 800, 600);

  // Sets the scene to the one that was chosen
  stage.setScene(scene);

  // Resize
  stage.sizeToScene();

  // Returns the instantiated scene
  return (Initializable) loader.getController();
}
项目:CSS-Editor-FX    文件:Util.java   
public static <C extends Initializable, P> Pair<C, P> renderFxml(String fileName) throws IOException {
  FXMLLoader loader = new FXMLLoader(Util.getFxmlResource(fileName));
  P filterPane = loader.load();
  C controller = loader.getController();
  return new Pair<>(controller, filterPane);
}
项目:CSS-Editor-FX    文件:Util.java   
public static <C extends Initializable, P> Pair<C, P> renderFxml(String fileName) throws IOException {
  FXMLLoader loader = new FXMLLoader(Util.getFxmlResource(fileName));
  P filterPane = loader.load();
  C controller = loader.getController();
  return new Pair<>(controller, filterPane);
}
项目:DevLaunch    文件:ApplicationDialog.java   
@SuppressWarnings("unchecked")
public <T extends Initializable> T getController() {
    return (T) controller;
}
项目:Omoikane    文件:SceneOverloaded.java   
public SceneOverloaded(Parent parent, Initializable controller) {
    super(parent);
    setController(controller);
}
项目:Omoikane    文件:SceneOverloaded.java   
public Initializable getController() {
    return controller;
}
项目:Omoikane    文件:SceneOverloaded.java   
public void setController(Initializable controller) {
    this.controller = controller;
}
项目:JavaFX_Game_Client    文件:ServerClient.java   
/**
 * set the login controller
 * 
 * @param controller
 */
public void setController(Initializable controller) {
    this.controller = controller;
}
项目:JavaFX_Game_Client    文件:ServerClient.java   
/**
 * set the room controller
 * 
 * @param gameRoomController
 */
public void setGameRoomController(Initializable gameRoomController) {
    this.gameRoomController = gameRoomController;
}
项目:JavaFX_Game_Client    文件:ServerClient.java   
/**
 * get client login controller
 * 
 * @return
 */
public Initializable getLoginController() {
    return loginController;
}
项目:JavaFX_Game_Client    文件:ServerClient.java   
/**
 * set client's login controller
 * 
 * @param loginController
 */
public void setLoginController(Initializable loginController) {
    this.loginController = loginController;
}