added saving file and credits and help

This commit is contained in:
Sem van der Hoeven
2020-01-06 21:46:55 +01:00
parent 72a7f56085
commit 4360ced993
6 changed files with 187 additions and 65 deletions

157
pom.xml
View File

@@ -1,59 +1,104 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" <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"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<modelVersion>4.0.0</modelVersion> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<groupId>brainfuck.interpreter</groupId> <modelVersion>4.0.0</modelVersion>
<artifactId>BrainfuckInterpreter</artifactId> <groupId>brainfuck.interpreter</groupId>
<packaging>jar</packaging> <artifactId>BrainfuckInterpreter</artifactId>
<version>1.0-SNAPSHOT</version> <packaging>jar</packaging>
<name>BrainfuckInterpreter</name> <version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url> <name>BrainfuckInterpreter</name>
<url>http://maven.apache.org</url>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>commons-io</groupId>
<artifactId>commons-io</artifactId> <artifactId>commons-io</artifactId>
<version>2.5</version> <version>2.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.openjfx</groupId> <groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId> <artifactId>javafx-fxml</artifactId>
<version>11.0.1</version> <version>11.0.1</version>
</dependency> </dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<!-- <plugin> <!-- <plugin>
<groupId>org.openjfx</groupId> <groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId> <artifactId>javafx-maven-plugin</artifactId>
<version>0.0.3</version> <version>0.0.3</version>
<configuration> <configuration>
<mainClass>brainfuck.interpreter.Main</mainClass> <mainClass>brainfuck.interpreter.Main</mainClass>
</configuration> </configuration>
</plugin> </plugin>
<plugin> --> <plugin> -->
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <version>3.8.0</version>
<configuration> <configuration>
<source>1.8</source> <source>1.8</source>
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>com.zenjava</groupId> <groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId> <artifactId>javafx-maven-plugin</artifactId>
<version>8.7.0</version> <version>8.7.0</version>
<configuration> <configuration>
<mainClass>brainfuck.interpreter.Main</mainClass> <mainClass>brainfuck.interpreter.Main</mainClass>
</configuration> </configuration>
</plugin> </plugin>
</plugins> <plugin>
</build>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals>
<goal>launch4j</goal>
</goals>
<configuration>
<headerType>gui</headerType>
<jar>${project.build.directory}/${artifactId}-${version}-shaded.jar</jar>
<outfile>${project.build.directory}/brainfuck-interpreter.exe</outfile>
<downloadUrl>http://java.com/download</downloadUrl>
<classPath>
<mainClass>brainfuck.interpreter.Main</mainClass>
<preCp>anything</preCp>
</classPath>
<icon>src/main/resources/icon/icon.ico</icon>
<!-- <div>Icons made by <a href="https://www.flaticon.com/authors/freepik" title="Freepik">Freepik</a> from <a href="https://www.flaticon.com/" title="Flaticon">www.flaticon.com</a></div>-->
<jre>
<minVersion>1.8.0</minVersion>
<jdkPreference>preferJre</jdkPreference>
</jre>
<versionInfo>
<fileVersion>1.0.0.0</fileVersion>
<txtFileVersion>${project.version}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>2019 Sem van der Hoeven</copyright>
<productVersion>1.0.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productName>${project.name}</productName>
<companyName>Sem van der Hoeven</companyName>
<internalName>Sem</internalName>
<originalFilename>brainfuck-interpreter.exe</originalFilename>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project> </project>

View File

@@ -2,6 +2,7 @@ package brainfuck.gui;
import brainfuck.interpreter.BfInterpreter; import brainfuck.interpreter.BfInterpreter;
import brainfuck.interpreter.Main; import brainfuck.interpreter.Main;
import javafx.application.Application;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
@@ -11,6 +12,8 @@ import org.apache.commons.io.IOUtils;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
public class Controller { public class Controller {
@@ -38,10 +41,34 @@ public class Controller {
@FXML @FXML
private Label statusText; private Label statusText;
@FXML
private MenuItem github;
@FXML
private MenuItem wiki;
public void initialize() { public void initialize() {
changeStatus("Idle", "#9a9c9a"); changeStatus("Idle", "#9a9c9a");
Main main = new Main();
saveMenu.setOnAction(e -> { saveMenu.setOnAction(e -> {
System.out.println("menu clicked"); System.out.println("menu clicked");
String content = textinput.getText();
if (content != null && !content.isEmpty()) {
FileChooser saveChooser = new FileChooser();
FileChooser.ExtensionFilter filter = new FileChooser.ExtensionFilter("Brainfuck file", "*.bf", "*.b");
saveChooser.getExtensionFilters().add(filter);
File file = saveChooser.showSaveDialog(rootPane.getScene().getWindow());
if (file != null) {
try {
saveToFile(file, content);
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
}
} else {
CustomAlert alert = new CustomAlert(AlertType.ERROR, "Nothing entered!", "Please enter some code you wish to save to a file", "No code enterd!");
alert.showAndWait();
}
}); });
interpretButton.setOnAction(e -> { interpretButton.setOnAction(e -> {
@@ -56,7 +83,7 @@ public class Controller {
loadButton.setOnAction(e -> { loadButton.setOnAction(e -> {
FileChooser fileChooser = new FileChooser(); FileChooser fileChooser = new FileChooser();
fileChooser.setSelectedExtensionFilter(new FileChooser.ExtensionFilter("Brainfuck file", ".bf", ".b")); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Brainfuck file", "*.bf", "*.b"));
fileChooser.setTitle("Choose file to import"); fileChooser.setTitle("Choose file to import");
changeStatus("Interpreting...", "#28fff5"); changeStatus("Interpreting...", "#28fff5");
@@ -82,9 +109,24 @@ public class Controller {
changeStatus("Done!", "#00ff12"); changeStatus("Done!", "#00ff12");
}); });
github.setOnAction(e -> {
main.getHostServices().showDocument("https://github.com/SemvdH/brainfuck-interpreter-java");
});
wiki.setOnAction(e -> {
main.getHostServices().showDocument("https://en.wikipedia.org/wiki/Brainfuck");
});
// interpretButton.setSkin(new ScaleSkin(interpretButton)); // interpretButton.setSkin(new ScaleSkin(interpretButton));
} }
private void saveToFile(File file, String content) throws FileNotFoundException {
PrintWriter writer = new PrintWriter(file);
writer.println(content);
writer.close();
}
private void changeStatus(String text, String color) { private void changeStatus(String text, String color) {
statusText.setStyle("-fx-text-fill: " + color); statusText.setStyle("-fx-text-fill: " + color);
statusText.setText(text); statusText.setText(text);

View File

@@ -1,6 +1,6 @@
/* VARIABLE DEFINITIONS: Only these 4 variables have to be adjusted, the rest is copy-paste */ /* VARIABLE DEFINITIONS: Only these 4 variables have to be adjusted, the rest is copy-paste */
* { * {
-fx-my-menu-color: #727374; /* Change according to your needs */ -fx-my-menu-color: #727374; /* #727374*/
-fx-my-menu-color-highlighted: #2a3b42; /* Change according to your needs */ -fx-my-menu-color-highlighted: #2a3b42; /* Change according to your needs */
-fx-my-menu-font-color: #FFFFFF; /* Change according to your needs */ -fx-my-menu-font-color: #FFFFFF; /* Change according to your needs */
-fx-my-menu-font-color-highlighted: #FFFFFF; /* Change according to your needs */ -fx-my-menu-font-color-highlighted: #FFFFFF; /* Change according to your needs */
@@ -50,6 +50,7 @@
/*** The item's label (not hovered / focused) ***/ /*** The item's label (not hovered / focused) ***/
.menu-item .label { .menu-item .label {
-fx-text-fill: -fx-my-menu-font-color; -fx-text-fill: -fx-my-menu-font-color;
-fx-background-color: -fx-my-menu-color;
} }
/*** The item's label (disabled) ***/ /*** The item's label (disabled) ***/
@@ -58,12 +59,12 @@
} }
/*** The item itself (hovered / focused) ***/ /*** The item itself (hovered / focused) ***/
.menu-item:focused, .menu-item:hovered { .menu-item:focused, .menu-item:hover {
-fx-background-color: -fx-my-menu-color-highlighted; -fx-background-color: -fx-my-menu-color-highlighted;
} }
/*** The item's label (hovered / focused) ***/ /*** The item's label (hovered / focused) ***/
.menu-item:focused .label, .menu-item:hovered .label { .menu-item:focused .label, .menu-item:hover .label {
-fx-text-fill: -fx-my-menu-font-color-highlighted; -fx-text-fill: -fx-my-menu-font-color-highlighted;
} }

View File

@@ -1,22 +1,29 @@
* { * {
-fx-font-family: "Consolas"; -fx-font-family: "Consolas";
-fx-font-size: 14px;
-fx-background-color: rgb(47, 45, 54); -fx-background-color: rgb(47, 45, 54);
-fx-button-color: rgb(12, 158, 126); -fx-button-color: rgb(12, 158, 126);
} }
.textValue {
-fx-font-size: 14px;
}
.button { .button {
-fx-background-color: -fx-button-color; -fx-background-color: -fx-button-color;
-fx-font-size: 14px;
} }
.textbox { .textbox {
-fx-text-fill: rgb(33, 189, 33); -fx-text-fill: rgb(33, 189, 33);
-fx-font-size: 14px;
} }
.textbox .content { .textbox .content {
-fx-background-color: rgb(43, 43, 43); -fx-background-color: rgb(43, 43, 43);
-fx-text-fill: rgb(33, 189, 33); -fx-text-fill: rgb(33, 189, 33);
-fx-font-size: 14px;
} }
@@ -25,6 +32,7 @@
-fx-font-weight: bold; -fx-font-weight: bold;
-fx-font-size: 14px; -fx-font-size: 14px;
-fx-padding: 0.833em; -fx-padding: 0.833em;
/* 10 */ /* 10 */
} }
@@ -42,3 +50,11 @@
-fx-padding: 0.833em 0 0 0.833em; -fx-padding: 0.833em 0 0 0.833em;
/* 10px 0px 0px 10px */ /* 10px 0px 0px 10px */
} }
.title {
-fx-font-size: 50;
}
.credits {
-fx-font-size: 11;
}

View File

@@ -23,6 +23,12 @@
<MenuItem fx:id="saveMenu" mnemonicParsing="false" text="Save" /> <MenuItem fx:id="saveMenu" mnemonicParsing="false" text="Save" />
</items> </items>
</Menu> </Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem fx:id="github" mnemonicParsing="false" text="GitHub page" />
<MenuItem fx:id="wiki" mnemonicParsing="false" text="What is brainfuck?" />
</items>
</Menu>
</menus> </menus>
</MenuBar> </MenuBar>
<TextArea fx:id="textinput" layoutX="124.0" layoutY="182.0" prefHeight="317.0" prefWidth="357.0" promptText="enter text" styleClass="textbox" wrapText="true"> <TextArea fx:id="textinput" layoutX="124.0" layoutY="182.0" prefHeight="317.0" prefWidth="357.0" promptText="enter text" styleClass="textbox" wrapText="true">
@@ -47,5 +53,17 @@
<Button fx:id="interpretButton" mnemonicParsing="false" text="Interpret" /> <Button fx:id="interpretButton" mnemonicParsing="false" text="Interpret" />
</children> </children>
</HBox> </HBox>
<Label layoutX="124.0" layoutY="165.0" styleClass="textValue" text="Input" textFill="#797979" />
<Label layoutX="637.0" layoutY="165.0" styleClass="textValue" text="Output" textFill="#797979" />
<Label layoutX="311.0" layoutY="60.0" styleClass="title" text="Brainfuck Interpreter" textFill="#0de823">
<font>
<Font name="Consolas" size="50.0" />
</font>
</Label>
<Label layoutX="14.0" layoutY="773.0" styleClass="credits" text="Made by Sem van der Hoeven" textFill="#757575">
<font>
<Font size="9.0" />
</font>
</Label>
</children> </children>
</AnchorPane> </AnchorPane>