mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Fixes for garbage code by Omar
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package org.toop.app;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.view.ViewStack;
|
||||
import org.toop.app.view.views.MainView;
|
||||
import org.toop.app.view.views.QuitView;
|
||||
import org.toop.app.widget.WidgetSystem;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
import org.toop.app.widget.complex.ConfirmWidget;
|
||||
import org.toop.app.widget.complex.PopupWidget;
|
||||
import org.toop.framework.audio.events.AudioEvents;
|
||||
import org.toop.framework.eventbus.EventFlow;
|
||||
import org.toop.framework.resource.ResourceManager;
|
||||
@@ -16,6 +18,8 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.layout.StackPane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class App extends Application {
|
||||
private static Stage stage;
|
||||
private static Scene scene;
|
||||
@@ -31,11 +35,8 @@ public final class App extends Application {
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws Exception {
|
||||
final StackPane root = WidgetSystem.setup();
|
||||
|
||||
final StackPane root = WidgetContainer.setup();
|
||||
final Scene scene = new Scene(root);
|
||||
ViewStack.setup(scene);
|
||||
scene.setRoot(root);
|
||||
|
||||
stage.setTitle(AppContext.getString("app-title"));
|
||||
stage.setWidth(1080);
|
||||
@@ -64,7 +65,22 @@ public final class App extends Application {
|
||||
AppSettings.applySettings();
|
||||
new EventFlow().addPostEvent(new AudioEvents.StartBackgroundMusic()).asyncPostEvent();
|
||||
|
||||
// ViewStack.push(new MainView());
|
||||
var abc = new ConfirmWidget("abc");
|
||||
var cab = new ConfirmWidget("cab");
|
||||
|
||||
abc.addButton("test", () -> {
|
||||
WidgetContainer.add(Pos.CENTER, cab);
|
||||
WidgetContainer.remove(abc);
|
||||
});
|
||||
abc.addButton("test3333", () -> IO.println("Second test works!"));
|
||||
|
||||
cab.addButton("cab321312", () -> IO.println("Third test"));
|
||||
cab.addButton("cab31232132131", () -> {
|
||||
IO.println("Fourth test");
|
||||
WidgetContainer.remove(cab);
|
||||
});
|
||||
|
||||
WidgetContainer.add(Pos.CENTER, abc);
|
||||
}
|
||||
|
||||
public static void startQuit() {
|
||||
@@ -89,7 +105,7 @@ public final class App extends Application {
|
||||
|
||||
public static void reload() {
|
||||
stage.setTitle(AppContext.getString("app-title"));
|
||||
ViewStack.reload();
|
||||
//ViewStack.reload();
|
||||
}
|
||||
|
||||
public static void setFullscreen(boolean fullscreen) {
|
||||
|
||||
6
app/src/main/java/org/toop/app/interfaces/Popup.java
Normal file
6
app/src/main/java/org/toop/app/interfaces/Popup.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package org.toop.app.interfaces;
|
||||
|
||||
public interface Popup {
|
||||
void push();
|
||||
void pop();
|
||||
}
|
||||
63
app/src/main/java/org/toop/app/widget/Primitive.java
Normal file
63
app/src/main/java/org/toop/app/widget/Primitive.java
Normal file
@@ -0,0 +1,63 @@
|
||||
package org.toop.app.widget;
|
||||
|
||||
import javafx.scene.Node;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
|
||||
public final class Primitive {
|
||||
public static Text header(String label) {
|
||||
var header = new Text(label);
|
||||
header.getStyleClass().add("header");
|
||||
return header;
|
||||
}
|
||||
|
||||
public static Text text(String label) {
|
||||
var text = new Text(label);
|
||||
text.getStyleClass().add("text");
|
||||
return text;
|
||||
}
|
||||
|
||||
public static Button button(String label) {
|
||||
var button = new Button(label);
|
||||
button.getStyleClass().add("button");
|
||||
return button;
|
||||
}
|
||||
|
||||
public static TextField input() {
|
||||
var input = new TextField();
|
||||
input.getStyleClass().add("input");
|
||||
return input;
|
||||
}
|
||||
|
||||
public static Slider slider() {
|
||||
var slider = new Slider();
|
||||
slider.getStyleClass().add("slider");
|
||||
return slider;
|
||||
}
|
||||
|
||||
public static <T> ComboBox<T> choice() {
|
||||
var choice = new ComboBox<T>();
|
||||
choice.getStyleClass().add("choice");
|
||||
return choice;
|
||||
}
|
||||
|
||||
public static ScrollPane scroll(Node content) {
|
||||
var scroll = new ScrollPane(content);
|
||||
scroll.getStyleClass().add("scroll");
|
||||
return scroll;
|
||||
}
|
||||
|
||||
public static HBox hbox(Node... nodes) {
|
||||
var hbox = new HBox(nodes);
|
||||
hbox.getStyleClass().add("container");
|
||||
return hbox;
|
||||
}
|
||||
|
||||
public static VBox vbox(Node... nodes) {
|
||||
var vbox = new VBox(nodes);
|
||||
vbox.getStyleClass().add("container");
|
||||
return vbox;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,16 @@
|
||||
package org.toop.app.widget;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.Node;
|
||||
|
||||
public interface Widget<T extends Node> {
|
||||
T getNode();
|
||||
|
||||
default void show(Pos position) {
|
||||
WidgetContainer.add(position, this);
|
||||
}
|
||||
|
||||
default void hide() {
|
||||
WidgetContainer.remove(this);
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package org.toop.app.widget;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
public final class WidgetSystem {
|
||||
public final class WidgetContainer {
|
||||
private static StackPane root;
|
||||
|
||||
public static StackPane setup() {
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import javafx.scene.layout.HBox;
|
||||
import org.toop.app.widget.Primitive;
|
||||
import org.toop.app.widget.Widget;
|
||||
|
||||
import javafx.scene.layout.VBox;
|
||||
|
||||
public class ConfirmWidget implements Widget<VBox> {
|
||||
private final HBox buttonsContainer;
|
||||
private final VBox container;
|
||||
|
||||
public ConfirmWidget(String confirm) {
|
||||
buttonsContainer = Primitive.hbox();
|
||||
container = Primitive.vbox(Primitive.text(confirm), buttonsContainer);
|
||||
}
|
||||
|
||||
public void addButton(String label, Runnable onClick) {
|
||||
var button = Primitive.button(label);
|
||||
button.setOnAction(_ -> onClick.run());
|
||||
buttonsContainer.getChildren().add(button);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VBox getNode() { return container; }
|
||||
}
|
||||
@@ -1,16 +1,20 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.WidgetSystem;
|
||||
import org.toop.app.interfaces.Popup;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
|
||||
public abstract class PopupWidget extends ViewWidget {
|
||||
public abstract class PopupWidget extends ViewWidget implements Popup {
|
||||
public PopupWidget() {
|
||||
super("bg-popup");
|
||||
WidgetSystem.add(Pos.CENTER, this);
|
||||
}
|
||||
|
||||
public void push() {
|
||||
WidgetContainer.add(Pos.CENTER, this);
|
||||
}
|
||||
|
||||
public void pop() {
|
||||
WidgetSystem.remove(this);
|
||||
WidgetContainer.remove(this);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,16 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
import org.toop.app.widget.WidgetSystem;
|
||||
|
||||
import javafx.geometry.Pos;
|
||||
import org.toop.app.widget.WidgetContainer;
|
||||
|
||||
public abstract class PrimaryWidget extends ViewWidget {
|
||||
public PrimaryWidget() {
|
||||
super("bg-primary");
|
||||
}
|
||||
public abstract class PrimaryWidget extends ViewWidget implements TransitionAnimation {
|
||||
public PrimaryWidget() {
|
||||
super("bg-primary");
|
||||
}
|
||||
|
||||
public void transition(PrimaryWidget primary) {
|
||||
WidgetSystem.add(Pos.CENTER, primary);
|
||||
WidgetSystem.remove(this);
|
||||
}
|
||||
@Override
|
||||
public void transition(PrimaryWidget primary) {
|
||||
WidgetContainer.add(Pos.CENTER, primary);
|
||||
WidgetContainer.remove(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.toop.app.widget.complex;
|
||||
|
||||
public interface TransitionAnimation {
|
||||
void transition(PrimaryWidget primary);
|
||||
}
|
||||
@@ -5,23 +5,22 @@ import org.toop.app.widget.Widget;
|
||||
|
||||
import javafx.scene.layout.StackPane;
|
||||
|
||||
public abstract class ViewWidget extends StackPane implements Widget<StackPane> {
|
||||
public abstract class ViewWidget implements Widget<StackPane> {
|
||||
private final StackPane container;
|
||||
|
||||
public ViewWidget(String cssClass) {
|
||||
getStyleClass().add(cssClass);
|
||||
container = new StackPane();
|
||||
container.getStyleClass().add(cssClass);
|
||||
}
|
||||
|
||||
public void add(Pos position, Widget<?> widget) {
|
||||
setAlignment(widget.getNode(), position);
|
||||
getChildren().add(widget.getNode());
|
||||
StackPane.setAlignment(widget.getNode(), position);
|
||||
container.getChildren().add(widget.getNode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public StackPane getNode() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void show() {
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
public abstract void reload();
|
||||
|
||||
4
app/src/main/java/org/toop/app/widget/view/MainView.java
Normal file
4
app/src/main/java/org/toop/app/widget/view/MainView.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package org.toop.app.widget.view;
|
||||
|
||||
public class MainView {
|
||||
}
|
||||
Reference in New Issue
Block a user