From 7518d076e880acddd22f2579b4590a45e603bd27 Mon Sep 17 00:00:00 2001 From: Honfika Date: Sat, 28 Dec 2013 09:31:54 +0100 Subject: [PATCH] separating gui, classeslisttree removed (it was a duplicated code, which currently is in tagtree) --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 2 - .../decompiler/flash/gui/MainFramePanel.java | 8 +- .../jpexs/decompiler/flash/gui/SWFRoot.java | 2 + .../decompiler/flash/gui/TagTreeModel.java | 19 ++- .../decompiler/flash/gui/abc/ABCPanel.java | 54 +----- .../flash/gui/abc/ClassesListTree.java | 160 ------------------ .../decompiler/flash/gui/abc/UsageFrame.java | 1 - 7 files changed, 26 insertions(+), 220 deletions(-) delete mode 100644 trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index fa7266076..b745ff391 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -55,7 +55,6 @@ import com.jpexs.decompiler.flash.flv.AUDIODATA; import com.jpexs.decompiler.flash.flv.FLVOutputStream; import com.jpexs.decompiler.flash.flv.FLVTAG; import com.jpexs.decompiler.flash.flv.VIDEODATA; -import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel; import com.jpexs.decompiler.flash.helpers.collections.MyEntry; import com.jpexs.decompiler.flash.tags.ABCContainerTag; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; @@ -213,7 +212,6 @@ public final class SWF { public HashMap characters; public List abcList; public JPEGTablesTag jtt; - public ClassesListTreeModel classTreeModel; /** * Gets all tags with specified id diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java index 23690a289..3c781c6d3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainFramePanel.java @@ -771,7 +771,6 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree pan1.add(new JScrollPane(tagTree), BorderLayout.CENTER); pan1.add(searchPanel, BorderLayout.SOUTH); - filterField.setActionCommand(ABCPanel.ACTION_FILTER_SCRIPT); filterField.addActionListener(this); searchPanel.setVisible(false); @@ -857,6 +856,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree swfs.add(swf); swf.abcList = abcList; + tagTree.setModel(new TagTreeModel(mainFrame, swfs)); boolean hasAbc = !abcList.isEmpty(); @@ -874,7 +874,6 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree } } - tagTree.setModel(new TagTreeModel(mainFrame, swfs)); expandSwfRoots(); for (Tag t : swf.tags) { @@ -1329,7 +1328,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree } updateClassesList(); reload(true); - abcPanel.hilightScript(abcPanel.decompiledTextArea.getScriptLeaf().getPath().toString()); + abcPanel.hilightScript(abcPanel.swf, abcPanel.decompiledTextArea.getScriptLeaf().getPath().toString()); } } } @@ -1535,7 +1534,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree showDetail(DETAILCARDAS3NAVIGATOR); showCard(CARDACTIONSCRIPT3PANEL); abcPanel.setSwf(swf); - abcPanel.hilightScript(documentClass); + abcPanel.hilightScript(swf, documentClass); } } @@ -2220,6 +2219,7 @@ public final class MainFramePanel extends JPanel implements ActionListener, Tree setSourceWorker.cancel(true); } if (!Main.isWorking()) { + Main.startWork(AppStrings.translate("work.decompiling") + "..."); CancellableWorker worker = new CancellableWorker() { @Override diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/SWFRoot.java b/trunk/src/com/jpexs/decompiler/flash/gui/SWFRoot.java index 5f9c102ff..b5a480b23 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/SWFRoot.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/SWFRoot.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.TagNode; import com.jpexs.decompiler.flash.TreeNode; +import com.jpexs.decompiler.flash.gui.abc.ClassesListTreeModel; import java.util.List; /** @@ -30,6 +31,7 @@ public class SWFRoot implements TreeNode { private SWF swf; private String name; public List list; + public ClassesListTreeModel classTreeModel; public SWFRoot(SWF swf, String name, List list) { this.swf = swf; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java b/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java index 08d472c55..0b4dcaf18 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java @@ -33,7 +33,9 @@ import com.jpexs.decompiler.flash.tags.base.ContainerItem; import com.jpexs.decompiler.flash.tags.base.SoundStreamHeadTypeTag; import java.io.File; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.swing.event.TreeModelListener; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; @@ -42,18 +44,23 @@ public class TagTreeModel implements TreeModel { private TagTreeRoot root = new TagTreeRoot(); private List swfs; + private Map swfToSwfRoot; private MainFrame mainFrame; public TagTreeModel(MainFrame mainFrame, List swfs) { this.mainFrame = mainFrame; this.swfs = new ArrayList<>(); + swfToSwfRoot = new HashMap<>(); for (SWF swf : swfs) { List objs = new ArrayList<>(); objs.addAll(swf.tags); - List list = createTagList(objs, null, swf); + ClassesListTreeModel classTreeModel = new ClassesListTreeModel(swf); + List list = createTagList(objs, null, swf, classTreeModel); SWFRoot swfRoot = new SWFRoot(swf, new File(swf.getFileTitle()).getName(), list); + swfRoot.classTreeModel = classTreeModel; this.swfs.add(swfRoot); + swfToSwfRoot.put(swf, swfRoot); } } @@ -76,7 +83,7 @@ public class TagTreeModel implements TreeModel { return ret; } - private List createTagList(List list, Object parent, SWF swf) { + private List createTagList(List list, Object parent, SWF swf, ClassesListTreeModel classTreeModel) { List ret = new ArrayList<>(); List frames = getTagNodesWithType(list, TagType.FRAME, parent, true); List shapes = getTagNodesWithType(list, TagType.SHAPE, parent, true); @@ -118,7 +125,7 @@ public class TagTreeModel implements TreeModel { TagNode tti = new TagNode(t, t.getSwf()); if (((Container) t).getItemCount() > 0) { List subItems = ((Container) t).getSubItems(); - tti.subItems = createTagList(subItems, t, swf); + tti.subItems = createTagList(subItems, t, swf, classTreeModel); } //ret.add(tti); } @@ -202,7 +209,7 @@ public class TagTreeModel implements TreeModel { if (hasAbc) { actionScriptNode.subItems.clear(); - actionScriptNode.tag = swf.classTreeModel; + actionScriptNode.tag = classTreeModel; } if ((!actionScriptNode.subItems.isEmpty()) || hasAbc) { ret.add(actionScriptNode); @@ -241,6 +248,10 @@ public class TagTreeModel implements TreeModel { return ret; } + public SWFRoot getSwfRoot(SWF swf) { + return swfToSwfRoot.get(swf); + } + public TreePath getTagPath(TreeElementItem obj) { List path = new ArrayList<>(); path.add(getRoot()); 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 5c119ae29..509940f58 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -82,7 +82,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr private MainFramePanel mainFramePanel; public TraitsList navigator; - public ClassesListTree classTree; public ABC abc; public SWF swf; public JComboBox abcComboBox; @@ -97,7 +96,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr public JLabel asmLabel = new HeaderLabel(AppStrings.translate("panel.disassembled")); public JLabel decLabel = new HeaderLabel(AppStrings.translate("panel.decompiled")); public DetailPanel detailPanel; - public JTextField filterField = new MyTextField(); public JPanel navPanel; public JTabbedPane tabbedPane; public JPanel searchPanel; @@ -113,7 +111,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr public JLabel scriptNameLabel; static final String ACTION_ADD_TRAIT = "ADDTRAIT"; - public static final String ACTION_FILTER_SCRIPT = "FILTERSCRIPT"; static final String ACTION_SEARCH_CANCEL = "SEARCHCANCEL"; static final String ACTION_SEARCH_PREV = "SEARCHPREV"; static final String ACTION_SEARCH_NEXT = "SEARCHNEXT"; @@ -122,7 +119,8 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr if ((txt != null) && (!txt.isEmpty())) { searchIgnoreCase = ignoreCase; searchRegexp = regexp; - ClassesListTreeModel clModel = (ClassesListTreeModel) classTree.getModel(); + TagTreeModel ttm = (TagTreeModel) mainFramePanel.tagTree.getModel(); + ClassesListTreeModel clModel = ttm.getSwfRoot(mainFramePanel.getCurrentSwf()).classTreeModel; List> allpacks = clModel.getList(); found = new ArrayList<>(); final Pattern pat = regexp ? @@ -272,7 +270,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr this.swf = null; this.abc = null; constantTable.setModel(new DefaultTableModel()); - classTree.clearDoABCTags(); abcComboBox.setModel(new ABCComboBoxModel(new ArrayList())); navigator.clearABC(); } @@ -294,7 +291,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr public void switchAbc(int index) { listIndex = index; - classTree.setSwf(swf); if (index != -1) { this.abc = swf.abcList.get(index).getABC(); @@ -418,37 +414,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr Main.startWork(AppStrings.translate("work.buildingscripttree") + "..."); - filterField.setActionCommand(ACTION_FILTER_SCRIPT); - filterField.addActionListener(this); - - - filterField.getDocument().addDocumentListener(new DocumentListener() { - @Override - public void changedUpdate(DocumentEvent e) { - warn(); - } - - @Override - public void removeUpdate(DocumentEvent e) { - warn(); - } - - @Override - public void insertUpdate(DocumentEvent e) { - warn(); - } - - public void warn() { - doFilter(); - } - }); - - JPanel treePanel = new JPanel(); - treePanel.setLayout(new BorderLayout()); - treePanel.add(new JScrollPane(classTree = new ClassesListTree(this)), BorderLayout.CENTER); - JPanel filterPanel = new JPanel(); - filterPanel.setLayout(new BorderLayout()); - filterPanel.add(filterField, BorderLayout.CENTER); JButton prevSearchButton = new JButton(View.getIcon("prev16")); prevSearchButton.setMargin(new Insets(3, 3, 3, 3)); prevSearchButton.addActionListener(this); @@ -471,9 +436,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr searchPanel.add(nextSearchButton); searchPanel.add(cancelSearchButton); searchPanel.setVisible(false); - JLabel picLabel = new JLabel(View.getIcon("search16")); - filterPanel.add(picLabel, BorderLayout.EAST); - treePanel.add(filterPanel, BorderLayout.NORTH); /* splitPaneTreeVSNavigator = new JSplitPane(JSplitPane.VERTICAL_SPLIT, treePanel, @@ -537,10 +499,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr tabbedPane.addTab(AppStrings.translate("constants"), panConstants); } - public void doFilter() { - classTree.applyFilter(filterField.getText()); - } - public void reload() { switchAbc(listIndex); decompiledTextArea.clearScriptCache(); @@ -570,8 +528,9 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr setVisible(true); } - public void hilightScript(String name) { - ClassesListTreeModel clModel = (ClassesListTreeModel) classTree.getModel(); + public void hilightScript(SWF swf, String name) { + TagTreeModel ttm = (TagTreeModel) mainFramePanel.tagTree.getModel(); + ClassesListTreeModel clModel = ttm.getSwfRoot(swf).classTreeModel; ScriptPack pack = null; for (MyEntry item : clModel.getList()) { if (item.key.toString().equals(name)) { @@ -719,9 +678,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Fr decompiledTextArea.gotoTrait(traitId); } - break; - case ACTION_FILTER_SCRIPT: - doFilter(); break; case ACTION_SEARCH_CANCEL: foundPos = 0; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java deleted file mode 100644 index 8bf3bd471..000000000 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/ClassesListTree.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2010-2013 JPEXS, Paolo Cancedda - * - * 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.SWF; -import com.jpexs.decompiler.flash.abc.ScriptPack; -import com.jpexs.decompiler.flash.abc.types.traits.Trait; -import com.jpexs.decompiler.flash.abc.types.traits.TraitClass; -import com.jpexs.decompiler.flash.gui.AppStrings; -import com.jpexs.decompiler.flash.gui.Main; -import com.jpexs.decompiler.flash.gui.View; -import com.jpexs.helpers.CancellableWorker; -import java.util.ArrayList; -import java.util.List; -import javax.swing.JTree; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.DefaultTreeCellRenderer; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; - -public final class ClassesListTree extends JTree implements TreeSelectionListener { - - private ABCPanel abcPanel; - private SWF swf; - - public void selectClass(int classIndex) { - ClassesListTreeModel model = (ClassesListTreeModel) getModel(); - TreeElement selectedElement = model.getElementByClassIndex(classIndex); - TreePath treePath = selectedElement.getTreePath(); - setSelectionPath(treePath); - scrollPathToVisible(treePath); - } - - public ClassesListTree(ABCPanel abcPanel) { - this.abcPanel = abcPanel; - addTreeSelectionListener(this); - DefaultTreeCellRenderer treeRenderer = new DefaultTreeCellRenderer(); - treeRenderer.setLeafIcon(View.getIcon("as16")); - setCellRenderer(treeRenderer); - } - - public List getSelectedScripts() { - TreeSelectionModel tsm = getSelectionModel(); - final List selectedScripts = new ArrayList<>(); - TreePath[] tps = tsm.getSelectionPaths(); - if (tps == null) { - return selectedScripts; - } - for (TreePath tp : tps) { - TreeElement te = (TreeElement) tp.getLastPathComponent(); - if (te.isLeaf()) { - Object item = te.getItem(); - if (item instanceof ScriptPack) { - selectedScripts.add((ScriptPack) item); - } - } else { - TreeVisitor tvi = new TreeVisitor() { - @Override - public void onBranch(TreeElement branch) { - } - - @Override - public void onLeaf(TreeElement leaf) { - Object item = leaf.getItem(); - if (item instanceof ScriptPack) { - selectedScripts.add((ScriptPack) item); - } - } - }; - te.visitBranches(tvi); - te.visitLeafs(tvi); - } - } - return selectedScripts; - } - - public void clearDoABCTags() { - this.swf = null; - setModel(null); - } - - public void setSwf(SWF swf) { - if (swf != this.swf) { - this.swf = swf; - if (swf.classTreeModel == null) { - swf.classTreeModel = new ClassesListTreeModel(swf); - } - setModel(swf.classTreeModel); - } - } - - public void applyFilter(String filter) { - getModel().setFilter(filter); - } - - @Override - public ClassesListTreeModel getModel() { - return (ClassesListTreeModel) super.getModel(); - } - - @Override - public void valueChanged(TreeSelectionEvent e) { - if (Main.isWorking()) { - return; - } - final TreeElement tp = (TreeElement) getLastSelectedPathComponent(); - if (tp == null) { - return; - } - Object item = tp.getItem(); - if (item instanceof ScriptPack) { - final ScriptPack scriptLeaf = (ScriptPack) item; - if (!Main.isWorking()) { - Main.startWork(AppStrings.translate("work.decompiling") + "..."); - new CancellableWorker() { - @Override - public Void doInBackground() throws Exception { - int classIndex = -1; - for (Trait t : scriptLeaf.abc.script_info[scriptLeaf.scriptIndex].traits.traits) { - if (t instanceof TraitClass) { - classIndex = ((TraitClass) t).class_info; - break; - } - } - abcPanel.navigator.setABC(swf.abcList, scriptLeaf.abc); - abcPanel.navigator.setClassIndex(classIndex, scriptLeaf.scriptIndex); - abcPanel.setAbc(scriptLeaf.abc); - abcPanel.decompiledTextArea.setScript(scriptLeaf, swf.abcList); - abcPanel.decompiledTextArea.setClassIndex(classIndex); - abcPanel.decompiledTextArea.setNoTrait(); - abcPanel.detailPanel.methodTraitPanel.methodCodePanel.clear(); - return null; - } - - @Override - protected void done() { - Main.stopWork(); - } - }.execute(); - } - - } - - } -} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java b/trunk/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java index 10a1ce75c..78fb34d1b 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/abc/UsageFrame.java @@ -87,7 +87,6 @@ public class UsageFrame extends AppFrame implements ActionListener, MouseListene MultinameUsage usage = usageListModel.getUsage(usageList.getSelectedIndex()); if (usage instanceof InsideClassMultinameUsage) { InsideClassMultinameUsage icu = (InsideClassMultinameUsage) usage; - abcPanel.classTree.selectClass(icu.classIndex); try { Thread.sleep(100); } catch (InterruptedException ex) {