From 9b15a255c63cbba1e17b86cf698f47295603b01a Mon Sep 17 00:00:00 2001 From: Honfika Date: Wed, 1 Jan 2014 21:12:27 +0100 Subject: [PATCH] Issue #458 Saving font settings to preserve font panel selection after program restart: individual behavior for each file --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 9 +- .../com/jpexs/decompiler/flash/TagNode.java | 10 +- .../flash/configuration/Configuration.java | 4 +- .../jpexs/decompiler/flash/gui/FontPanel.java | 14 +- .../jpexs/decompiler/flash/gui/MainPanel.java | 166 +------------ .../jpexs/decompiler/flash/gui/TagTree.java | 219 ++++++++++++++++++ .../decompiler/flash/gui/TagTreeModel.java | 2 +- .../decompiler/flash/tags/DefineFont2Tag.java | 2 +- .../decompiler/flash/tags/DefineFont3Tag.java | 2 +- .../decompiler/flash/tags/DefineFontTag.java | 4 +- .../decompiler/flash/tags/DefineText2Tag.java | 2 +- .../decompiler/flash/tags/DefineTextTag.java | 2 +- .../decompiler/flash/tags/DoABCDefineTag.java | 2 +- .../jpexs/decompiler/flash/tags/DoABCTag.java | 2 +- .../flash/tags/DoInitActionTag.java | 2 +- .../com/jpexs/decompiler/flash/tags/Tag.java | 8 +- .../flash/tags/base/CharacterIdTag.java | 8 +- .../flash/tags/base/Exportable.java | 2 +- .../decompiler/flash/tags/base/FontTag.java | 18 +- .../tags/base/MissingCharacterHandler.java | 2 +- .../decompiler/flash/tags/base/TextTag.java | 2 +- .../flash/tags/gfx/DefineCompactedFont.java | 2 +- .../flash/types/BUTTONCONDACTION.java | 2 +- .../flash/types/CLIPACTIONRECORD.java | 2 +- .../decompiler/flash/xfl/XFLConverter.java | 10 +- 25 files changed, 295 insertions(+), 203 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/gui/TagTree.java diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index b0e905291..ce65bd2f0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -430,6 +430,13 @@ public final class SWF { return file; } + public String getShortFileName() { + if (file == null) { + return ""; + } + return new File(file).getName(); + } + private void findFileAttributes() { for (Tag t : tags) { if (t instanceof FileAttributesTag) { @@ -713,7 +720,7 @@ public final class SWF { outdir += File.separator; } outdir += "scripts" + File.separator; - ret.addAll(TagNode.exportNodeAS(tags, handler, list, outdir, exportMode, evl)); + ret.addAll(TagNode.exportNodeAS(handler, list, outdir, exportMode, evl)); return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/TagNode.java b/trunk/src/com/jpexs/decompiler/flash/TagNode.java index ee30d8057..56dcaa89f 100644 --- a/trunk/src/com/jpexs/decompiler/flash/TagNode.java +++ b/trunk/src/com/jpexs/decompiler/flash/TagNode.java @@ -270,7 +270,7 @@ public class TagNode implements TreeNode { return count; } - public static List exportNodeAS(final List allTags, final AbortRetryIgnoreHandler handler, final List nodeList, final String outdir, final ExportMode exportMode, final EventListener ev) throws IOException { + public static List exportNodeAS(final AbortRetryIgnoreHandler handler, final List nodeList, final String outdir, final ExportMode exportMode, final EventListener ev) throws IOException { try { List result = CancellableWorker.call(new Callable>() { @@ -278,7 +278,7 @@ public class TagNode implements TreeNode { public List call() throws Exception { AtomicInteger cnt = new AtomicInteger(1); int totalCount = TagNode.getTagCountRecursive(nodeList); - return exportNodeAS(allTags, handler, nodeList, outdir, exportMode, cnt, totalCount, ev); + return exportNodeAS(handler, nodeList, outdir, exportMode, cnt, totalCount, ev); } }, Configuration.exportTimeout.get(), TimeUnit.SECONDS); return result; @@ -287,7 +287,7 @@ public class TagNode implements TreeNode { return new ArrayList<>(); } - public static List exportNodeAS(List allTags, AbortRetryIgnoreHandler handler, List nodeList, String outdir, ExportMode exportMode, AtomicInteger index, int count, EventListener ev) throws IOException { + public static List exportNodeAS(AbortRetryIgnoreHandler handler, List nodeList, String outdir, ExportMode exportMode, AtomicInteger index, int count, EventListener ev) throws IOException { File dir = new File(outdir); List ret = new ArrayList<>(); if (!outdir.endsWith(File.separator)) { @@ -297,7 +297,7 @@ public class TagNode implements TreeNode { for (TagNode node : nodeList) { String name = ""; if (node.tag instanceof Exportable) { - name = ((Exportable) node.tag).getExportFileName(allTags); + name = ((Exportable) node.tag).getExportFileName(); } else { name = Helper.makeFileName(node.tag.toString()); } @@ -375,7 +375,7 @@ public class TagNode implements TreeNode { } while (retry); } } else { - ret.addAll(exportNodeAS(allTags, handler, node.subItems, outdir + name, exportMode, index, count, ev)); + ret.addAll(exportNodeAS(handler, node.subItems, outdir + name, exportMode, index, count, ev)); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java index 15acf3b1b..69248bbc2 100644 --- a/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java +++ b/trunk/src/com/jpexs/decompiler/flash/configuration/Configuration.java @@ -306,8 +306,10 @@ public class Configuration { return result; } - public static void addFontPair(String fontName, String systemFontName) { + public static void addFontPair(String fileName, int fontId, String fontName, String systemFontName) { + String key = fileName + "_" + fontId + "_" + fontName; Map fontPairs = getFontPairs(); + fontPairs.put(key, systemFontName); fontPairs.put(fontName, systemFontName); StringBuilder sb = new StringBuilder(); int i = 0; diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java index ace4530ac..18e0c6955 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/FontPanel.java @@ -34,6 +34,7 @@ import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.io.File; import java.util.Set; import java.util.TreeSet; import javax.swing.Box; @@ -192,7 +193,7 @@ public class FontPanel extends JPanel implements ActionListener { SWF swf = f.getSwf(); String selectedSystemFont = (String) fontSelection.getSelectedItem(); swf.sourceFontsMap.put(f.getFontId(), selectedSystemFont); - Configuration.addFontPair(f.getFontName(swf.tags), selectedSystemFont); + Configuration.addFontPair(swf.getShortFileName(), f.getFontId(), f.getFontName(), selectedSystemFont); } } }); @@ -290,7 +291,7 @@ public class FontPanel extends JPanel implements ActionListener { } } - fontNameLabel.setText(ft.getFontName(swf.tags)); + fontNameLabel.setText(ft.getFontName()); if (fontNameTag != null) { fontDisplayNameLabel.setText(fontNameTag.fontName); fontCopyrightLabel.setText(fontNameTag.fontCopyright); @@ -303,12 +304,15 @@ public class FontPanel extends JPanel implements ActionListener { fontLeadingLabel.setText(ft.getLeading() == -1 ? translate("value.unknown") : "" + ft.getLeading()); String chars = ft.getCharacters(swf.tags); fontCharactersTextArea.setText(chars); + String key = swf.getShortFileName() + "_" + ft.getFontId() + "_" + ft.getFontName(); if (swf.sourceFontsMap.containsKey(ft.getFontId())) { fontSelection.setSelectedItem(swf.sourceFontsMap.get(ft.getFontId())); - } else if (Configuration.getFontPairs().containsKey(ft.getFontName(swf.tags))) { - fontSelection.setSelectedItem(Configuration.getFontPairs().get(ft.getFontName(swf.tags))); + } else if (Configuration.getFontPairs().containsKey(key)) { + fontSelection.setSelectedItem(Configuration.getFontPairs().get(key)); + } else if (Configuration.getFontPairs().containsKey(ft.getFontName())) { + fontSelection.setSelectedItem(Configuration.getFontPairs().get(ft.getFontName())); } else { - fontSelection.setSelectedItem(FontTag.findInstalledFontName(ft.getFontName(swf.tags))); + fontSelection.setSelectedItem(FontTag.findInstalledFontName(ft.getFontName())); } fontChangeList.componentResized(null); } diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 3c74c8229..ee6cae94c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -204,7 +204,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private FontPanel fontPanel; private JProgressBar progressBar = new JProgressBar(0, 100); private DeobfuscationDialog deobfuscationDialog; - public JTree tagTree; + public TagTree tagTree; private FlashPlayerPanel flashPanel; private JPanel contentPanel; private JPanel displayPanel; @@ -492,19 +492,8 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec cl2.show(detailPanel, DETAILCARDEMPTYPANEL); UIManager.getDefaults().put("TreeUI", BasicTreeUI.class.getName()); - tagTree = new JTree((TreeModel) null); - tagTree.setRootVisible(false); + tagTree = new TagTree((TagTreeModel) null); tagTree.addTreeSelectionListener(this); - tagTree.setBackground(Color.white); - tagTree.setUI(new BasicTreeUI() { - @Override - public void paint(Graphics g, JComponent c) { - setHashColor(Color.gray); - super.paint(g, c); - } - }); - - DragSource dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(tagTree, DnDConstants.ACTION_COPY_OR_MOVE, new DragGestureListener() { @@ -590,53 +579,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec createContextMenu(); - TreeCellRenderer tcr = new DefaultTreeCellRenderer() { - @Override - public Component getTreeCellRendererComponent( - JTree tree, - Object value, - boolean sel, - boolean expanded, - boolean leaf, - int row, - boolean hasFocus) { - - super.getTreeCellRendererComponent( - tree, value, sel, - expanded, leaf, row, - hasFocus); - Object val = value; - if (val instanceof TagNode) { - val = ((TagNode) val).tag; - } - TagType type = getTagType(val); - if (val instanceof SWFRoot) { - setIcon(View.getIcon("flash16")); - } else if (type != null) { - if (type == TagType.FOLDER && expanded) { - type = TagType.FOLDER_OPEN; - } - String tagTypeStr = type.toString().toLowerCase().replace("_", ""); - setIcon(View.getIcon(tagTypeStr + "16")); - //setToolTipText("This book is in the Tutorial series."); - } else { - //setToolTipText(null); //no tool tip - } - - String tos = value.toString(); - int sw = getFontMetrics(getFont()).stringWidth(tos); - setPreferredSize(new Dimension(18 + sw, getPreferredSize().height)); - setUI(new BasicLabelUI()); - setOpaque(false); - //setBackground(Color.green); - setBackgroundNonSelectionColor(Color.white); - //setBackgroundSelectionColor(Color.ORANGE); - return this; - } - }; - - tagTree.setCellRenderer(tcr); - statusPanel = new MainFrameStatusPanel(this); add(statusPanel, BorderLayout.SOUTH); @@ -1231,92 +1173,6 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec return ret; } - public static TagType getTagType(Object t) { - if ((t instanceof DefineFontTag) - || (t instanceof DefineFont2Tag) - || (t instanceof DefineFont3Tag) - || (t instanceof DefineFont4Tag) - || (t instanceof DefineCompactedFont)) { - return TagType.FONT; - } - if ((t instanceof DefineTextTag) - || (t instanceof DefineText2Tag) - || (t instanceof DefineEditTextTag)) { - return TagType.TEXT; - } - - if ((t instanceof DefineBitsTag) - || (t instanceof DefineBitsJPEG2Tag) - || (t instanceof DefineBitsJPEG3Tag) - || (t instanceof DefineBitsJPEG4Tag) - || (t instanceof DefineBitsLosslessTag) - || (t instanceof DefineBitsLossless2Tag)) { - return TagType.IMAGE; - } - if ((t instanceof DefineShapeTag) - || (t instanceof DefineShape2Tag) - || (t instanceof DefineShape3Tag) - || (t instanceof DefineShape4Tag)) { - return TagType.SHAPE; - } - - if ((t instanceof DefineMorphShapeTag) || (t instanceof DefineMorphShape2Tag)) { - return TagType.MORPH_SHAPE; - } - - if (t instanceof DefineSpriteTag) { - return TagType.SPRITE; - } - if ((t instanceof DefineButtonTag) || (t instanceof DefineButton2Tag)) { - return TagType.BUTTON; - } - if (t instanceof ASMSource) { - return TagType.AS; - } - if (t instanceof TreeElement) { - TreeElement te = (TreeElement) t; - if (te.getItem() instanceof ScriptPack) { - return TagType.AS; - } else { - return TagType.PACKAGE; - } - } - if (t instanceof PackageNode) { - return TagType.PACKAGE; - } - if (t instanceof FrameNode) { - return TagType.FRAME; - } - if (t instanceof ShowFrameTag) { - return TagType.SHOW_FRAME; - } - - if (t instanceof DefineVideoStreamTag) { - return TagType.MOVIE; - } - - if ((t instanceof DefineSoundTag) || (t instanceof SoundStreamHeadTag) || (t instanceof SoundStreamHead2Tag)) { - return TagType.SOUND; - } - - if (t instanceof DefineBinaryDataTag) { - return TagType.BINARY_DATA; - } - - return TagType.FOLDER; - } - - public List getTagsWithType(List list, TagType type) { - List ret = new ArrayList<>(); - for (Object o : list) { - TagType ttype = getTagType(o); - if (type == ttype) { - ret.add(o); - } - } - return ret; - } - public void renameIdentifier(SWF swf, String identifier) throws InterruptedException { String oldName = identifier; String newName = View.showInputDialog(translate("rename.enternew"), oldName); @@ -1464,25 +1320,25 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec if (n.getSwf() != swf) { continue; } - if (getTagType(n.tag) == TagType.IMAGE) { + if (TagTree.getTagType(n.tag) == TagType.IMAGE) { images.add((Tag) n.tag); } - if (getTagType(n.tag) == TagType.SHAPE) { + if (TagTree.getTagType(n.tag) == TagType.SHAPE) { shapes.add((Tag) n.tag); } - if (getTagType(n.tag) == TagType.AS) { + if (TagTree.getTagType(n.tag) == TagType.AS) { actionNodes.add(n); } - if (getTagType(n.tag) == TagType.MOVIE) { + if (TagTree.getTagType(n.tag) == TagType.MOVIE) { movies.add((Tag) n.tag); } - if (getTagType(n.tag) == TagType.SOUND) { + if (TagTree.getTagType(n.tag) == TagType.SOUND) { sounds.add((Tag) n.tag); } - if (getTagType(n.tag) == TagType.BINARY_DATA) { + if (TagTree.getTagType(n.tag) == TagType.BINARY_DATA) { binaryData.add((Tag) n.tag); } - if (getTagType(n.tag) == TagType.TEXT) { + if (TagTree.getTagType(n.tag) == TagType.TEXT) { texts.add((Tag) n.tag); } } @@ -1515,7 +1371,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec allNodes.add(asn); TagNode.setExport(allNodes, false); TagNode.setExport(actionNodes, true); - ret.addAll(TagNode.exportNodeAS(swf.tags, handler, allNodes, selFile, exportMode, null)); + ret.addAll(TagNode.exportNodeAS(handler, allNodes, selFile, exportMode, null)); } } } @@ -1996,7 +1852,7 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec public boolean handle(FontTag font, List tags, char character) { String fontName = font.getSwf().sourceFontsMap.get(font.getFontId()); if (fontName == null) { - fontName = font.getFontName(tags); + fontName = font.getFontName(); } fontName = FontTag.findInstalledFontName(fontName); Font f = new Font(fontName, font.getFontStyle(), 18); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/TagTree.java b/trunk/src/com/jpexs/decompiler/flash/gui/TagTree.java new file mode 100644 index 000000000..be5375d9c --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/gui/TagTree.java @@ -0,0 +1,219 @@ +/* + * Copyright (C) 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.FrameNode; +import com.jpexs.decompiler.flash.PackageNode; +import com.jpexs.decompiler.flash.TagNode; +import com.jpexs.decompiler.flash.abc.ScriptPack; +import com.jpexs.decompiler.flash.gui.abc.TreeElement; +import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; +import com.jpexs.decompiler.flash.tags.DefineBitsJPEG2Tag; +import com.jpexs.decompiler.flash.tags.DefineBitsJPEG3Tag; +import com.jpexs.decompiler.flash.tags.DefineBitsJPEG4Tag; +import com.jpexs.decompiler.flash.tags.DefineBitsLossless2Tag; +import com.jpexs.decompiler.flash.tags.DefineBitsLosslessTag; +import com.jpexs.decompiler.flash.tags.DefineBitsTag; +import com.jpexs.decompiler.flash.tags.DefineButton2Tag; +import com.jpexs.decompiler.flash.tags.DefineButtonTag; +import com.jpexs.decompiler.flash.tags.DefineEditTextTag; +import com.jpexs.decompiler.flash.tags.DefineFont2Tag; +import com.jpexs.decompiler.flash.tags.DefineFont3Tag; +import com.jpexs.decompiler.flash.tags.DefineFont4Tag; +import com.jpexs.decompiler.flash.tags.DefineFontTag; +import com.jpexs.decompiler.flash.tags.DefineMorphShape2Tag; +import com.jpexs.decompiler.flash.tags.DefineMorphShapeTag; +import com.jpexs.decompiler.flash.tags.DefineShape2Tag; +import com.jpexs.decompiler.flash.tags.DefineShape3Tag; +import com.jpexs.decompiler.flash.tags.DefineShape4Tag; +import com.jpexs.decompiler.flash.tags.DefineShapeTag; +import com.jpexs.decompiler.flash.tags.DefineSoundTag; +import com.jpexs.decompiler.flash.tags.DefineSpriteTag; +import com.jpexs.decompiler.flash.tags.DefineText2Tag; +import com.jpexs.decompiler.flash.tags.DefineTextTag; +import com.jpexs.decompiler.flash.tags.DefineVideoStreamTag; +import com.jpexs.decompiler.flash.tags.ShowFrameTag; +import com.jpexs.decompiler.flash.tags.SoundStreamHead2Tag; +import com.jpexs.decompiler.flash.tags.SoundStreamHeadTag; +import com.jpexs.decompiler.flash.tags.base.ASMSource; +import com.jpexs.decompiler.flash.tags.gfx.DefineCompactedFont; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.Graphics; +import java.util.ArrayList; +import java.util.List; +import javax.swing.JComponent; +import javax.swing.JTree; +import javax.swing.plaf.basic.BasicLabelUI; +import javax.swing.plaf.basic.BasicTreeUI; +import javax.swing.tree.DefaultTreeCellRenderer; + +/** + * + * @author JPEXS + */ +public class TagTree extends JTree { + + public class TagTreeCellRenderer extends DefaultTreeCellRenderer { + + @Override + public Component getTreeCellRendererComponent( + JTree tree, + Object value, + boolean sel, + boolean expanded, + boolean leaf, + int row, + boolean hasFocus) { + + super.getTreeCellRendererComponent( + tree, value, sel, + expanded, leaf, row, + hasFocus); + Object val = value; + if (val instanceof TagNode) { + val = ((TagNode) val).tag; + } + TagType type = getTagType(val); + if (val instanceof SWFRoot) { + setIcon(View.getIcon("flash16")); + } else if (type != null) { + if (type == TagType.FOLDER && expanded) { + type = TagType.FOLDER_OPEN; + } + String tagTypeStr = type.toString().toLowerCase().replace("_", ""); + setIcon(View.getIcon(tagTypeStr + "16")); + //setToolTipText("This book is in the Tutorial series."); + } else { + //setToolTipText(null); //no tool tip + } + + String tos = value.toString(); + int sw = getFontMetrics(getFont()).stringWidth(tos); + setPreferredSize(new Dimension(18 + sw, getPreferredSize().height)); + setUI(new BasicLabelUI()); + setOpaque(false); + //setBackground(Color.green); + setBackgroundNonSelectionColor(Color.white); + //setBackgroundSelectionColor(Color.ORANGE); + //setFont(getFont().deriveFont(Font.BOLD)); + return this; + } + } + + TagTree(TagTreeModel treeModel) { + super(treeModel); + setCellRenderer(new TagTreeCellRenderer()); + setRootVisible(false); + setBackground(Color.white); + setUI(new BasicTreeUI() { + @Override + public void paint(Graphics g, JComponent c) { + setHashColor(Color.gray); + super.paint(g, c); + } + }); + } + + public static TagType getTagType(Object t) { + if ((t instanceof DefineFontTag) + || (t instanceof DefineFont2Tag) + || (t instanceof DefineFont3Tag) + || (t instanceof DefineFont4Tag) + || (t instanceof DefineCompactedFont)) { + return TagType.FONT; + } + if ((t instanceof DefineTextTag) + || (t instanceof DefineText2Tag) + || (t instanceof DefineEditTextTag)) { + return TagType.TEXT; + } + + if ((t instanceof DefineBitsTag) + || (t instanceof DefineBitsJPEG2Tag) + || (t instanceof DefineBitsJPEG3Tag) + || (t instanceof DefineBitsJPEG4Tag) + || (t instanceof DefineBitsLosslessTag) + || (t instanceof DefineBitsLossless2Tag)) { + return TagType.IMAGE; + } + if ((t instanceof DefineShapeTag) + || (t instanceof DefineShape2Tag) + || (t instanceof DefineShape3Tag) + || (t instanceof DefineShape4Tag)) { + return TagType.SHAPE; + } + + if ((t instanceof DefineMorphShapeTag) || (t instanceof DefineMorphShape2Tag)) { + return TagType.MORPH_SHAPE; + } + + if (t instanceof DefineSpriteTag) { + return TagType.SPRITE; + } + if ((t instanceof DefineButtonTag) || (t instanceof DefineButton2Tag)) { + return TagType.BUTTON; + } + if (t instanceof ASMSource) { + return TagType.AS; + } + if (t instanceof TreeElement) { + TreeElement te = (TreeElement) t; + if (te.getItem() instanceof ScriptPack) { + return TagType.AS; + } else { + return TagType.PACKAGE; + } + } + if (t instanceof PackageNode) { + return TagType.PACKAGE; + } + if (t instanceof FrameNode) { + return TagType.FRAME; + } + if (t instanceof ShowFrameTag) { + return TagType.SHOW_FRAME; + } + + if (t instanceof DefineVideoStreamTag) { + return TagType.MOVIE; + } + + if ((t instanceof DefineSoundTag) || (t instanceof SoundStreamHeadTag) || (t instanceof SoundStreamHead2Tag)) { + return TagType.SOUND; + } + + if (t instanceof DefineBinaryDataTag) { + return TagType.BINARY_DATA; + } + + return TagType.FOLDER; + } + + public List getTagsWithType(List list, TagType type) { + List ret = new ArrayList<>(); + for (Object o : list) { + TagType ttype = getTagType(o); + if (type == ttype) { + ret.add(o); + } + } + return ret; + } +} diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java b/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java index 888aa2fbc..94dfb76ac 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/TagTreeModel.java @@ -72,7 +72,7 @@ public class TagTreeModel implements TreeModel { List ret = new ArrayList<>(); int frameCnt = 0; for (ContainerItem o : list) { - TagType ttype = MainPanel.getTagType(o); + TagType ttype = TagTree.getTagType(o); if (ttype == TagType.SHOW_FRAME && type == TagType.FRAME) { frameCnt++; ret.add(new TagNode(new FrameNode(o.getSwf(), frameCnt, parent, display), o.getSwf())); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java index b4bb6aabb..b26e0b0d5 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont2Tag.java @@ -267,7 +267,7 @@ public class DefineFont2Tag extends FontTag { } @Override - public String getFontName(List tags) { + public String getFontName() { String ret = fontName; if (ret.contains("" + (char) 0)) { ret = ret.substring(0, ret.indexOf(0)); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java index 23ececee1..3af4840b4 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineFont3Tag.java @@ -254,7 +254,7 @@ public class DefineFont3Tag extends FontTag { } @Override - public String getFontName(List tags) { + public String getFontName() { String ret = fontName; if (ret.contains("" + (char) 0)) { ret = ret.substring(0, ret.indexOf(0)); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java index 2f3fc9c2c..9133479e1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineFontTag.java @@ -170,8 +170,8 @@ public class DefineFontTag extends FontTag { } @Override - public String getFontName(List tags) { - ensureFontInfo(tags); + public String getFontName() { + ensureFontInfo(swf.tags); if (fontInfo2Tag != null) { return fontInfo2Tag.fontName; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java index c1e1b4363..a5151c509 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineText2Tag.java @@ -207,7 +207,7 @@ public class DefineText2Tag extends TextTag implements DrawableTag { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == fontId) { font = (FontTag) t; - fontName = font.getSystemFontName(tags); + fontName = font.getSystemFontName(); break; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java index c4ef7c6ac..8fa86d1db 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DefineTextTag.java @@ -207,7 +207,7 @@ public class DefineTextTag extends TextTag implements DrawableTag { if (t instanceof FontTag) { if (((FontTag) t).getFontId() == fontId) { font = (FontTag) t; - fontName = font.getSystemFontName(tags); + fontName = font.getSystemFontName(); break; } } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java index 88fc4a9a9..7ad76dac7 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoABCDefineTag.java @@ -56,7 +56,7 @@ public class DoABCDefineTag extends Tag implements ABCContainerTag { public static final int ID = 82; @Override - public String getName(List tags) { + public String getName() { return "DoABCDefine (" + name + ")"; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoABCTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoABCTag.java index 805a3b650..717899168 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoABCTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoABCTag.java @@ -45,7 +45,7 @@ public class DoABCTag extends Tag implements ABCContainerTag { } @Override - public String getName(List tags) { + public String getName() { return "DoABC"; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java index 11dc9e73c..38d0ab952 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/DoInitActionTag.java @@ -176,7 +176,7 @@ public class DoInitActionTag extends CharacterIdTag implements ASMSource { } @Override - public String getExportFileName(List tags) { + public String getExportFileName() { String expName = getExportName(); if ((expName == null) || expName.isEmpty()) { return super.toString(); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java index f6e57dcb9..1ddc119f3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -51,13 +51,13 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem { public Tag previousTag; protected SWF swf; - public String getName(List tags) { + public String getName() { return name; } @Override - public String getExportFileName(List tags) { - return getName(tags); + public String getExportFileName() { + return getName(); } /** @@ -263,7 +263,7 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem { */ @Override public String toString() { - return getName(swf.tags); + return getName(); } public final long getOrigDataLength() { diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java index 7f470e967..7bfccbc6d 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/CharacterIdTag.java @@ -53,7 +53,7 @@ public abstract class CharacterIdTag extends Tag { } @Override - public String getName(List tags) { + public String getName() { String nameAppend = ""; if (exportName != null) { nameAppend = ": " + exportName; @@ -61,12 +61,12 @@ public abstract class CharacterIdTag extends Tag { if (className != null) { nameAppend = ": " + className; } - return super.getName(tags) + " (" + getCharacterId() + nameAppend + ")"; + return super.getName() + " (" + getCharacterId() + nameAppend + ")"; } @Override - public String getExportFileName(List tags) { - return super.getName(tags) + "_" + getCharacterId() + (((exportName != null) && (!exportName.isEmpty())) ? "_" + exportName : ""); + public String getExportFileName() { + return super.getName() + "_" + getCharacterId() + (((exportName != null) && (!exportName.isEmpty())) ? "_" + exportName : ""); } public String getCharacterExportFileName() { diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/Exportable.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/Exportable.java index edee3661c..9dd44d32a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/Exportable.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/Exportable.java @@ -25,5 +25,5 @@ import java.util.List; */ public interface Exportable { - public String getExportFileName(List tags); + public String getExportFileName(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java index 42cd86238..01c1a2b2c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/FontTag.java @@ -67,7 +67,7 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable public abstract int getGlyphWidth(int glyphIndex); - public abstract String getFontName(List tags); + public abstract String getFontName(); public abstract boolean isSmall(); @@ -115,7 +115,7 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable public abstract String getCharacters(List tags); @Override - public String getName(List tags) { + public String getName() { String nameAppend = ""; if (exportName != null) { nameAppend = ": " + exportName; @@ -123,18 +123,22 @@ public abstract class FontTag extends CharacterTag implements AloneTag, Drawable if (className != null) { nameAppend = ": " + className; } - String fontName = getFontName(tags); + String fontName = getFontName(); if (fontName != null) { nameAppend = ": " + fontName; } return name + " (" + getCharacterId() + nameAppend + ")"; } - public String getSystemFontName(List tags) { + public String getSystemFontName() { Map fontPairs = Configuration.getFontPairs(); - String name = getFontName(tags); - if (fontPairs.containsKey(name)) { - return fontPairs.get(name); + String key = swf.getShortFileName() + "_" + getFontId() + "_" + getFontName(); + if (fontPairs.containsKey(key)) { + return fontPairs.get(key); + } + key = getFontName(); + if (fontPairs.containsKey(key)) { + return fontPairs.get(key); } return defaultFontName; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java index d15da9d10..83211c6d0 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/MissingCharacterHandler.java @@ -27,7 +27,7 @@ import java.util.List; public class MissingCharacterHandler { public boolean handle(FontTag font, List tags, char character) { - String fontName = font.getFontName(tags); + String fontName = font.getFontName(); if (!FontTag.fontNames.contains(fontName)) { return false; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java index 30bb6d0c8..1c94a1aa6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/base/TextTag.java @@ -117,7 +117,7 @@ public abstract class TextTag extends CharacterTag implements BoundedTag { glyphs = font.getGlyphShapeTable(); if (!font.hasLayout()) { - String fontName = FontTag.getFontNameWithFallback(font.getFontName(tags)); + String fontName = FontTag.getFontNameWithFallback(font.getFontName()); aFont = new Font(fontName, font.getFontStyle(), textHeight / 20); fontMetrics = bi.getGraphics().getFontMetrics(aFont); LineMetrics lm = fontMetrics.getLineMetrics("A", bi.getGraphics()); diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java b/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java index e49e13ec4..109b0b3c1 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/gfx/DefineCompactedFont.java @@ -177,7 +177,7 @@ public final class DefineCompactedFont extends FontTag implements DrawableTag { } @Override - public String getFontName(List tags) { + public String getFontName() { String ret = ""; for (int i = 0; i < fonts.size(); i++) { if (i > 0) { diff --git a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java index 75f4d4a3b..59703f376 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/BUTTONCONDACTION.java @@ -289,7 +289,7 @@ public class BUTTONCONDACTION implements ASMSource, Exportable, ContainerItem { } @Override - public String getExportFileName(List tags) { + public String getExportFileName() { return getHeader(true); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java index 9f00b4d66..218957345 100644 --- a/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java +++ b/trunk/src/com/jpexs/decompiler/flash/types/CLIPACTIONRECORD.java @@ -248,7 +248,7 @@ public class CLIPACTIONRECORD implements ASMSource, Exportable, ContainerItem { } @Override - public String getExportFileName(List tags) { + public String getExportFileName() { return eventFlags.getHeader(keyCode, true); } } diff --git a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java index 182994e27..ac37e861a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java +++ b/trunk/src/com/jpexs/decompiler/flash/xfl/XFLConverter.java @@ -2289,7 +2289,7 @@ public class XFLConverter { } } if ((fontName == null) && (font != null)) { - fontName = font.getFontName(tags); + fontName = font.getFontName(); } int fontStyle = 0; if (font != null) { @@ -2447,7 +2447,7 @@ public class XFLConverter { } if (ft != null) { if (fontName == null) { - fontName = ft.getFontName(tags); + fontName = ft.getFontName(); } italic = ft.isItalic(); bold = ft.isBold(); @@ -3082,7 +3082,7 @@ public class XFLConverter { } if (ft != null) { if (fontName == null) { - fontName = ft.getFontName(tags); + fontName = ft.getFontName(); } italic = ft.isItalic(); bold = ft.isBold(); @@ -3160,7 +3160,7 @@ public class XFLConverter { if (tag instanceof FontTag) { FontTag ft = (FontTag) tag; String fontName = null; - if (f.equals(ft.getFontName(tags))) { + if (f.equals(ft.getFontName())) { for (Tag u : tags) { if (u instanceof DefineFontNameTag) { if (((DefineFontNameTag) u).fontId == ft.getFontId()) { @@ -3169,7 +3169,7 @@ public class XFLConverter { } } if (fontName == null) { - fontName = ft.getFontName(tags); + fontName = ft.getFontName(); } String installedFont; if ((installedFont = FontTag.isFontInstalled(fontName)) != null) {