bayern.steinbrecher.screens.WizardScreen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ScreenSwitcher Show documentation
Show all versions of ScreenSwitcher Show documentation
An abstract structure for JavaFX based applications for handling dialogs and switching between them.
package bayern.steinbrecher.screens;
import bayern.steinbrecher.wizard.Wizard;
import bayern.steinbrecher.wizard.WizardPage;
import bayern.steinbrecher.wizard.WizardState;
import javafx.fxml.LoadException;
import javafx.scene.Parent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.ResourceBundle;
public abstract class WizardScreen extends Screen {
private final Wizard wizard;
protected WizardScreen() throws LoadException {
super(WizardScreen.class.getResource("WizardScreen.fxml"),
ResourceBundle.getBundle("bayern.steinbrecher.screens.WizardScreen"));
this.wizard = Wizard.create(generatePages());
}
@Override
protected void afterControllerIsInitialized(@NotNull WizardScreenController controller) {
super.afterControllerIsInitialized(controller);
wizard.stateProperty()
.addListener(((obs, oldVal, newVal) -> {
if (newVal == WizardState.FINISHED) {
controller.getScreenManager()
.switchBack();
}
}));
wizard.atFinishProperty()
.addListener((observable, oldValue, newValue) -> {
System.out.println("HERE");
});
}
@Override
@NotNull
public final Parent create(@NotNull ScreenManager manager) {
return wizard.getRoot();
}
@NotNull
public final Optional getResult() {
return wizard.getVisitedPages()
.map(this::getResultImpl);
}
@NotNull
protected abstract Map> generatePages() throws LoadException;
@Nullable
protected abstract R getResultImpl(@NotNull Collection visitedPages);
}