Skip to content

Commit ce62fb9

Browse files
committed
Add dagger and decouple the UI into components
1 parent 1e66b67 commit ce62fb9

22 files changed

Lines changed: 697 additions & 400 deletions

odradek-app/pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,27 @@
7171
<groupId>org.slf4j</groupId>
7272
<artifactId>slf4j-api</artifactId>
7373
</dependency>
74+
<dependency>
75+
<groupId>com.google.dagger</groupId>
76+
<artifactId>dagger</artifactId>
77+
</dependency>
7478
</dependencies>
7579

7680
<build>
7781
<plugins>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-compiler-plugin</artifactId>
85+
<configuration>
86+
<annotationProcessorPaths>
87+
<path>
88+
<groupId>com.google.dagger</groupId>
89+
<artifactId>dagger-compiler</artifactId>
90+
<version>2.57</version>
91+
</path>
92+
</annotationProcessorPaths>
93+
</configuration>
94+
</plugin>
7895
<plugin>
7996
<groupId>org.apache.maven.plugins</groupId>
8097
<artifactId>maven-jar-plugin</artifactId>

odradek-app/src/main/java/module-info.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
requires com.formdev.flatlaf;
66
requires com.github.weisj.jsvg;
77
requires com.miglayout.swing;
8+
requires dagger;
89
requires info.picocli;
10+
requires jakarta.inject;
911
requires java.desktop;
1012
requires odradek.core;
1113
requires odradek.game.hfw;

odradek-app/src/main/java/sh/adelessfox/odradek/app/Application.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ private static Path chooseGameDirectory() {
6363
}
6464

6565
private static void start(Path source, ForbiddenWestGame game) {
66+
ApplicationComponent component = DaggerApplicationComponent.builder()
67+
.game(game)
68+
.build();
69+
6670
var frame = new JFrame();
67-
frame.add(new ApplicationWindow(game));
71+
frame.add(component.presenter().getRoot());
6872
frame.setJMenuBar(Actions.createMenuBar(ActionIds.MAIN_MENU_ID, DataContext.focusedComponent()));
6973
frame.setTitle("Odradek - " + source);
7074
frame.setSize(1280, 720);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package sh.adelessfox.odradek.app;
2+
3+
import dagger.BindsInstance;
4+
import dagger.Component;
5+
import jakarta.inject.Singleton;
6+
import sh.adelessfox.odradek.app.component.EventBusModule;
7+
import sh.adelessfox.odradek.app.component.main.MainPresenter;
8+
import sh.adelessfox.odradek.game.hfw.game.ForbiddenWestGame;
9+
10+
@Singleton
11+
@Component(modules = {
12+
EventBusModule.class
13+
})
14+
interface ApplicationComponent {
15+
MainPresenter presenter();
16+
17+
@Component.Builder
18+
interface Builder {
19+
@BindsInstance
20+
Builder game(ForbiddenWestGame game);
21+
22+
@SuppressWarnings("ClassEscapesDefinedScope")
23+
ApplicationComponent build();
24+
}
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package sh.adelessfox.odradek.app;
2+
3+
import com.formdev.flatlaf.extras.FlatSVGIcon;
4+
5+
import java.util.Objects;
6+
7+
public final class ApplicationIcons {
8+
public static final FlatSVGIcon CASE_SENSITIVE = load("/icons/case-sensitive.svg");
9+
public static final FlatSVGIcon WHOLE_WORD = load("/icons/whole-word.svg");
10+
11+
private ApplicationIcons() {
12+
}
13+
14+
private static FlatSVGIcon load(String path) {
15+
return new FlatSVGIcon(Objects.requireNonNull(ApplicationIcons.class.getResource(path), path));
16+
}
17+
}

0 commit comments

Comments
 (0)