From 4a256652a7ec5f198a76cbf4dbb0d48337938c9a Mon Sep 17 00:00:00 2001 From: code-witch <38577792+code-witch@users.noreply.github.com> Date: Mon, 25 Mar 2019 18:21:27 -0600 Subject: [PATCH] Initial commit --- .gitignore | 19 +++++++++++ README.md | 2 ++ src/fetch/commands/Command.java | 10 ++++++ src/fetch/controller/App.java | 35 ++++++++++++++++++++ src/fetch/controller/Fetch.java | 9 ++++++ src/fetch/events/WidgetAdd.java | 57 +++++++++++++++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 src/fetch/commands/Command.java create mode 100644 src/fetch/controller/App.java create mode 100644 src/fetch/controller/Fetch.java create mode 100644 src/fetch/events/WidgetAdd.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ef5ccb8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,19 @@ +# IntelliJ IDE Files +*.iml +*.idea/* +out/* + +# Eclipse IDE Files +.project +.classpath +.settings + +# VS Code Files +.vscode + +# Java Compiled Files +bin/* +*.class + +# Misc +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..0d11f26 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# JavaTUI +A Java Terminal User Interface diff --git a/src/fetch/commands/Command.java b/src/fetch/commands/Command.java new file mode 100644 index 0000000..1b822ee --- /dev/null +++ b/src/fetch/commands/Command.java @@ -0,0 +1,10 @@ +package fetch.commands; + +public abstract class Command { + + /** + * Runs the Command + */ + public abstract void run(); + +} diff --git a/src/fetch/controller/App.java b/src/fetch/controller/App.java new file mode 100644 index 0000000..d0e3aed --- /dev/null +++ b/src/fetch/controller/App.java @@ -0,0 +1,35 @@ +package fetch.controller; + +import fetch.events.*; + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.HBox; +import javafx.stage.Stage; + +public final class App extends Application { + public static final HBox root = new HBox(); + public static final Scene scene = new Scene(root); + + + @Override + public void init() { + // Put more init stuff here if need be. + System.out.println("Initialization Completed"); + } + + + @Override + public void start(Stage stage) { + // There's got to be a cleaner way.. + scene.addEventFilter(KeyEvent.KEY_PRESSED, new WidgetAdd()); + + stage.setTitle("JavaTUI"); + stage.setScene(scene); + stage.show(); + } + + + +} diff --git a/src/fetch/controller/Fetch.java b/src/fetch/controller/Fetch.java new file mode 100644 index 0000000..0775fdf --- /dev/null +++ b/src/fetch/controller/Fetch.java @@ -0,0 +1,9 @@ +package fetch.controller; + +import javafx.application.Application; + +public final class Fetch { + public static void main(String[] args) { + Application.launch(App.class, args); + } +} diff --git a/src/fetch/events/WidgetAdd.java b/src/fetch/events/WidgetAdd.java new file mode 100644 index 0000000..57c2be9 --- /dev/null +++ b/src/fetch/events/WidgetAdd.java @@ -0,0 +1,57 @@ +package fetch.events; + +import fetch.controller.App; +import javafx.event.EventHandler; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.*; +import javafx.scene.input.*; +import javafx.scene.Node; + +import java.util.Random; + +/** + * UIOP to spawn widgets + * u = left + * i = down + * o = up + * p = right + */ +public class WidgetAdd implements EventHandler { + + // Find better way of doing this, maybe each widget has x,y associated with it? + // private int yAmount = 0; + private int xAmount = 0; + + @Override + public void handle(KeyEvent keyEvent) { + System.out.println(keyEvent.getCode().getName()); + if (keyEvent.getCode() == KeyCode.P) { // Spawn Widget Right + xAmount++; + StackPane sp = new StackPane(); + sp.setStyle( + String.format("-fx-background-color: rgb(%02d, %02d, %02d);", + new Random().nextInt(256), + new Random().nextInt(256), + new Random().nextInt(256))); + App.root.getChildren().add(sp); + for(Node n : App.root.getChildren()){ + if(n instanceof StackPane){ + ((StackPane)n).setMinSize(App.scene.getWidth() / xAmount, App.scene.getHeight()); + } + } + } else if (keyEvent.getCode() == KeyCode.U) { // Delete Widget Left + App.root.getChildren().remove(App.root.getChildren().size() - 1); + xAmount--; + for(Node n : App.root.getChildren()){ + if(n instanceof StackPane){ + ((StackPane)n).setMinSize(App.scene.getWidth() /xAmount, App.scene.getHeight()); + } + } + } else if (keyEvent.getCode() == KeyCode.I) { // Spawn Widget Down + + } else if (keyEvent.getCode() == KeyCode.O) { // Delete Widget Up + + } + } + +}