All Downloads are FREE. Search and download functionalities are using the official Maven repository.

bayern.steinbrecher.wizard.StandaloneWizardPage Maven / Gradle / Ivy

Go to download

Contains a library to create dynamic and branching JavaFX wizards in an abstract way. Comes with a predefined collection of typical wizard pages.

There is a newer version: 1.60
Show newest version
package bayern.steinbrecher.wizard;

import javafx.fxml.FXMLLoader;
import javafx.fxml.LoadException;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.util.Objects;
import java.util.Optional;
import java.util.ResourceBundle;

/**
 * Represents a {@link WizardPage} which can be shown without being embedded into a {@link Wizard}.
 *
 * @author Stefan Huber
 * @since 1.23
 */
public abstract class StandaloneWizardPage, C extends StandaloneWizardPageController>
        extends WizardPage {

    /**
     * @since 1.26
     */
    protected StandaloneWizardPage(@NotNull String fxmlPath, @Nullable ResourceBundle bundle) {
        super(fxmlPath, bundle);
    }

    /**
     * @since 1.37
     */
    public void embedStandaloneWizardPage(@NotNull Stage stage, @Nullable String closeText) throws LoadException {
        FXMLLoader fxmlLoader = new FXMLLoader(
                StandaloneWizardPage.class.getResource("StandaloneWizardPage.fxml"),
                ResourceBundle.getBundle("bayern.steinbrecher.wizard.StandaloneWizardPage"));
        Pane root;
        try {
            root = fxmlLoader.load();
        } catch (IOException ex) {
            throw new LoadException("Could not load the standalone wizard page wrapper description", ex);
        }
        if (stage.getScene() == null) {
            stage.setScene(new Scene(root));
        } else {
            stage.getScene()
                    .setRoot(root);
        }

        // Setup standalone controller
        StandaloneWizardPageController standaloneController = fxmlLoader.getController();
        standaloneController.setCloseText(closeText);
        standaloneController.setStage(
                Objects.requireNonNull(stage, "For being used as a standalone window a stage is required"));
        standaloneController.setContent(generateEmbeddableWizardPage().getRoot());

        // Make this page aware of the stage as well
        getController().setStage(stage);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy