gui stuff

This commit is contained in:
Sem van der Hoeven
2019-12-27 23:03:37 +01:00
parent a9213d6169
commit 7fd94e0a61
8 changed files with 212 additions and 5 deletions

View File

@@ -43,7 +43,7 @@
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target> <!--or <release>10</release>-->
<target>1.8</target>
</configuration>
</plugin>
<plugin>

View File

@@ -1,21 +1,62 @@
package brainfuck.gui;
import brainfuck.interpreter.BfInterpreter;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextArea;
import javafx.scene.control.Alert.AlertType;
public class Controller {
@FXML
MenuBar menuBar;
private MenuBar menuBar;
@FXML
MenuItem saveMenu;
private TextArea textoutput;
@FXML
private Button interpretButton;
@FXML
private MenuItem saveMenu;
@FXML
private TextArea textinput;
@FXML
private Button loadButton;
public void initialize() {
saveMenu.setOnAction(e -> {
System.out.println("menu clicked");
});
interpretButton.setOnAction(e -> {
try {
interpretFromText();
} catch (Exception e1) {
e1.printStackTrace();
}
});
// interpretButton.setSkin(new ScaleSkin(interpretButton));
}
private void interpretFromText() throws Exception {
String inputCode = textinput.getText();
if (inputCode == null || inputCode.isEmpty()) {
CustomAlert alert = new CustomAlert(AlertType.ERROR, "Nothing entered!", "Please enter some brainfuck code!", "No code entered");
alert.showAndWait();
} else {
BfInterpreter interpreter = new BfInterpreter(inputCode);
String interpreted = interpreter.interpret();
textoutput.setText(interpreted);
}
}
}

View File

@@ -0,0 +1,29 @@
package brainfuck.gui;
import javafx.scene.control.Alert;
import javafx.scene.control.DialogPane;
/**
* CustomAlert
*/
public class CustomAlert extends Alert{
/**
* makes a new alert
* @param alert the alertType
* @param title the title
* @param message the message
* @param headerText the header text
*/
public CustomAlert(AlertType alert, String title, String message, String headerText) {
super(alert);
this.setTitle(title);
this.setContentText(message);
this.setHeaderText(headerText);
DialogPane dialogPane = this.getDialogPane();
dialogPane.getStylesheets().add("/css/stylesheet.css");
}
}

View File

@@ -41,8 +41,9 @@ public class BfInterpreter {
}
public void interpret() {
public String interpret() {
int loop = 0;
StringBuilder result = new StringBuilder();
for (int i = 0; i < code.length(); i++) {
// System.out.println("char is now " + this.code.charAt(i));
@@ -64,6 +65,7 @@ public class BfInterpreter {
// System.out.println("printing");
// output the value in the array
System.out.print((char) memory[pointer]);
result.append((char) memory[pointer]);
} else if (code.charAt(i) == ',') {
// the next value in the array is the next input character
// System.out.println("input");
@@ -101,6 +103,7 @@ public class BfInterpreter {
}
sc.close();
return result.toString();
}

View File

@@ -20,11 +20,14 @@ public class Main extends Application {
launch(Main.class);
}
//TODO change alert style
@Override
public void start(Stage stage) throws Exception {
Parent pane = FXMLLoader.load(getClass().getResource("/fxml/layout.fxml"));
Scene scene = new Scene(pane);
scene.getStylesheets().add("/css/menuBar.css");
scene.getStylesheets().add("/css/stylesheet.css");
stage.setTitle("Brainfuck Interpreter");
stage.setScene(scene);
stage.show();

View File

@@ -0,0 +1,74 @@
/* 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-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 */
}
/* MENU BAR + Top-level MENU BUTTONS */
/*** The menu bar itself ***/
.menu-bar {
-fx-background-color: -fx-my-menu-color;
}
/*** Top-level menu itself (not selected / hovered) ***/
.menu-bar > .container > .menu-button {
-fx-background-color: -fx-my-menu-color;
}
/*** Top-level menu's label (not selected / hovered) ***/
.menu-bar > .container > .menu-button > .label {
-fx-text-fill: -fx-my-menu-font-color;
}
/*** Top-level menu's label (disabled) ***/
.menu-bar > .container > .menu-button > .label:disabled {
-fx-opacity: 1.0;
}
/*** Top-level menu itself (selected / hovered) ***/
.menu-bar > .container > .menu-button:hover,
.menu-bar > .container > .menu-button:focused,
.menu-bar > .container > .menu-button:showing {
-fx-background-color: -fx-my-menu-color-highlighted;
}
/*** Top-level menu's label (selected / hovered) ***/
.menu-bar > .container > .menu-button:hover > .label,
.menu-bar > .container > .menu-button:focused > .label,
.menu-bar > .container > .menu-button:showing > .label {
-fx-text-fill: -fx-my-menu-font-color-highlighted;
}
/* MENU ITEM (children of a MENU BUTTON) */
/*** The item itself (not hovered / focused) ***/
.menu-item {
-fx-background-color: -fx-my-menu-color;
}
/*** The item's label (not hovered / focused) ***/
.menu-item .label {
-fx-text-fill: -fx-my-menu-font-color;
}
/*** The item's label (disabled) ***/
.menu-item .label:disabled {
-fx-opacity: 1.0;
}
/*** The item itself (hovered / focused) ***/
.menu-item:focused, .menu-item:hovered {
-fx-background-color: -fx-my-menu-color-highlighted;
}
/*** The item's label (hovered / focused) ***/
.menu-item:focused .label, .menu-item:hovered .label {
-fx-text-fill: -fx-my-menu-font-color-highlighted;
}
/* CONTEXT MENU */
/*** The context menu that contains a menu's menu items ***/
.context-menu {
-fx-background-color: -fx-my-menu-color;
}

View File

@@ -0,0 +1,43 @@
* {
-fx-font-family: "Consolas";
-fx-font-size: 14px;
-fx-background-color: rgb(47, 45, 54);
-fx-button-color: rgb(12, 158, 126);
}
.button {
-fx-background-color: -fx-button-color;
}
.textbox {
-fx-text-fill: rgb(33, 189, 33);
}
.textbox .content {
-fx-background-color: rgb(43, 43, 43);
-fx-text-fill: rgb(33, 189, 33);
}
.dialog-pane>.content {
-fx-text-fill: -fx-button-color;
-fx-font-weight: bold;
-fx-font-size: 14px;
-fx-padding: 0.833em;
/* 10 */
}
.dialog-pane>.header-panel {
-fx-text-fill: -fx-button-color;
-fx-font-size: 14px;
-fx-padding: 0.833em 0 0 0.833em;
/* 10px 0px 0px 10px */
}
.dialog-pane>.header-panel>.label {
-fx-text-fill: -fx-button-color;
-fx-font-size: 14px;
-fx-padding: 0.833em 0 0 0.833em;
/* 10px 0px 0px 10px */
}

View File

@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import com.jfoenix.controls.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
@@ -9,7 +11,7 @@
<AnchorPane prefHeight="800.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="brainfuck.gui.Controller">
<children>
<MenuBar fx:id="menuBar" layoutY="2.0">
<MenuBar fx:id="menuBar">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
@@ -18,5 +20,17 @@
</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">
<font>
<Font name="Consolas" size="14.0" />
</font>
</TextArea>
<TextArea fx:id="textoutput" editable="false" layoutX="637.0" layoutY="182.0" prefHeight="317.0" prefWidth="357.0" styleClass="textbox" wrapText="true">
<font>
<Font name="Consolas" size="14.0" />
</font>
</TextArea>
<Button fx:id="interpretButton" layoutX="418.0" layoutY="499.0" mnemonicParsing="false" text="Interpret" />
<Button fx:id="loadButton" layoutX="124.0" layoutY="499.0" mnemonicParsing="false" text="Load from file" />
</children>
</AnchorPane>