added saving file and credits and help
This commit is contained in:
159
pom.xml
159
pom.xml
@@ -1,59 +1,104 @@
|
||||
<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>brainfuck.interpreter</groupId>
|
||||
<artifactId>BrainfuckInterpreter</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>BrainfuckInterpreter</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<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>brainfuck.interpreter</groupId>
|
||||
<artifactId>BrainfuckInterpreter</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>BrainfuckInterpreter</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>11.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- <plugin>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>0.0.3</version>
|
||||
<configuration>
|
||||
<mainClass>brainfuck.interpreter.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin> -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.zenjava</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>8.7.0</version>
|
||||
<configuration>
|
||||
<mainClass>brainfuck.interpreter.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-fxml</artifactId>
|
||||
<version>11.0.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<!-- <plugin>
|
||||
<groupId>org.openjfx</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>0.0.3</version>
|
||||
<configuration>
|
||||
<mainClass>brainfuck.interpreter.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin> -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.zenjava</groupId>
|
||||
<artifactId>javafx-maven-plugin</artifactId>
|
||||
<version>8.7.0</version>
|
||||
<configuration>
|
||||
<mainClass>brainfuck.interpreter.Main</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
||||
<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>
|
||||
|
||||
@@ -2,6 +2,7 @@ package brainfuck.gui;
|
||||
|
||||
import brainfuck.interpreter.BfInterpreter;
|
||||
import brainfuck.interpreter.Main;
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
@@ -11,6 +12,8 @@ import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class Controller {
|
||||
@@ -38,10 +41,34 @@ public class Controller {
|
||||
@FXML
|
||||
private Label statusText;
|
||||
|
||||
@FXML
|
||||
private MenuItem github;
|
||||
|
||||
@FXML
|
||||
private MenuItem wiki;
|
||||
|
||||
public void initialize() {
|
||||
changeStatus("Idle", "#9a9c9a");
|
||||
Main main = new Main();
|
||||
saveMenu.setOnAction(e -> {
|
||||
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 -> {
|
||||
@@ -56,7 +83,7 @@ public class Controller {
|
||||
|
||||
loadButton.setOnAction(e -> {
|
||||
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");
|
||||
|
||||
changeStatus("Interpreting...", "#28fff5");
|
||||
@@ -82,9 +109,24 @@ public class Controller {
|
||||
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));
|
||||
}
|
||||
|
||||
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) {
|
||||
statusText.setStyle("-fx-text-fill: " + color);
|
||||
statusText.setText(text);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class Main extends Application {
|
||||
|
||||
}
|
||||
//TODO change alert style
|
||||
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
this.stage = stage;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* 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-font-color: #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) ***/
|
||||
.menu-item .label {
|
||||
-fx-text-fill: -fx-my-menu-font-color;
|
||||
-fx-background-color: -fx-my-menu-color;
|
||||
}
|
||||
|
||||
/*** The item's label (disabled) ***/
|
||||
@@ -58,12 +59,12 @@
|
||||
}
|
||||
|
||||
/*** The item itself (hovered / focused) ***/
|
||||
.menu-item:focused, .menu-item:hovered {
|
||||
-fx-background-color: -fx-my-menu-color-highlighted;
|
||||
.menu-item:focused, .menu-item:hover {
|
||||
-fx-background-color: -fx-my-menu-color-highlighted;
|
||||
}
|
||||
|
||||
/*** The item's label (hovered / focused) ***/
|
||||
.menu-item:focused .label, .menu-item:hovered .label {
|
||||
/*** The item's label (hovered / focused) ***/
|
||||
.menu-item:focused .label, .menu-item:hover .label {
|
||||
-fx-text-fill: -fx-my-menu-font-color-highlighted;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,29 @@
|
||||
* {
|
||||
-fx-font-family: "Consolas";
|
||||
-fx-font-size: 14px;
|
||||
|
||||
-fx-background-color: rgb(47, 45, 54);
|
||||
-fx-button-color: rgb(12, 158, 126);
|
||||
|
||||
}
|
||||
|
||||
.textValue {
|
||||
-fx-font-size: 14px;
|
||||
}
|
||||
|
||||
.button {
|
||||
-fx-background-color: -fx-button-color;
|
||||
-fx-font-size: 14px;
|
||||
}
|
||||
|
||||
.textbox {
|
||||
-fx-text-fill: rgb(33, 189, 33);
|
||||
-fx-font-size: 14px;
|
||||
}
|
||||
|
||||
.textbox .content {
|
||||
-fx-background-color: rgb(43, 43, 43);
|
||||
-fx-text-fill: rgb(33, 189, 33);
|
||||
-fx-font-size: 14px;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +32,7 @@
|
||||
-fx-font-weight: bold;
|
||||
-fx-font-size: 14px;
|
||||
-fx-padding: 0.833em;
|
||||
|
||||
/* 10 */
|
||||
}
|
||||
|
||||
@@ -42,3 +50,11 @@
|
||||
-fx-padding: 0.833em 0 0 0.833em;
|
||||
/* 10px 0px 0px 10px */
|
||||
}
|
||||
.title {
|
||||
-fx-font-size: 50;
|
||||
}
|
||||
|
||||
.credits {
|
||||
-fx-font-size: 11;
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@
|
||||
<MenuItem fx:id="saveMenu" mnemonicParsing="false" text="Save" />
|
||||
</items>
|
||||
</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>
|
||||
</MenuBar>
|
||||
<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" />
|
||||
</children>
|
||||
</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>
|
||||
</AnchorPane>
|
||||
|
||||
Reference in New Issue
Block a user