Skip to content

Commit ea6a20c

Browse files
committed
Update InfoTab.java
1 parent f134fa7 commit ea6a20c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/messageTab/Info/InfoTab.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.awt.Component;
44
import java.util.ArrayList;
55
import java.util.List;
6+
import java.util.UUID;
67

78
import javax.swing.JPanel;
89
import javax.swing.SwingUtilities;
@@ -32,6 +33,8 @@ public class InfoTab implements IMessageEditorTab {
3233

3334
int triggerTime = 1;
3435
boolean debug = false;
36+
private UUID currentTaskId = null;
37+
3538

3639
public byte[] getOriginContent() {
3740
return originContent;
@@ -125,6 +128,14 @@ public void setMessage(byte[] content, boolean isRequest) {
125128
} else if (ByteArrayUtils.equals(originContent, content)) {
126129
return;
127130
} else {
131+
UUID taskId = UUID.randomUUID();
132+
currentTaskId = taskId;
133+
134+
//setMessage() 就是在 EDT中调用的
135+
InfoTableModel model = ((InfoPanel) panel).getTable().getInfoTableModel();
136+
model.clear();
137+
model.addNewInfoEntry(new InfoEntry("Loading...", InfoEntry.Type_URL));
138+
128139
originContent = content;
129140
SwingWorker<List<InfoEntry>, Void> worker = new SwingWorker<List<InfoEntry>, Void>() {
130141
/*
@@ -167,6 +178,11 @@ protected List<InfoEntry> doInBackground() {
167178

168179
@Override
169180
protected void done() {
181+
182+
if (!taskId.equals(currentTaskId)) {
183+
return; // 丢弃旧任务的结果
184+
}
185+
170186
try {
171187
List<InfoEntry> newEntries = get();
172188
InfoTableModel model = ((InfoPanel) panel).getTable().getInfoTableModel();

0 commit comments

Comments
 (0)