From 79027e085c97b44375d85a378f49bb4355ee4c8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 6 Nov 2022 21:29:33 +0100 Subject: [PATCH] Added #1232 Needed/dependent characters list in basic tag info can be expanded to show tag names --- CHANGELOG.md | 2 + .../com/jpexs/decompiler/flash/tags/Tag.java | 3 ++ .../jpexs/decompiler/flash/tags/TagInfo.java | 10 ++++ .../jpexs/decompiler/flash/gui/MainPanel.java | 4 +- .../decompiler/flash/gui/TagInfoPanel.java | 47 ++++++++++++++----- .../gui/taglistview/TagListTreeModel.java | 3 +- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f55a6709f..d3d8ba1c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - Create new empty SWF file - Checking missing needed character tags and their proper position (Marking them as red - with tooltip) - [#1432] Save as EXE from commandline +- [#1232] Needed/dependent characters list in basic tag info can be expanded to show tag names ### Fixed - Flash viewer - subtract blend mode @@ -2503,6 +2504,7 @@ All notable changes to this project will be documented in this file. [#1832]: https://www.free-decompiler.com/flash/issues/1832 [#1849]: https://www.free-decompiler.com/flash/issues/1849 [#1432]: https://www.free-decompiler.com/flash/issues/1432 +[#1232]: https://www.free-decompiler.com/flash/issues/1232 [#1712]: https://www.free-decompiler.com/flash/issues/1712 [#1857]: https://www.free-decompiler.com/flash/issues/1857 [#1455]: https://www.free-decompiler.com/flash/issues/1455 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java index 5ea6f5c95..dcfdd4a91 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -603,6 +603,9 @@ public abstract class Tag implements NeedsCharacters, Exportable, Serializable { return needed; } Timelined tim = getTimelined(); + if (tim == null) { + return needed; + } ReadOnlyTagList tags = tim.getTags(); for (int i = tags.indexOf(this) - 1; i >= -1; i--) { if (i == -1) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagInfo.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagInfo.java index 120d2fed8..6fcf75f95 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagInfo.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/tags/TagInfo.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.tags; +import com.jpexs.decompiler.flash.SWF; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; @@ -27,8 +28,17 @@ import java.util.Map; */ public class TagInfo { + private SWF swf; private final Map> infos = new LinkedHashMap<>(); + public TagInfo(SWF swf) { + this.swf = swf; + } + + public SWF getSwf() { + return swf; + } + public void addInfo(String categoryName, String name, Object value) { categoryName = "general"; // temporary add everything to general catagory List category = infos.get(categoryName); diff --git a/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 1cc6cdd48..825ab67b4 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -4056,7 +4056,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se if (treeItem instanceof Tag) { Tag tag = (Tag) treeItem; - TagInfo tagInfo = new TagInfo(); + TagInfo tagInfo = new TagInfo(treeItem.getSwf()); tag.getTagInfo(tagInfo); if (!tagInfo.isEmpty()) { tagInfoPanel.setTagInfos(tagInfo); @@ -4071,7 +4071,7 @@ public final class MainPanel extends JPanel implements TreeSelectionListener, Se frame.getNeededCharacters(needed); if (!needed.isEmpty()) { - TagInfo tagInfo = new TagInfo(); + TagInfo tagInfo = new TagInfo(treeItem.getSwf()); tagInfo.addInfo("general", "neededCharacters", Helper.joinStrings(needed, ", ")); tagInfoPanel.setTagInfos(tagInfo); showDetail(DETAILCARDTAGINFO); diff --git a/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java b/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java index 5d49a9f73..245ea7ae4 100644 --- a/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/TagInfoPanel.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.tags.TagInfo; +import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.treeitems.TreeItem; import java.awt.BorderLayout; import java.awt.Color; @@ -48,7 +49,7 @@ public class TagInfoPanel extends JPanel { private final JEditorPane editorPane = new JEditorPane(); - private TagInfo tagInfo = new TagInfo(); + private TagInfo tagInfo = new TagInfo(null); public TagInfoPanel(MainPanel mainPanel) { this.mainPanel = mainPanel; @@ -74,11 +75,13 @@ public class TagInfoPanel extends JPanel { String scheme = url.getScheme(); String strId = url.getHost(); - Integer id = Integer.parseInt(strId); + Integer id = "expand".equals(scheme) ? null : Integer.parseInt(strId); SWF swf = mainPanel.getCurrentSwf(); TreeItem item = null; - if ("char".equals(scheme)) { + if ("expand".equals(scheme)) { + updateHtmlContent(true); + } else if ("char".equals(scheme)) { item = swf.getCharacter(id); } else if ("frame".equals(scheme)) { item = swf.getTimeline().getFrame(id); @@ -97,7 +100,7 @@ public class TagInfoPanel extends JPanel { buildHtmlContent(); } - private void buildHtmlContent() { + private void updateHtmlContent(boolean expand) { String categoryName = "general"; String result = ""; Boolean flipFlop = false; @@ -119,6 +122,7 @@ public class TagInfoPanel extends JPanel { ); result += ""; + SWF swf = tagInfo.getSwf(); for (TagInfo.TagInfoItem item : items) { flipFlop = !flipFlop; @@ -160,14 +164,31 @@ public class TagInfoPanel extends JPanel { Collections.sort(sortedIds); - String scheme = frameList ? "frame" : "char"; + String scheme = frameList ? "frame" : "char"; for (int id : sortedIds) { int displayId = frameList ? id + 1 : id; - strValue += String.format("%d, ", scheme, id, displayId); + + if (!frameList && expand) { + String charName; + CharacterTag character = swf == null ? null : swf.getCharacter(id); + if (swf == null || character == null) { + charName = "???"; + } else { + charName = character.getTagName(); + } + + strValue += String.format("%s (%d)
", scheme, id, charName, id); + } else { + strValue += String.format("%d, ", scheme, id, displayId); + } } value = strValue.substring(0, strValue.length() - 2); + + if (!frameList && !expand) { + value = value + " +"; + } } result += ""; @@ -178,6 +199,10 @@ public class TagInfoPanel extends JPanel { result += "
" + value + "
"; editorPane.setText(result); + } + + private void buildHtmlContent() { + updateHtmlContent(false); Font font = UIManager.getFont("Table.font"); String bodyRule = "body { font-family: " + font.getFamily() + ";" @@ -196,20 +221,19 @@ public class TagInfoPanel extends JPanel { Color bgColor = UIManager.getColor("Table.background"); int light = (bgColor.getRed() + bgColor.getGreen() + bgColor.getBlue()) / 3; boolean nightMode = light <= 128; - + Color linkColor = Color.blue; if (nightMode) { - linkColor = new Color(0x88,0x88,0xff); + linkColor = new Color(0x88, 0x88, 0xff); } - + bodyRule += "background-color: " + getUIColorToHex("Table.background") + ";" + "color:" + getUIColorToHex("Table.foreground") + ";" + "padding:1px;" + "}" + "td { border: 1px solid " + getUIColorToHex("Table.gridColor") + "; }" + "html { border: 1px solid " + getUIColorToHex("Table.gridColor") + "; }" - + "a {color: " + getColorToHex(linkColor) + "}" - ; + + "a {color: " + getColorToHex(linkColor) + "}"; } ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); @@ -222,6 +246,7 @@ public class TagInfoPanel extends JPanel { private static String getColorToHex(Color c) { return String.format("#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue()); } + private static String getUIColorToHex(String name) { Color c = UIManager.getColor(name); return getColorToHex(c); diff --git a/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTreeModel.java b/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTreeModel.java index c4d7500fb..f3946e74c 100644 --- a/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTreeModel.java +++ b/src/com/jpexs/decompiler/flash/gui/taglistview/TagListTreeModel.java @@ -33,6 +33,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import javax.swing.event.TreeModelEvent; import javax.swing.tree.TreePath; @@ -274,7 +275,7 @@ public class TagListTreeModel extends AbstractTagTreeModel { newPath.addAll(path); newPath.add(n); - if (obj.equals(n)) { + if (Objects.equals(obj, n)) { return newPath; }