feature: added tutorial window
This commit is contained in:
@@ -11,6 +11,9 @@ import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.AnchorPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.stage.WindowEvent;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
@@ -40,6 +43,9 @@ public class MainFXMLController {
|
||||
@FXML
|
||||
private Button tutorial_button;
|
||||
|
||||
private final Stage tutorialModal = new Stage();
|
||||
|
||||
|
||||
/**
|
||||
* go to home pane
|
||||
*/
|
||||
@@ -95,11 +101,23 @@ public class MainFXMLController {
|
||||
}
|
||||
|
||||
/**
|
||||
* go to Tutorial pane
|
||||
* Show the tutorial window
|
||||
*/
|
||||
public void goToTutorial() {
|
||||
showPaneAsMainView("Tutorial.fxml");
|
||||
styleChangeButton(tutorial_button);
|
||||
public void showTutorial() {
|
||||
if (!tutorialModal.isShowing()) {
|
||||
if (tutorialModal.getScene() == null) {
|
||||
try {
|
||||
appLoader.loadSceneToStage("Tutorial.fxml", tutorialModal);
|
||||
tutorialModal.initModality(Modality.NONE);
|
||||
tutorialModal.setResizable(false);
|
||||
tutorialModal.sizeToScene();
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.SEVERE, "Could not load Tutorial");
|
||||
}
|
||||
}
|
||||
tutorialModal.show();
|
||||
}
|
||||
tutorialModal.requestFocus();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +150,6 @@ public class MainFXMLController {
|
||||
appLoader.loadAndCacheFxml("MyGarden.fxml");
|
||||
appLoader.loadAndCacheFxml("MySchedule.fxml");
|
||||
appLoader.loadAndCacheFxml("Plants.fxml");
|
||||
appLoader.loadAndCacheFxml("Tutorial.fxml");
|
||||
}
|
||||
|
||||
private void styleChangeButton(Button button) {
|
||||
@@ -153,12 +170,14 @@ public class MainFXMLController {
|
||||
} catch (IOException e) {
|
||||
LOG.log(Level.SEVERE, "Failed to load FXML-Pane!", e);
|
||||
}
|
||||
mainPane.getScene().getWindow().setOnCloseRequest(this::closeWindowHandler);
|
||||
setIconToButton(home_button, "homeIcon.png");
|
||||
setIconToButton(settings_button, "settingsIcon.png");
|
||||
Settings.getInstance().getShowTutorialProperty().addListener((observable, oldValue, newValue) -> {
|
||||
tutorial_button.setVisible(newValue);
|
||||
});
|
||||
tutorial_button.setVisible(Settings.getInstance().getShowTutorial());
|
||||
tutorial_button.visibleProperty().bind(Settings.getInstance().getShowTutorialProperty());
|
||||
}
|
||||
|
||||
private void closeWindowHandler(WindowEvent windowEvent) {
|
||||
tutorialModal.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -173,7 +192,4 @@ public class MainFXMLController {
|
||||
imageView.setPreserveRatio(true);
|
||||
button.setGraphic(imageView);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,61 @@
|
||||
package ch.zhaw.gartenverwaltung;
|
||||
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.image.ImageView;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
public class TutorialController {
|
||||
|
||||
@FXML
|
||||
public Button previousPageButton;
|
||||
@FXML
|
||||
public Button nextPageButton;
|
||||
@FXML
|
||||
public StackPane tourPages;
|
||||
public ImageView imgAddNewPlant;
|
||||
public ImageView imgTaskList;
|
||||
public ImageView imgSelectDate;
|
||||
|
||||
private int page = 0;
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
switchViews();
|
||||
setButtonAbilities();
|
||||
|
||||
Image placeholder = new Image(String.valueOf(PlantsController.class.getResource("placeholder.png")));
|
||||
imgAddNewPlant.setImage(placeholder);
|
||||
imgSelectDate.setImage(placeholder);
|
||||
imgTaskList.setImage(placeholder);
|
||||
}
|
||||
|
||||
public void viewNextPage() {
|
||||
page++;
|
||||
switchViews();
|
||||
setButtonAbilities();
|
||||
}
|
||||
public void viewPreviousPage() {
|
||||
page--;
|
||||
switchViews();
|
||||
setButtonAbilities();
|
||||
}
|
||||
|
||||
private void setButtonAbilities() {
|
||||
previousPageButton.setDisable(page <= 0);
|
||||
nextPageButton.setDisable(page >= tourPages.getChildren().size() - 1);
|
||||
}
|
||||
|
||||
private void switchViews() {
|
||||
tourPages.getChildren().forEach(node -> node.setOpacity(0));
|
||||
tourPages.getChildren().get(page).setOpacity(1);
|
||||
}
|
||||
|
||||
public void closeTutorial() {
|
||||
Stage root = (Stage) tourPages.getScene().getWindow();
|
||||
root.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user