Skip to content

Commit 2b4a7ed

Browse files
committed
The first iteration of lin-bus NBT editor
1 parent 5fc34e2 commit 2b4a7ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2066
-568
lines changed

gradle/libs.versions.toml

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,40 @@
1+
[versions]
2+
javafx = "22.0.2"
3+
tinylog = "2.7.0"
4+
15
[libraries]
26
jspecify-annotations = "org.jspecify:jspecify:0.3.0"
37
guava = "com.google.guava:guava:31.0.1-jre"
4-
junit-bom = "org.junit:junit-bom:5.10.2"
8+
9+
ikonli-bom = "org.kordamp.ikonli:ikonli-bom:12.3.1"
10+
ikonli-javafx.module = "org.kordamp.ikonli:ikonli-javafx"
11+
ikonli-fontawesome5.module = "org.kordamp.ikonli:ikonli-fontawesome5-pack"
12+
13+
junit-bom = "org.junit:junit-bom:5.10.3"
514
junit-jupiter-api.module = "org.junit.jupiter:junit-jupiter-api"
615
junit-jupiter-engine.module = "org.junit.jupiter:junit-jupiter-engine"
7-
truth = "com.google.truth:truth:1.4.2"
16+
truth = "com.google.truth:truth:1.4.4"
17+
18+
[libraries.tinylog-api]
19+
module = "org.tinylog:tinylog-api"
20+
version.ref = "tinylog"
21+
22+
[libraries.tinylog-impl]
23+
module = "org.tinylog:tinylog-impl"
24+
version.ref = "tinylog"
25+
26+
[libraries.tinylog-slf4j-impl]
27+
module = "org.tinylog:slf4j-tinylog"
28+
version.ref = "tinylog"
29+
30+
[libraries.javafx-base]
31+
module = "org.openjfx:javafx-base"
32+
version.ref = "javafx"
33+
34+
[libraries.javafx-controls]
35+
module = "org.openjfx:javafx-controls"
36+
version.ref = "javafx"
37+
38+
[libraries.javafx-graphics]
39+
module = "org.openjfx:javafx-graphics"
40+
version.ref = "javafx"

gradle/wrapper/gradle-wrapper.jar

51 Bytes
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gui/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
lin-bus NBT editor
2+
==================
3+
4+
This is a JavaFX-based editor for NBT files. It serves as an example of what you can do with this API, as well as a
5+
modern editor for NBT files. It is not yet feature-complete on the editing side, but it works great to view files.
6+
7+
## TODO
8+
9+
- Add/remove entries
10+
- Undo/redo changes
11+
- Refine editing UX/design
12+
- Right-click menus for easier access to common actions

gui/build.gradle.kts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,53 +2,60 @@ plugins {
22
java
33
application
44
id("com.google.osdetector") version "1.7.0"
5+
id("org.enginehub.lin-bus.jvm")
6+
id("org.enginehub.lin-bus.publishing")
57
}
68

79
java {
8-
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
10+
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
911
}
1012

1113
application {
12-
mainClass.set("org.enginehub.linbus.gui.LinBusGui")
1314
mainModule.set("org.enginehub.linbus.gui")
1415
}
1516

1617
repositories {
1718
maven {
1819
name = "Sonatype Snapshots"
1920
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
20-
}
21-
}
22-
23-
configurations.all {
24-
resolutionStrategy.dependencySubstitution {
25-
val injectApi = libs.jakarta.injectApi.get()
26-
substitute(module("javax.inject:javax.inject:1"))
27-
.using(module(
28-
"${injectApi.module.group}:${injectApi.module.name}:${injectApi.versionConstraint.requiredVersion}"
29-
))
21+
mavenContent {
22+
snapshotsOnly()
23+
}
3024
}
3125
}
3226

3327
dependencies {
34-
compileOnly(libs.jetbrains.annotations)
35-
compileOnly(libs.polymerization.annotations)
28+
compileOnly(libs.jspecify.annotations)
3629

37-
annotationProcessor(libs.dagger.compiler)
38-
annotationProcessor(libs.polymerization.processor)
39-
40-
implementation(project(":core"))
41-
implementation(libs.dagger.core)
30+
implementation(project(":tree"))
4231
implementation(libs.guava)
32+
implementation(libs.tinylog.api)
33+
runtimeOnly(libs.tinylog.impl)
34+
runtimeOnly(libs.tinylog.slf4j.impl)
4335

4436
for (lib in listOf(libs.javafx.base, libs.javafx.controls, libs.javafx.graphics)) {
4537
implementation(lib)
4638
implementation(variantOf(lib) {
4739
classifier(
4840
when (osdetector.os) {
49-
"osx" -> "mac"
50-
"windows" -> "win"
51-
else -> "linux"
41+
"osx" -> when (osdetector.arch) {
42+
"x86_64" -> "mac"
43+
"aarch_64" -> "mac-aarch64"
44+
else -> error("Unsupported architecture: ${osdetector.arch}")
45+
}
46+
47+
"windows" -> when (osdetector.arch) {
48+
"x86_64" -> "win"
49+
else -> error("Unsupported architecture: ${osdetector.arch}")
50+
}
51+
52+
"linux" -> when (osdetector.arch) {
53+
"x86_64" -> "linux"
54+
"aarch_64" -> "linux-aarch64"
55+
else -> error("Unsupported architecture: ${osdetector.arch}")
56+
}
57+
58+
else -> error("Unsupported OS: ${osdetector.os}")
5259
}
5360
)
5461
})
@@ -67,15 +74,19 @@ dependencies {
6774
}
6875
}
6976

70-
tasks.withType<JavaCompile>().configureEach {
71-
options.compilerArgs.add("--enable-preview")
77+
tasks.compileJava {
78+
options.javaModuleMainClass = "org.enginehub.linbus.gui.LinBusGui"
79+
}
80+
81+
tasks.javadoc {
82+
(options as CoreJavadocOptions).addBooleanOption("Xdoclint:-missing").value = true
7283
}
7384

7485
tasks.test {
7586
useJUnitPlatform()
76-
jvmArgs("-Dglass.disableThreadChecks=true", "--enable-preview")
7787
}
7888

79-
tasks.named<JavaExec>("run").configure {
80-
jvmArgs("-Dglass.disableThreadChecks=true", "--enable-preview")
89+
tasks.named<JavaExec>("run") {
90+
// Allow scenic-view hooking
91+
jvmArgs("-XX:+EnableDynamicAgentLoading")
8192
}

gui/src/main/java/module-info.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jspecify.annotations.NullMarked;
2+
13
/*
24
* Copyright (c) EngineHub <https://enginehub.org>
35
* Copyright (c) contributors
@@ -15,17 +17,17 @@
1517
* You should have received a copy of the GNU General Public License
1618
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1719
*/
18-
20+
@NullMarked
1921
module org.enginehub.linbus.gui {
20-
exports org.enginehub.linbus.gui;
21-
requires static java.inject;
22-
requires static net.octyl.polymer.annotations;
23-
requires dagger;
22+
exports org.enginehub.linbus.gui to javafx.graphics;
23+
2424
requires com.google.common;
2525
requires java.base;
2626
requires javafx.controls;
27-
requires org.enginehub.linbus.core;
27+
requires org.enginehub.linbus.stream;
28+
requires org.enginehub.linbus.tree;
2829
requires org.kordamp.ikonli.core;
2930
requires org.kordamp.ikonli.javafx;
3031
requires org.kordamp.ikonli.fontawesome5;
32+
requires org.tinylog.api;
3133
}

gui/src/main/java/org/enginehub/linbus/gui/LinBusGui.java

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,58 @@
1919
package org.enginehub.linbus.gui;
2020

2121
import javafx.application.Application;
22+
import javafx.beans.binding.Bindings;
2223
import javafx.stage.Stage;
23-
import org.enginehub.linbus.gui.inject.ApplicationComponent;
24-
import org.enginehub.linbus.gui.inject.DaggerApplicationComponent;
24+
import org.enginehub.linbus.gui.javafx.MainSceneSetup;
25+
import org.tinylog.Logger;
26+
27+
import java.nio.file.Path;
28+
import java.util.Objects;
29+
import java.util.concurrent.ExecutorService;
30+
import java.util.concurrent.Executors;
31+
import java.util.concurrent.TimeUnit;
2532

2633
public class LinBusGui extends Application {
34+
public static final String TITLE_BASE = "lin-bus NBT Editor";
35+
36+
private final ExecutorService backgroundExecutor = Executors.newCachedThreadPool();
37+
2738
public static void main(String[] args) {
2839
launch(args);
2940
}
3041

31-
private final ApplicationComponent component = DaggerApplicationComponent.create();
3242

3343
@Override
3444
public void start(Stage stage) {
35-
stage.setTitle("LIN Bus NBT Editor");
36-
stage.setScene(
37-
component.fxDef()
38-
.primaryStage(stage)
39-
.build()
40-
.mainScene()
45+
MainSceneSetup factory = new MainSceneSetup(stage, backgroundExecutor);
46+
factory.mainScene.getStylesheets().add(
47+
Objects.requireNonNull(
48+
getClass().getResource("/org/enginehub/linbus/gui/css/all.css"),
49+
"Could not find CSS file"
50+
).toExternalForm()
4151
);
52+
53+
stage.setOnCloseRequest(event -> {
54+
if (!factory.checkExitOkay()) {
55+
event.consume();
56+
}
57+
});
58+
stage.titleProperty().bind(Bindings.createStringBinding(() -> {
59+
Path path = factory.openPath.get();
60+
if (path == null) {
61+
return TITLE_BASE;
62+
}
63+
boolean modified = factory.isModified.get();
64+
return TITLE_BASE + " - " + path.getFileName() + (modified ? " (modified)" : "");
65+
}, factory.openPath, factory.isModified));
66+
stage.setScene(factory.mainScene);
4267
stage.show();
4368
}
69+
70+
@Override public void stop() throws Exception {
71+
backgroundExecutor.shutdownNow();
72+
if (!backgroundExecutor.awaitTermination(1, TimeUnit.MINUTES)) {
73+
Logger.error("Background executor did not shut down in time");
74+
}
75+
}
4476
}

gui/src/main/java/org/enginehub/linbus/gui/fx/FxEventLoop.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)