From 9a25549435e37de771f30b689f9046e1686069e8 Mon Sep 17 00:00:00 2001 From: code-witch Date: Tue, 26 Mar 2019 15:55:01 -0600 Subject: [PATCH] Initial planning --- javatui/commands/Command.java | 10 ++++++ javatui/events/WidgetAdd.java | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 javatui/commands/Command.java create mode 100644 javatui/events/WidgetAdd.java diff --git a/javatui/commands/Command.java b/javatui/commands/Command.java new file mode 100644 index 0000000..066951f --- /dev/null +++ b/javatui/commands/Command.java @@ -0,0 +1,10 @@ +package commands; + +public abstract class Command { + + /** + * Runs the Command + */ + public abstract void run(); + +} diff --git a/javatui/events/WidgetAdd.java b/javatui/events/WidgetAdd.java new file mode 100644 index 0000000..cc1b08a --- /dev/null +++ b/javatui/events/WidgetAdd.java @@ -0,0 +1,57 @@ +package events; + +import 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 + + } + } + +}