Monday, October 12, 2020

Java Basic Util - ViewLoader

 package basic.util;


import java.io.IOException;

import java.util.Locale;

import java.util.Optional;


import basic.util.exception.BaseException;

import basic.util.resource.ResourceUtil;

import javafx.fxml.FXMLLoader;

import javafx.scene.layout.Pane;


public class ViewLoader {


final public static String MenuBarPath = "/com/atlastool/view/MenuBar.fxml";

final public static String SettingPath = "/com/atlastool/view/Setting.fxml";

public static Optional<Pane> load(String path, Locale locale) {

FXMLLoader fxmlLoader = new FXMLLoader();

        fxmlLoader.setResources(ResourceUtil.getResourceBundle());

Pane pane = null;

try {

pane = (Pane) fxmlLoader.load(ViewLoader.class

.getResource(path).openStream());

pane.setUserData(fxmlLoader.getController());

} catch (IOException exception) {

BaseException.throwException(BaseException.NotLoaded, exception, "Fxml File", path);

} catch (NullPointerException exception) {

BaseException.throwException(BaseException.NotFound, exception, "Fxml File", path);

}

return Optional.ofNullable(pane);

}

}


No comments:

Post a Comment