Update WidgetAdd

This commit is contained in:
code-witch 2019-07-20 20:07:56 -06:00
parent a8abd6173a
commit 75b3fb4eab

View File

@ -1,13 +1,16 @@
package fetch.events;
import java.util.Random;
import fetch.controller.App;
import fetch.widgets.*;
import javafx.event.EventHandler;
import javafx.scene.control.TextArea;
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
@ -19,32 +22,35 @@ import java.util.Random;
public class WidgetAdd implements EventHandler<KeyEvent> {
// Find better way of doing this, maybe each widget has x,y associated with it?
// private int yAmount = 0;
private int yAmount = 0;
private int xAmount = 0;
@Override
public void handle(KeyEvent keyEvent) {
// Debug Stuffs
debug();
System.out.println(keyEvent.getCode().getName());
if (keyEvent.getCode() == KeyCode.P) { // Spawn Widget Right
xAmount++;
StackPane sp = new StackPane();
sp.setStyle(
var terminalWidget = new TerminalWidget(xAmount,yAmount);
terminalWidget.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);
App.root.getChildren().add(terminalWidget);
for(Node n : App.root.getChildren()){
if(n instanceof StackPane){
((StackPane)n).setMinSize(App.scene.getWidth() / xAmount, App.scene.getHeight());
if(n instanceof Widget){
((Widget)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());
if(n instanceof Widget){
((Widget)n).setMinSize(App.scene.getWidth() /xAmount, App.scene.getHeight());
}
}
} else if (keyEvent.getCode() == KeyCode.I) { // Spawn Widget Down
@ -52,6 +58,34 @@ public class WidgetAdd implements EventHandler<KeyEvent> {
} else if (keyEvent.getCode() == KeyCode.O) { // Delete Widget Up
}
else if(keyEvent.getCode() == KeyCode.E) {
for(Node n : App.root.getChildren()) {
if(n instanceof Widget) {
Widget w = (Widget) n;
if(w.getHost().isFocused()){
((TextArea) ((Widget)n).getHost()).setEditable(true);
}
}
}
}
else if(keyEvent.getCode() == KeyCode.ESCAPE) {
for(Node n : App.root.getChildren()) {
if(n instanceof Widget) {
var w = (Widget) n;
if(w.getHost().isFocused()){
((TextArea) ((Widget)n).getHost()).setEditable(false);
}
}
}
}
}
}
private void debug(){
if(xAmount == 5){
for(Node n: App.root.getChildren()){
System.out.println(n);
}
}
}
}