Add about feature

This commit is contained in:
Oystein Kristoffer Tveit 2021-02-24 11:36:04 +01:00
parent bfc867b8fd
commit bcbf6b5153
5 changed files with 43 additions and 1 deletions

View File

@ -58,6 +58,7 @@ public class Main extends Application {
MainController mainController = fxmlLoader.getController();
mainController.getEventBus().post(new LanguageChangedEvent("Java"));
mainController.getEventBus().post(new FileSaveStateChangedEvent(true));
mainController.setHostServices(getHostServices());
}
/**
@ -75,6 +76,8 @@ public class Main extends Application {
window.setScene(scene);
window.show();
getHostServices().showDocument("https://google.com");
}
}

View File

@ -10,7 +10,9 @@ import com.google.common.eventbus.Subscribe;
import app.controllers.*;
import app.events.ExitApplicationEvent;
import app.events.LanguageChangedEvent;
import app.events.OpenLinkInBrowserEvent;
import app.model.Model;
import javafx.application.HostServices;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
@ -30,6 +32,7 @@ public class MainController implements Initializable {
private MenubarController menubarController;
private EventBus eventBus;
private HostServices hostServices;
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
@ -53,6 +56,15 @@ public class MainController implements Initializable {
return this.eventBus;
}
public HostServices getHostServices() {
return hostServices;
}
public void setHostServices(HostServices hostServices) {
this.hostServices = hostServices;
}
/**
* Change the CSS according to which language is being used.
* @param event
@ -73,6 +85,12 @@ public class MainController implements Initializable {
Model.getScene().getStylesheets().add(nextStyleSheet);
}
@Subscribe
private void handle(OpenLinkInBrowserEvent event) {
this.getHostServices().showDocument(event.getLink());
}
/**
* Handle an exit request for the whole program.
* @param event

View File

@ -9,6 +9,7 @@ import com.google.common.eventbus.Subscribe;
import app.events.ExitApplicationEvent;
import app.events.LanguageChangedEvent;
import app.events.OpenLinkInBrowserEvent;
import app.events.ToggleCommentEvent;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
@ -120,6 +121,11 @@ public class MenubarController implements Initializable, Controller {
/* ABOUT */
/* ------------------------------------------------------------------------ */
@FXML
private void handleAbout(ActionEvent event) {
String aboutLink = "https://gitlab.stud.idi.ntnu.no/oysteikt/tdt4100-project-2021v/-/blob/master/README.md";
this.eventBus.post(new OpenLinkInBrowserEvent(aboutLink));
}
/* ------------------------------------------------------------------------ */
/* SUBSCRIPTIONS */

View File

@ -0,0 +1,15 @@
package app.events;
public class OpenLinkInBrowserEvent extends Event {
private String link;
public OpenLinkInBrowserEvent(String link) {
this.link = link;
}
public String getLink() {
return link;
}
}

View File

@ -67,7 +67,7 @@
<items>
<MenuItem mnemonicParsing="false" text="Tips and tricks" accelerator="f1"/>
<MenuItem mnemonicParsing="false" text="Keyboard Shortcut list" accelerator="f2"/>
<MenuItem mnemonicParsing="false" text="About" accelerator="f3"/>
<MenuItem mnemonicParsing="false" text="About" accelerator="f3" onAction="#handleAbout"/>
</items>
</Menu>
</menus>