Skip to content

Commit ff416d1

Browse files
authored
Moved full app to java swing with FlatLaf UI
1 parent a69c5ce commit ff416d1

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

+1520
-1905
lines changed

.github/workflows/release.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ jobs:
1212

1313
steps:
1414
- uses: actions/checkout@v2
15-
- name: Set up JDK 15
15+
- name: Set up JDK 11
1616
uses: actions/setup-java@v2
1717
with:
1818
distribution: 'adopt'
19-
java-version: '15'
19+
java-version: '11'
2020
- name: Build with Gradle
21-
run: ./gradlew.bat createDistributable
21+
run: ./gradlew.bat shadowJar runtime
2222
- uses: papeloto/action-zip@v1
2323
with:
24-
files: build/compose/binaries/main/app/TotalDebugCompanion
24+
files: build/image build/libs
2525
dest: TotalDebugCompanion.zip
2626
recursive: true
2727
- name: Create Release
@@ -34,7 +34,7 @@ jobs:
3434
release_name: Release ${{ github.ref }}
3535
body: |
3636
Changes in this Release
37-
- Initial release
37+
- Switched to java swing
3838
draft: false
3939
prerelease: false
4040
- name: Upload zip to release

build.gradle

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
plugins {
2+
id('java')
3+
id('com.github.johnrengelman.shadow') version '7.0.0'
4+
id 'org.beryx.runtime' version '1.12.5'
5+
}
6+
7+
group = "com.github.minecraft_ta"
8+
version = "1.2.1"
9+
10+
repositories {
11+
jcenter()
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
implementation("com.formdev:flatlaf:1.2")
17+
implementation("com.formdev:flatlaf-intellij-themes:1.2")
18+
implementation("com.formdev:flatlaf-extras:1.2")
19+
implementation("com.github.javaparser:javaparser-core:3.22.0")
20+
}
21+
22+
shadowJar {
23+
classifier("")
24+
}
25+
26+
runtime {
27+
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
28+
modules = [
29+
'java.desktop',
30+
'java.logging',
31+
'java.prefs',
32+
'java.xml',
33+
'java.datatransfer'
34+
]
35+
}
36+
37+
application {
38+
mainClass = "com.github.minecraft_ta.totalDebugCompanion.CompanionApp"
39+
}

build.gradle.kts

-34
This file was deleted.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

settings.gradle

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
mavenCentral()
5+
}
6+
7+
}
8+
rootProject.name = "TotalDebugCompanion"
9+

settings.gradle.kts

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.github.minecraft_ta.totalDebugCompanion;
2+
3+
import com.formdev.flatlaf.FlatDarculaLaf;
4+
import com.github.minecraft_ta.totalDebugCompanion.ui.MainWindow;
5+
6+
import javax.swing.*;
7+
import javax.swing.plaf.BorderUIResource;
8+
import javax.swing.plaf.ColorUIResource;
9+
import java.awt.*;
10+
import java.nio.file.Files;
11+
import java.nio.file.Paths;
12+
13+
public class CompanionApp {
14+
15+
public static void main(String[] args) {
16+
if (args.length != 1) {
17+
System.out.println("Missing argument");
18+
return;
19+
}
20+
21+
var rootPath = Paths.get(args[0]);
22+
if (!Files.exists(rootPath)) {
23+
System.out.println("Path does not exist");
24+
return;
25+
}
26+
27+
FlatDarculaLaf.setup();
28+
UIManager.put("Component.focusColor", new ColorUIResource(new Color(0, 0, 0, 0)));
29+
UIManager.put("TabbedPane.tabInsets", new Insets(0, 10, 0, 10));
30+
UIManager.put("TabbedPane.tabHeight", 25);
31+
UIManager.put("Slider.focusedColor", new ColorUIResource(new Color(0, 0, 0, 0)));
32+
UIManager.put("Table.focusSelectedCellHighlightBorder", new BorderUIResource(BorderFactory.createEmptyBorder(0, 5, 0, 0)));
33+
UIManager.put("Table.focusCellHighlightBorder", new BorderUIResource(BorderFactory.createEmptyBorder(0, 3, 0, 0)));
34+
35+
var mainWindow = new MainWindow(rootPath);
36+
mainWindow.setSize(1280, 720);
37+
mainWindow.setVisible(true);
38+
39+
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
40+
mainWindow.setLocation(dim.width / 2 - mainWindow.getSize().width / 2, dim.height / 2 - mainWindow.getSize().height / 2);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.github.minecraft_ta.totalDebugCompanion;
2+
3+
import java.beans.PropertyChangeListener;
4+
import java.beans.PropertyChangeSupport;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
8+
public class GlobalConfig {
9+
10+
private static GlobalConfig INSTANCE;
11+
12+
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
13+
14+
private final Map<String, Object> properties = new HashMap<>();
15+
16+
private GlobalConfig() {
17+
addDefaults();
18+
}
19+
20+
public void addPropertyChangeListener(String property, PropertyChangeListener listener) {
21+
pcs.addPropertyChangeListener(property, listener);
22+
}
23+
24+
public void removePropertyChangeListener(PropertyChangeListener listener) {
25+
pcs.removePropertyChangeListener(listener);
26+
}
27+
28+
public void setValue(String property, Object value) {
29+
pcs.firePropertyChange(property, properties.put(property, value), value);
30+
}
31+
32+
public <T> T getValue(String property) {
33+
return (T) properties.get(property);
34+
}
35+
36+
private void addDefaults() {
37+
properties.put("fontSize", 14f);
38+
properties.put("scrollMul", 1.2f);
39+
}
40+
41+
public static GlobalConfig getInstance() {
42+
if (INSTANCE == null)
43+
INSTANCE = new GlobalConfig();
44+
45+
return INSTANCE;
46+
}
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package com.github.minecraft_ta.totalDebugCompanion.model;
2+
3+
import com.formdev.flatlaf.extras.FlatSVGIcon;
4+
import com.formdev.flatlaf.util.StringUtils;
5+
import com.github.minecraft_ta.totalDebugCompanion.ui.components.editors.CodeViewPanel;
6+
import com.github.minecraft_ta.totalDebugCompanion.ui.components.FontSizeSliderBar;
7+
import com.github.minecraft_ta.totalDebugCompanion.util.CodeUtils;
8+
import com.github.minecraft_ta.totalDebugCompanion.util.UIUtils;
9+
10+
import javax.swing.*;
11+
import java.awt.*;
12+
import java.io.IOException;
13+
import java.nio.file.Files;
14+
import java.nio.file.Path;
15+
import java.util.concurrent.CompletableFuture;
16+
17+
public class CodeView implements IEditorPanel {
18+
19+
private static final Icon CLASS_ICON = new FlatSVGIcon("icons/class.svg");
20+
21+
private final Path path;
22+
private final CodeViewPanel codeViewPanel;
23+
24+
public CodeView(Path path, int focusLine) {
25+
this.path = path;
26+
this.codeViewPanel = new CodeViewPanel(this);
27+
28+
CompletableFuture.runAsync(() -> {
29+
try {
30+
String code = Files.readString(this.path);
31+
code = StringUtils.removeTrailing(code, "\n");
32+
33+
codeViewPanel.setCode(code);
34+
CodeUtils.highlightJavaCode(code, codeViewPanel.getEditorPane());
35+
focusLine(focusLine);
36+
} catch (IOException e) {
37+
e.printStackTrace();
38+
}
39+
});
40+
}
41+
42+
/**
43+
* @param line the line to scroll to, starting at index 1
44+
*/
45+
public void focusLine(int line) {
46+
if (line < 1)
47+
throw new IllegalArgumentException();
48+
49+
this.codeViewPanel.focusLine(line);
50+
}
51+
52+
@Override
53+
public String getTitle() {
54+
String fullClassName = this.path.getFileName().toString().replace(".java", "");
55+
return fullClassName.substring(fullClassName.lastIndexOf('.') + 1);
56+
}
57+
58+
@Override
59+
public Icon getIcon() {
60+
return CLASS_ICON;
61+
}
62+
63+
@Override
64+
public String getTooltip() {
65+
return this.path.getFileName().toString();
66+
}
67+
68+
@Override
69+
public Component getComponent() {
70+
return UIUtils.topAndBottomStickyLayout(this.codeViewPanel, new FontSizeSliderBar());
71+
}
72+
73+
public Path getPath() {
74+
return this.path;
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.minecraft_ta.totalDebugCompanion.model;
2+
3+
import javax.swing.*;
4+
import java.awt.*;
5+
6+
public interface IEditorPanel {
7+
8+
String getTitle();
9+
10+
String getTooltip();
11+
12+
Icon getIcon();
13+
14+
Component getComponent();
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.github.minecraft_ta.totalDebugCompanion.model;
2+
3+
import com.formdev.flatlaf.extras.FlatSVGIcon;
4+
import com.github.minecraft_ta.totalDebugCompanion.ui.components.editors.SearchResultViewPanel;
5+
6+
import javax.swing.*;
7+
import java.awt.*;
8+
import java.util.Collections;
9+
import java.util.List;
10+
11+
public class SearchResultView implements IEditorPanel {
12+
13+
private static final Icon SEARCH_ICON = new FlatSVGIcon("icons/search.svg");
14+
15+
private final String query;
16+
private final List<String> results;
17+
private final boolean methodSearch;
18+
private final int classesCount;
19+
private final int time;
20+
21+
public SearchResultView(String query, List<String> results, boolean methodSearch, int classesCount, int time) {
22+
this.query = query;
23+
this.results = Collections.unmodifiableList(results);
24+
this.methodSearch = methodSearch;
25+
this.classesCount = classesCount;
26+
this.time = time;
27+
}
28+
29+
@Override
30+
public String getTitle() {
31+
return this.query;
32+
}
33+
34+
@Override
35+
public String getTooltip() {
36+
return this.query;
37+
}
38+
39+
@Override
40+
public Icon getIcon() {
41+
return SEARCH_ICON;
42+
}
43+
44+
@Override
45+
public Component getComponent() {
46+
return new SearchResultViewPanel(this);
47+
}
48+
49+
public String getQuery() {
50+
return query;
51+
}
52+
53+
public List<String> getResults() {
54+
return results;
55+
}
56+
57+
public boolean isMethodSearch() {
58+
return methodSearch;
59+
}
60+
61+
public int getClassesCount() {
62+
return classesCount;
63+
}
64+
65+
public int getTime() {
66+
return time;
67+
}
68+
}

0 commit comments

Comments
 (0)