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

Commit 5d2dee9

Browse files
committed
info
1 parent 1775111 commit 5d2dee9

File tree

4 files changed

+318
-6
lines changed

4 files changed

+318
-6
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
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.gui.panel.file.tabbed.tab;
18+
19+
20+
import cn.enaium.joe.util.StringUtil;
21+
import org.benf.cfr.reader.util.StringUtils;
22+
import org.objectweb.asm.tree.ClassNode;
23+
24+
import javax.swing.*;
25+
import java.awt.*;
26+
import java.util.ArrayList;
27+
import java.util.Arrays;
28+
29+
/**
30+
* @author Enaium
31+
* @since 0.6.0
32+
*/
33+
public class ClassInfoTabPanel extends ClassNodeTabPanel {
34+
public ClassInfoTabPanel(ClassNode classNode) {
35+
super(classNode);
36+
setLayout(new BorderLayout());
37+
JPanel labels = new JPanel(new GridLayout(0, 1));
38+
JPanel rights = new JPanel(new GridLayout(0, 1));
39+
add(labels, BorderLayout.WEST);
40+
add(rights, BorderLayout.CENTER);
41+
labels.add(new JLabel("Name:"));
42+
JTextField name = new JTextField(classNode.name);
43+
rights.add(name);
44+
labels.add(new JLabel("SourceFile:"));
45+
JTextField sourceFile = new JTextField(classNode.sourceFile);
46+
rights.add(sourceFile);
47+
labels.add(new JLabel("DebugFile:"));
48+
JTextField sourceDebug = new JTextField(classNode.sourceDebug);
49+
rights.add(sourceDebug);
50+
labels.add(new JLabel("Access:"));
51+
JTextField access = new JTextField(String.valueOf(classNode.access));
52+
rights.add(access);
53+
labels.add(new JLabel("Version:"));
54+
JTextField version = new JTextField(String.valueOf(classNode.version));
55+
rights.add(version);
56+
labels.add(new JLabel("Signature:"));
57+
JTextField signature = new JTextField(classNode.signature);
58+
rights.add(signature);
59+
labels.add(new JLabel("Super Name:"));
60+
JTextField superName = new JTextField(classNode.superName);
61+
rights.add(superName);
62+
labels.add(new JLabel("Interfaces:"));
63+
JTextField interfaces = new JTextField(StringUtils.join(classNode.interfaces, ";"));
64+
rights.add(interfaces);
65+
labels.add(new JLabel("Outer Class:"));
66+
JTextField outerClass = new JTextField(classNode.outerClass);
67+
rights.add(outerClass);
68+
labels.add(new JLabel("Outer Method:"));
69+
JTextField outerMethod = new JTextField(classNode.outerMethod);
70+
rights.add(outerMethod);
71+
labels.add(new JLabel("Outer Method Description:"));
72+
JTextField outerMethodDesc = new JTextField(classNode.outerMethodDesc);
73+
rights.add(outerMethodDesc);
74+
add(new JButton("Save") {{
75+
addActionListener(e -> {
76+
77+
if (!StringUtil.isBlank(name.getText())) {
78+
classNode.name = name.getText();
79+
}
80+
81+
if (!StringUtil.isBlank(sourceFile.getText())) {
82+
classNode.sourceFile = sourceFile.getText();
83+
} else {
84+
classNode.sourceFile = null;
85+
}
86+
87+
if (!StringUtil.isBlank(sourceDebug.getText())) {
88+
classNode.sourceDebug = sourceDebug.getText();
89+
} else {
90+
classNode.sourceDebug = null;
91+
}
92+
93+
if (!StringUtil.isBlank(access.getText())) {
94+
classNode.access = Integer.parseInt(access.getText());
95+
}
96+
97+
if (!StringUtil.isBlank(version.getText())) {
98+
classNode.version = Integer.parseInt(version.getText());
99+
}
100+
101+
if (!StringUtil.isBlank(signature.getText())) {
102+
classNode.signature = signature.getName();
103+
} else {
104+
classNode.signature = null;
105+
}
106+
107+
if (!StringUtil.isBlank(interfaces.getText())) {
108+
classNode.interfaces = Arrays.asList(superName.getText().split(";"));
109+
} else {
110+
classNode.interfaces = new ArrayList<>();
111+
}
112+
113+
if (!StringUtil.isBlank(outerClass.getText())) {
114+
classNode.outerClass = outerClass.getText();
115+
} else {
116+
classNode.outerClass = null;
117+
}
118+
119+
if (!StringUtil.isBlank(outerMethod.getText())) {
120+
classNode.outerMethod = outerMethod.getText();
121+
} else {
122+
classNode.outerClass = null;
123+
}
124+
125+
if (!StringUtil.isBlank(outerMethodDesc.getText())) {
126+
classNode.outerMethodDesc = outerMethodDesc.getText();
127+
} else {
128+
classNode.outerClass = null;
129+
}
130+
131+
JOptionPane.showMessageDialog(ClassInfoTabPanel.this, "Save success");
132+
});
133+
}}, BorderLayout.SOUTH);
134+
}
135+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.gui.panel.file.tabbed.tab;
18+
19+
import cn.enaium.joe.util.StringUtil;
20+
import org.objectweb.asm.tree.FieldNode;
21+
22+
import javax.swing.*;
23+
import java.awt.*;
24+
25+
/**
26+
* @author Enaium
27+
* @since 0.6.0
28+
*/
29+
public class FieldInfoPanel extends JPanel {
30+
public FieldInfoPanel(FieldNode fieldNode) {
31+
setLayout(new BorderLayout());
32+
JPanel labels = new JPanel(new GridLayout(0, 1));
33+
JPanel rights = new JPanel(new GridLayout(0, 1));
34+
add(labels, BorderLayout.WEST);
35+
add(rights, BorderLayout.CENTER);
36+
labels.add(new JLabel("Name:"));
37+
JTextField name = new JTextField(fieldNode.name);
38+
rights.add(name);
39+
labels.add(new JLabel("Description:"));
40+
JTextField description = new JTextField(fieldNode.desc);
41+
rights.add(description);
42+
labels.add(new JLabel("Access:"));
43+
JTextField access = new JTextField(String.valueOf(fieldNode.access));
44+
rights.add(access);
45+
labels.add(new JLabel("Signature:"));
46+
JTextField signature = new JTextField(fieldNode.signature);
47+
rights.add(signature);
48+
add(new JButton("Save") {{
49+
addActionListener(e -> {
50+
51+
if (!StringUtil.isBlank(name.getText())) {
52+
fieldNode.name = name.getText();
53+
}
54+
55+
56+
if (!StringUtil.isBlank(description.getText())) {
57+
fieldNode.desc = description.getText();
58+
} else {
59+
fieldNode.desc = null;
60+
}
61+
62+
if (!StringUtil.isBlank(access.getText())) {
63+
fieldNode.access = Integer.parseInt(access.getText());
64+
}
65+
66+
if (!StringUtil.isBlank(signature.getText())) {
67+
fieldNode.signature = signature.getName();
68+
} else {
69+
fieldNode.signature = null;
70+
}
71+
72+
JOptionPane.showMessageDialog(FieldInfoPanel.this, "Save success");
73+
});
74+
}}, BorderLayout.SOUTH);
75+
}
76+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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.gui.panel.file.tabbed.tab;
18+
19+
import cn.enaium.joe.util.StringUtil;
20+
import org.benf.cfr.reader.util.StringUtils;
21+
import org.objectweb.asm.tree.MethodNode;
22+
23+
import javax.swing.*;
24+
import java.awt.*;
25+
import java.util.ArrayList;
26+
import java.util.Arrays;
27+
28+
/**
29+
* @author Enaium
30+
* @since 0.6.0
31+
*/
32+
public class MethodInfoTabPanel extends JPanel {
33+
public MethodInfoTabPanel(MethodNode methodNode) {
34+
setLayout(new BorderLayout());
35+
JPanel labels = new JPanel(new GridLayout(0, 1));
36+
JPanel rights = new JPanel(new GridLayout(0, 1));
37+
add(labels, BorderLayout.WEST);
38+
add(rights, BorderLayout.CENTER);
39+
labels.add(new JLabel("Name:"));
40+
JTextField name = new JTextField(methodNode.name);
41+
rights.add(name);
42+
labels.add(new JLabel("Description:"));
43+
JTextField description = new JTextField(methodNode.desc);
44+
rights.add(description);
45+
labels.add(new JLabel("Access:"));
46+
JTextField access = new JTextField(String.valueOf(methodNode.access));
47+
rights.add(access);
48+
labels.add(new JLabel("Signature:"));
49+
JTextField signature = new JTextField(methodNode.signature);
50+
rights.add(signature);
51+
labels.add(new JLabel("Exceptions:"));
52+
JTextField exceptions = new JTextField(StringUtils.join(methodNode.exceptions, ";"));
53+
rights.add(exceptions);
54+
add(new JButton("Save") {{
55+
addActionListener(e -> {
56+
57+
if (!StringUtil.isBlank(name.getText())) {
58+
methodNode.name = name.getText();
59+
}
60+
61+
62+
if (!StringUtil.isBlank(description.getText())) {
63+
methodNode.desc = description.getText();
64+
} else {
65+
methodNode.desc = null;
66+
}
67+
68+
if (!StringUtil.isBlank(access.getText())) {
69+
methodNode.access = Integer.parseInt(access.getText());
70+
}
71+
72+
if (!StringUtil.isBlank(signature.getText())) {
73+
methodNode.signature = signature.getName();
74+
} else {
75+
methodNode.signature = null;
76+
}
77+
78+
if (!StringUtil.isBlank(signature.getText())) {
79+
methodNode.exceptions = Arrays.asList(signature.getText().split(";"));
80+
} else {
81+
methodNode.exceptions = new ArrayList<>();
82+
}
83+
84+
JOptionPane.showMessageDialog(MethodInfoTabPanel.this, "Save success");
85+
});
86+
}}, BorderLayout.SOUTH);
87+
}
88+
}

src/main/java/cn/enaium/joe/gui/panel/file/tree/FileTreePanel.java

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

1919
import cn.enaium.joe.JavaOctetEditor;
2020
import cn.enaium.joe.gui.panel.file.FileDropTarget;
21-
import cn.enaium.joe.gui.panel.file.tabbed.tab.FileTabPanel;
21+
import cn.enaium.joe.gui.panel.file.tabbed.tab.ClassTabPanel;
22+
import cn.enaium.joe.gui.panel.file.tabbed.tab.FieldInfoPanel;
23+
import cn.enaium.joe.gui.panel.file.tabbed.tab.MethodInfoTabPanel;
2224
import cn.enaium.joe.gui.panel.file.tree.node.*;
2325
import cn.enaium.joe.jar.Jar;
2426
import cn.enaium.joe.util.ASyncUtil;
@@ -30,8 +32,6 @@
3032
import javax.swing.*;
3133
import javax.swing.tree.DefaultMutableTreeNode;
3234
import javax.swing.tree.DefaultTreeModel;
33-
import javax.swing.tree.TreeNode;
34-
import javax.swing.tree.TreePath;
3535
import java.awt.dnd.DnDConstants;
3636
import java.awt.dnd.DropTarget;
3737
import java.awt.event.MouseAdapter;
@@ -59,10 +59,21 @@ public FileTreePanel() {
5959

6060
addTreeSelectionListener(e -> {
6161
DefaultTreeNode lastPathComponent = (DefaultTreeNode) e.getPath().getLastPathComponent();
62-
if (lastPathComponent instanceof ClassTreeNode) {
63-
JavaOctetEditor.getInstance().fileTabbedPanel.addTab(lastPathComponent.toString(), new FileTabPanel(((ClassTreeNode) lastPathComponent).classNode));
62+
SwingUtilities.invokeLater(() -> {
63+
if (lastPathComponent instanceof ClassTreeNode) {
64+
ClassNode classNode = ((ClassTreeNode) lastPathComponent).classNode;
65+
JavaOctetEditor.getInstance().fileTabbedPanel.addTab(classNode.name.substring(classNode.name.lastIndexOf("/") + 1), new ClassTabPanel(classNode));
66+
} else if (lastPathComponent instanceof MethodTreeNode) {
67+
MethodTreeNode methodTreeNode = (MethodTreeNode) lastPathComponent;
68+
MethodNode methodNode = methodTreeNode.methodNode;
69+
JavaOctetEditor.getInstance().fileTabbedPanel.addTab(methodTreeNode.classNode.name.substring(methodTreeNode.classNode.name.lastIndexOf("/") + 1) + "#" + methodNode.name, new MethodInfoTabPanel(methodNode));
70+
} else if (lastPathComponent instanceof FieldTreeNode) {
71+
FieldTreeNode fieldTreeNode = (FieldTreeNode) lastPathComponent;
72+
FieldNode fieldNode = fieldTreeNode.fieldNode;
73+
JavaOctetEditor.getInstance().fileTabbedPanel.addTab(fieldTreeNode.classNode.name.substring(fieldTreeNode.classNode.name.lastIndexOf("/") + 1) + "#" + fieldNode.name, new FieldInfoPanel(fieldNode));
74+
}
6475
JavaOctetEditor.getInstance().fileTabbedPanel.setSelectedIndex(JavaOctetEditor.getInstance().fileTabbedPanel.getTabCount() - 1);
65-
}
76+
});
6677
});
6778

6879
new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new FileDropTarget(".jar", files -> {
@@ -102,6 +113,8 @@ public void refresh(Jar jar) {
102113
classesRoot.removeAllChildren();
103114
resourceRoot.removeAllChildren();
104115

116+
JavaOctetEditor.getInstance().fileTabbedPanel.removeAll();
117+
105118
Map<String, DefaultTreeNode> hasMap = new HashMap<>();
106119

107120

0 commit comments

Comments
 (0)