dev #1
44
src/fetch/commands/SpawnWidget.java
Normal file
44
src/fetch/commands/SpawnWidget.java
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
package fetch.commands;
|
||||||
|
|
||||||
|
import fetch.widgets.Widget;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
|
||||||
|
public class SpawnWidget<T extends Node> extends Command {
|
||||||
|
private int x, y;
|
||||||
|
private Widget<T> widget;
|
||||||
|
|
||||||
|
public SpawnWidget(int x, int y, Widget<T> widget) {
|
||||||
|
setX(x);
|
||||||
|
setY(y);
|
||||||
|
setWidget(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setY(int y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Widget<T> getWidget() {
|
||||||
|
return widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWidget(Widget<T> widget) {
|
||||||
|
this.widget = widget;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,20 +6,20 @@ import javafx.application.Application;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
public final class App extends Application {
|
public final class App extends Application {
|
||||||
public static final HBox root = new HBox();
|
public static final HBox root = new HBox();
|
||||||
public static final Scene scene = new Scene(root);
|
public static final Scene scene = new Scene(root);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
// Put more init stuff here if need be.
|
scene.setFill(Color.BLACK);
|
||||||
|
// scene.getStylesheets().add("");
|
||||||
System.out.println("Initialization Completed");
|
System.out.println("Initialization Completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) {
|
public void start(Stage stage) {
|
||||||
// There's got to be a cleaner way..
|
// There's got to be a cleaner way..
|
||||||
|
@ -30,6 +30,4 @@ public final class App extends Application {
|
||||||
stage.show();
|
stage.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
|
@ -1,13 +1,16 @@
|
||||||
package fetch.events;
|
package fetch.events;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
import fetch.controller.App;
|
import fetch.controller.App;
|
||||||
|
import fetch.widgets.*;
|
||||||
|
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.input.KeyEvent;
|
import javafx.scene.input.KeyEvent;
|
||||||
import javafx.scene.layout.*;
|
|
||||||
import javafx.scene.input.*;
|
import javafx.scene.input.*;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UIOP to spawn widgets
|
* UIOP to spawn widgets
|
||||||
|
@ -19,32 +22,35 @@ import java.util.Random;
|
||||||
public class WidgetAdd implements EventHandler<KeyEvent> {
|
public class WidgetAdd implements EventHandler<KeyEvent> {
|
||||||
|
|
||||||
// Find better way of doing this, maybe each widget has x,y associated with it?
|
// 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;
|
private int xAmount = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(KeyEvent keyEvent) {
|
public void handle(KeyEvent keyEvent) {
|
||||||
|
// Debug Stuffs
|
||||||
|
debug();
|
||||||
|
|
||||||
System.out.println(keyEvent.getCode().getName());
|
System.out.println(keyEvent.getCode().getName());
|
||||||
if (keyEvent.getCode() == KeyCode.P) { // Spawn Widget Right
|
if (keyEvent.getCode() == KeyCode.P) { // Spawn Widget Right
|
||||||
xAmount++;
|
xAmount++;
|
||||||
StackPane sp = new StackPane();
|
var terminalWidget = new TerminalWidget(xAmount,yAmount);
|
||||||
sp.setStyle(
|
terminalWidget.setStyle(
|
||||||
String.format("-fx-background-color: rgb(%02d, %02d, %02d);",
|
String.format("-fx-background-color: rgb(%02d, %02d, %02d);",
|
||||||
new Random().nextInt(256),
|
new Random().nextInt(256),
|
||||||
new Random().nextInt(256),
|
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()){
|
for(Node n : App.root.getChildren()){
|
||||||
if(n instanceof StackPane){
|
if(n instanceof Widget){
|
||||||
((StackPane)n).setMinSize(App.scene.getWidth() / xAmount, App.scene.getHeight());
|
((Widget)n).setMinSize(App.scene.getWidth() / xAmount, App.scene.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (keyEvent.getCode() == KeyCode.U) { // Delete Widget Left
|
} else if (keyEvent.getCode() == KeyCode.U) { // Delete Widget Left
|
||||||
App.root.getChildren().remove(App.root.getChildren().size() - 1);
|
App.root.getChildren().remove(App.root.getChildren().size() - 1);
|
||||||
xAmount--;
|
xAmount--;
|
||||||
for(Node n : App.root.getChildren()){
|
for(Node n : App.root.getChildren()){
|
||||||
if(n instanceof StackPane){
|
if(n instanceof Widget){
|
||||||
((StackPane)n).setMinSize(App.scene.getWidth() /xAmount, App.scene.getHeight());
|
((Widget)n).setMinSize(App.scene.getWidth() /xAmount, App.scene.getHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (keyEvent.getCode() == KeyCode.I) { // Spawn Widget Down
|
} 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.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
17
src/fetch/widgets/EmptyWidget.java
Normal file
17
src/fetch/widgets/EmptyWidget.java
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package fetch.widgets;
|
||||||
|
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
|
||||||
|
public class EmptyWidget extends Widget<StackPane> {
|
||||||
|
|
||||||
|
public EmptyWidget(int x, int y) {
|
||||||
|
super(x, y, new StackPane());
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "EmptyWidget{" +
|
||||||
|
"x=" + getX() +
|
||||||
|
", y=" + getY() +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
20
src/fetch/widgets/TerminalWidget.java
Normal file
20
src/fetch/widgets/TerminalWidget.java
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
package fetch.widgets;
|
||||||
|
|
||||||
|
|
||||||
|
import javafx.scene.control.TextArea;
|
||||||
|
|
||||||
|
public class TerminalWidget extends Widget<TextArea> {
|
||||||
|
|
||||||
|
public TerminalWidget(int x,int y) {
|
||||||
|
super(x,y, new TextArea());
|
||||||
|
getHost().setEditable(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "TerminalWidget{" +
|
||||||
|
"x=" + getX() +
|
||||||
|
", y=" + getY() +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
50
src/fetch/widgets/Widget.java
Normal file
50
src/fetch/widgets/Widget.java
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package fetch.widgets;
|
||||||
|
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.layout.StackPane;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class Widget<T extends Node> extends StackPane {
|
||||||
|
private int x, y;
|
||||||
|
private T host; // i wanted to use parent, but that's taken by the StackPane already
|
||||||
|
|
||||||
|
public Widget(int x,int y, T host) {
|
||||||
|
setX(x);
|
||||||
|
setY(y);
|
||||||
|
setHost(host);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setX(int x) {
|
||||||
|
this.x = x;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setY(int y) {
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getHost(){
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setHost(T host){
|
||||||
|
this.host = host;
|
||||||
|
this.getChildren().add(getHost());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Widget{" +
|
||||||
|
"x=" + getX() +
|
||||||
|
", y=" + getY() +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user