diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 44ce96834..b48ca52f9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2152,8 +2152,9 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (tagObj instanceof ScriptPack) { final ScriptPack scriptLeaf = (ScriptPack) tagObj; final List abcList = scriptLeaf.abc.swf.abcList; - if (setSourceWorker != null) { + if (setSourceWorker != null && !setSourceWorker.isDone()) { setSourceWorker.cancel(true); + setSourceWorker = null; } if (!Main.isWorking()) { Main.startWork(AppStrings.translate("work.decompiling") + "..."); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/SearchListener.java b/trunk/src/com/jpexs/decompiler/flash/gui/SearchListener.java new file mode 100644 index 000000000..8b236ffd0 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/SearchListener.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010-2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.jpexs.decompiler.flash.gui; + +/** + * + * @author JPEXS + */ +public interface SearchListener { + + public void updateSearchPos(E item); +} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/SearchPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/SearchPanel.java new file mode 100644 index 000000000..e6f4c8029 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/SearchPanel.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2010-2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.jpexs.decompiler.flash.gui; + +import com.jpexs.decompiler.flash.AppStrings; +import java.awt.Insets; +import java.awt.LayoutManager; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.ArrayList; +import java.util.List; +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; +import javax.swing.text.JTextComponent; +import jsyntaxpane.actions.DocumentSearchData; + +/** + * + * @author JPEXS + */ +public class SearchPanel extends JPanel implements ActionListener { + static final String ACTION_SEARCH_PREV = "SEARCHPREV"; + static final String ACTION_SEARCH_NEXT = "SEARCHNEXT"; + static final String ACTION_SEARCH_CANCEL = "SEARCHCANCEL"; + + private final SearchListener listener; + + private final JLabel searchPos; + private int foundPos = 0; + private final JLabel searchForLabel; + private String searchFor; + private boolean searchIgnoreCase; + private boolean searchRegexp; + private List found = new ArrayList<>(); + + public SearchPanel(LayoutManager lm, SearchListener listener) { + super(lm); + + this.listener = listener; + + JButton prevSearchButton = new JButton(View.getIcon("prev16")); + prevSearchButton.setMargin(new Insets(3, 3, 3, 3)); + prevSearchButton.addActionListener(this); + prevSearchButton.setActionCommand(ACTION_SEARCH_PREV); + JButton nextSearchButton = new JButton(View.getIcon("next16")); + nextSearchButton.setMargin(new Insets(3, 3, 3, 3)); + nextSearchButton.addActionListener(this); + nextSearchButton.setActionCommand(ACTION_SEARCH_NEXT); + JButton cancelSearchButton = new JButton(View.getIcon("cancel16")); + cancelSearchButton.setMargin(new Insets(3, 3, 3, 3)); + cancelSearchButton.addActionListener(this); + cancelSearchButton.setActionCommand(ACTION_SEARCH_CANCEL); + searchPos = new JLabel("0/0"); + searchForLabel = new JLabel(AppStrings.translate("search.info").replace("%text%", "")); + add(searchForLabel); + add(prevSearchButton); + add(new JLabel(AppStrings.translate("search.script") + " ")); + add(searchPos); + add(nextSearchButton); + add(cancelSearchButton); + setVisible(false); + } + + public void showQuickFindDialog(JTextComponent editor) { + DocumentSearchData dsd = DocumentSearchData.getFromEditor(editor); + dsd.setPattern(searchFor, searchRegexp, searchIgnoreCase); + dsd.showQuickFindDialogEx(editor, searchIgnoreCase, searchRegexp); + } + + public void setSearchText(String txt) { + searchFor = txt; + searchForLabel.setText(AppStrings.translate("search.info").replace("%text%", txt) + " "); + } + + public boolean setResults(List results) { + found = results; + if (found.isEmpty()) { + setVisible(false); + return false; + } else { + setPos(0); + setVisible(true); + return true; + } + } + + public void setOptions(boolean ignoreCase, boolean regExp) { + searchIgnoreCase = ignoreCase; + searchRegexp = regExp; + } + + public void setPos(int pos) { + foundPos = pos; + doUpdate(); + } + + public void clear() { + foundPos = 0; + found.clear(); + } + + private void doUpdate() { + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + searchPos.setText((foundPos + 1) + "/" + found.size()); + listener.updateSearchPos(found.get(foundPos)); + } + }); + } + + @Override + public void actionPerformed(ActionEvent e) { + switch (e.getActionCommand()) { + case ACTION_SEARCH_CANCEL: + foundPos = 0; + setVisible(false); + found = new ArrayList<>(); + searchFor = null; + break; + case ACTION_SEARCH_PREV: + foundPos--; + if (foundPos < 0) { + foundPos += found.size(); + } + doUpdate(); + break; + case ACTION_SEARCH_NEXT: + foundPos = (foundPos + 1) % found.size(); + doUpdate(); + break; + } + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index bc2315287..2c34c3164 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -40,6 +40,8 @@ import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.HeaderLabel; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.MainPanel; +import com.jpexs.decompiler.flash.gui.SearchListener; +import com.jpexs.decompiler.flash.gui.SearchPanel; import com.jpexs.decompiler.flash.gui.TagTreeModel; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.gui.abc.tablemodels.DecimalTableModel; @@ -74,9 +76,8 @@ import javax.swing.*; import javax.swing.table.*; import javax.swing.tree.TreePath; import jsyntaxpane.DefaultSyntaxKit; -import jsyntaxpane.actions.DocumentSearchData; -public class ABCPanel extends JPanel implements ItemListener, ActionListener, Freed { +public class ABCPanel extends JPanel implements ItemListener, ActionListener, SearchListener, Freed { private MainPanel mainPanel; public TraitsList navigator; @@ -96,30 +97,18 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr public DetailPanel detailPanel; public JPanel navPanel; public JTabbedPane tabbedPane; - public JPanel searchPanel; - public JLabel searchPos; - private List found = new ArrayList<>(); - private List foundPath = new ArrayList<>(); - private int foundPos = 0; - private JLabel searchForLabel; - private String searchFor; - private boolean searchIgnoreCase; - private boolean searchRegexp; + public SearchPanel searchPanel; private NewTraitDialog newTraitDialog; public JLabel scriptNameLabel; static final String ACTION_ADD_TRAIT = "ADDTRAIT"; - static final String ACTION_SEARCH_CANCEL = "SEARCHCANCEL"; - static final String ACTION_SEARCH_PREV = "SEARCHPREV"; - static final String ACTION_SEARCH_NEXT = "SEARCHNEXT"; public boolean search(String txt, boolean ignoreCase, boolean regexp) { if ((txt != null) && (!txt.isEmpty())) { - searchIgnoreCase = ignoreCase; - searchRegexp = regexp; + searchPanel.setOptions(ignoreCase, regexp); TagTreeModel ttm = (TagTreeModel) mainPanel.tagTree.getModel(); TreeNode scriptsNode = ttm.getSwfRoot(mainPanel.getCurrentSwf()).scriptsNode; - found = new ArrayList<>(); + final List found = new ArrayList<>(); if (scriptsNode.getItem() instanceof ClassesListTreeModel) { ClassesListTreeModel clModel = (ClassesListTreeModel) scriptsNode.getItem(); List> allpacks = clModel.getList(); @@ -142,8 +131,10 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr public Void doInBackground() throws Exception { decompiledTextArea.cacheScriptPack(item.value, swf.abcList); if (pat.matcher(decompiledTextArea.getCachedText(item.value)).find()) { - found.add(item.value); - foundPath.add(item.key); + ABCPanelSearchResult searchResult = new ABCPanelSearchResult(); + searchResult.scriptPack = item.value; + searchResult.classPath = item.key; + found.add(searchResult); } return null; } @@ -161,18 +152,8 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr System.gc(); Main.stopWork(); - if (found.isEmpty()) { - searchPanel.setVisible(false); - return false; - } else { - foundPos = 0; - decompiledTextArea.setScript(found.get(foundPos), swf.abcList); - searchPanel.setVisible(true); - searchFor = txt; - updateSearchPos(); - searchForLabel.setText(AppStrings.translate("search.info").replace("%text%", txt) + " "); - } - return true; + searchPanel.setSearchText(txt); + return searchPanel.setResults(found); } return false; } @@ -337,7 +318,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr decompiledTextArea = new DecompiledEditorPane(this); - searchPanel = new JPanel(new FlowLayout()); + searchPanel = new SearchPanel<>(new FlowLayout(), this); decompiledScrollPane = new JScrollPane(decompiledTextArea); @@ -412,29 +393,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr Main.startWork(AppStrings.translate("work.buildingscripttree") + "..."); - JButton prevSearchButton = new JButton(View.getIcon("prev16")); - prevSearchButton.setMargin(new Insets(3, 3, 3, 3)); - prevSearchButton.addActionListener(this); - prevSearchButton.setActionCommand(ACTION_SEARCH_PREV); - - JButton nextSearchButton = new JButton(View.getIcon("next16")); - nextSearchButton.setMargin(new Insets(3, 3, 3, 3)); - nextSearchButton.addActionListener(this); - nextSearchButton.setActionCommand(ACTION_SEARCH_NEXT); - JButton cancelSearchButton = new JButton(View.getIcon("cancel16")); - cancelSearchButton.setMargin(new Insets(3, 3, 3, 3)); - cancelSearchButton.addActionListener(this); - cancelSearchButton.setActionCommand(ACTION_SEARCH_CANCEL); - searchPos = new JLabel("0/0"); - searchForLabel = new JLabel(AppStrings.translate("search.info").replace("%text%", "") + " "); - searchPanel.add(searchForLabel); - searchPanel.add(prevSearchButton); - searchPanel.add(new JLabel(AppStrings.translate("search.script") + " ")); - searchPanel.add(searchPos); - searchPanel.add(nextSearchButton); - searchPanel.add(cancelSearchButton); - searchPanel.setVisible(false); - /* splitPaneTreeVSNavigator = new JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, navPanel); @@ -557,23 +515,15 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr } - public void updateSearchPos() { - searchPos.setText((foundPos + 1) + "/" + found.size()); - ScriptPack pack = found.get(foundPos); + @Override + public void updateSearchPos(ABCPanelSearchResult item) { + ScriptPack pack = item.scriptPack; setAbc(pack.abc); decompiledTextArea.setScript(pack, swf.abcList); - hilightScript(found.get(foundPos)); + hilightScript(pack); decompiledTextArea.setCaretPosition(0); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - DocumentSearchData dsd = DocumentSearchData.getFromEditor(decompiledTextArea); - dsd.setPattern(searchFor, searchRegexp, searchIgnoreCase); - dsd.showQuickFindDialogEx(decompiledTextArea, searchIgnoreCase, searchRegexp); - } - }); - + searchPanel.showQuickFindDialog(decompiledTextArea); } @Override @@ -679,23 +629,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr decompiledTextArea.gotoTrait(traitId); } - break; - case ACTION_SEARCH_CANCEL: - foundPos = 0; - searchPanel.setVisible(false); - found = new ArrayList<>(); - searchFor = null; - break; - case ACTION_SEARCH_PREV: - foundPos--; - if (foundPos < 0) { - foundPos += found.size(); - } - updateSearchPos(); - break; - case ACTION_SEARCH_NEXT: - foundPos = (foundPos + 1) % found.size(); - updateSearchPos(); break; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java new file mode 100644 index 000000000..4513105bc --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanelSearchResult.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2010-2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.jpexs.decompiler.flash.gui.abc; + +import com.jpexs.decompiler.flash.abc.ClassPath; +import com.jpexs.decompiler.flash.abc.ScriptPack; + +/** + * + * @author JPEXS + */ +public class ABCPanelSearchResult { + + public ScriptPack scriptPack; + public ClassPath classPath; +} 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 32f51f783..061db419a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/action/ActionPanel.java @@ -31,6 +31,8 @@ import com.jpexs.decompiler.flash.gui.GraphFrame; import com.jpexs.decompiler.flash.gui.HeaderLabel; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.MainPanel; +import com.jpexs.decompiler.flash.gui.SearchListener; +import com.jpexs.decompiler.flash.gui.SearchPanel; import com.jpexs.decompiler.flash.gui.TagTreeModel; import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.gui.abc.LineMarkedEditorPane; @@ -71,18 +73,13 @@ import javax.swing.JScrollPane; import javax.swing.JSplitPane; import javax.swing.JToggleButton; import javax.swing.SwingConstants; -import javax.swing.SwingUtilities; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; import javax.swing.tree.TreePath; import jsyntaxpane.DefaultSyntaxKit; -import jsyntaxpane.actions.DocumentSearchData; -public class ActionPanel extends JPanel implements ActionListener { +public class ActionPanel extends JPanel implements ActionListener, SearchListener { - static final String ACTION_SEARCH_PREV = "SEARCHPREV"; - static final String ACTION_SEARCH_NEXT = "SEARCHNEXT"; - static final String ACTION_SEARCH_CANCEL = "SEARCHCANCEL"; static final String ACTION_GRAPH = "GRAPH"; static final String ACTION_HEX = "HEX"; static final String ACTION_HEX_ONLY = "HEXONLY"; @@ -121,14 +118,7 @@ public class ActionPanel extends JPanel implements ActionListener { private HilightedText srcHexOnly; private String lastDecompiled = ""; private ASMSource lastASM; - public JPanel searchPanel; - public JLabel searchPos; - private List found = new ArrayList<>(); - private int foundPos = 0; - private JLabel searchForLabel; - private String searchFor; - private boolean searchIgnoreCase; - private boolean searchRegexp; + public SearchPanel searchPanel; private Cache cache = Cache.getInstance(true); private CancellableWorker setSourceWorker; @@ -136,8 +126,7 @@ public class ActionPanel extends JPanel implements ActionListener { lastCode = null; lastASM = null; lastDecompiled = null; - found = new ArrayList<>(); - foundPos = 0; + searchPanel.clear(); src = null; srcWithHex = null; srcNoHex = null; @@ -230,11 +219,10 @@ public class ActionPanel extends JPanel implements ActionListener { public boolean search(String txt, boolean ignoreCase, boolean regexp) { if ((txt != null) && (!txt.isEmpty())) { - searchIgnoreCase = ignoreCase; - searchRegexp = regexp; + searchPanel.setOptions(ignoreCase, regexp); List list = SWF.createASTagList(mainPanel.getCurrentSwf().tags, null); Map asms = getASMs("", list); - found = new ArrayList<>(); + List found = new ArrayList<>(); Pattern pat = null; if (regexp) { pat = Pattern.compile(txt, ignoreCase ? Pattern.CASE_INSENSITIVE : 0); @@ -261,18 +249,8 @@ public class ActionPanel extends JPanel implements ActionListener { } Main.stopWork(); - if (found.isEmpty()) { - searchPanel.setVisible(false); - return false; - } else { - foundPos = 0; - setSource(found.get(foundPos), true); - searchPanel.setVisible(true); - searchFor = txt; - updateSearchPos(); - searchForLabel.setText(AppStrings.translate("search.info").replace("%text%", txt) + " "); - } - return true; + searchPanel.setSearchText(txt); + return searchPanel.setResults(found); } return false; } @@ -385,6 +363,7 @@ public class ActionPanel extends JPanel implements ActionListener { public void setSource(final ASMSource src, final boolean useCache) { if (setSourceWorker != null) { setSourceWorker.cancel(true); + setSourceWorker = null; } this.src = src; @@ -460,29 +439,7 @@ public class ActionPanel extends JPanel implements ActionListener { decompiledEditor = new LineMarkedEditorPane(); decompiledEditor.setEditable(false); - searchPanel = new JPanel(new FlowLayout()); - - JButton prevSearchButton = new JButton(View.getIcon("prev16")); - prevSearchButton.setMargin(new Insets(3, 3, 3, 3)); - prevSearchButton.addActionListener(this); - prevSearchButton.setActionCommand(ACTION_SEARCH_PREV); - JButton nextSearchButton = new JButton(View.getIcon("next16")); - nextSearchButton.setMargin(new Insets(3, 3, 3, 3)); - nextSearchButton.addActionListener(this); - nextSearchButton.setActionCommand(ACTION_SEARCH_NEXT); - JButton cancelSearchButton = new JButton(View.getIcon("cancel16")); - cancelSearchButton.setMargin(new Insets(3, 3, 3, 3)); - cancelSearchButton.addActionListener(this); - cancelSearchButton.setActionCommand(ACTION_SEARCH_CANCEL); - searchPos = new JLabel("0/0"); - searchForLabel = new JLabel(AppStrings.translate("search.info").replace("%text%", "")); - searchPanel.add(searchForLabel); - searchPanel.add(prevSearchButton); - searchPanel.add(new JLabel("Script ")); - searchPanel.add(searchPos); - searchPanel.add(nextSearchButton); - searchPanel.add(cancelSearchButton); - + searchPanel = new SearchPanel<>(new FlowLayout(), this); JButton graphButton = new JButton(View.getIcon("graph16")); graphButton.setActionCommand(ACTION_GRAPH); @@ -574,7 +531,6 @@ public class ActionPanel extends JPanel implements ActionListener { decPanel.add(new JScrollPane(decompiledEditor), BorderLayout.CENTER); decPanel.add(searchPanel, BorderLayout.NORTH); - searchPanel.setVisible(false); JPanel panA = new JPanel(); panA.setLayout(new BorderLayout()); panA.add(decPanel, BorderLayout.CENTER); @@ -741,23 +697,6 @@ public class ActionPanel extends JPanel implements ActionListener { @Override public void actionPerformed(ActionEvent e) { - if (e.getActionCommand().equals("SEARCHCANCEL")) { - foundPos = 0; - searchPanel.setVisible(false); - found = new ArrayList<>(); - searchFor = null; - } - if (e.getActionCommand().equals("SEARCHPREV")) { - foundPos--; - if (foundPos < 0) { - foundPos += found.size(); - } - updateSearchPos(); - } - if (e.getActionCommand().equals("SEARCHNEXT")) { - foundPos = (foundPos + 1) % found.size(); - updateSearchPos(); - } switch (e.getActionCommand()) { case ACTION_GRAPH: if (lastCode != null) { @@ -834,23 +773,15 @@ public class ActionPanel extends JPanel implements ActionListener { return exportMode; } - public void updateSearchPos() { - searchPos.setText((foundPos + 1) + "/" + found.size()); - setSource(found.get(foundPos), true); + @Override + public void updateSearchPos(ASMSource item) { TagTreeModel ttm = (TagTreeModel) mainPanel.tagTree.getModel(); - TreePath tp = ttm.getTagPath(found.get(foundPos)); + TreePath tp = ttm.getTagPath(item); mainPanel.tagTree.setSelectionPath(tp); mainPanel.tagTree.scrollPathToVisible(tp); decompiledEditor.setCaretPosition(0); - java.util.Timer t = new java.util.Timer(); - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - DocumentSearchData dsd = DocumentSearchData.getFromEditor(decompiledEditor); - dsd.setPattern(searchFor, searchRegexp, searchIgnoreCase); - dsd.showQuickFindDialogEx(decompiledEditor, searchIgnoreCase, searchRegexp); - } - }); + + searchPanel.showQuickFindDialog(decompiledEditor); } private void uncache(ASMSource pack) {