Lot of stuff
This commit is contained in:
parent
f0a724888d
commit
d2f7ad1828
|
@ -0,0 +1,169 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>tdt4100-v2021</groupId>
|
||||
<artifactId>banana-editor</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<release>15</release>
|
||||
<showWarnings>true</showWarnings>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<compilerArgs>
|
||||
<arg>--enable-preview</arg>
|
||||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M5</version>
|
||||
<configuration>
|
||||
<argLine>@{argLine} --enable-preview</argLine>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>0.0.3</version>
|
||||
<configuration>
|
||||
<mainClass>app.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.jacoco</groupId>
|
||||
<artifactId>jacoco-maven-plugin</artifactId>
|
||||
<version>0.8.6</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-prepare-agent</id>
|
||||
<goals>
|
||||
<goal>prepare-agent</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-report</id>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>report</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer>
|
||||
<mainClass>app.MainLauncher</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.8.0-M1</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testfx</groupId>
|
||||
<artifactId>testfx-core</artifactId>
|
||||
<version>4.0.16-alpha</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<groupId>org.assertj</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testfx</groupId>
|
||||
<artifactId>testfx-junit5</artifactId>
|
||||
<version>4.0.16-alpha</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
<version>2.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testfx</groupId>
|
||||
<artifactId>openjfx-monocle</artifactId>
|
||||
<version>jdk-12.0.1+2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-inline</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<groupId>org.mockito</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>2.23.0</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<groupId>org.mockito</groupId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.target>15</maven.compiler.target>
|
||||
<maven.compiler.source>15</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
</project>
|
||||
|
60
pom.xml
60
pom.xml
|
@ -1,5 +1,4 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<!-- Please read https://maven.apache.org/guides/introduction/introduction-to-the-pom.html -->
|
||||
|
||||
|
@ -30,9 +29,9 @@
|
|||
|
||||
<!-- RichTextFX -->
|
||||
<dependency>
|
||||
<groupId>org.fxmisc.richtext</groupId>
|
||||
<artifactId>richtextfx</artifactId>
|
||||
<version>0.10.5</version>
|
||||
<groupId>org.fxmisc.richtext</groupId>
|
||||
<artifactId>richtextfx</artifactId>
|
||||
<version>0.10.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Guava Eventbus -->
|
||||
|
@ -44,10 +43,10 @@
|
|||
|
||||
<!-- JUnit 5 -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.8.0-M1</version>
|
||||
<scope>test</scope>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>5.8.0-M1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- TestFX -->
|
||||
|
@ -102,7 +101,7 @@
|
|||
<type>maven-plugin</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<!-- <dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-graphics</artifactId>
|
||||
<version>13</version>
|
||||
|
@ -119,7 +118,7 @@
|
|||
<artifactId>javafx-graphics</artifactId>
|
||||
<version>13</version>
|
||||
<classifier>mac</classifier>
|
||||
</dependency>
|
||||
</dependency> -->
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
@ -138,7 +137,7 @@
|
|||
</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<!-- Plugin to test all junit tests with 'surefire:test' -->
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
@ -184,25 +183,24 @@
|
|||
|
||||
<!-- Plugin to bundle dependencies to generate a jar file -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer
|
||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>app.MainLauncher</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<mainClass>app.MainLauncher</mainClass>
|
||||
</transformer>
|
||||
</transformers>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
|
|
@ -12,6 +12,7 @@ import app.events.FileSaveStateChangedEvent;
|
|||
import app.events.LanguageChangedEvent;
|
||||
import app.events.ThemeChangedEvent;
|
||||
import app.model.Model;
|
||||
import app.settings.SettingsProvider;
|
||||
|
||||
public class Main extends Application {
|
||||
|
||||
|
@ -24,6 +25,7 @@ public class Main extends Application {
|
|||
|
||||
/**
|
||||
* Boilerplate function to launch the application.
|
||||
*
|
||||
* @param args Additional arguments from commandline
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
@ -40,7 +42,9 @@ public class Main extends Application {
|
|||
}
|
||||
|
||||
/**
|
||||
* Loads all FXML documents of the main UI and initializes all correlated subcontrollers
|
||||
* Loads all FXML documents of the main UI and initializes all correlated
|
||||
* subcontrollers
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void loadFXML() throws IOException {
|
||||
|
@ -65,14 +69,15 @@ public class Main extends Application {
|
|||
scene.getStylesheets().setAll("", "");
|
||||
|
||||
MainController mainController = fxmlLoader.getController();
|
||||
mainController.getEventBus().post(new LanguageChangedEvent("Java"));
|
||||
mainController.getEventBus().post(new ThemeChangedEvent("Monokai"));
|
||||
SettingsProvider SP = new SettingsProvider(mainController.getEventBus());
|
||||
SP.loadSettings();
|
||||
mainController.getEventBus().post(new FileSaveStateChangedEvent(true));
|
||||
mainController.setHostServices(getHostServices());
|
||||
}
|
||||
|
||||
/**
|
||||
* The entrypoint of the application.
|
||||
*
|
||||
* @param window The primary window of the application
|
||||
*/
|
||||
@Override
|
||||
|
|
|
@ -13,6 +13,7 @@ import app.controllers.*;
|
|||
import app.events.ExitApplicationEvent;
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.events.OpenLinkInBrowserEvent;
|
||||
import app.events.SaveFileEvent;
|
||||
import app.events.ThemeChangedEvent;
|
||||
import app.model.Model;
|
||||
import javafx.application.HostServices;
|
||||
|
@ -66,14 +67,9 @@ public class MainController implements Initializable {
|
|||
return hostServices;
|
||||
}
|
||||
|
||||
//TODO: Document
|
||||
// TODO: Document
|
||||
public List<Controller> getInnerControllers() {
|
||||
return List.of(
|
||||
editorController,
|
||||
filetreeController,
|
||||
modelineController,
|
||||
menubarController
|
||||
);
|
||||
return List.of(editorController, filetreeController, modelineController, menubarController);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -139,10 +135,11 @@ public class MainController implements Initializable {
|
|||
@Subscribe
|
||||
private void handle(ExitApplicationEvent event) {
|
||||
if (!Model.getFileIsSaved()) {
|
||||
int g = JOptionPane.showConfirmDialog(null, "Your files are not saved.\nGo back to save?", "Exit",
|
||||
int g = JOptionPane.showConfirmDialog(null, "Your files are not saved.\nSave before exit?", "Exit",
|
||||
JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (!(g == JOptionPane.YES_OPTION)) {
|
||||
if (g == JOptionPane.YES_OPTION) {
|
||||
this.eventBus.post(new SaveFileEvent(false));
|
||||
Platform.exit();
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -47,8 +47,12 @@ public class MenubarController implements Initializable, Controller {
|
|||
@FXML
|
||||
private ToggleGroup languageToggleGroup;
|
||||
|
||||
@FXML
|
||||
private ToggleGroup themeToggleGroup;
|
||||
|
||||
@Override
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {}
|
||||
public void initialize(URL url, ResourceBundle resourceBundle) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEventBus(EventBus eventBus) {
|
||||
|
@ -68,10 +72,7 @@ public class MenubarController implements Initializable, Controller {
|
|||
|
||||
@FXML
|
||||
private void handleNewFolder() {
|
||||
// Er dette en nødvendig funksjon? Er vel svært få editorer (word f.eks) som har
|
||||
// dette.
|
||||
// Er vel innebygd i stage window at en kan lage en folder direkte fra
|
||||
// filutforskeren.
|
||||
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
@ -244,15 +245,19 @@ public class MenubarController implements Initializable, Controller {
|
|||
*/
|
||||
@Subscribe
|
||||
private void handle(LanguageChangedEvent event) {
|
||||
this.languageToggleGroup
|
||||
.getToggles()
|
||||
.stream()
|
||||
.map(RadioMenuItem.class::cast)
|
||||
.filter(t -> t.getId()
|
||||
.equals("toggle" + event.getLanguage()))
|
||||
.findFirst()
|
||||
.orElseThrow()
|
||||
.setSelected(true);
|
||||
this.languageToggleGroup.getToggles().stream().map(RadioMenuItem.class::cast)
|
||||
.filter(t -> t.getId().equals("toggle" + event.getLanguage())).findFirst().orElseThrow().setSelected(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates menubuttons whenever the theme is changed
|
||||
*/
|
||||
|
||||
@Subscribe
|
||||
private void handle(ThemeChangedEvent event) {
|
||||
this.themeToggleGroup.getToggles().stream().map(RadioMenuItem.class::cast)
|
||||
.filter(t -> t.getId().equals("toggle" + event.getTheme().replace(" ", "_"))).findFirst().orElseThrow().setSelected(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package app.events;
|
||||
|
||||
import app.model.Model;
|
||||
|
||||
/**
|
||||
* Event signalizing that the theme of the applicaton has been changed
|
||||
*/
|
||||
|
@ -9,12 +11,14 @@ public class ThemeChangedEvent extends Event {
|
|||
|
||||
/**
|
||||
* Event signalizing that the theme of the applicaton has been changed
|
||||
*
|
||||
* @param theme The name of the theme
|
||||
*/
|
||||
public ThemeChangedEvent(String theme) {
|
||||
Model.setTheme(theme);
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The name of the theme
|
||||
*/
|
||||
|
|
|
@ -2,6 +2,7 @@ package app.model;
|
|||
|
||||
import java.nio.file.Path;
|
||||
|
||||
import app.settings.SettingsProvider;
|
||||
import javafx.scene.Scene;
|
||||
|
||||
/**
|
||||
|
@ -15,7 +16,9 @@ public class Model {
|
|||
private static Path activeFilePath;
|
||||
private static Path currentProjectPath;
|
||||
private static ProgrammingLanguage currentProgrammingLanguage;
|
||||
private static String theme;
|
||||
private static Scene scene;
|
||||
private static SettingsProvider settings;
|
||||
|
||||
public static Path getActiveFilePath() {
|
||||
return activeFilePath;
|
||||
|
@ -41,10 +44,22 @@ public class Model {
|
|||
return scene;
|
||||
}
|
||||
|
||||
public static String getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
||||
public static boolean getFileIsSaved() {
|
||||
return fileIsSaved;
|
||||
}
|
||||
|
||||
public static SettingsProvider getSettingsProvider() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public static void setTheme(String theme) {
|
||||
Model.theme = theme;
|
||||
}
|
||||
|
||||
public static void setLanguage(ProgrammingLanguage language) {
|
||||
Model.currentProgrammingLanguage = language;
|
||||
}
|
||||
|
@ -57,4 +72,8 @@ public class Model {
|
|||
Model.fileIsSaved = fileIsSaved;
|
||||
}
|
||||
|
||||
public static void setSettingsProvider(SettingsProvider settings) {
|
||||
Model.settings = settings;
|
||||
}
|
||||
|
||||
}
|
|
@ -27,7 +27,7 @@ public class FileOperations {
|
|||
if (chosenFile == null)
|
||||
throw new FileNotFoundException();
|
||||
// if (chosenFile != null) {
|
||||
// String correctFormat = chosenFile.getAbsolutePath().replace("\\", "\\\\");
|
||||
// String correctFormat = chosenFile.getAbsolutePath().replace("\\", "\\\\");
|
||||
// }
|
||||
|
||||
return chosenFile;
|
||||
|
@ -48,17 +48,11 @@ public class FileOperations {
|
|||
}
|
||||
|
||||
public static boolean saveFile(String filepath, String content) {
|
||||
|
||||
|
||||
try (PrintWriter writer = new PrintWriter(new File(filepath))) {
|
||||
if (filepath.endsWith(".java") || filepath.endsWith(".md")) {
|
||||
writer.println(content);
|
||||
} else {
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException ex) {
|
||||
|
||||
DialogBoxes.showErrorMessage("Could not save file!\nMust be a java or md file. Try again.");
|
||||
DialogBoxes.showErrorMessage("Could not save file!");
|
||||
System.err.println(filepath);
|
||||
return false;
|
||||
}
|
||||
|
@ -93,26 +87,22 @@ public class FileOperations {
|
|||
public static String readFile(Path filePath) {
|
||||
|
||||
if (filePath == null)
|
||||
return "";
|
||||
|
||||
return "";
|
||||
|
||||
String result = "";
|
||||
|
||||
try (Scanner sc = new Scanner(filePath.toFile())) {
|
||||
if (filePath.endsWith(".java") || filePath.endsWith(".md")) {
|
||||
while (sc.hasNextLine()) {
|
||||
result += (sc.nextLine() + "\n");
|
||||
}
|
||||
} else {
|
||||
throw new FileNotFoundException();
|
||||
while (sc.hasNextLine()) {
|
||||
result += (sc.nextLine() + "\n");
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException ex) {
|
||||
DialogBoxes.showErrorMessage("Could not be opened!\nMust be a java or md file or not null. Try again.");
|
||||
DialogBoxes.showErrorMessage("Could not be opened!");
|
||||
System.err.println(filePath);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
package app.settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import app.events.LanguageChangedEvent;
|
||||
import app.events.ThemeChangedEvent;
|
||||
import app.model.Model;
|
||||
|
||||
public class SettingsProvider implements SettingsProviderI {
|
||||
|
||||
private static EventBus eventBus;
|
||||
private static final String SETTINGS_PATH = "/BNNsettings/settings.dat";
|
||||
|
||||
public SettingsProvider(EventBus eB) {
|
||||
setEventBus(eB);
|
||||
Model.setSettingsProvider(this);
|
||||
}
|
||||
|
||||
public void setEventBus(EventBus eB) {
|
||||
eventBus = eB;
|
||||
SettingsProvider.eventBus.register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadSettings() {
|
||||
List<String> settings = new ArrayList<>();
|
||||
List<String> legalSettings = Arrays.asList("Java", "Markdown", "Monokai", "Solarized Light");
|
||||
try (Scanner sc = new Scanner(new File(getClass().getResource(SETTINGS_PATH).getPath()))) {
|
||||
|
||||
while (sc.hasNextLine()) {
|
||||
var nextLine = sc.nextLine().trim();
|
||||
if (nextLine.isEmpty() || nextLine.startsWith("-")) {
|
||||
continue;
|
||||
} else {
|
||||
settings.add(nextLine.substring(nextLine.indexOf("=") + 2));
|
||||
}
|
||||
}
|
||||
|
||||
if (legalSettings.containsAll(settings)) {
|
||||
eventBus.post(new LanguageChangedEvent(settings.get(0)));
|
||||
eventBus.post(new ThemeChangedEvent(settings.get(1)));
|
||||
} else {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
eventBus.post(new LanguageChangedEvent("Java"));
|
||||
eventBus.post(new ThemeChangedEvent("Monokai"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveSettings() {
|
||||
try (PrintWriter writer = new PrintWriter(new File(getClass().getResource(SETTINGS_PATH).getPath()))) {
|
||||
writer.println("- Settings:");
|
||||
writer.println("Programming Language = " + Model.getLanguage().getName());
|
||||
writer.println("Theme = " + Model.getTheme());
|
||||
} catch (IOException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void handle(ThemeChangedEvent event) {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void handle(LanguageChangedEvent event) {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package app.settings;
|
||||
|
||||
public interface SettingsProviderI {
|
||||
|
||||
void loadSettings();
|
||||
|
||||
void saveSettings();
|
||||
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
- Settings:
|
||||
ProgrammingLanguage = Java
|
||||
Theme = Solarized Light
|
|
@ -58,10 +58,11 @@
|
|||
<items>
|
||||
<!-- TODO: Generate buttons based on classes -->
|
||||
<RadioMenuItem text="Monokai"
|
||||
selected="true"
|
||||
fx:id="toggleMonokai"
|
||||
onAction="#handleThemeChange"
|
||||
toggleGroup="$themeToggleGroup"/>
|
||||
<RadioMenuItem text="Solarized Light"
|
||||
fx:id="toggleSolarized_Light"
|
||||
onAction="#handleThemeChange"
|
||||
toggleGroup="$themeToggleGroup"/>
|
||||
</items>
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
package app;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.platform.commons.annotation.Testable;
|
||||
|
||||
import app.controllers.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javafx.scene.layout.BorderPane;
|
||||
|
||||
import app.testing.FxTestTemplate;
|
||||
|
||||
|
||||
@Testable
|
||||
public class MainTest extends FxTestTemplate {
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that the stage title is correct")
|
||||
public void should_have_stage_title() {
|
||||
assertEquals("Banana Editor", this.getStage().getTitle());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(1)
|
||||
@DisplayName("Check that the stage has an icon")
|
||||
public void should_have_stage_icon() {
|
||||
assertEquals(1, this.getStage().getIcons().size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Order(2)
|
||||
@DisplayName("Check that the root element is present")
|
||||
public void should_have_root() {
|
||||
BorderPane app = (BorderPane) find("#root");
|
||||
assertNotNull(app);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(3)
|
||||
@DisplayName("Check that all subcontrollers are present")
|
||||
public void should_have_subcontrollers() {
|
||||
this
|
||||
.getMainController()
|
||||
.getInnerControllers()
|
||||
.forEach((Controller controller) -> assertNotNull(controller));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that the scene is correct")
|
||||
public void should_have_scene() throws IOException {
|
||||
assertNotNull(this.getStage().getScene());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that the CSS is set")
|
||||
public void should_have_css() {
|
||||
List<String> expectedCSS =
|
||||
List.of("/styling/themes/monokai.css", "/styling/languages/java.css")
|
||||
.stream()
|
||||
.map(p -> getClass().getResource(p).toExternalForm())
|
||||
.collect(Collectors.toList());
|
||||
assertEquals(expectedCSS, this.getStage().getScene().getStylesheets());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue