Skip to content

Commit

Permalink
feat(getting started): add NavigationPane functional
Browse files Browse the repository at this point in the history
  • Loading branch information
DaiYuANg committed Dec 11, 2024
1 parent 10962e5 commit 4dc3528
Show file tree
Hide file tree
Showing 27 changed files with 344 additions and 163 deletions.
20 changes: 0 additions & 20 deletions document/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,8 @@ plugins {
idea
}

apply<ModulePlugin>()

group = "org.visual.document"
repositories { ruby { gems() } }

dependencies {
implementation(libs.guava)
}

asciidoctorj { modules { diagram.use() } }

tasks.asciidoctor {
Expand All @@ -31,8 +24,6 @@ tasks.asciidoctor {
}
}

tasks.build { dependsOn(tasks.asciidoctor) }

idea {
module {
sourceDirs =
Expand All @@ -41,15 +32,4 @@ idea {
.sourceFileTree
.toMutableSet()
}
}

tasks.create("copyDocument", Copy::class) {
group = "build"
from(layout.buildDirectory.dir("docs"))
destinationDir = layout.buildDirectory.dir("classes/java/main/org/visual/document").get().asFile
dependsOn(tasks.asciidoctor)
}

tasks.jar {
dependsOn("copyDocument")
}
9 changes: 0 additions & 9 deletions document/src/main/java/module-info.java

This file was deleted.

30 changes: 0 additions & 30 deletions document/src/main/java/org/visual/document/FindDocument.java

This file was deleted.

2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fluentuiIcon = { group = "org.kordamp.ikonli", name = "ikonli-fluentui-pack", ve
devicons = { group = "org.kordamp.ikonli", name = "ikonli-devicons-pack", version.ref = "ikonli" }
materialIcons = { group = "org.kordamp.ikonli", name = "ikonli-materialdesign2-pack", version.ref = "ikonli" }
fontawesome5 = { group = "org.kordamp.ikonli", name = "ikonli-fontawesome5-pack", version.ref = "ikonli" }
javafxUnitTest = { group = "org.testfx", name = "testfx-junit5", version = "4.0.18" }
testfx-junit5 = { group = "org.testfx", name = "testfx-junit5", version = "4.0.18" }
atlantafx = { group = "io.github.mkpaz", name = "atlantafx-base", version = "2.0.1" }
controlfx = { group = "org.controlsfx", name = "controlsfx", version = "11.2.1" }
ikonliJavafx = { group = "org.kordamp.ikonli", name = "ikonli-javafx", version.ref = "ikonliJavafx" }
Expand Down
4 changes: 1 addition & 3 deletions visual-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {

implementation(libs.logback)

testImplementation(libs.javafxUnitTest)
testImplementation(libs.testfx.junit5)

runtimeOnly(libs.h2)
implementation(libs.ebean.api)
Expand Down Expand Up @@ -118,8 +118,6 @@ dependencies {
implementation(libs.avaje.inject)
annotationProcessor(libs.avaje.inject.generator)
testImplementation(libs.avaje.inject.test)

implementation(projects.document)
}

javafx {
Expand Down
2 changes: 1 addition & 1 deletion visual-app/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
requires org.visual.core;
requires org.visual.database;
requires org.visual.data.structure;
requires org.visual.document;

requires com.fasterxml.jackson.annotation;
requires com.fasterxml.jackson.databind;
Expand All @@ -73,6 +72,7 @@
requires org.github.gestalt.core;
requires org.github.gestalt.toml;
requires org.github.gestalt.yaml;
requires io.vertx.core;

exports org.visual.app.entity;
exports org.visual.app.lifecycle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.visual.app.command.VisualCommand;
import org.visual.app.context.DIContext;
import org.visual.app.exception.GlobalExceptionHandler;

import static java.lang.Thread.setDefaultUncaughtExceptionHandler;
import static org.visual.app.context.DIContext.INSTANCE;

@Slf4j
public class VisualApplication {
static {
val exceptionHandler = DIContext.INSTANCE.get(GlobalExceptionHandler.class);
val exceptionHandler = INSTANCE.get(GlobalExceptionHandler.class);
setDefaultUncaughtExceptionHandler(exceptionHandler);
}

@SneakyThrows
public static void main(String[] args) {
DIContext.INSTANCE.get(VisualCommand.class).run();
INSTANCE.get(VisualCommand.class).run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.visual.app.component;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import lombok.Getter;

import static javafx.scene.layout.Priority.ALWAYS;

@Getter
public class NavigationBar extends HBox {

private final Button backButton = new Button("Back");
private final Button forwardButton = new Button("Forward");

private final Region spacer = new Region();

public NavigationBar() {
super(20);
setAlignment(Pos.CENTER);
HBox.setHgrow(spacer, ALWAYS);
getChildren().addAll(backButton, spacer, forwardButton);
}

public void setOnForward(EventHandler<ActionEvent> event) {
forwardButton.setOnAction(event);
}

public void setOnBack(EventHandler<ActionEvent> event) {
backButton.setOnAction(event);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.visual.app.component;

import it.unimi.dsi.fastutil.objects.Object2ObjectMaps;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.MapChangeListener;
import javafx.collections.ObservableMap;
import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.layout.StackPane;
import javafx.scene.control.Separator;
import javafx.scene.layout.VBox;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.commons.collections4.CollectionUtils;
import org.eclipse.collections.api.factory.Stacks;
import org.eclipse.collections.api.stack.MutableStack;

import static javafx.collections.FXCollections.observableArrayList;

@Slf4j
@SuppressWarnings("unused")
@Getter
public class NavigationPane extends StackPane {
public class NavigationPane extends VBox {

private final ObservableMap<String, Node> page = FXCollections.observableMap(Object2ObjectMaps.emptyMap());
private final ObservableList<Route> routes = observableArrayList(new ObjectArrayList<>());

private final StringProperty currentPage = new SimpleStringProperty();

Expand All @@ -30,12 +31,21 @@ public class NavigationPane extends StackPane {

private final StringProperty index = new SimpleStringProperty("/");

private final StringProperty current = new SimpleStringProperty();

private final OnlyOneStackPane stackPane = new OnlyOneStackPane();

private final NavigationBar navigationBar = new NavigationBar();

{
page.addListener((MapChangeListener<String, Node>) change -> {
log.atInfo().log("change{}", change);
});
index.addListener((observable, oldValue, newValue) -> {
log.atInfo().log(oldValue);
routes.addListener((ListChangeListener<Route>) c -> {
log.atInfo().log("c:{}", c);
log.atInfo().log("Routes:{}", routes);
stackPane.getChildren().clear();
c.getList().stream()
.filter(route -> route.getPath().equals(index.get()))
.findFirst()
.ifPresent(route -> stackPane.setContent(route.getContent()));
});
}

Expand All @@ -50,22 +60,44 @@ public NavigationPane(Node... children) {
}

private void setup() {
val children = getChildren();
if (CollectionUtils.isNotEmpty(children)) {
page.put(index.get(), children.getFirst());
}
navigationBar.setOnBack(event -> back());
navigationBar.setOnForward(event -> forward());
this.getChildren().addAll(navigationBar, new Separator(), stackPane);
}

public void to(String route) {

public void to(String to) {

routes.stream()
.filter(route -> route.getPath().equals(to))
.findFirst()
.ifPresent(route -> {
// 当前页面加入到 backStack
backStack.push(stackPane.getContent());
// 清空 forwardStack,因为我们从一个新的页面跳转过来
forwardStack.clear();
// 设置新的内容
stackPane.setContent(route.getContent());
// 更新当前的 index
// setIndex(to);
});
}

public void back() {

if (backStack.isEmpty()) {
return;
}
forwardStack.push(stackPane.getContent());
val lastContent = backStack.pop();
stackPane.setContent(lastContent);
}

public void forward() {

if (forwardStack.isEmpty()) {
return;
}
backStack.push(stackPane.getContent());
val nextContent = forwardStack.pop();
stackPane.setContent(nextContent);
}

public void setIndex(String index) {
Expand All @@ -75,4 +107,16 @@ public void setIndex(String index) {
public String getIndex() {
return this.index.get();
}

public void setCurrent(String currentPage) {
current.set(currentPage);
}

public String getCurrent() {
return current.get();
}

public void addRoute(Route route) {
routes.add(route);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.visual.app.component;

import javafx.scene.Node;
import javafx.scene.layout.StackPane;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class OnlyOneStackPane extends StackPane {

public void setContent(Node content) {
getChildren().clear();
getChildren().addFirst(content);
}

public Node getContent() {
return getChildren().getFirst();
}
}
33 changes: 33 additions & 0 deletions visual-app/src/main/java/org/visual/app/component/Route.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.visual.app.component;

import javafx.beans.DefaultProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.scene.Node;
import lombok.EqualsAndHashCode;

@DefaultProperty("content")
@EqualsAndHashCode
public class Route {
private final StringProperty path = new SimpleStringProperty();

private final ObjectProperty<Node> content = new SimpleObjectProperty<>();

public String getPath() {
return path.get();
}

public void setPath(String path) {
this.path.set(path);
}

public Node getContent() {
return content.get();
}

public void setContent(Node content) {
this.content.set(content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.visual.app.constant;

public interface EventBusNaming {

String CLOSE_GETTING_START_WINDOW = "CLOSE.GETTING.START.WINDOW";
}
Loading

0 comments on commit 4dc3528

Please sign in to comment.