Exemple #1
0
 public Object load(String fxmlName, Class<?> controller) {
   try {
     URL url = controller.getClassLoader().getResource(fxmlName);
     FXMLLoader loader = new FXMLLoader();
     loader.setResources(ResourceBundle.getBundle(BUNDLE_NAME, Locale.getDefault()));
     loader.setControllerFactory(this);
     return loader.load(url.openStream());
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   }
 }
Exemple #2
0
 public MediaListView(ResourceBundle bundle) throws IOException {
   String fxml = "/fxml/MediaListView.fxml";
   FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml));
   loader.setResources(bundle);
   loader.setRoot(this);
   try {
     loader.load();
   } catch (IOException e) {
     log.error("Failed to load {}. {}", fxml, e.getMessage());
     throw e;
   }
   controller = (MediaListController) loader.getController();
 }
Exemple #3
0
  /**
   * Load a FXML component.
   *
   * <p>The fxml path could be :
   *
   * <ul>
   *   <li>Relative : fxml file will be loaded with the classloader of the given model class
   *   <li>Absolute : fxml file will be loaded with default thread class loader, packages must be
   *       separated by / character
   * </ul>
   *
   * @param model the model that will manage the fxml node
   * @param fxmlPath the fxml string path
   * @param bundlePath the bundle string path
   * @return a FXMLComponent object that wrap a fxml node with its controller
   * @param <M> the model type that will manage this fxml node
   */
  @SuppressWarnings("unchecked")
  public static <M extends Model> FXMLComponentBase loadFXML(
      final M model, final String fxmlPath, final String bundlePath) {

    final FXMLLoader fxmlLoader = new FXMLLoader();

    // Use Custom controller factory to attach the root model to the controller
    fxmlLoader.setControllerFactory(new DefaultFXMLControllerBuilder(model));

    fxmlLoader.setLocation(convertFxmlUrl(model, fxmlPath));

    try {
      if (bundlePath != null) {
        fxmlLoader.setResources(ResourceBundle.getBundle(bundlePath));
      }
    } catch (final MissingResourceException e) {
      LOGGER.log(MISSING_RESOURCE_BUNDLE, e, bundlePath);
    }

    Node node = null;
    boolean error = false;
    try {
      error = fxmlLoader.getLocation() == null;
      if (error) {
        node = TextBuilder.create().text(FXML_ERROR_NODE_LABEL.getText(fxmlPath)).build();
      } else {
        node = (Node) fxmlLoader.load(fxmlLoader.getLocation().openStream());
      }

    } catch (final IOException e) {
      throw new CoreRuntimeException(FXML_NODE_DOESNT_EXIST.getText(fxmlPath), e);
    }

    final FXMLController<M, ?> fxmlController = (FXMLController<M, ?>) fxmlLoader.getController();

    // It's tolerated to have a null controller for an fxml node
    if (fxmlController != null) {
      // The fxml controller must extends AbstractFXMLController
      if (!error && !(fxmlLoader.getController() instanceof AbstractFXMLController)) {
        throw new CoreRuntimeException(
            BAD_FXML_CONTROLLER_ANCESTOR.getText(
                fxmlLoader.getController().getClass().getCanonicalName()));
      }
      // Link the View component with the fxml controller
      fxmlController.setModel(model);
    }

    return new FXMLComponentBase(node, fxmlController);
  }
  @Override
  public EventSheetEditorController create(EventSheet aEventSheet) {
    try (InputStream fxml =
        EventSheetEditorControllerFactory.class.getResourceAsStream("EventSheetEditor.fxml")) {
      FXMLLoader theLoader = fxmlLoaderFactory.createLoader();
      ResourceBundle theBundle =
          ResourceBundle.getBundle(
              "de.mirkosertic.gamecomposer.contentarea.eventsheet.EventSheetEditor");
      theLoader.setResources(theBundle);
      BorderPane root = (BorderPane) theLoader.load(fxml);

      EventSheetEditorController theController = theLoader.getController();

      return theController.initialize(root, aEventSheet);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
 @InvokableAction(
     name = "Open IDE",
     category = "development",
     description = "Open new IDE window for Basic/Assembly/Plasma coding",
     alternatives = "dev,development,acme,assembler,editor",
     defaultKeyMapping = {"ctrl+shift+i"})
 public static void showIDE() {
   FXMLLoader fxmlLoader = new FXMLLoader(EmulatorUILogic.class.getResource("/fxml/editor.fxml"));
   fxmlLoader.setResources(null);
   try {
     Stage editorWindow = new Stage();
     AnchorPane node = (AnchorPane) fxmlLoader.load();
     IdeController controller = fxmlLoader.getController();
     controller.initialize();
     Scene s = new Scene(node);
     editorWindow.setScene(s);
     editorWindow.show();
   } catch (IOException exception) {
     throw new RuntimeException(exception);
   }
 }
 @InvokableAction(
     name = "Configuration",
     category = "general",
     description = "Edit emulator configuraion",
     alternatives = "Reconfigure,Preferences,Settings",
     defaultKeyMapping = {"f4", "ctrl+shift+c"})
 public static void showConfig() {
   FXMLLoader fxmlLoader =
       new FXMLLoader(EmulatorUILogic.class.getResource("/fxml/Configuration.fxml"));
   fxmlLoader.setResources(null);
   try {
     Stage configWindow = new Stage();
     AnchorPane node = (AnchorPane) fxmlLoader.load();
     ConfigurationUIController controller = fxmlLoader.getController();
     controller.initialize();
     Scene s = new Scene(node);
     configWindow.setScene(s);
     configWindow.show();
   } catch (IOException exception) {
     throw new RuntimeException(exception);
   }
 }
Exemple #7
0
  public CodeTab(TabPane pane, String className, String displayName) {
    this.className = className;
    this.setText(CLASS_PATH_SEPARATOR_PATTERN.matcher(displayName).replaceAll("."));

    pane.getTabs().add(this);

    FXMLLoader loader = new FXMLLoader(ClassLoader.getSystemResource("fxml/CodeTab.fxml"));
    loader.setResources(Main.getResourceBundle());
    loader.setRoot(this);
    loader.setController(this);

    try {
      loader.load();
    } catch (IOException e) {
      e.printStackTrace();
    }

    CODE_TABS.put(className, this);
    getTabPane().getSelectionModel().select(this);

    this.setOnClosed(event -> CODE_TABS.remove(this.getClassName()));
  }
  @Nullable
  protected Node loadFromFXML(@Nonnull String baseName) {
    requireNonBlank(baseName, "Argument 'baseName' must not be blank");
    if (baseName.endsWith(FXML_SUFFIX)) {
      baseName = stripFilenameExtension(baseName);
    }
    baseName = baseName.replace('.', '/');
    String viewName = baseName + FXML_SUFFIX;
    String styleName = baseName + ".css";

    URL viewResource = getResourceAsURL(viewName);
    if (viewResource == null) {
      return null;
    }

    FXMLLoader fxmlLoader = new FXMLLoader(viewResource);
    fxmlLoader.setResources(getApplication().getMessageSource().asResourceBundle());
    fxmlLoader.setBuilderFactory(
        new JavaFXBuilderFactory(getApplication().getApplicationClassLoader().get()));
    fxmlLoader.setClassLoader(getApplication().getApplicationClassLoader().get());
    fxmlLoader.setControllerFactory(klass -> getMvcGroup().getView());

    try {
      fxmlLoader.load();
    } catch (IOException e) {
      throw new GriffonException(e);
    }

    Parent node = fxmlLoader.getRoot();

    URL cssResource = getResourceAsURL(styleName);
    if (cssResource != null) {
      String uriToCss = cssResource.toExternalForm();
      node.getStylesheets().add(uriToCss);
    }

    return node;
  }