Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit cbe8fd2

Browse files
authored
Merge pull request #16 from Enaium/develop
Develop
2 parents 953b5ae + 93d4917 commit cbe8fd2

Some content is hidden

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

60 files changed

+2079
-506
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# JavaOctetEditor
22

3-
![Snipaste_2022-08-30_09-02-03](https://user-images.githubusercontent.com/32991121/187325154-249f6d48-a22e-4472-951a-bb4f69301802.png)
4-
![Snipaste_2022-08-30_09-02-22](https://user-images.githubusercontent.com/32991121/187325158-37d291fa-daeb-445d-9418-472254a32ea6.png)
3+
![](https://user-images.githubusercontent.com/32991121/188775455-da15ea74-dac0-4982-bc4e-a5794b339ad3.png)
4+
![](https://user-images.githubusercontent.com/32991121/188775462-2bedb357-7c3a-4212-a652-5a4e53f583e6.png)

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
group 'cn.enaium'
11-
version '1.1.0'
11+
version '1.2.0'
1212

1313
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
1414

@@ -48,7 +48,7 @@ dependencies {
4848
implementation 'org.benf:cfr:0.152'
4949
implementation 'com.github.mstrobel.procyon:procyon-decompiler:v0.6.0'
5050
implementation 'org.quiltmc:quiltflower:1.8.1'
51-
implementation 'org.javassist:javassist:3.29.0-GA'
51+
implementation 'org.javassist:javassist:3.29.1-GA'
5252
implementation 'com.google.code.gson:gson:2.9.0'
5353
implementation 'org.tinylog:tinylog:1.3.6'
5454
implementation 'com.github.FabricMC:mapping-io:597f0722d6'

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

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

1919
import cn.enaium.joe.config.ConfigManager;
20+
import cn.enaium.joe.event.EventManager;
2021
import cn.enaium.joe.gui.panel.BottomPanel;
22+
import cn.enaium.joe.gui.panel.file.tree.FileTreePanel;
2123
import cn.enaium.joe.gui.panel.LeftPanel;
2224
import cn.enaium.joe.gui.panel.file.tabbed.FileTabbedPanel;
23-
import cn.enaium.joe.gui.panel.file.tree.FileTreePanel;
25+
import cn.enaium.joe.gui.component.FileTree;
2426
import cn.enaium.joe.gui.panel.menu.*;
2527
import cn.enaium.joe.jar.Jar;
2628
import cn.enaium.joe.task.TaskManager;
29+
import cn.enaium.joe.util.KeyStrokeUtil;
2730
import cn.enaium.joe.util.LangUtil;
2831
import cn.enaium.joe.util.MessageUtil;
2932
import cn.enaium.joe.util.ReflectUtil;
30-
import com.sun.tools.attach.VirtualMachine;
3133
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
3234
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
33-
import org.pmw.tinylog.Logger;
3435

3536
import javax.swing.*;
3637
import java.awt.*;
37-
import java.awt.event.WindowAdapter;
38-
import java.awt.event.WindowEvent;
38+
import java.awt.event.*;
3939

4040
/**
4141
* @author Enaium
@@ -51,22 +51,26 @@ public class JavaOctetEditor {
5151

5252
public FileTabbedPanel fileTabbedPanel;
5353

54-
public FileTreePanel fileTreePanel;
54+
public FileTree fileTree;
5555

5656
public BottomPanel bottomPanel;
5757

58+
public EventManager event;
59+
5860
public ConfigManager config;
5961

6062
public TaskManager task;
6163

64+
6265
public JavaOctetEditor() {
6366
instance = this;
67+
event = new EventManager();
6468
config = new ConfigManager();
6569
config.load();
6670
task = new TaskManager();
6771
Runtime.getRuntime().addShutdownHook(new Thread(config::save));
6872
fileTabbedPanel = new FileTabbedPanel();
69-
fileTreePanel = new FileTreePanel();
73+
fileTree = new FileTree();
7074
bottomPanel = new BottomPanel();
7175
}
7276

@@ -92,16 +96,16 @@ public void run() {
9296
add(new HelpMenu());
9397
}});
9498

95-
window.setContentPane(new JPanel(new BorderLayout()) {
96-
{
97-
add(new JSplitPane() {{
98-
setDividerLocation(150);
99-
setLeftComponent(new LeftPanel());
100-
setRightComponent(fileTabbedPanel);
101-
}}, BorderLayout.CENTER);
102-
add(bottomPanel, BorderLayout.SOUTH);
103-
}
104-
});
99+
window.setContentPane(new JPanel(new BorderLayout()) {{
100+
add(new LeftPanel(), BorderLayout.WEST);
101+
add(new JSplitPane() {{
102+
setLeftComponent(new FileTreePanel());
103+
setRightComponent(fileTabbedPanel);
104+
}}, BorderLayout.CENTER);
105+
add(bottomPanel, BorderLayout.SOUTH);
106+
}});
107+
108+
105109
window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
106110
window.addWindowListener(new WindowAdapter() {
107111
@Override
@@ -113,7 +117,7 @@ public void windowClosing(WindowEvent e) {
113117
});
114118
}
115119
});
116-
window.setSize(800, 500);
120+
window.setSize(1000, 600);
117121
window.setLocationRelativeTo(null);
118122
window.setVisible(true);
119123
}
@@ -124,7 +128,7 @@ public Jar getJar() {
124128

125129
public void setJar(Jar jar) {
126130
this.jar = jar;
127-
fileTreePanel.refresh(jar);
131+
fileTree.refresh(jar);
128132
}
129133

130134
public static JavaOctetEditor getInstance() {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import cn.enaium.joe.annotation.NoUI;
2020
import cn.enaium.joe.config.Config;
21+
import cn.enaium.joe.config.value.EnableValue;
2122
import cn.enaium.joe.config.value.ModeValue;
2223
import cn.enaium.joe.config.value.StringSetValue;
2324

@@ -33,6 +34,7 @@ public class ApplicationConfig extends Config {
3334
public ModeValue decompilerMode = new ModeValue("Decompiler", "CFR", "Java Decompiler", Arrays.asList("CFR", "Procyon", "FernFlower"));
3435
public ModeValue language = new ModeValue("Language", "System", "UI language", Arrays.asList("System", "zh_CN", "en_US"));
3536
public ModeValue packagePresentation = new ModeValue("Package Presentation", "Hierarchical", "Package Mode", Arrays.asList("Flat", "Hierarchical"));
37+
public EnableValue compactMiddlePackage = new EnableValue("Compact Middle Package", true, "Only Hierarchical Mode");
3638
@NoUI
3739
public final StringSetValue loadRecent = new StringSetValue("Load Recent", new HashSet<>(), "");
3840

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.dialog;
18+
19+
import cn.enaium.joe.util.JMenuUtil;
20+
import cn.enaium.joe.util.LangUtil;
21+
import cn.enaium.joe.wrapper.ObjectWrapper;
22+
import org.objectweb.asm.tree.AnnotationNode;
23+
24+
import javax.swing.*;
25+
import javax.swing.table.DefaultTableModel;
26+
import java.awt.*;
27+
import java.util.List;
28+
29+
/**
30+
* @author Enaium
31+
* @since 1.2.0
32+
*/
33+
public class AnnotationListDialog extends Dialog {
34+
public AnnotationListDialog(List<AnnotationNode> annotationNodes) {
35+
super("Annotation");
36+
setLayout(new BorderLayout());
37+
DefaultTableModel dm = new DefaultTableModel(new Object[][]{}, new String[]{"Description", "Has Value"});
38+
for (AnnotationNode annotationNode : annotationNodes) {
39+
dm.addRow(new Object[]{new ObjectWrapper(annotationNode), annotationNode.values != null});
40+
}
41+
JTable jTable = new JTable(dm) {
42+
public boolean isCellEditable(int row, int column) {
43+
return false;
44+
}
45+
};
46+
jTable.getTableHeader().setReorderingAllowed(false);
47+
jTable.getTableHeader().setResizingAllowed(false);
48+
add(new JScrollPane(jTable), BorderLayout.CENTER);
49+
JMenuUtil.addPopupMenu(jTable, new JPopupMenu() {{
50+
add(new JMenuItem(LangUtil.i18n("button.edit")) {{
51+
addActionListener(e -> {
52+
new AnnotationValueDialog(((AnnotationNode) ((ObjectWrapper) dm.getValueAt(jTable.getSelectedRow(), 0)).getWrapper()).values).setVisible(true);
53+
});
54+
}});
55+
}}, () -> jTable.getSelectedRow() != -1 && Boolean.parseBoolean(dm.getValueAt(jTable.getSelectedRow(), 1).toString()));
56+
}
57+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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.dialog;
18+
19+
import cn.enaium.joe.gui.panel.confirm.ListValueEditPanel;
20+
import cn.enaium.joe.gui.panel.confirm.ValueEditPanel;
21+
import cn.enaium.joe.util.JMenuUtil;
22+
import cn.enaium.joe.util.LangUtil;
23+
import cn.enaium.joe.util.ListUtil;
24+
import cn.enaium.joe.util.MessageUtil;
25+
import cn.enaium.joe.wrapper.ObjectWrapper;
26+
import org.objectweb.asm.tree.AnnotationNode;
27+
28+
import javax.swing.*;
29+
import javax.swing.table.DefaultTableModel;
30+
import java.awt.*;
31+
import java.util.ArrayList;
32+
import java.util.Arrays;
33+
import java.util.List;
34+
import java.util.stream.Collectors;
35+
36+
/**
37+
* @author Enaium
38+
* @since 1.2.0
39+
*/
40+
public class AnnotationValueDialog extends Dialog {
41+
public AnnotationValueDialog(List<Object> objects) {
42+
super("Annotation Value");
43+
DefaultTableModel dm = new DefaultTableModel(new Object[][]{}, new String[]{"Description", "Value"});
44+
45+
for (Object object : objects) {
46+
int index = objects.indexOf(object);
47+
if (index % 2 == 1) {
48+
dm.addRow(new Object[]{objects.get(index - 1), new ObjectWrapper(object)});
49+
}
50+
}
51+
JTable jTable = new JTable(dm) {
52+
public boolean isCellEditable(int row, int column) {
53+
return false;
54+
}
55+
};
56+
jTable.getTableHeader().setReorderingAllowed(false);
57+
jTable.getTableHeader().setResizingAllowed(false);
58+
add(new JScrollPane(jTable), BorderLayout.CENTER);
59+
JMenuUtil.addPopupMenu(jTable, new JPopupMenu() {{
60+
add(new JMenuItem(LangUtil.i18n("button.edit")) {{
61+
addActionListener(e -> {
62+
ObjectWrapper valueAt = (ObjectWrapper) dm.getValueAt(jTable.getSelectedRow(), 1);
63+
if (valueAt.getWrapper() instanceof ArrayList<?>) {
64+
@SuppressWarnings("unchecked") List<Object> wrapper = (List<Object>) valueAt.getWrapper();
65+
if (ListUtil.getType(wrapper) == AnnotationNode.class) {
66+
new AnnotationListDialog(wrapper.stream().map(it -> ((AnnotationNode) it)).collect(Collectors.toList())).setVisible(true);
67+
} else {
68+
MessageUtil.confirm(new ListValueEditPanel(wrapper), "List");
69+
}
70+
} else {
71+
int index = (jTable.getSelectedRow() + 1) * 2 - 1;
72+
if (valueAt.getWrapper().getClass().isArray()) {
73+
ArrayList<Object> newList = new ArrayList<>(Arrays.asList(((Object[]) valueAt.getWrapper())));
74+
MessageUtil.confirm(new ListValueEditPanel(newList), "List", () -> {
75+
String[] strings = newList.stream().map(Object::toString).toArray(String[]::new);
76+
valueAt.setWrapper(strings);
77+
objects.set(index, strings);
78+
});
79+
} else {
80+
ObjectWrapper objectWrapper = new ObjectWrapper(valueAt.getWrapper());
81+
ValueEditPanel confirmPanel = new ValueEditPanel(objectWrapper);
82+
MessageUtil.confirm(confirmPanel, LangUtil.i18n("button.edit"), () -> {
83+
valueAt.setWrapper(objectWrapper.getWrapper());
84+
objects.set(index, objectWrapper.getWrapper());
85+
});
86+
}
87+
}
88+
});
89+
}});
90+
}}, () -> jTable.getSelectedRow() != -1);
91+
}
92+
}

src/main/java/cn/enaium/joe/gui/panel/file/tree/node/FieldTreeNode.java renamed to src/main/java/cn/enaium/joe/dialog/FieldDialog.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
package cn.enaium.joe.gui.panel.file.tree.node;
17+
package cn.enaium.joe.dialog;
1818

19+
import cn.enaium.joe.gui.panel.FieldInfoPanel;
1920
import org.objectweb.asm.tree.ClassNode;
2021
import org.objectweb.asm.tree.FieldNode;
2122

23+
import java.awt.*;
24+
2225
/**
2326
* @author Enaium
27+
* @since 1.2.0
2428
*/
25-
public class FieldTreeNode extends PackageTreeNode {
26-
public ClassNode classNode;
27-
public FieldNode fieldNode;
28-
29-
public FieldTreeNode(ClassNode classNode, FieldNode fieldNode) {
30-
super(fieldNode.name);
31-
this.classNode = classNode;
32-
this.fieldNode = fieldNode;
29+
public class FieldDialog extends Dialog {
30+
public FieldDialog(ClassNode classNode, FieldNode fieldNode) {
31+
super(classNode.name + "#" + fieldNode.name);
32+
setLayout(new BorderLayout());
33+
add(new FieldInfoPanel(fieldNode), BorderLayout.CENTER);
3334
}
3435
}

src/main/java/cn/enaium/joe/gui/panel/file/tree/node/MethodTreeNode.java renamed to src/main/java/cn/enaium/joe/dialog/MethodDialog.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,22 @@
1414
* limitations under the License.
1515
*/
1616

17-
package cn.enaium.joe.gui.panel.file.tree.node;
17+
package cn.enaium.joe.dialog;
1818

19+
import cn.enaium.joe.gui.panel.method.MethodTabPanel;
1920
import org.objectweb.asm.tree.ClassNode;
2021
import org.objectweb.asm.tree.MethodNode;
2122

23+
import java.awt.*;
24+
2225
/**
2326
* @author Enaium
27+
* @since 1.2.0
2428
*/
25-
public class MethodTreeNode extends PackageTreeNode {
26-
public ClassNode classNode;
27-
public MethodNode methodNode;
28-
29-
public MethodTreeNode(ClassNode classNode, MethodNode methodNode) {
30-
super(methodNode.name);
31-
this.classNode = classNode;
32-
this.methodNode = methodNode;
29+
public class MethodDialog extends Dialog {
30+
public MethodDialog(ClassNode classNode, MethodNode methodNode) {
31+
super(classNode.name + "#" + methodNode.name);
32+
setLayout(new BorderLayout());
33+
add(new MethodTabPanel(methodNode), BorderLayout.CENTER);
3334
}
3435
}

0 commit comments

Comments
 (0)