UI thread invoke fixes/improvements 2

This commit is contained in:
2016-12-28 12:57:06 +01:00
parent 5b0bd1f0c5
commit 9dc4752c04
7 changed files with 184 additions and 161 deletions
@@ -76,7 +76,7 @@ public class ASMSourceEditorPane extends DebuggableEditorPane implements CaretLi
return scriptIndex;
}
private HighlightedText highlightedText = new HighlightedText();
private HighlightedText highlightedText = HighlightedText.EMPTY;
private final List<DocsListener> docsListeners = new ArrayList<>();
@@ -34,6 +34,7 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction;
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.gui.AppStrings;
import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.decompiler.flash.gui.editor.DebuggableEditorPane;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
@@ -43,11 +44,15 @@ import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.flash.helpers.hilight.Highlighting;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import com.jpexs.decompiler.graph.DottedChain;
import com.jpexs.helpers.CancellableWorker;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CancellationException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import jsyntaxpane.SyntaxDocument;
@@ -60,7 +65,9 @@ import jsyntaxpane.TokenType;
*/
public class DecompiledEditorPane extends DebuggableEditorPane implements CaretListener {
private HighlightedText highlightedText = new HighlightedText();
private static final Logger logger = Logger.getLogger(DecompiledEditorPane.class.getName());
private HighlightedText highlightedText = HighlightedText.EMPTY;
private Highlighting currentMethodHighlight;
@@ -80,6 +87,8 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
private boolean isStatic = false;
private CancellableWorker setSourceWorker;
private final List<Runnable> scriptListeners = new ArrayList<>();
public void addScriptListener(Runnable l) {
@@ -649,6 +658,13 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
}
public void setScript(ScriptPack scriptLeaf, boolean force) {
View.checkAccess();
if (setSourceWorker != null) {
setSourceWorker.cancel(true);
setSourceWorker = null;
}
if (!force && this.script == scriptLeaf) {
return;
}
@@ -661,23 +677,76 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
if (scriptIndex > -1) {
nscript = abc.script_info.get(scriptIndex);
}
if (nscript == null) {
highlightedText = new HighlightedText();
this.script = scriptLeaf;
highlightedText = HighlightedText.EMPTY;
return;
}
setText("// " + AppStrings.translate("pleasewait") + "...");
this.script = scriptLeaf;
HighlightedText cd = null;
try {
cd = SWF.getCached(scriptLeaf);
} catch (InterruptedException ex) {
HighlightedText decompiledText = SWF.getFromCache(scriptLeaf);
boolean decompileNeeded = decompiledText == null;
if (decompileNeeded) {
CancellableWorker worker = new CancellableWorker() {
@Override
protected Void doInBackground() throws Exception {
if (decompileNeeded) {
View.execInEventDispatch(() -> {
setText("// " + AppStrings.translate("work.decompiling") + "...");
});
HighlightedText htext = SWF.getCached(scriptLeaf);
View.execInEventDispatch(() -> {
setSourceCompleted(scriptLeaf, htext);
});
}
return null;
}
@Override
protected void done() {
View.execInEventDispatch(() -> {
setSourceWorker = null;
if (!Main.isDebugging()) {
Main.stopWork();
}
try {
get();
} catch (CancellationException ex) {
setText("// " + AppStrings.translate("work.canceled"));
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error", ex);
setText("// " + AppStrings.translate("decompilationError") + ": " + ex);
}
});
}
};
worker.execute();
setSourceWorker = worker;
if (!Main.isDebugging()) {
Main.startWork(AppStrings.translate("work.decompiling") + "...", worker);
}
} else {
setSourceCompleted(scriptLeaf, decompiledText);
}
}
private void setSourceCompleted(ScriptPack scriptLeaf, HighlightedText decompiledText) {
View.checkAccess();
if (decompiledText == null) {
decompiledText = HighlightedText.EMPTY;
}
if (cd != null) {
String hilightedCode = cd.text;
highlightedText = cd;
script = scriptLeaf;
highlightedText = decompiledText;
if (decompiledText != null) {
String hilightedCode = decompiledText.text;
setText(hilightedCode);
if (highlightedText.getClassHighlights().size() > 0) {
@@ -688,15 +757,19 @@ public class DecompiledEditorPane extends DebuggableEditorPane implements CaretL
}
}
}
fireScript();
}
public void reloadClass() {
View.checkAccess();
int ci = classIndex;
SWF.uncache(script);
if (script != null && getABC() != null) {
setScript(script, true);
}
setNoTrait();
setClassIndex(ci);
}
@@ -25,7 +25,6 @@ import com.jpexs.decompiler.flash.gui.Main;
import com.jpexs.decompiler.flash.gui.TagEditorPanel;
import com.jpexs.decompiler.flash.gui.View;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.helpers.CancellableWorker;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
@@ -130,7 +129,6 @@ public class DetailPanel extends JPanel implements TagEditorPanel {
buttonsPanel.setVisible(false);
conListener = new DebuggerHandler.ConnectionListener() {
@Override
public void connected() {
synchronized (DetailPanel.this) {
@@ -305,23 +303,21 @@ public class DetailPanel extends JPanel implements TagEditorPanel {
private void saveButtonActionPerformed(ActionEvent evt) {
if (cardMap.get(selectedCard) instanceof TraitDetail) {
if (((TraitDetail) cardMap.get(selectedCard)).save()) {
CancellableWorker worker = new CancellableWorker() {
DecompiledEditorPane decompiledTextArea = abcPanel.decompiledTextArea;
int lastTrait = decompiledTextArea.lastTraitIndex;
decompiledTextArea.reloadClass();
Runnable reloadComplete = new Runnable() {
@Override
public Void doInBackground() throws Exception {
int lasttrait = abcPanel.decompiledTextArea.lastTraitIndex;
abcPanel.decompiledTextArea.reloadClass();
abcPanel.decompiledTextArea.gotoTrait(lasttrait);
return null;
}
@Override
protected void done() {
public void run() {
decompiledTextArea.removeScriptListener(this);
decompiledTextArea.gotoTrait(lastTrait);
setEditMode(false);
View.showMessageDialog(null, AppStrings.translate("message.trait.saved"), AppStrings.translate("dialog.message.title"), JOptionPane.INFORMATION_MESSAGE, Configuration.showTraitSavedMessage);
}
};
worker.execute();
decompiledTextArea.addScriptListener(reloadComplete);
}
}
}
@@ -103,11 +103,13 @@ public class UsageFrame extends AppDialog implements MouseListener {
if (usage instanceof InsideClassMultinameUsageInterface) {
final InsideClassMultinameUsageInterface icu = (InsideClassMultinameUsageInterface) usage;
Runnable settrait = new Runnable() {
DecompiledEditorPane decompiledTextArea = abcPanel.decompiledTextArea;
ABC abc = abcPanel.abc;
Runnable setTrait = new Runnable() {
@Override
public void run() {
abcPanel.decompiledTextArea.removeScriptListener(this);
abcPanel.decompiledTextArea.setClassIndex(icu.getClassIndex());
decompiledTextArea.removeScriptListener(this);
decompiledTextArea.setClassIndex(icu.getClassIndex());
if (usage instanceof TraitMultinameUsage) {
TraitMultinameUsage tmu = (TraitMultinameUsage) usage;
int traitIndex;
@@ -117,23 +119,23 @@ public class UsageFrame extends AppDialog implements MouseListener {
traitIndex = tmu.getTraitIndex();
}
if (tmu.getTraitsType() == TraitMultinameUsage.TRAITS_TYPE_INSTANCE) {
traitIndex += abcPanel.abc.class_info.get(tmu.getClassIndex()).static_traits.traits.size();
traitIndex += abc.class_info.get(tmu.getClassIndex()).static_traits.traits.size();
}
if (tmu instanceof MethodMultinameUsage) {
MethodMultinameUsage mmu = (MethodMultinameUsage) usage;
if (mmu.isInitializer() == true) {
traitIndex = abcPanel.abc.class_info.get(mmu.getClassIndex()).static_traits.traits.size() + abcPanel.abc.instance_info.get(mmu.getClassIndex()).instance_traits.traits.size() + (mmu.getTraitsType() == TraitMultinameUsage.TRAITS_TYPE_CLASS ? 1 : 0);
traitIndex = abc.class_info.get(mmu.getClassIndex()).static_traits.traits.size() + abc.instance_info.get(mmu.getClassIndex()).instance_traits.traits.size() + (mmu.getTraitsType() == TraitMultinameUsage.TRAITS_TYPE_CLASS ? 1 : 0);
}
}
abcPanel.decompiledTextArea.gotoTrait(traitIndex);
decompiledTextArea.gotoTrait(traitIndex);
}
}
};
if (abcPanel.decompiledTextArea.getClassIndex() == icu.getClassIndex() && abcPanel.abc == icu.getAbc()) {
settrait.run();
if (decompiledTextArea.getClassIndex() == icu.getClassIndex() && abc == icu.getAbc()) {
setTrait.run();
} else {
abcPanel.decompiledTextArea.addScriptListener(settrait);
decompiledTextArea.addScriptListener(setTrait);
abcPanel.hilightScript(abcPanel.getSwf(), icu.getAbc().instance_info.get(icu.getClassIndex()).getName(icu.getAbc().constants).getNameWithNamespace(icu.getAbc().constants, true).toRawString());
}
}