From 0690a69efa247e09595ff334c16732be3d8af266 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 10 Nov 2014 22:47:42 +0100 Subject: [PATCH 1/3] loading multiple embedded swfs: progress window fixed, allow to close embedded swf --- .../jpexs/decompiler/flash/gui/MainPanel.java | 29 +++++++++++++------ .../flash/gui/tagtree/TagTreeContextMenu.java | 20 ++++++++++--- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 459b64ff0..0d4a08c40 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -2216,6 +2216,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec } public void loadFromBinaryTag(final DefineBinaryDataTag binaryDataTag) { + loadFromBinaryTag(Arrays.asList(binaryDataTag)); + } + + public void loadFromBinaryTag(final List binaryDataTags) { if (Main.loadingDialog == null || Main.loadingDialog.getOwner() == null) { Main.loadingDialog = new LoadingDialog(mainFrame == null ? null : mainFrame.getWindow()); @@ -2227,19 +2231,26 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec @Override public void run() { try { - SWF bswf = new SWF(new ByteArrayInputStream(binaryDataTag.binaryData.getRangeData()), new ProgressListener() { + for (DefineBinaryDataTag binaryDataTag : binaryDataTags) { + try { + SWF bswf = new SWF(new ByteArrayInputStream(binaryDataTag.binaryData.getRangeData()), new ProgressListener() { - @Override - public void progress(int p) { - Main.loadingDialog.setPercent(p); + @Override + public void progress(int p) { + Main.loadingDialog.setPercent(p); + } + }, Configuration.parallelSpeedUp.get()); + bswf.fileTitle = "(SWF Data)"; + binaryDataTag.innerSwf = bswf; + bswf.binaryData = binaryDataTag; + } catch (IOException ex) { + //ignore } - }, Configuration.parallelSpeedUp.get()); - bswf.fileTitle = "(SWF Data)"; - binaryDataTag.innerSwf = bswf; - bswf.binaryData = binaryDataTag; - } catch (IOException | InterruptedException ex) { + } + } catch (InterruptedException ex) { //ignore } + Main.loadingDialog.setVisible(false); Main.stopWork(); } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index 7411911c3..6b2f8d821 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -194,8 +194,9 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener { allSelectedIsSwf = false; break; } else if (item instanceof SWF) { + SWF swf = (SWF) item; // Do not allow to close SWF in bundle - if (((SWF) item).swfList.isBundle) { + if (swf.swfList != null &&swf.swfList.isBundle) { allSelectedIsSwf = false; } } @@ -328,11 +329,15 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener { switch (e.getActionCommand()) { case ACTION_OPEN_SWFINSIDE: { List sel = tagTree.getSelected(tagTree); + List binaryDatas = new ArrayList<>(); for (TreeItem item : sel) { - if (item instanceof DefineBinaryDataTag) { - mainPanel.loadFromBinaryTag((DefineBinaryDataTag) item); + DefineBinaryDataTag binaryData = (DefineBinaryDataTag) item; + if (binaryData.isSwfData()) { + binaryDatas.add((DefineBinaryDataTag) item); } } + + mainPanel.loadFromBinaryTag(binaryDatas); } break; case ACTION_RAW_EDIT: { @@ -403,7 +408,14 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener { List sel = tagTree.getSelected(tagTree); for (TreeItem item : sel) { if (item instanceof SWF) { - Main.closeFile(((SWF) item).swfList); + SWF swf = (SWF) item; + if (swf.binaryData != null) { + // embedded swf + swf.binaryData.innerSwf = null; + mainPanel.refreshTree(); + } else { + Main.closeFile(swf.swfList); + } } else if (item instanceof SWFList) { Main.closeFile((SWFList) item); } From 5a8c3bcca859f7026a53768b473539db8c63d476 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 10 Nov 2014 23:42:40 +0100 Subject: [PATCH 2/3] faster expanding all treenodes --- .../jpexs/decompiler/flash/gui/MyTree.java | 63 ------------------- .../jpexs/decompiler/flash/gui/MyTreeUI.java | 60 ------------------ src/com/jpexs/decompiler/flash/gui/View.java | 10 ++- .../flash/gui/dumpview/DumpTree.java | 2 +- .../decompiler/flash/gui/tagtree/TagTree.java | 15 ++--- .../flash/gui/tagtree/TagTreeContextMenu.java | 2 +- .../flash/gui/tagtree/TagTreeModel.java | 2 +- 7 files changed, 20 insertions(+), 134 deletions(-) delete mode 100644 src/com/jpexs/decompiler/flash/gui/MyTree.java delete mode 100644 src/com/jpexs/decompiler/flash/gui/MyTreeUI.java diff --git a/src/com/jpexs/decompiler/flash/gui/MyTree.java b/src/com/jpexs/decompiler/flash/gui/MyTree.java deleted file mode 100644 index d895f35ed..000000000 --- a/src/com/jpexs/decompiler/flash/gui/MyTree.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2010-2014 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 java.awt.Color; -import javax.swing.JTree; -import javax.swing.tree.TreeModel; - -/** - * - * @author JPEXS - */ -public class MyTree extends JTree { - - public MyTree() { - setUI(new MyTreeUI()); - setBackground(Color.white); - } - - public MyTree(TreeModel newModel) { - super(newModel); - setUI(new MyTreeUI()); - setBackground(Color.white); - } - private boolean overrideIsEnabled = false; - - public void setOverrideIsEnable(boolean b) { - overrideIsEnabled = true; - } - - public boolean isOverrideIsEnable(boolean b) { - return overrideIsEnabled; - } - - @Override - public boolean isEnabled() { - if (overrideIsEnabled) { - return false; - } - return super.isEnabled(); - } - /* - @Override - public void paint(Graphics g) { - g.setColor(Color.white); - g.fillRect(0, 0, getWidth(), getHeight()); - super.paint(g); - }*/ -} diff --git a/src/com/jpexs/decompiler/flash/gui/MyTreeUI.java b/src/com/jpexs/decompiler/flash/gui/MyTreeUI.java deleted file mode 100644 index 731eb07fe..000000000 --- a/src/com/jpexs/decompiler/flash/gui/MyTreeUI.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (C) 2010-2014 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 java.awt.Graphics; -import java.awt.Insets; -import java.awt.Rectangle; -import java.lang.reflect.Field; -import javax.swing.tree.TreePath; -import org.pushingpixels.substance.internal.ui.SubstanceTreeUI; - -/** - * - * @author JPEXS - */ -class MyTreeUI extends SubstanceTreeUI { - - @Override - protected void paintHorizontalPartOfLeg(Graphics g, Rectangle clipBounds, - Insets insets, Rectangle bounds, TreePath path, int row, - boolean isExpanded, boolean hasBeenExpanded, boolean isLeaf) { - System.out.println(""); - if (this.tree instanceof MyTree) { - Field f = null; - Boolean v = false; - try { - f = SubstanceTreeUI.class.getDeclaredField("inside"); - f.setAccessible(true); - v = (Boolean) f.get(this); - f.set(this, Boolean.TRUE); - ((MyTree) this.tree).setOverrideIsEnable(true); - } catch (Throwable t) { - //want to default back to substanceUI if this fails. - } - - super.paintHorizontalPartOfLeg(g, bounds, insets, bounds, path, row, isLeaf, isLeaf, isLeaf); - try { - f.set(this, v); - ((MyTree) this.tree).setOverrideIsEnable(true); - } catch (Throwable t) { - //see above - } - } - } -//repeat for Vertical -} diff --git a/src/com/jpexs/decompiler/flash/gui/View.java b/src/com/jpexs/decompiler/flash/gui/View.java index d78bc0e7b..acca77440 100644 --- a/src/com/jpexs/decompiler/flash/gui/View.java +++ b/src/com/jpexs/decompiler/flash/gui/View.java @@ -69,6 +69,7 @@ import javax.swing.UIDefaults; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; import javax.swing.plaf.FontUIResource; +import javax.swing.plaf.TreeUI; import javax.swing.plaf.basic.BasicColorChooserUI; import javax.swing.text.JTextComponent; import javax.swing.tree.TreeModel; @@ -514,7 +515,14 @@ public class View { tree.expandPath(tp); } - public static void expandTreeNodesRecursive(JTree tree, TreePath parent, boolean expand) { + public static void expandTreeNodes(JTree tree, TreePath parent, boolean expand) { + TreeUI ui = tree.getUI(); + tree.setUI(null); + expandTreeNodesRecursive(tree, parent, expand); + tree.setUI(ui); + } + + private static void expandTreeNodesRecursive(JTree tree, TreePath parent, boolean expand) { TreeModel model = tree.getModel(); Object node = parent.getLastPathComponent(); diff --git a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java index a364f501c..116abe314 100644 --- a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java +++ b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java @@ -211,7 +211,7 @@ public class DumpTree extends JTree implements ActionListener { if (path == null) { return; } - View.expandTreeNodesRecursive(this, path, true); + View.expandTreeNodes(this, path, true); } break; case ACTION_SAVE_TO_FILE: { diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java index bf61b3214..e2e23803c 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java @@ -113,15 +113,14 @@ import com.jpexs.decompiler.flash.treeitems.TreeItem; import java.awt.Color; import java.awt.Component; import java.awt.Font; -import java.awt.Graphics; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.swing.Icon; -import javax.swing.JComponent; import javax.swing.JTree; +import javax.swing.plaf.TreeUI; import javax.swing.plaf.basic.BasicLabelUI; import javax.swing.plaf.basic.BasicTreeUI; import javax.swing.tree.DefaultTreeCellRenderer; @@ -216,13 +215,15 @@ public class TagTree extends JTree { setCellRenderer(new TagTreeCellRenderer()); setRootVisible(false); setBackground(Color.white); - setUI(new BasicTreeUI() { - @Override - public void paint(Graphics g, JComponent c) { + setRowHeight(16); + setLargeModel(true); + + TreeUI treeUI = new BasicTreeUI() { + { setHashColor(Color.gray); - super.paint(g, c); } - }); + }; + setUI(treeUI); } public void createContextMenu() { diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index 6b2f8d821..403074c66 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -364,7 +364,7 @@ public class TagTreeContextMenu extends JPopupMenu implements ActionListener { if (path == null) { return; } - View.expandTreeNodesRecursive(tagTree, path, true); + View.expandTreeNodes(tagTree, path, true); } break; case ACTION_REMOVE_ITEM: diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java index d8c565ce4..bb69f4237 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeModel.java @@ -461,7 +461,7 @@ public class TagTreeModel implements TreeModel { } else if (parentNode instanceof Frame) { return ((Frame) parentNode).innerTags.indexOf(childNode); } else if (parentNode instanceof DefineSpriteTag) { - return ((Frame) parentNode).frame; + return ((Frame) childNode).frame; } else if (parentNode instanceof DefineBinaryDataTag) { return 0; // binary data tag can have only 1 child } else if (parentNode instanceof AS2Package) { From 50ccddb4e66db6d2801556c6710f5db6049e4a2d Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Tue, 11 Nov 2014 00:05:51 +0100 Subject: [PATCH 3/3] exception fixed in hexview --- src/com/jpexs/decompiler/flash/gui/hexview/HexView.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java b/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java index b07599270..6cb63e4f3 100644 --- a/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java +++ b/src/com/jpexs/decompiler/flash/gui/hexview/HexView.java @@ -228,6 +228,9 @@ public class HexView extends JTable { private int getIdxByColAndRow(int row, int col) { int idx = -1; + if (row < 0 || col < 0) { + return -1; + } if (col > 0 && col != bytesInRow + 1) { idx = row * bytesInRow + ((col > bytesInRow + 1) ? (col - bytesInRow - 2) : (col - 1)); }