From dd333ce658db7458e8a22f3ebd2db242947b945b Mon Sep 17 00:00:00 2001 From: Honfika Date: Thu, 2 Jan 2014 16:22:13 +0100 Subject: [PATCH] jsyntaxpane issue fixed: Resetting content type for multiple editor panes yields NPE http://code.google.com/p/jsyntaxpane/issues/detail?id=172 singleton_editor_kit.patch applied --- .../flash/action/ActionListReader.java | 2 +- .../flash/configuration/Configuration.java | 2 + .../flash/gui/abc/DecompiledEditorPane.java | 6 +- .../flash/gui/abc/LineMarkedEditorPane.java | 6 ++ .../flash/gui/abc/UndoFixedEditorPane.java | 23 +++++- .../flash/gui/action/ActionPanel.java | 71 +++++++++++-------- .../com/jpexs/helpers/CancellableWorker.java | 2 +- 7 files changed, 74 insertions(+), 38 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java index 396b3d914..b7baa9abd 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -193,7 +193,7 @@ public class ActionListReader { actions = deobfuscateActionList(listeners, containerSWFOffset, actions, version, ip, path); updateActionLengths(actions, version); removeZeroJumps(actions, version); - } catch (TranslateException ex) { + } catch (OutOfMemoryError | StackOverflowError | TranslateException ex) { // keep orignal (not deobfuscated) actions Logger.getLogger(ActionListReader.class.getName()).log(Level.SEVERE, null, ex); } diff --git a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 69248bbc2..21baf059a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -182,6 +182,8 @@ public class Configuration { public static final ConfigurationItem guiSplitPane2DividerLocation = null; @ConfigurationDefaultInt(3) public static final ConfigurationItem saveAsExeScaleMode = null; + @ConfigurationDefaultInt(1024 * 100/*100KB*/) + public static final ConfigurationItem syntaxHighlightLimit = null; private enum OSId { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java index 12d789778..58ded436c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/DecompiledEditorPane.java @@ -494,11 +494,7 @@ public class DecompiledEditorPane extends LineMarkedEditorPane implements CaretL traitHighlights = cd.getTraitHighlights(); methodHighlights = cd.getMethodHighlights(); classHighlights = cd.getClassHighlights(); - if (hilightedCode.length() > 1024 * 1024 * 2/*2MB*/) { - setContentType("text/plain"); - } else { - setContentType("text/actionscript"); - } + setContentType("text/actionscript"); setText(hilightedCode); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java index 5433c8ef0..3caf8fc44 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/LineMarkedEditorPane.java @@ -62,6 +62,12 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane { super.setText(t); } + @Override + public void setText(String t, String contentType) { + lastLine = -1; + super.setText(t, contentType); + } + @Override public void paint(Graphics g) { g.setColor(Color.white); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java index c835ed125..64956d4c2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/UndoFixedEditorPane.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.gui.abc; +import com.jpexs.decompiler.flash.configuration.Configuration; import javax.swing.JEditorPane; import javax.swing.text.Document; import jsyntaxpane.SyntaxDocument; @@ -28,8 +29,26 @@ public class UndoFixedEditorPane extends JEditorPane { @Override public void setText(String t) { - super.setText(t); - clearUndos(); + if (getText() != t) { + super.setText(t); + clearUndos(); + } + } + + public void setText(String t, String contentType) { + if (getText() != t) { + // OK to check reference equals, because the string object should be the same + super.setText(null); + if(t.length() > Configuration.syntaxHighlightLimit.get()){ + setContentType("text/plain"); + } else { + if (!getContentType().equals(contentType)) { + setContentType(contentType); + } + } + super.setText(t); + clearUndos(); + } } public void clearUndos() { diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java index bba8cd55f..d1c07e341 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -277,7 +277,31 @@ public class ActionPanel extends JPanel implements ActionListener { return false; } - public void setText(HilightedText text) { + private void setDecompiledText(final String text) { + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + ignoreCarret = true; + decompiledEditor.setText(text, "text/actionscript"); + ignoreCarret = false; + } + }); + } + + private void setEditorText(final String text, final String contentType) { + View.execInEventDispatch(new Runnable() { + + @Override + public void run() { + ignoreCarret = true; + editor.setText(text, contentType); + ignoreCarret = false; + } + }); + } + + private void setText(HilightedText text, String contentType) { int pos = editor.getCaretPosition(); Highlighting lastH = null; for (Highlighting h : disassembledHilights) { @@ -287,22 +311,17 @@ public class ActionPanel extends JPanel implements ActionListener { lastH = h; } String offset = lastH == null ? "0" : lastH.getPropertyString("offset"); - editor.setText("; " + AppStrings.translate("work.gettinghilights") + "..."); + // getting hilights is fast now + // setEditorText("; " + AppStrings.translate("work.gettinghilights") + "...", "text/flasm"); disassembledHilights = text.instructionHilights; String stripped = text.text; - /*if(stripped.length()>30000){ - editor.setContentType("text/plain"); - }else{ - editor.setContentType("text/flasm"); - }*/ - editor.setText(stripped); + setEditorText(stripped, contentType); Highlighting h = Highlighting.search(disassembledHilights, "offset", offset); if (h != null) { if (h.startPos <= editor.getText().length()) { editor.setCaretPosition(h.startPos); } } - } private HilightedText getHilightedText(ExportMode exportMode) { @@ -321,26 +340,24 @@ public class ActionPanel extends JPanel implements ActionListener { public void setHex(ExportMode exportMode) { if (exportMode != ExportMode.HEX) { - editor.setContentType("text/flasm"); if (exportMode == ExportMode.PCODE) { if (srcNoHex == null) { srcNoHex = getHilightedText(exportMode); } - setText(srcNoHex); + setText(srcNoHex, "text/flasm"); } else { if (srcWithHex == null) { srcWithHex = getHilightedText(exportMode); } - setText(srcWithHex); + setText(srcWithHex, "text/flasm"); } } else { - editor.setContentType("text/plain"); if (srcHexOnly == null) { HilightedTextWriter writer = new HilightedTextWriter(true); Helper.byteArrayToHexWithHeader(writer, src.getActionBytes()); srcHexOnly = new HilightedText(writer); } - setText(srcHexOnly); + setText(srcHexOnly, "text/plain"); } } @@ -358,7 +375,7 @@ public class ActionPanel extends JPanel implements ActionListener { if (((newpercent > percent) || (!this.phase.equals(phase))) && newpercent <= 100) { percent = newpercent; this.phase = phase; - editor.setText("; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%..."); + setEditorText("; " + AppStrings.translate("work.disassembling") + " - " + phase + " " + percent + "%...", "text/flasm"); } } }; @@ -377,9 +394,9 @@ public class ActionPanel extends JPanel implements ActionListener { @Override protected Void doInBackground() throws Exception { - editor.setText("; " + AppStrings.translate("work.disassembling") + "..."); + setEditorText("; " + AppStrings.translate("work.disassembling") + "...", "text/flasm"); if (Configuration.decompile.get()) { - decompiledEditor.setText("//" + AppStrings.translate("work.waitingfordissasembly") + "..."); + setDecompiledText("//" + AppStrings.translate("work.waitingfordissasembly") + "..."); } DisassemblyListener listener = getDisassemblyListener(); asm.addDisassemblyListener(listener); @@ -391,7 +408,7 @@ public class ActionPanel extends JPanel implements ActionListener { srcHexOnly = null; setHex(getExportMode()); if (Configuration.decompile.get()) { - decompiledEditor.setText("//" + AppStrings.translate("work.decompiling") + "..."); + setDecompiledText("//" + AppStrings.translate("work.decompiling") + "..."); if (!useCache) { uncache(asm); } @@ -400,7 +417,7 @@ public class ActionPanel extends JPanel implements ActionListener { decompiledHilights = sc.hilights; lastDecompiled = sc.text; lastASM = asm; - decompiledEditor.setText(lastDecompiled); + setDecompiledText(lastDecompiled); } setEditMode(false); setDecompiledEditMode(false); @@ -419,9 +436,9 @@ public class ActionPanel extends JPanel implements ActionListener { try { get(); } catch (CancellationException ex) { - editor.setText("; " + AppStrings.translate("work.canceled")); + setEditorText("; " + AppStrings.translate("work.canceled"), "text/flasm"); } catch (Exception ex) { - decompiledEditor.setText("//Decompilation error: " + ex); + setDecompiledText("//Decompilation error: " + ex); } } }); @@ -580,9 +597,7 @@ public class ActionPanel extends JPanel implements ActionListener { Configuration.guiActionSplitPaneDividerLocation.set((int) pce.getNewValue()); } }); - editor.setContentType("text/flasm"); editor.setFont(new Font("Monospaced", Font.PLAIN, editor.getFont().getSize())); - decompiledEditor.setContentType("text/actionscript"); decompiledEditor.setFont(new Font("Monospaced", Font.PLAIN, decompiledEditor.getFont().getSize())); //tagTree.addTreeSelectionListener(this); @@ -660,11 +675,9 @@ public class ActionPanel extends JPanel implements ActionListener { if (val) { if (rawEdit) { - editor.setContentType("text/plain"); - setText(srcHexOnly); + setText(srcHexOnly, "text/plain"); } else { - editor.setContentType("text/flasm"); - setText(srcNoHex); + setText(srcNoHex, "text/flasm"); } editor.setEditable(true); saveButton.setVisible(true); @@ -695,7 +708,7 @@ public class ActionPanel extends JPanel implements ActionListener { int prefLines = lastASM.getPrefixLineCount(); if (val) { String newText = lastASM.removePrefixAndSuffix(lastDecompiled); - decompiledEditor.setText(newText); + setDecompiledText(newText); if (lastLine > -1) { if (lastLine - prefLines >= 0) { decompiledEditor.gotoLine(lastLine - prefLines + 1); @@ -710,7 +723,7 @@ public class ActionPanel extends JPanel implements ActionListener { decLabel.setIcon(View.getIcon("editing16")); } else { String newText = lastDecompiled; - decompiledEditor.setText(newText); + setDecompiledText(newText); if (lastLine > -1) { decompiledEditor.gotoLine(lastLine + prefLines + 1); } diff --git a/trunk/src/com/jpexs/helpers/CancellableWorker.java b/trunk/src/com/jpexs/helpers/CancellableWorker.java index 4572d5852..4c1967c65 100644 --- a/trunk/src/com/jpexs/helpers/CancellableWorker.java +++ b/trunk/src/com/jpexs/helpers/CancellableWorker.java @@ -93,7 +93,7 @@ public abstract class CancellableWorker implements RunnableFuture { @Override public final T get(long timeout, TimeUnit unit) throws InterruptedException, - ExecutionException, TimeoutException { + ExecutionException, TimeoutException { return future.get(timeout, unit); }