Add exit handler
This commit is contained in:
parent
26bcb9f29c
commit
0ba350395b
@ -8,8 +8,10 @@ import com.google.common.eventbus.EventBus;
|
|||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
import app.controllers.*;
|
import app.controllers.*;
|
||||||
|
import app.events.ExitApplicationEvent;
|
||||||
import app.events.LanguageChangedEvent;
|
import app.events.LanguageChangedEvent;
|
||||||
import app.model.Model;
|
import app.model.Model;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
|
|
||||||
@ -71,4 +73,11 @@ public class MainController implements Initializable {
|
|||||||
Model.getScene().getStylesheets().add(nextStyleSheet);
|
Model.getScene().getStylesheets().add(nextStyleSheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
private void handle(ExitApplicationEvent event) {
|
||||||
|
// TODO: send save file event, exit application safely.
|
||||||
|
|
||||||
|
Platform.exit();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -7,8 +7,8 @@ import java.util.ResourceBundle;
|
|||||||
import com.google.common.eventbus.EventBus;
|
import com.google.common.eventbus.EventBus;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import app.events.ExitApplicationEvent;
|
||||||
import app.events.LanguageChangedEvent;
|
import app.events.LanguageChangedEvent;
|
||||||
import app.model.Model;
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
@ -84,6 +84,7 @@ public class MenubarController implements Initializable, Controller {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the event where the language was change from the menu.
|
* Handles the event where the language was change from the menu.
|
||||||
|
* @param event
|
||||||
*/
|
*/
|
||||||
@FXML
|
@FXML
|
||||||
private void handleLanguageChange(ActionEvent event) {
|
private void handleLanguageChange(ActionEvent event) {
|
||||||
@ -92,8 +93,18 @@ public class MenubarController implements Initializable, Controller {
|
|||||||
((RadioMenuItem) event.getSource()).getText()));
|
((RadioMenuItem) event.getSource()).getText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the event where there was an exit request from the menu.
|
||||||
|
* @param event
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
private void handleExitApplication(ActionEvent event) {
|
||||||
|
this.eventBus.post(new ExitApplicationEvent());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates menubuttons whenever the language is changed
|
* Updates menubuttons whenever the language is changed
|
||||||
|
* @param event
|
||||||
*/
|
*/
|
||||||
@Subscribe
|
@Subscribe
|
||||||
private void handle(LanguageChangedEvent event) {
|
private void handle(LanguageChangedEvent event) {
|
||||||
|
5
src/main/java/app/events/ExitApplicationEvent.java
Normal file
5
src/main/java/app/events/ExitApplicationEvent.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package app.events;
|
||||||
|
|
||||||
|
public class ExitApplicationEvent {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user