From f633fa03dfcb6a9e4528f8647147070d5fa89ebc Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 9 Apr 2015 09:40:17 +0200 Subject: [PATCH] expand swf nodes when the initial view was the dump view and the user changed it to resources view --- .../jpexs/decompiler/flash/gui/MainPanel.java | 27 ++++++++++--------- .../flash/gui/dumpview/DumpTree.java | 24 ++++++++++------- .../decompiler/flash/gui/tagtree/TagTree.java | 15 +++++++++++ 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index e22e72aa8..cdb2133c2 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -621,11 +621,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec tagTree.setSelectionPath(ttm.getTreePath(ttm.getRoot())); } ttm.updateSwfs(e); - TreeItem root = ttm.getRoot(); - int childCount = ttm.getChildCount(root); - for (int i = 0; i < childCount; i++) { - tagTree.expandPath(new TreePath(new Object[]{root, ttm.getChild(root, i)})); - } + tagTree.expandRoot(); + tagTree.expandFirstLevelNodes(); } DumpTreeModel dtm = dumpTree.getModel(); @@ -633,12 +630,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec List> expandedNodes = View.getExpandedNodes(dumpTree); dtm.updateSwfs(); View.expandTreeNodes(dumpTree, expandedNodes); - DumpInfo root = dtm.getRoot(); - int childCount = dtm.getChildCount(root); - for (int i = 0; i < childCount; i++) { - dumpTree.expandPath(new TreePath(new Object[]{root, dtm.getChild(root, i)})); - dumpTree.expandRow(i); - } + dumpTree.expandRoot(); + dumpTree.expandFirstLevelNodes(); } if (swfs.isEmpty()) { @@ -2360,6 +2353,10 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec // show welcome panel after closing swfs updateUi(); } else { + if (swf == null) { + swf = swfs.get(0).get(0); + } + updateUi(swf); } } else { @@ -2405,12 +2402,16 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec switch (view) { case VIEW_DUMP: if (dumpTree.getModel() == null) { - dumpTree.setModel(new DumpTreeModel(swfs)); + DumpTreeModel dtm = new DumpTreeModel(swfs); + dumpTree.setModel(dtm); + dumpTree.expandFirstLevelNodes(); } break; case VIEW_RESOURCES: if (tagTree.getModel() == null) { - tagTree.setModel(new TagTreeModel(swfs, Configuration.tagTreeShowEmptyFolders.get())); + TagTreeModel ttm = new TagTreeModel(swfs, Configuration.tagTreeShowEmptyFolders.get()); + tagTree.setModel(ttm); + tagTree.expandFirstLevelNodes(); } break; } diff --git a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java index b805d9942..5cbbe326a 100644 --- a/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java +++ b/src/com/jpexs/decompiler/flash/gui/dumpview/DumpTree.java @@ -290,16 +290,20 @@ public class DumpTree extends JTree implements ActionListener { public DumpTreeModel getModel() { return (DumpTreeModel) super.getModel(); } - - @Override - public void setModel(TreeModel tm) { - super.setModel(tm); - - if (tm != null) { - int rowCount = tm.getChildCount(tm.getRoot()); - for (int i = rowCount - 1; i >= 0; i--) { - expandRow(i); - } + + public void expandRoot() { + DumpTreeModel dtm = getModel(); + DumpInfo root = dtm.getRoot(); + expandPath(new TreePath(new Object[]{root})); + } + + public void expandFirstLevelNodes() { + DumpTreeModel dtm = getModel(); + DumpInfo root = dtm.getRoot(); + int childCount = dtm.getChildCount(root); + expandPath(new TreePath(new Object[]{root})); + for (int i = 0; i < childCount; i++) { + expandPath(new TreePath(new Object[]{root, dtm.getChild(root, i)})); } } } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java index a4a1185a7..1360dab45 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTree.java @@ -574,4 +574,19 @@ public class TagTree extends JTree { public TagTreeModel getModel() { return (TagTreeModel) super.getModel(); } + + public void expandRoot() { + TagTreeModel ttm = getModel(); + TreeItem root = ttm.getRoot(); + expandPath(new TreePath(new Object[]{root})); + } + + public void expandFirstLevelNodes() { + TagTreeModel ttm = getModel(); + TreeItem root = ttm.getRoot(); + int childCount = ttm.getChildCount(root); + for (int i = 0; i < childCount; i++) { + expandPath(new TreePath(new Object[]{root, ttm.getChild(root, i)})); + } + } }