Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
8e93eed
Update build.gradle
Enaium Sep 22, 2022
d0ba29a
compile
Enaium Sep 22, 2022
1e428a5
fix language
Enaium Sep 29, 2022
d8f7771
Update build.gradle
Enaium Oct 2, 2022
a407de1
Update build.gradle
Enaium Oct 2, 2022
5f402a7
Update build.gradle
Enaium Oct 2, 2022
100f670
Update README.md
Enaium Oct 3, 2022
81acaf5
save text
Enaium Oct 3, 2022
e63e88d
Update TaskManager.java
Enaium Oct 3, 2022
b93e569
message
Enaium Oct 3, 2022
0faf805
Update Dialog.java
Enaium Oct 5, 2022
957fa6b
update asm
Enaium Oct 10, 2022
30f33d9
fix size at high resolution
Enaium Oct 10, 2022
bf4cb13
option
Enaium Oct 10, 2022
e41e927
fix size at high resolution
Enaium Oct 10, 2022
98a984d
add inherit to tab
Enaium Oct 10, 2022
30f168c
Update VerticalLabelUI.java
Enaium Oct 14, 2022
ef2351e
fix font size in high resolution
Enaium Oct 14, 2022
60711a2
fix module class
Enaium Oct 14, 2022
df8d66a
Update CFRDecompiler.java
Enaium Oct 14, 2022
7d87496
edit utils
Enaium Oct 14, 2022
12def6c
decompile and compile
Enaium Oct 14, 2022
c45f8f2
Update CodeAreaPanel.java
Enaium Oct 14, 2022
a008446
i18n
Enaium Oct 14, 2022
8e908fe
tab index consistent
Enaium Oct 14, 2022
6cc4d2f
dialog
Enaium Oct 14, 2022
c39207a
Update Compiler.java
Enaium Oct 14, 2022
a910897
Update build.gradle
Enaium Oct 16, 2022
b5d77a3
classTabIndex
Enaium Oct 16, 2022
469bd33
Update ClassTabPanel.java
Enaium Oct 16, 2022
542c92c
add message
Enaium Oct 16, 2022
95f6134
gson
Enaium Nov 24, 2022
5a383ca
fix integer value
Enaium Nov 24, 2022
1a8d6fb
fix size
Enaium Nov 24, 2022
58a2ec0
add ui scale
Enaium Nov 24, 2022
a7a86e9
flatlaf
Enaium Nov 24, 2022
7119707
version
Enaium Nov 25, 2022
033ff1e
key
Enaium Nov 25, 2022
429b764
key config
Enaium Nov 25, 2022
4f8eb36
layout
Enaium Nov 25, 2022
ea66ba9
key
Enaium Nov 25, 2022
7e95e35
key
Enaium Nov 26, 2022
81c46ce
Merge branch 'master' into upstream_dev
Ecdcaeb Nov 24, 2024
9fcc699
postMerge
Ecdcaeb Nov 24, 2024
a66c1f0
=
Ecdcaeb Nov 24, 2024
aa5a6d2
KeyStroke value
Ecdcaeb Nov 24, 2024
7f8bb83
svg decoder
Ecdcaeb Nov 24, 2024
9f1e35b
fixup
Ecdcaeb Nov 24, 2024
12441da
impl
Ecdcaeb Nov 24, 2024
1984651
resetup config
Ecdcaeb Nov 24, 2024
9bc90b9
Merge branch 'master' into upstream_dev
Ecdcaeb Nov 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Keep the latest library, remove upstream problems and absorb upstream ideas.

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

![](https://user-images.githubusercontent.com/32991121/190947407-bbc6642e-2c9d-46f3-921c-6558c74272cf.png)
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ dependencies {

implementation 'com.formdev:flatlaf:3.5.2'
implementation 'com.formdev:flatlaf-extras:3.5.2'
implementation 'com.github.weisj:jsvg:1.6.1'
//noinspection GradlePackageUpdate
implementation 'com.miglayout:miglayout-swing:11.4.2'
implementation 'com.github.bobbylight:RSyntaxTextArea:3.5.2'
Expand All @@ -65,11 +66,11 @@ shadowJar {
dependencies {
include(dependency('com.formdev:.*'))
include(dependency('com.miglayout:.*'))
include(dependency('com.github.weisj:.*'))
include(dependency('com.github.bobbylight:RSyntaxTextArea'))
include(dependency('org.ow2.asm:.*'))
include(dependency('org.benf:cfr'))
include(dependency('com.github.mstrobel.procyon:procyon-decompiler'))
include(dependency('org.javassist:javassist'))
include(dependency('com.google.code.gson:gson'))
include(dependency('org.tinylog:.*'))
include(dependency('org.vineflower:vineflower'))
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/cn/enaium/joe/Instance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cn.enaium.joe;

public enum Instance {
INSTANCE;
public int classTabIndex = 0;
}
33 changes: 22 additions & 11 deletions src/main/java/cn/enaium/joe/JavaOctetEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
package cn.enaium.joe;

import cn.enaium.joe.config.ConfigManager;
import cn.enaium.joe.config.extend.ApplicationConfig;
import cn.enaium.joe.event.EventManager;
import cn.enaium.joe.gui.panel.BorderPanel;
import cn.enaium.joe.gui.panel.BottomPanel;
import cn.enaium.joe.gui.panel.file.tree.CenterPanel;
import cn.enaium.joe.gui.panel.file.tabbed.FileTabbedPanel;
import cn.enaium.joe.gui.component.FileTree;
import cn.enaium.joe.gui.panel.menu.*;
import cn.enaium.joe.jar.Jar;
import cn.enaium.joe.task.TaskManager;
import cn.enaium.joe.util.BytecodeTokenMaker;
import cn.enaium.joe.util.LangUtil;
import cn.enaium.joe.util.MessageUtil;
import cn.enaium.joe.util.ReflectUtil;
import cn.enaium.joe.util.*;
import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.extras.FlatSVGIcon;
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
Expand All @@ -45,7 +45,7 @@ public class JavaOctetEditor {

public static final String TITLE = "JavaOctetEditor";

public JFrame window = new JFrame(TITLE);
public JFrame window;

private Jar jar;

Expand All @@ -64,11 +64,22 @@ public class JavaOctetEditor {

public JavaOctetEditor() {
instance = this;

event = new EventManager();
config = new ConfigManager();
config.load();
task = new TaskManager();
Runtime.getRuntime().addShutdownHook(new Thread(config::save));

Integer value = config.getByClass(ApplicationConfig.class).scale.getValue();

if (value > 0) {
System.setProperty("sun.java2d.uiScale", value.toString());
}

FlatDarkLaf.setup();
UIManager.put("Tree.paintLines", true);

fileTabbedPanel = new FileTabbedPanel();
fileTree = new FileTree();
bottomPanel = new BottomPanel();
Expand All @@ -77,10 +88,10 @@ public JavaOctetEditor() {
public void run() {

ToolTipManager.sharedInstance().setInitialDelay(0);

FlatDarkLaf.setup();
AbstractTokenMakerFactory abstractTokenMakerFactory = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
abstractTokenMakerFactory.putMapping("text/custom", BytecodeTokenMaker.class.getName());

window = new JFrame(TITLE);
window.setIconImage(new FlatSVGIcon("icons/logo.svg").getImage());

window.setJMenuBar(new JMenuBar() {{
Expand All @@ -98,9 +109,9 @@ public void run() {
add(new HelpMenu());
}});

window.setContentPane(new JPanel(new BorderLayout()) {{
add(new CenterPanel(), BorderLayout.CENTER);
add(bottomPanel, BorderLayout.SOUTH);
window.setContentPane(new BorderPanel() {{
setCenter(new CenterPanel());
setBottom(bottomPanel);
}});


Expand All @@ -115,7 +126,7 @@ public void windowClosing(WindowEvent e) {
});
}
});
window.setSize(1000, 600);
window.setSize(Util.screenSize(1000, 600));
window.setLocationRelativeTo(null);
window.setVisible(true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/cn/enaium/joe/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package cn.enaium.joe;

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

Logger.info("DIR:{}", System.getProperty("user.dir"));
FlatDarkLaf.setup();
UIManager.put("Tree.paintLines", true);
new JavaOctetEditor().run();
}

Expand Down
77 changes: 77 additions & 0 deletions src/main/java/cn/enaium/joe/compiler/Compiler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2022 Enaium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.enaium.joe.compiler;

import javax.tools.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author Enaium
* @since 1.4.0
*/
public class Compiler {
private final Map<String, VirtualJavaFileObject> javaFileObjectMap = new HashMap<>();

private DiagnosticListener<VirtualJavaFileObject> listener;

public void addSource(String name, String content) {
javaFileObjectMap.put(name, new VirtualJavaFileObject(name, content));
}

public Map<String, byte[]> getClasses() {
return javaFileObjectMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().getBytecode()));
}

@SuppressWarnings("unchecked")
public boolean compile() {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
VirtualFileManager fileManager = new VirtualFileManager(compiler.getStandardFileManager(null, null, StandardCharsets.UTF_8));
try {
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, ((DiagnosticListener<? super JavaFileObject>) (Object) listener), null, null, javaFileObjectMap.values());
Boolean b = task.call();
return b != null && b;
} catch (Exception e) {
return false;
}
}

public void setListener(DiagnosticListener<VirtualJavaFileObject> listener) {
this.listener = listener;
}

private final class VirtualFileManager extends ForwardingJavaFileManager<JavaFileManager> {
public VirtualFileManager(JavaFileManager fileManager) {
super(fileManager);
}

@Override
public JavaFileObject getJavaFileForOutput(JavaFileManager.Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException {
if (JavaFileObject.Kind.CLASS == kind) {
VirtualJavaFileObject virtualJavaFileObject = new VirtualJavaFileObject(className, null);
javaFileObjectMap.put(className, virtualJavaFileObject);
return virtualJavaFileObject;
} else {
return super.getJavaFileForOutput(location, className, kind, sibling);
}
}
}
}
52 changes: 52 additions & 0 deletions src/main/java/cn/enaium/joe/compiler/VirtualJavaFileObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright 2022 Enaium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package cn.enaium.joe.compiler;

import javax.tools.SimpleJavaFileObject;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URI;

/**
* @author Enaium
* @since 1.4.0
*/
public class VirtualJavaFileObject extends SimpleJavaFileObject {

private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

private final String content;

protected VirtualJavaFileObject(String className, String content) {
super(URI.create("string:///" + className.replace(".", "/") + Kind.SOURCE.extension), Kind.SOURCE);
this.content = content;
}

public byte[] getBytecode() {
return outputStream.toByteArray();
}

@Override
public ByteArrayOutputStream openOutputStream() {
return outputStream;
}

@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
return content;
}
}
34 changes: 7 additions & 27 deletions src/main/java/cn/enaium/joe/config/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@

package cn.enaium.joe.config;

import cn.enaium.joe.config.extend.ApplicationConfig;
import cn.enaium.joe.config.extend.CFRConfig;
import cn.enaium.joe.config.extend.FernFlowerConfig;
import cn.enaium.joe.config.extend.ProcyonConfig;
import cn.enaium.joe.config.extend.*;
import cn.enaium.joe.config.value.*;
import cn.enaium.joe.util.MessageUtil;
import com.google.gson.*;

import javax.swing.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
Expand All @@ -44,6 +42,7 @@ public ConfigManager() {
addByInstance(new CFRConfig());
addByInstance(new FernFlowerConfig());
addByInstance(new ProcyonConfig());
addByInstance(new KeymapConfig());
}

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

private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
private Gson gson() {
return new GsonBuilder().setPrettyPrinting().create();
return GSON;
}

public void load() {
Expand All @@ -106,14 +106,13 @@ public void load() {
File file = new File(System.getProperty("."), config.getName() + ".json");
if (file.exists()) {
JsonObject jsonObject = gson().fromJson(Files.readString(file.toPath()), JsonObject.class);

for (Field configField : klass.getDeclaredFields()) {
configField.setAccessible(true);
if (!jsonObject.has(configField.getName())) {
continue;
}

if (!jsonObject.has(configField.getName())) {
if (!jsonObject.get(configField.getName()).isJsonObject()) {
continue;
}

Expand All @@ -126,26 +125,7 @@ public void load() {
Object valueObject = configField.get(config);
if (valueObject instanceof Value<?>) {
Value<?> value = (Value<?>) valueObject;
if (value instanceof EnableValue) {
((EnableValue) value).setValue(valueJsonElement.getAsBoolean());
} else if (value instanceof IntegerValue) {
((IntegerValue) value).setValue(valueJsonElement.getAsInt());
} else if (value instanceof ModeValue) {
ModeValue modeValue = (ModeValue) value;
if (modeValue.getMode().contains(valueJsonElement.getAsString())) {
modeValue.setValue(valueJsonElement.getAsString());
} else {
modeValue.setValue(modeValue.getMode().get(0));
}
} else if (value instanceof StringSetValue) {
Set<String> strings = new HashSet<>();
for (JsonElement jsonElement : valueJsonElement.getAsJsonArray()) {
strings.add(jsonElement.getAsString());
}
((StringSetValue) value).setValue(strings);
} else if (value instanceof StringValue) {
((StringValue) value).setValue(valueJsonElement.getAsString());
}
value.decode(valueJsonElement);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import cn.enaium.joe.annotation.NoUI;
import cn.enaium.joe.config.Config;
import cn.enaium.joe.config.value.EnableValue;
import cn.enaium.joe.config.value.IntegerValue;
import cn.enaium.joe.config.value.ModeValue;
import cn.enaium.joe.config.value.StringSetValue;

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

public ApplicationConfig() {
super("Application");
Expand Down
Loading