mirror of
https://github.com/2OOP/pism.git
synced 2026-02-04 10:54:51 +00:00
Added find functionality
This commit is contained in:
@@ -31,6 +31,8 @@ import javafx.scene.Scene;
|
|||||||
import javafx.scene.layout.StackPane;
|
import javafx.scene.layout.StackPane;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public final class App extends Application {
|
public final class App extends Application {
|
||||||
private static Stage stage;
|
private static Stage stage;
|
||||||
private static Scene scene;
|
private static Scene scene;
|
||||||
@@ -138,11 +140,11 @@ public final class App extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void escapePopup() {
|
public void escapePopup() {
|
||||||
if (WidgetContainer.getAllWidgets().stream().anyMatch(
|
if (!Objects.requireNonNull(
|
||||||
e -> e instanceof QuitPopup || e instanceof EscapePopup
|
WidgetContainer.find(widget -> widget instanceof QuitPopup || widget instanceof EscapePopup)
|
||||||
)) {
|
).isEmpty()) {
|
||||||
WidgetContainer.findRemoveFirst(QuitPopup.class);
|
WidgetContainer.removeFirst(QuitPopup.class);
|
||||||
WidgetContainer.findRemoveFirst(EscapePopup.class);
|
WidgetContainer.removeFirst(EscapePopup.class);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.toop.app.widget;
|
package org.toop.app.widget;
|
||||||
|
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
import org.toop.app.widget.complex.PopupWidget;
|
import org.toop.app.widget.complex.PopupWidget;
|
||||||
import org.toop.app.widget.complex.ViewWidget;
|
import org.toop.app.widget.complex.ViewWidget;
|
||||||
@@ -10,6 +11,7 @@ import javafx.scene.layout.StackPane;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
|
||||||
public final class WidgetContainer {
|
public final class WidgetContainer {
|
||||||
private static StackPane root;
|
private static StackPane root;
|
||||||
@@ -63,7 +65,7 @@ public final class WidgetContainer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findRemove(Class<? extends Widget> widgetClass) {
|
public static void remove(Class<? extends Widget> widgetClass) {
|
||||||
if (root == null || currentView == null) return;
|
if (root == null || currentView == null) return;
|
||||||
|
|
||||||
Platform.runLater(() ->
|
Platform.runLater(() ->
|
||||||
@@ -71,7 +73,7 @@ public final class WidgetContainer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findRemoveFirst(Class<? extends Widget> widgetClass) {
|
public static void removeFirst(Class<? extends Widget> widgetClass) {
|
||||||
if (root == null || currentView == null) return;
|
if (root == null || currentView == null) return;
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
@@ -84,6 +86,33 @@ public final class WidgetContainer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Widget> find(Class<? extends Widget> widgetClass) {
|
||||||
|
if (root == null || currentView == null) return null;
|
||||||
|
|
||||||
|
return getAllWidgets()
|
||||||
|
.stream()
|
||||||
|
.filter(widget -> widget.getClass().isAssignableFrom(widgetClass))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Widget> find(Predicate<Widget> predicate) {
|
||||||
|
if (root == null || currentView == null) return null;
|
||||||
|
|
||||||
|
return getAllWidgets()
|
||||||
|
.stream()
|
||||||
|
.filter(predicate)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Widget findFirst(Class<? extends Widget> widgetClass) {
|
||||||
|
if (root == null || currentView == null) return null;
|
||||||
|
|
||||||
|
return getAllWidgets()
|
||||||
|
.stream()
|
||||||
|
.filter(widget -> widget.getClass().isAssignableFrom(widgetClass))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
public static ViewWidget getCurrentView() {
|
public static ViewWidget getCurrentView() {
|
||||||
return currentView;
|
return currentView;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.toop.app.widget.view.OptionsView;
|
|||||||
|
|
||||||
public class EscapePopup extends PopupWidget {
|
public class EscapePopup extends PopupWidget {
|
||||||
public EscapePopup() {
|
public EscapePopup() {
|
||||||
var con = Primitive.button("Continue", () -> { hide(); }, false); // TODO, localize
|
var con = Primitive.button("Continue", this::hide, false); // TODO, localize
|
||||||
|
|
||||||
var qui = Primitive.button("quit", () -> {
|
var qui = Primitive.button("quit", () -> {
|
||||||
hide();
|
hide();
|
||||||
|
|||||||
Reference in New Issue
Block a user