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

Commit 4387eca

Browse files
committed
task
1 parent 5153bb1 commit 4387eca

File tree

6 files changed

+93
-75
lines changed

6 files changed

+93
-75
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.TYPE)
30+
public @interface Indeterminate {
31+
}

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

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/main/java/cn/enaium/joe/gui/panel/BottomPanel.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
package cn.enaium.joe.gui.panel;
1818

1919
import cn.enaium.joe.JavaOctetEditor;
20-
import cn.enaium.joe.dialog.TaskDialog;
20+
import cn.enaium.joe.annotation.Indeterminate;
2121
import cn.enaium.joe.task.AbstractTask;
22+
import cn.enaium.joe.task.DecompileTask;
2223
import org.benf.cfr.reader.bytecode.analysis.parse.utils.Pair;
2324

2425
import javax.swing.*;
@@ -36,21 +37,12 @@
3637
* @author Enaium
3738
*/
3839
public class BottomPanel extends JPanel {
39-
private final JLabel scale = new JLabel();
4040

4141
public BottomPanel() {
4242
super(new GridLayout(1, 4, 10, 10));
4343
this.setBorder(new EmptyBorder(5, 5, 5, 5));
4444

45-
JProgressBar jProgressBar = new JProgressBar() {{
46-
addMouseListener(new MouseAdapter() {
47-
@Override
48-
public void mouseReleased(MouseEvent e) {
49-
new TaskDialog().setVisible(true);
50-
super.mouseReleased(e);
51-
}
52-
});
53-
}};
45+
JProgressBar jProgressBar = new JProgressBar();
5446

5547
add(jProgressBar);
5648

@@ -61,22 +53,28 @@ public void mouseReleased(MouseEvent e) {
6153
SwingUtilities.invokeLater(() -> {
6254
jProgressBar.setValue(0);
6355
jProgressBar.setStringPainted(true);
56+
jProgressBar.setIndeterminate(false);
6457
jProgressBar.setString("");
6558
jProgressBar.repaint();
6659
});
6760
} else {
68-
Pair<AbstractTask<?>, CompletableFuture<?>> classCompletableFuturePair = task.get(0);
61+
Pair<AbstractTask<?>, CompletableFuture<?>> classCompletableFuturePair = task.get(task.size() - 1);
6962
SwingUtilities.invokeLater(() -> {
7063
int progress = classCompletableFuturePair.getFirst().getProgress();
71-
jProgressBar.setValue(progress);
72-
jProgressBar.setStringPainted(true);
73-
jProgressBar.setString(String.format("%s:%s", classCompletableFuturePair.getFirst().getName(), progress) + "%");
64+
if (!classCompletableFuturePair.getFirst().getClass().isAnnotationPresent(Indeterminate.class)) {
65+
jProgressBar.setValue(progress);
66+
jProgressBar.setStringPainted(true);
67+
jProgressBar.setIndeterminate(false);
68+
jProgressBar.setString(String.format("%s:%s", classCompletableFuturePair.getFirst().getName(), progress) + "%");
69+
} else {
70+
jProgressBar.setString(classCompletableFuturePair.getFirst().getName());
71+
jProgressBar.setIndeterminate(true);
72+
}
7473
jProgressBar.repaint();
7574
});
7675
}
7776
}, 1, 1, TimeUnit.MILLISECONDS);
7877

79-
add(scale);
8078
JLabel label = new JLabel("\u00A9 Enaium 2022");
8179
label.setHorizontalAlignment(SwingConstants.RIGHT);
8280
add(label);

src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/ASMifierTablePanel.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public void keyReleased(KeyEvent e) {
100100
codeAreaPanel.getTextArea().setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
101101
codeAreaPanel.getTextArea().setEditable(true);
102102
StringWriter stringWriter = new StringWriter();
103+
103104
ASyncUtil.execute(() -> {
104105
classNode.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(stringWriter)));
105106
}, () -> {

src/main/java/cn/enaium/joe/gui/panel/file/tabbed/tab/classes/DecompileTabPanel.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
package cn.enaium.joe.gui.panel.file.tabbed.tab.classes;
1818

19+
import cn.enaium.joe.JavaOctetEditor;
1920
import cn.enaium.joe.service.DecompileService;
2021
import cn.enaium.joe.gui.panel.CodeAreaPanel;
22+
import cn.enaium.joe.task.DecompileTask;
2123
import cn.enaium.joe.util.ASyncUtil;
2224
import org.objectweb.asm.tree.ClassNode;
2325

@@ -32,8 +34,8 @@ public DecompileTabPanel(ClassNode classNode) {
3234
setLayout(new BorderLayout());
3335
CodeAreaPanel codeAreaPanel = new CodeAreaPanel();
3436
codeAreaPanel.getTextArea().setSyntaxEditingStyle("text/java");
35-
ASyncUtil.execute(() -> {
36-
codeAreaPanel.getTextArea().setText(DecompileService.getService().decompile(classNode));
37+
JavaOctetEditor.getInstance().task.submit(new DecompileTask(classNode)).thenAccept(it -> {
38+
codeAreaPanel.getTextArea().setText(it);
3739
});
3840
codeAreaPanel.getTextArea().setCaretPosition(0);
3941
add(codeAreaPanel);
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.task;
18+
19+
import cn.enaium.joe.annotation.Repeatable;
20+
import cn.enaium.joe.service.DecompileService;
21+
import org.objectweb.asm.tree.ClassNode;
22+
import org.tinylog.Logger;
23+
24+
/**
25+
* @author Enaium
26+
* @since 0.10.0
27+
*/
28+
@Repeatable
29+
public class DecompileTask extends AbstractTask<String> {
30+
31+
private final ClassNode classNode;
32+
33+
public DecompileTask(ClassNode classNode) {
34+
super("Decompile");
35+
this.classNode = classNode;
36+
}
37+
38+
@Override
39+
public String get() {
40+
Logger.info("DECOMPILE:{}", classNode.name);
41+
return DecompileService.getService().decompile(classNode);
42+
}
43+
}

0 commit comments

Comments
 (0)