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

Commit 6e120b5

Browse files
committed
load recent
1 parent 277f6a6 commit 6e120b5

File tree

8 files changed

+143
-0
lines changed

8 files changed

+143
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.annotation;
18+
19+
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Retention;
21+
import java.lang.annotation.RetentionPolicy;
22+
import java.lang.annotation.Target;
23+
24+
/**
25+
* @author Enaium
26+
* @since 0.9.0
27+
*/
28+
@Retention(RetentionPolicy.RUNTIME)
29+
@Target(ElementType.FIELD)
30+
public @interface NoUI {
31+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@
1616

1717
package cn.enaium.joe.config.extend;
1818

19+
import cn.enaium.joe.annotation.NoUI;
1920
import cn.enaium.joe.config.Config;
2021
import cn.enaium.joe.config.value.ModeValue;
22+
import cn.enaium.joe.config.value.StringSetValue;
2123

24+
import java.util.ArrayList;
2225
import java.util.Arrays;
26+
import java.util.HashSet;
2327

2428
/**
2529
* @author Enaium
@@ -28,6 +32,8 @@
2832
public class ApplicationConfig extends Config {
2933
public final ModeValue decompilerMode = new ModeValue("Decompiler", "CFR", "Java Decompiler", Arrays.asList("CFR", "Procyon", "JD-Core"));
3034
public final ModeValue language = new ModeValue("Language", "System", "UI language", Arrays.asList("System", "zh_CN", "en_US"));
35+
@NoUI
36+
public final StringSetValue loadRecent = new StringSetValue("Load Recent", new HashSet<>(), "");
3137

3238
public ApplicationConfig() {
3339
super("Application");
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.config.value;
18+
19+
import java.util.List;
20+
import java.util.Set;
21+
22+
/**
23+
* @author Enaium
24+
* @since 0.9.0
25+
*/
26+
public class StringSetValue extends Value<Set<String>>{
27+
public StringSetValue(String name, Set<String> value, String description) {
28+
super(name, value, description);
29+
}
30+
}

src/main/java/cn/enaium/joe/dialog/ConfigDialog.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cn.enaium.joe.dialog;
1818

1919
import cn.enaium.joe.JavaOctetEditor;
20+
import cn.enaium.joe.annotation.NoUI;
2021
import cn.enaium.joe.config.Config;
2122
import cn.enaium.joe.config.value.*;
2223
import cn.enaium.joe.util.LangUtil;
@@ -44,6 +45,12 @@ public ConfigDialog(Config config) {
4445
try {
4546
for (Field declaredField : config.getClass().getDeclaredFields()) {
4647
declaredField.setAccessible(true);
48+
49+
50+
if (declaredField.isAnnotationPresent(NoUI.class)) {
51+
continue;
52+
}
53+
4754
Object o = declaredField.get(config);
4855

4956
if (o instanceof Value) {

src/main/java/cn/enaium/joe/gui/panel/menu/FileMenu.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cn.enaium.joe.gui.panel.menu;
1818

1919
import cn.enaium.joe.gui.panel.menu.file.LoadMenuItem;
20+
import cn.enaium.joe.gui.panel.menu.file.LoadRecentMenu;
2021
import cn.enaium.joe.gui.panel.menu.file.SaveAllSourceMenuItem;
2122
import cn.enaium.joe.gui.panel.menu.file.SaveMenuItem;
2223
import cn.enaium.joe.util.LangUtil;
@@ -30,6 +31,7 @@ public class FileMenu extends JMenu {
3031
public FileMenu() {
3132
super(LangUtil.i18n("menu.file"));
3233
add(new LoadMenuItem());
34+
add(new LoadRecentMenu());
3335
add(new SaveMenuItem());
3436
add(new JSeparator());
3537
add(new SaveAllSourceMenuItem());

src/main/java/cn/enaium/joe/gui/panel/menu/file/LoadMenuItem.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cn.enaium.joe.gui.panel.menu.file;
1818

1919
import cn.enaium.joe.JavaOctetEditor;
20+
import cn.enaium.joe.config.extend.ApplicationConfig;
2021
import cn.enaium.joe.jar.Jar;
2122
import cn.enaium.joe.util.ASyncUtil;
2223
import cn.enaium.joe.util.JFileChooserUtil;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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.menu.file;
18+
19+
import cn.enaium.joe.JavaOctetEditor;
20+
import cn.enaium.joe.config.extend.ApplicationConfig;
21+
import cn.enaium.joe.jar.Jar;
22+
import cn.enaium.joe.util.ASyncUtil;
23+
import cn.enaium.joe.util.LangUtil;
24+
25+
import javax.swing.*;
26+
import java.awt.event.MouseAdapter;
27+
import java.awt.event.MouseEvent;
28+
import java.io.File;
29+
import java.util.Set;
30+
31+
/**
32+
* @author Enaium
33+
* @since 0.9.0
34+
*/
35+
public class LoadRecentMenu extends JMenuItem {
36+
public LoadRecentMenu() {
37+
super(LangUtil.i18n("menu.file.loadRecent"));
38+
addMouseListener(new MouseAdapter() {
39+
@Override
40+
public void mouseReleased(MouseEvent e) {
41+
JPopupMenu jPopupMenu = new JPopupMenu();
42+
Set<String> loadRecent = JavaOctetEditor.getInstance().configManager.getByClass(ApplicationConfig.class).loadRecent.getValue();
43+
for (String s : loadRecent) {
44+
jPopupMenu.add(new JMenuItem(s) {{
45+
addActionListener(e -> {
46+
System.out.println(s);
47+
File file = new File(s);
48+
if (file.exists()) {
49+
ASyncUtil.execute(() -> {
50+
Jar jar = new Jar();
51+
jar.load(file);
52+
JavaOctetEditor.getInstance().fileTreePanel.refresh(jar);
53+
});
54+
} else {
55+
loadRecent.remove(s);
56+
}
57+
});
58+
}});
59+
}
60+
jPopupMenu.show(JavaOctetEditor.getInstance().fileTreePanel, e.getX(), e.getY());
61+
}
62+
});
63+
}
64+
}

src/main/java/cn/enaium/joe/jar/Jar.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package cn.enaium.joe.jar;
1818

1919
import cn.enaium.joe.JavaOctetEditor;
20+
import cn.enaium.joe.config.extend.ApplicationConfig;
2021
import cn.enaium.joe.util.Util;
2122
import org.objectweb.asm.ClassReader;
2223
import org.objectweb.asm.tree.ClassNode;
@@ -39,6 +40,7 @@ public class Jar {
3940
public Map<String, byte[]> resources = new LinkedHashMap<>();
4041

4142
public void load(File file) {
43+
JavaOctetEditor.getInstance().configManager.getByClass(ApplicationConfig.class).loadRecent.getValue().add(show.getAbsolutePath());
4244
JavaOctetEditor.getInstance().jar = this;
4345
JavaOctetEditor.getInstance().window.setTitle(JavaOctetEditor.TITLE + "-" + file.getName());
4446
try {

0 commit comments

Comments
 (0)