Skip to content

Commit 63dff8d

Browse files
authored
Make Keyset Config, Improve the screen
2 parents 22ab5d7 + 9bc90b9 commit 63dff8d

Some content is hidden

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

47 files changed

+767
-244
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Keep the latest library, remove upstream problems and absorb upstream ideas.
55

66
![GitHub all releases](https://img.shields.io/github/downloads/Ecdcaeb/JavaOctetEditor/total?style=flat-square)
77
![GitHub release (latest by date)](https://img.shields.io/github/v/release/Ecdcaeb/JavaOctetEditor?style=flat-square)
8+
![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/Ecdcaeb/JavaOctetEditor?include_prereleases&style=flat-square)
89
![GitHub](https://img.shields.io/github/license/Ecdcaeb/JavaOctetEditor?style=flat-square)
910

1011
![](https://user-images.githubusercontent.com/32991121/190947407-bbc6642e-2c9d-46f3-921c-6558c74272cf.png)

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ dependencies {
4141

4242
implementation 'com.formdev:flatlaf:3.5.2'
4343
implementation 'com.formdev:flatlaf-extras:3.5.2'
44+
implementation 'com.github.weisj:jsvg:1.6.1'
4445
//noinspection GradlePackageUpdate
4546
implementation 'com.miglayout:miglayout-swing:11.4.2'
4647
implementation 'com.github.bobbylight:RSyntaxTextArea:3.5.2'
@@ -65,11 +66,11 @@ shadowJar {
6566
dependencies {
6667
include(dependency('com.formdev:.*'))
6768
include(dependency('com.miglayout:.*'))
69+
include(dependency('com.github.weisj:.*'))
6870
include(dependency('com.github.bobbylight:RSyntaxTextArea'))
6971
include(dependency('org.ow2.asm:.*'))
7072
include(dependency('org.benf:cfr'))
7173
include(dependency('com.github.mstrobel.procyon:procyon-decompiler'))
72-
include(dependency('org.javassist:javassist'))
7374
include(dependency('com.google.code.gson:gson'))
7475
include(dependency('org.tinylog:.*'))
7576
include(dependency('org.vineflower:vineflower'))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cn.enaium.joe;
2+
3+
public enum Instance {
4+
INSTANCE;
5+
public int classTabIndex = 0;
6+
}

src/main/java/cn/enaium/joe/JavaOctetEditor.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
package cn.enaium.joe;
1818

1919
import cn.enaium.joe.config.ConfigManager;
20+
import cn.enaium.joe.config.extend.ApplicationConfig;
2021
import cn.enaium.joe.event.EventManager;
22+
import cn.enaium.joe.gui.panel.BorderPanel;
2123
import cn.enaium.joe.gui.panel.BottomPanel;
2224
import cn.enaium.joe.gui.panel.file.tree.CenterPanel;
2325
import cn.enaium.joe.gui.panel.file.tabbed.FileTabbedPanel;
2426
import cn.enaium.joe.gui.component.FileTree;
2527
import cn.enaium.joe.gui.panel.menu.*;
2628
import cn.enaium.joe.jar.Jar;
2729
import cn.enaium.joe.task.TaskManager;
28-
import cn.enaium.joe.util.BytecodeTokenMaker;
29-
import cn.enaium.joe.util.LangUtil;
30-
import cn.enaium.joe.util.MessageUtil;
31-
import cn.enaium.joe.util.ReflectUtil;
30+
import cn.enaium.joe.util.*;
31+
import com.formdev.flatlaf.FlatDarkLaf;
3232
import com.formdev.flatlaf.extras.FlatSVGIcon;
3333
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
3434
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
@@ -45,7 +45,7 @@ public class JavaOctetEditor {
4545

4646
public static final String TITLE = "JavaOctetEditor";
4747

48-
public JFrame window = new JFrame(TITLE);
48+
public JFrame window;
4949

5050
private Jar jar;
5151

@@ -64,11 +64,22 @@ public class JavaOctetEditor {
6464

6565
public JavaOctetEditor() {
6666
instance = this;
67+
6768
event = new EventManager();
6869
config = new ConfigManager();
6970
config.load();
7071
task = new TaskManager();
7172
Runtime.getRuntime().addShutdownHook(new Thread(config::save));
73+
74+
Integer value = config.getByClass(ApplicationConfig.class).scale.getValue();
75+
76+
if (value > 0) {
77+
System.setProperty("sun.java2d.uiScale", value.toString());
78+
}
79+
80+
FlatDarkLaf.setup();
81+
UIManager.put("Tree.paintLines", true);
82+
7283
fileTabbedPanel = new FileTabbedPanel();
7384
fileTree = new FileTree();
7485
bottomPanel = new BottomPanel();
@@ -77,10 +88,10 @@ public JavaOctetEditor() {
7788
public void run() {
7889

7990
ToolTipManager.sharedInstance().setInitialDelay(0);
80-
91+
FlatDarkLaf.setup();
8192
AbstractTokenMakerFactory abstractTokenMakerFactory = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
8293
abstractTokenMakerFactory.putMapping("text/custom", BytecodeTokenMaker.class.getName());
83-
94+
window = new JFrame(TITLE);
8495
window.setIconImage(new FlatSVGIcon("icons/logo.svg").getImage());
8596

8697
window.setJMenuBar(new JMenuBar() {{
@@ -98,9 +109,9 @@ public void run() {
98109
add(new HelpMenu());
99110
}});
100111

101-
window.setContentPane(new JPanel(new BorderLayout()) {{
102-
add(new CenterPanel(), BorderLayout.CENTER);
103-
add(bottomPanel, BorderLayout.SOUTH);
112+
window.setContentPane(new BorderPanel() {{
113+
setCenter(new CenterPanel());
114+
setBottom(bottomPanel);
104115
}});
105116

106117

@@ -115,7 +126,7 @@ public void windowClosing(WindowEvent e) {
115126
});
116127
}
117128
});
118-
window.setSize(1000, 600);
129+
window.setSize(Util.screenSize(1000, 600));
119130
window.setLocationRelativeTo(null);
120131
window.setVisible(true);
121132
}

src/main/java/cn/enaium/joe/Main.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package cn.enaium.joe;
1818

19+
import cn.enaium.joe.config.extend.ApplicationConfig;
1920
import cn.enaium.joe.jar.Jar;
2021
import cn.enaium.joe.util.*;
2122
import com.formdev.flatlaf.FlatDarkLaf;
@@ -77,8 +78,6 @@ private static void launch() {
7778
System.setErr(new TinyLogPrintStream(System.err, STDERR));
7879

7980
Logger.info("DIR:{}", System.getProperty("user.dir"));
80-
FlatDarkLaf.setup();
81-
UIManager.put("Tree.paintLines", true);
8281
new JavaOctetEditor().run();
8382
}
8483

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2022 Enaium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cn.enaium.joe.compiler;
18+
19+
import javax.tools.*;
20+
import java.io.IOException;
21+
import java.nio.charset.StandardCharsets;
22+
import java.util.Arrays;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
import java.util.stream.Collectors;
26+
27+
/**
28+
* @author Enaium
29+
* @since 1.4.0
30+
*/
31+
public class Compiler {
32+
private final Map<String, VirtualJavaFileObject> javaFileObjectMap = new HashMap<>();
33+
34+
private DiagnosticListener<VirtualJavaFileObject> listener;
35+
36+
public void addSource(String name, String content) {
37+
javaFileObjectMap.put(name, new VirtualJavaFileObject(name, content));
38+
}
39+
40+
public Map<String, byte[]> getClasses() {
41+
return javaFileObjectMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().getBytecode()));
42+
}
43+
44+
@SuppressWarnings("unchecked")
45+
public boolean compile() {
46+
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
47+
VirtualFileManager fileManager = new VirtualFileManager(compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8));
48+
try {
49+
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, ((DiagnosticListener<? super JavaFileObject>) (Object) listener), null, null, javaFileObjectMap.values());
50+
Boolean b = task.call();
51+
return b != null && b;
52+
} catch (Exception e) {
53+
return false;
54+
}
55+
}
56+
57+
public void setListener(DiagnosticListener<VirtualJavaFileObject> listener) {
58+
this.listener = listener;
59+
}
60+
61+
private final class VirtualFileManager extends ForwardingJavaFileManager<JavaFileManager> {
62+
public VirtualFileManager(JavaFileManager fileManager) {
63+
super(fileManager);
64+
}
65+
66+
@Override
67+
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException {
68+
if (JavaFileObject.Kind.CLASS == kind) {
69+
VirtualJavaFileObject virtualJavaFileObject = new VirtualJavaFileObject(className, null);
70+
javaFileObjectMap.put(className, virtualJavaFileObject);
71+
return virtualJavaFileObject;
72+
} else {
73+
return super.getJavaFileForOutput(location, className, kind, sibling);
74+
}
75+
}
76+
}
77+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2022 Enaium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package cn.enaium.joe.compiler;
18+
19+
import javax.tools.SimpleJavaFileObject;
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.IOException;
22+
import java.net.URI;
23+
24+
/**
25+
* @author Enaium
26+
* @since 1.4.0
27+
*/
28+
public class VirtualJavaFileObject extends SimpleJavaFileObject {
29+
30+
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
31+
32+
private final String content;
33+
34+
protected VirtualJavaFileObject(String className, String content) {
35+
super(URI.create("string:///" + className.replace(".", "/") + Kind.SOURCE.extension), Kind.SOURCE);
36+
this.content = content;
37+
}
38+
39+
public byte[] getBytecode() {
40+
return outputStream.toByteArray();
41+
}
42+
43+
@Override
44+
public ByteArrayOutputStream openOutputStream() {
45+
return outputStream;
46+
}
47+
48+
@Override
49+
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
50+
return content;
51+
}
52+
}

src/main/java/cn/enaium/joe/config/ConfigManager.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,12 @@
1616

1717
package cn.enaium.joe.config;
1818

19-
import cn.enaium.joe.config.extend.ApplicationConfig;
20-
import cn.enaium.joe.config.extend.CFRConfig;
21-
import cn.enaium.joe.config.extend.FernFlowerConfig;
22-
import cn.enaium.joe.config.extend.ProcyonConfig;
19+
import cn.enaium.joe.config.extend.*;
2320
import cn.enaium.joe.config.value.*;
2421
import cn.enaium.joe.util.MessageUtil;
2522
import com.google.gson.*;
2623

24+
import javax.swing.*;
2725
import java.io.File;
2826
import java.io.IOException;
2927
import java.lang.reflect.Field;
@@ -44,6 +42,7 @@ public ConfigManager() {
4442
addByInstance(new CFRConfig());
4543
addByInstance(new FernFlowerConfig());
4644
addByInstance(new ProcyonConfig());
45+
addByInstance(new KeymapConfig());
4746
}
4847

4948
@SuppressWarnings("unchecked")
@@ -93,8 +92,9 @@ public Map<String, Value<?>> getConfigMap(Class<? extends Config> config) {
9392
return map;
9493
}
9594

95+
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
9696
private Gson gson() {
97-
return new GsonBuilder().setPrettyPrinting().create();
97+
return GSON;
9898
}
9999

100100
public void load() {
@@ -106,14 +106,13 @@ public void load() {
106106
File file = new File(System.getProperty("."), config.getName() + ".json");
107107
if (file.exists()) {
108108
JsonObject jsonObject = gson().fromJson(Files.readString(file.toPath()), JsonObject.class);
109-
110109
for (Field configField : klass.getDeclaredFields()) {
111110
configField.setAccessible(true);
112111
if (!jsonObject.has(configField.getName())) {
113112
continue;
114113
}
115114

116-
if (!jsonObject.has(configField.getName())) {
115+
if (!jsonObject.get(configField.getName()).isJsonObject()) {
117116
continue;
118117
}
119118

@@ -126,26 +125,7 @@ public void load() {
126125
Object valueObject = configField.get(config);
127126
if (valueObject instanceof Value<?>) {
128127
Value<?> value = (Value<?>) valueObject;
129-
if (value instanceof EnableValue) {
130-
((EnableValue) value).setValue(valueJsonElement.getAsBoolean());
131-
} else if (value instanceof IntegerValue) {
132-
((IntegerValue) value).setValue(valueJsonElement.getAsInt());
133-
} else if (value instanceof ModeValue) {
134-
ModeValue modeValue = (ModeValue) value;
135-
if (modeValue.getMode().contains(valueJsonElement.getAsString())) {
136-
modeValue.setValue(valueJsonElement.getAsString());
137-
} else {
138-
modeValue.setValue(modeValue.getMode().get(0));
139-
}
140-
} else if (value instanceof StringSetValue) {
141-
Set<String> strings = new HashSet<>();
142-
for (JsonElement jsonElement : valueJsonElement.getAsJsonArray()) {
143-
strings.add(jsonElement.getAsString());
144-
}
145-
((StringSetValue) value).setValue(strings);
146-
} else if (value instanceof StringValue) {
147-
((StringValue) value).setValue(valueJsonElement.getAsString());
148-
}
128+
value.decode(valueJsonElement);
149129
}
150130
}
151131
}

src/main/java/cn/enaium/joe/config/extend/ApplicationConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import cn.enaium.joe.annotation.NoUI;
2020
import cn.enaium.joe.config.Config;
2121
import cn.enaium.joe.config.value.EnableValue;
22+
import cn.enaium.joe.config.value.IntegerValue;
2223
import cn.enaium.joe.config.value.ModeValue;
2324
import cn.enaium.joe.config.value.StringSetValue;
2425

@@ -37,6 +38,7 @@ public class ApplicationConfig extends Config {
3738
public EnableValue compactMiddlePackage = new EnableValue("Compact Middle Package", true, "Only Hierarchical Mode");
3839
@NoUI
3940
public final StringSetValue loadRecent = new StringSetValue("Load Recent", new HashSet<>(), "");
41+
public IntegerValue scale = new IntegerValue("Scale", 0, "UI scale,it doesn't scale if value 0");
4042

4143
public ApplicationConfig() {
4244
super("Application");

0 commit comments

Comments
 (0)