From 9cb75db772a00b8b2df4d2cf37a77d42d0cdbe54 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sun, 19 Jan 2014 23:39:59 +0100 Subject: [PATCH] #463 Global search in Define*Texts parameters implemented --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 5 +- .../jpexs/decompiler/flash/gui/FontPanel.java | 4 +- .../jpexs/decompiler/flash/gui/MainPanel.java | 87 +++++++++++++------ .../decompiler/flash/gui/SearchDialog.java | 19 +++- .../flash/gui/locales/SearchDialog.properties | 1 + .../gui/locales/SearchDialog_hu.properties | 1 + .../flash/tags/DefineEditTextTag.java | 8 +- .../decompiler/flash/tags/DefineText2Tag.java | 19 ++-- .../decompiler/flash/tags/DefineTextTag.java | 19 ++-- .../decompiler/flash/tags/base/TextTag.java | 8 +- 10 files changed, 109 insertions(+), 62 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 4ae4195cc..103252f9c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -1417,15 +1417,14 @@ public final class SWF implements TreeItem { for (final Tag t : tags) { if (t instanceof TextTag) { final File file = new File(outdir + File.separator + ((TextTag) t).getCharacterId() + ".txt"); - final List ttags = this.tags; new RetryTask(new RunnableIOEx() { @Override public void run() throws IOException { try (FileOutputStream fos = new FileOutputStream(file)) { if (formatted) { - fos.write(Utf8Helper.getBytes(((TextTag) t).getFormattedText(ttags))); + fos.write(Utf8Helper.getBytes(((TextTag) t).getFormattedText())); } else { - fos.write(Utf8Helper.getBytes(((TextTag) t).getText(ttags))); + fos.write(Utf8Helper.getBytes(((TextTag) t).getText())); } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java index bf78d3154..01826414e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java @@ -127,8 +127,8 @@ public class FontPanel extends javax.swing.JPanel { for (Tag tag : swf.tags) { if (tag instanceof TextTag) { TextTag textTag = (TextTag) tag; - if (textTag.getFontIds(swf.tags).contains(fontId)) { - String text = textTag.getFormattedText(textTag.getSwf().tags); + if (textTag.getFontIds().contains(fontId)) { + String text = textTag.getFormattedText(); mainPanel.saveText(textTag, text); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 623ecd24e..1fcb58da1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -151,6 +151,7 @@ import java.util.Stack; import java.util.concurrent.CancellationException; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.Icon; @@ -187,7 +188,7 @@ import javax.swing.tree.TreeSelectionModel; * * @author JPEXS */ -public final class MainPanel extends JPanel implements ActionListener, TreeSelectionListener, Freed { +public final class MainPanel extends JPanel implements ActionListener, TreeSelectionListener, SearchListener, Freed { private final MainFrame mainFrame; private final List swfs; @@ -224,6 +225,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private static final String INTERNAL_VIEWER_CARD = "INTERNALVIEWER"; private static final String SPLIT_PANE1 = "SPLITPANE1"; private static final String WELCOME_PANEL = "WELCOMEPANEL"; + private SearchPanel textSearchPanel; private final LineMarkedEditorPane textValue; private final JSplitPane splitPane1; private final JSplitPane splitPane2; @@ -611,13 +613,14 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec add(statusPanel, BorderLayout.SOUTH); JPanel textTopPanel = new JPanel(new BorderLayout()); + textSearchPanel = new SearchPanel<>(new FlowLayout(), this); + textTopPanel.add(textSearchPanel, BorderLayout.NORTH); textValue = new LineMarkedEditorPane(); textTopPanel.add(new JScrollPane(textValue), BorderLayout.CENTER); textValue.setEditable(false); //textValue.setFont(UIManager.getFont("TextField.font")); - JPanel textButtonsPanel = new JPanel(); textButtonsPanel.setLayout(new FlowLayout()); @@ -1487,31 +1490,30 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec @Override protected Void doInBackground() throws Exception { boolean found = false; - if (swf.isAS3) { - if (abcPanel != null && abcPanel.search(txt, searchDialog.ignoreCaseCheckBox.isSelected(), searchDialog.regexpCheckBox.isSelected())) { - found = true; - View.execInEventDispatch(new Runnable() { - @Override - public void run() { - showDetail(DETAILCARDAS3NAVIGATOR); - showCard(CARDACTIONSCRIPT3PANEL); - } - }); - } - } else { - if (actionPanel.search(txt, searchDialog.ignoreCaseCheckBox.isSelected(), searchDialog.regexpCheckBox.isSelected())) { - found = true; - View.execInEventDispatch(new Runnable() { - @Override - public void run() { - showCard(CARDACTIONSCRIPTPANEL); - } - }); + if (searchDialog.searchInASRadioButton.isSelected()) { + if (swf.isAS3) { + if (abcPanel != null && abcPanel.search(txt, searchDialog.ignoreCaseCheckBox.isSelected(), searchDialog.regexpCheckBox.isSelected())) { + found = true; + View.execInEventDispatch(new Runnable() { + @Override + public void run() { + showDetail(DETAILCARDAS3NAVIGATOR); + showCard(CARDACTIONSCRIPT3PANEL); + } + }); + } } else { + if (actionPanel.search(txt, searchDialog.ignoreCaseCheckBox.isSelected(), searchDialog.regexpCheckBox.isSelected())) { + found = true; + View.execInEventDispatch(new Runnable() { + @Override + public void run() { + showCard(CARDACTIONSCRIPTPANEL); + } + }); + } } - } - - if (!found && searchDialog.searchInTextsCheckBox.isSelected()) { + } else if (searchDialog.searchInTextsRadioButton.isSelected()) { if (searchText(txt, searchDialog.ignoreCaseCheckBox.isSelected(), searchDialog.regexpCheckBox.isSelected(), swf)) { found = true; } @@ -1529,9 +1531,40 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } private boolean searchText(String txt, boolean ignoreCase, boolean regexp, SWF swf) { + if ((txt != null) && (!txt.isEmpty())) { + textSearchPanel.setOptions(ignoreCase, regexp); + List found = new ArrayList<>(); + Pattern pat = null; + if (regexp) { + pat = Pattern.compile(txt, ignoreCase ? Pattern.CASE_INSENSITIVE : 0); + } else { + pat = Pattern.compile(Pattern.quote(txt), ignoreCase ? Pattern.CASE_INSENSITIVE : 0); + } + for (Tag tag : swf.tags) { + if (tag instanceof TextTag) { + TextTag textTag = (TextTag) tag; + if (pat.matcher(textTag.getFormattedText()).find()) { + found.add(textTag); + } + } + } + textSearchPanel.setSearchText(txt); + return textSearchPanel.setResults(found); + } return false; } + @Override + public void updateSearchPos(TextTag item) { + TagTreeModel ttm = (TagTreeModel) tagTree.getModel(); + TreePath tp = ttm.getTagPath(item); + tagTree.setSelectionPath(tp); + tagTree.scrollPathToVisible(tp); + textValue.setCaretPosition(0); + + textSearchPanel.showQuickFindDialog(textValue); + } + public void autoDeobfuscateChanged() { clearCache(); if (abcPanel != null) { @@ -1914,7 +1947,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec return true; } - }, textTag.getSwf().tags, text)) { + }, text)) { return true; } } catch (ParseException ex) { @@ -2293,7 +2326,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec previewSplitPane.setDividerLocation(Configuration.guiPreviewSplitPaneDividerLocation.get(previewSplitPane.getWidth() / 2)); showDetailWithPreview(CARDTEXTPANEL); textValue.setContentType("text/swf_text"); - textValue.setText(textTag.getFormattedText(textTag.getSwf().tags)); + textValue.setText(textTag.getFormattedText()); textValue.setCaretPosition(0); } else if (tagObj instanceof FontTag) { showFontTag((FontTag) tagObj); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/SearchDialog.java b/trunk/src/com/jpexs/decompiler/flash/gui/SearchDialog.java index ea55b6fd2..1205fa3a3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/SearchDialog.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/SearchDialog.java @@ -24,12 +24,14 @@ import java.awt.event.ActionListener; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; +import javax.swing.JRadioButton; import javax.swing.JTextField; /** @@ -44,7 +46,8 @@ public class SearchDialog extends AppDialog implements ActionListener { public JTextField searchField = new MyTextField(); public JCheckBox ignoreCaseCheckBox = new JCheckBox(translate("checkbox.ignorecase")); public JCheckBox regexpCheckBox = new JCheckBox(translate("checkbox.regexp")); - public JCheckBox searchInTextsCheckBox = new JCheckBox(translate("checkbox.searchText")); + public JRadioButton searchInASRadioButton = new JRadioButton(translate("checkbox.searchAS")); + public JRadioButton searchInTextsRadioButton = new JRadioButton(translate("checkbox.searchText")); public boolean result = false; public SearchDialog() { @@ -70,11 +73,19 @@ public class SearchDialog extends AppDialog implements ActionListener { JPanel checkPanel = new JPanel(new FlowLayout()); checkPanel.add(ignoreCaseCheckBox); checkPanel.add(regexpCheckBox); - // todo: honfika: add checkbox when text search is implemented - //searchInTextsCheckBox.setSelected(true); - //checkPanel.add(searchInTextsCheckBox); cnt.add(checkPanel); + ButtonGroup group = new ButtonGroup(); + group.add(searchInASRadioButton); + group.add(searchInTextsRadioButton); + + JPanel rbPanel = new JPanel(new FlowLayout()); + searchInASRadioButton.setSelected(true); + searchInTextsRadioButton.setSelected(false); + rbPanel.add(searchInASRadioButton); + rbPanel.add(searchInTextsRadioButton); + cnt.add(rbPanel); + cnt.add(panButtons); getRootPane().setDefaultButton(okButton); View.centerScreen(this); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog.properties index 72f539391..6074c82b5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog.properties @@ -23,3 +23,4 @@ error = Error error.invalidregexp = Invalid pattern checkbox.searchText = Search in texts +checkbox.searchAS = Search in AS diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog_hu.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog_hu.properties index 6466c54fd..35d939e10 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog_hu.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/SearchDialog_hu.properties @@ -23,3 +23,4 @@ error = Hiba error.invalidregexp = \u00c9rv\u00e9nytelen minta checkbox.searchText = Keres\u00e9s a sz\u00f6vegek k\u00f6z\u00f6tt +checkbox.searchAS = Keres\u00e9s az ActionScriptekben diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java index c4f658fff..e71c04f11 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineEditTextTag.java @@ -128,7 +128,7 @@ public class DefineEditTextTag extends TextTag { } @Override - public String getText(List tags) { + public String getText() { String ret = ""; if (hasText) { ret = initialText; @@ -141,14 +141,14 @@ public class DefineEditTextTag extends TextTag { } @Override - public List getFontIds(List tags) { + public List getFontIds() { List ret = new ArrayList<>(); ret.add(fontId); return ret; } @Override - public String getFormattedText(List tags) { + public String getFormattedText() { String ret = ""; ret += "["; String[] alignValues = {"left", "right", "center", "justify"}; @@ -171,7 +171,7 @@ public class DefineEditTextTag extends TextTag { } @Override - public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException { + public boolean setFormattedText(MissingCharacterHandler missingCharHandler, String text) throws ParseException { try { TextLexer lexer = new TextLexer(new StringReader(text)); ParsedSymbol s = null; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java index 805b81897..6f4adb310 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java @@ -78,12 +78,12 @@ public class DefineText2Tag extends TextTag implements DrawableTag { } @Override - public String getText(List tags) { + public String getText() { FontTag fnt = null; String ret = ""; for (TEXTRECORD rec : textRecords) { if (rec.styleFlagsHasFont) { - for (Tag t : tags) { + for (Tag t : swf.tags) { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == rec.fontId) { fnt = ((FontTag) t); @@ -97,13 +97,13 @@ public class DefineText2Tag extends TextTag implements DrawableTag { ret += "\r\n"; } } - ret += rec.getText(tags, fnt); + ret += rec.getText(swf.tags, fnt); } return ret; } @Override - public List getFontIds(List tags) { + public List getFontIds() { List ret = new ArrayList<>(); for (TEXTRECORD rec : textRecords) { if (rec.styleFlagsHasFont) { @@ -114,7 +114,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { } @Override - public String getFormattedText(List tags) { + public String getFormattedText() { FontTag fnt = null; String ret = ""; ret += "[\r\nxmin " + textBounds.Xmin + "\r\nymin " + textBounds.Ymin + "\r\nxmax " + textBounds.Xmax + "\r\nymax " + textBounds.Ymax; @@ -136,7 +136,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { for (TEXTRECORD rec : textRecords) { String params = ""; if (rec.styleFlagsHasFont) { - for (Tag t : tags) { + for (Tag t : swf.tags) { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == rec.fontId) { fnt = ((FontTag) t); @@ -158,13 +158,13 @@ public class DefineText2Tag extends TextTag implements DrawableTag { if (params.length() > 0) { ret += "[" + params + "\r\n]"; } - ret += Helper.escapeString(rec.getText(tags, fnt)).replace("[", "\\[").replace("]", "\\]"); + ret += Helper.escapeString(rec.getText(swf.tags, fnt)).replace("[", "\\[").replace("]", "\\]"); } return ret; } @Override - public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException { + public boolean setFormattedText(MissingCharacterHandler missingCharHandler, String text) throws ParseException { List oldTextRecords = textRecords; try { TextLexer lexer = new TextLexer(new StringReader(text)); @@ -203,7 +203,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { try { fontId = Integer.parseInt(paramValue); - for (Tag t : tags) { + for (Tag t : swf.tags) { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == fontId) { font = (FontTag) t; @@ -347,6 +347,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { } String txt = (String) s.values[0]; tr.glyphEntries = new GLYPHENTRY[txt.length()]; + List tags = swf.tags; for (int i = 0; i < txt.length(); i++) { char c = txt.charAt(i); Character nextChar = null; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java index 15f9dd572..f156f7d59 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java @@ -79,12 +79,12 @@ public class DefineTextTag extends TextTag implements DrawableTag { } @Override - public String getText(List tags) { + public String getText() { FontTag fnt = null; String ret = ""; for (TEXTRECORD rec : textRecords) { if (rec.styleFlagsHasFont) { - for (Tag t : tags) { + for (Tag t : swf.tags) { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == rec.fontId) { fnt = ((FontTag) t); @@ -98,13 +98,13 @@ public class DefineTextTag extends TextTag implements DrawableTag { ret += "\r\n"; } } - ret += rec.getText(tags, fnt); + ret += rec.getText(swf.tags, fnt); } return ret; } @Override - public List getFontIds(List tags) { + public List getFontIds() { List ret = new ArrayList<>(); for (TEXTRECORD rec : textRecords) { if (rec.styleFlagsHasFont) { @@ -115,7 +115,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { } @Override - public String getFormattedText(List tags) { + public String getFormattedText() { FontTag fnt = null; String ret = ""; ret += "[\r\nxmin " + textBounds.Xmin + "\r\nymin " + textBounds.Ymin + "\r\nxmax " + textBounds.Xmax + "\r\nymax " + textBounds.Ymax; @@ -137,7 +137,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { for (TEXTRECORD rec : textRecords) { String params = ""; if (rec.styleFlagsHasFont) { - for (Tag t : tags) { + for (Tag t : swf.tags) { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == rec.fontId) { fnt = ((FontTag) t); @@ -163,14 +163,14 @@ public class DefineTextTag extends TextTag implements DrawableTag { if (fnt == null) { ret += AppStrings.translate("fontNotFound").replace("%fontId%", Integer.toString(rec.fontId)); } else { - ret += Helper.escapeString(rec.getText(tags, fnt)).replace("[", "\\[").replace("]", "\\]"); + ret += Helper.escapeString(rec.getText(swf.tags, fnt)).replace("[", "\\[").replace("]", "\\]"); } } return ret; } @Override - public boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException { + public boolean setFormattedText(MissingCharacterHandler missingCharHandler, String text) throws ParseException { List oldTextRecords = textRecords; try { TextLexer lexer = new TextLexer(new StringReader(text)); @@ -209,7 +209,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { try { fontId = Integer.parseInt(paramValue); - for (Tag t : tags) { + for (Tag t : swf.tags) { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == fontId) { font = (FontTag) t; @@ -353,6 +353,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { } String txt = (String) s.values[0]; tr.glyphEntries = new GLYPHENTRY[txt.length()]; + List tags = swf.tags; for (int i = 0; i < txt.length(); i++) { char c = txt.charAt(i); Character nextChar = null; diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index 6f731a319..a6f13a993 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -50,13 +50,13 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { public abstract MATRIX getTextMatrix(); - public abstract String getText(List tags); + public abstract String getText(); - public abstract List getFontIds(List tags); + public abstract List getFontIds(); - public abstract String getFormattedText(List tags); + public abstract String getFormattedText(); - public abstract boolean setFormattedText(MissingCharacterHandler missingCharHandler, List tags, String text) throws ParseException; + public abstract boolean setFormattedText(MissingCharacterHandler missingCharHandler, String text) throws ParseException; @Override public abstract int getCharacterId();