111 lines
3.1 KiB
Java
111 lines
3.1 KiB
Java
package ch.zhaw.gartenverwaltung;
|
|
|
|
import ch.zhaw.gartenverwaltung.bootstrap.AfterInject;
|
|
import ch.zhaw.gartenverwaltung.bootstrap.AppLoader;
|
|
import ch.zhaw.gartenverwaltung.bootstrap.ChangeViewEvent;
|
|
import ch.zhaw.gartenverwaltung.bootstrap.Inject;
|
|
import javafx.event.EventHandler;
|
|
import javafx.fxml.FXML;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.layout.Pane;
|
|
|
|
import java.io.IOException;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
|
|
public class MainFXMLController {
|
|
private static final Logger LOG = Logger.getLogger(MainFXMLController.class.getName());
|
|
|
|
@Inject
|
|
AppLoader appLoader;
|
|
|
|
@FXML
|
|
private Button home_button;
|
|
|
|
@FXML
|
|
private AnchorPane mainPane;
|
|
|
|
@FXML
|
|
private Button myGarden_button;
|
|
|
|
@FXML
|
|
private Button mySchedule_button;
|
|
|
|
@FXML
|
|
private Button plants_button;
|
|
|
|
@FXML
|
|
void goToHome() {
|
|
showPaneAsMainView("Home.fxml");
|
|
styleChangeButton(home_button);
|
|
}
|
|
|
|
@FXML
|
|
void goToMyPlants() {
|
|
showPaneAsMainView("MyGarden.fxml");
|
|
styleChangeButton(myGarden_button);
|
|
}
|
|
|
|
@FXML
|
|
void goToMySchedule() {
|
|
showPaneAsMainView("MySchedule.fxml");
|
|
styleChangeButton(mySchedule_button);
|
|
}
|
|
|
|
@FXML
|
|
void goToPlants() {
|
|
showPaneAsMainView("Plants.fxml");
|
|
styleChangeButton(plants_button);
|
|
}
|
|
|
|
/**
|
|
* Updates the mainPane with the selected fxml file.
|
|
* set HGrow and VGrow to parent AnchorPane.
|
|
* Sends MainController to other Controllers.
|
|
* @param fxmlFile string of fxml file
|
|
*/
|
|
public void showPaneAsMainView(String fxmlFile) {
|
|
try {
|
|
Pane anchorPane = appLoader.loadPane(fxmlFile);
|
|
mainPane.getChildren().setAll(anchorPane);
|
|
anchorPane.prefWidthProperty().bind(mainPane.widthProperty());
|
|
anchorPane.prefHeightProperty().bind(mainPane.heightProperty());
|
|
|
|
anchorPane.removeEventHandler(ChangeViewEvent.CHANGE_MAIN_VIEW, changeMainViewHandler);
|
|
anchorPane.addEventHandler(ChangeViewEvent.CHANGE_MAIN_VIEW, changeMainViewHandler);
|
|
} catch (IOException e) {
|
|
LOG.log(Level.SEVERE, "Could not load pane.", e);
|
|
}
|
|
}
|
|
|
|
private final EventHandler<ChangeViewEvent> changeMainViewHandler = (ChangeViewEvent event) -> showPaneAsMainView(event.view());
|
|
|
|
private void preloadPanes() throws IOException {
|
|
appLoader.loadAndCacheFxml("MyGarden.fxml");
|
|
appLoader.loadAndCacheFxml("MySchedule.fxml");
|
|
appLoader.loadAndCacheFxml("Plants.fxml");
|
|
}
|
|
|
|
private void styleChangeButton(Button button) {
|
|
//ToDo changeStyle of the menu buttons
|
|
}
|
|
|
|
/**
|
|
* loads the default FXML File
|
|
* {@inheritDoc}
|
|
*/
|
|
@AfterInject
|
|
@SuppressWarnings("unused")
|
|
public void init() {
|
|
try {
|
|
preloadPanes();
|
|
showPaneAsMainView("Home.fxml");
|
|
styleChangeButton(home_button);
|
|
} catch (IOException e) {
|
|
LOG.log(Level.SEVERE, "Failed to load FXML-Pane!", e);
|
|
}
|
|
}
|
|
}
|
|
|