diff --git a/src/com/jpexs/decompiler/flash/gui/AsLinkageDialog.java b/src/com/jpexs/decompiler/flash/gui/AsLinkageDialog.java index d09462be6..2220bb790 100644 --- a/src/com/jpexs/decompiler/flash/gui/AsLinkageDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/AsLinkageDialog.java @@ -69,7 +69,7 @@ public class AsLinkageDialog extends AppDialog { private String selectedParentClass = null; private ExportAssetsTag originalExportAssetsTag; private ExportAssetsTag selectedExportAssetsTag; - private String originalClassName; + private String originalClassName; private Tag selectedPosition; private Timelined selectedTimelined; private int result = ERROR_OPTION; @@ -79,18 +79,18 @@ public class AsLinkageDialog extends AppDialog { private final int characterId; private int characterFrame = -1; - + private int exportAssetsCount = 0; private final JLabel errorLabel = new JLabel(); - + private final JLabel parentClassNameLabel = new JLabel(translate("class.parentname")); - + private final JRadioButton existingExportAssetsTagRadioButton = new JRadioButton(translate("linkage.notfound.exportAssets.where.existing")); private final JRadioButton newExportAssetsTagRadioButton = new JRadioButton(translate("linkage.notfound.exportAssets.where.new")); private static final Map, String> tagTypeToParentClass = new HashMap<>(); - + private Set existingNames = new HashSet<>(); static { @@ -110,7 +110,7 @@ public class AsLinkageDialog extends AppDialog { } return null; } - + public AsLinkageDialog(Window owner, SWF swf, int characterId) { super(owner); @@ -123,7 +123,6 @@ public class AsLinkageDialog extends AppDialog { } //parentClassNameTextField.setText(getParentClassFromCharacter(ch)); - int frame = 1; for (Tag t : swf.getTags()) { if (t == ch) { @@ -158,11 +157,11 @@ public class AsLinkageDialog extends AppDialog { } String originalIdentifier = ch.getExportName(); - - identifierTextField.setText(originalIdentifier); - + + identifierTextField.setText(originalIdentifier); + originalClassName = ch.getAs2ClassName(); - + if (originalClassName != null) { classNameTextField.setText(originalClassName); classNameTextField.setEnabled(false); @@ -174,18 +173,18 @@ public class AsLinkageDialog extends AppDialog { Container cnt = getContentPane(); cnt.setLayout(new BoxLayout(cnt, BoxLayout.Y_AXIS)); - + cnt.add(new JLabel(translate("identifier"))); cnt.add(identifierTextField); - + cnt.add(new JLabel(translate("classname"))); cnt.add(classNameTextField); if (originalClassName == null) { cnt.add(parentClassNameLabel); - cnt.add(parentClassNameTextField); + cnt.add(parentClassNameTextField); } - cnt.add(errorLabel); - + cnt.add(errorLabel); + if (originalClassName == null && originalExportAssetsTag == null) { ButtonGroup whereToStoreMappingButtonGroup = new ButtonGroup(); whereToStoreMappingButtonGroup.add(existingExportAssetsTagRadioButton); @@ -196,18 +195,18 @@ public class AsLinkageDialog extends AppDialog { whereToStoreMappingPanel.add(existingExportAssetsTagRadioButton); whereToStoreMappingPanel.add(newExportAssetsTagRadioButton); cnt.add(whereToStoreMappingPanel); - existingExportAssetsTagRadioButton.setSelected(true); + existingExportAssetsTagRadioButton.setSelected(true); } - + JPanel buttonsPanel = new JPanel(new FlowLayout()); proceedButton.addActionListener(this::okButtonActionPerformed); cancelButton.addActionListener(this::cancelButtonActionPerformed); buttonsPanel.add(proceedButton); buttonsPanel.add(cancelButton); - + cnt.add(buttonsPanel); - setCentralAlignment((JComponent) cnt); + setCentralAlignment((JComponent) cnt); if (exportAssetsCount == 0) { newExportAssetsTagRadioButton.setSelected(true); @@ -226,7 +225,7 @@ public class AsLinkageDialog extends AppDialog { public void stateChanged(ChangeEvent e) { checkEnabled(); } - }); + }); DocumentListener updateDocumentListener = new DocumentListener() { @Override @@ -244,7 +243,7 @@ public class AsLinkageDialog extends AppDialog { checkEnabled(); } }; - + identifierTextField.getDocument().addDocumentListener(updateDocumentListener); classNameTextField.getDocument().addDocumentListener(updateDocumentListener); parentClassNameTextField.getDocument().addDocumentListener(updateDocumentListener); @@ -272,7 +271,7 @@ public class AsLinkageDialog extends AppDialog { boolean ok = true; CharacterTag ch = swf.getCharacter(characterId); - + String oldIdentifier = ch.getExportName(); String newIdentifier = identifierTextField.getText(); String newClassName = classNameTextField.getText(); @@ -282,29 +281,29 @@ public class AsLinkageDialog extends AppDialog { proceedButton.setText(translate("button.ok")); errorLabel.setText(""); } - + if (!classNameTextField.isEnabled() && newIdentifier.isEmpty()) { ok = false; proceedButton.setText(translate("button.ok")); errorLabel.setText(translate("error.cannotRemoveIdentifierClassExists")); } - + if (newClassName.endsWith(".")) { ok = false; proceedButton.setText(translate("button.ok")); errorLabel.setText(""); } - + if (newIdentifier.isEmpty() && !newClassName.isEmpty()) { ok = false; proceedButton.setText(translate("button.ok")); errorLabel.setText(""); } - + if (!newIdentifier.isEmpty() && oldIdentifier != null && !oldIdentifier.equals(newIdentifier) && existingNames.contains(newIdentifier)) { ok = false; proceedButton.setText(translate("button.ok")); - errorLabel.setText(""); + errorLabel.setText(""); } if (ok) { @@ -312,7 +311,7 @@ public class AsLinkageDialog extends AppDialog { if (oldClassName == null && newClassName != null && ch.getSwf().getCharacterByExportName("__Packages." + newClassName) != null) { ok = false; errorLabel.setText(translate("error.alreadyExistsClass")); - } + } } if (ok) { @@ -322,7 +321,7 @@ public class AsLinkageDialog extends AppDialog { proceedButton.setText(translate("button.ok")); } else { proceedButton.setText(translate("button.proceed")); - } + } } else { proceedButton.setText(translate("button.ok")); } @@ -354,7 +353,7 @@ public class AsLinkageDialog extends AppDialog { } selectedPosition = selectTagPositionDialog.getSelectedTag(); selectedTimelined = selectTagPositionDialog.getSelectedTimelined(); - } + } } result = OK_OPTION; selectedIdentifier = identifierTextField.getText(); @@ -412,6 +411,6 @@ public class AsLinkageDialog extends AppDialog { public String getSelectedIdentifier() { return selectedIdentifier; - } + } } diff --git a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java index f4a649875..cabe64909 100644 --- a/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/tagtree/TagTreeContextMenu.java @@ -174,9 +174,9 @@ public class TagTreeContextMenu extends JPopupMenu { private final MainPanel mainPanel; private JMenuItem configurePathResolvingMenuItem; - + private JMenuItem setAsLinkageMenuItem; - + private JMenuItem setAs3ClassLinkageMenuItem; private JMenuItem expandRecursiveMenuItem; @@ -378,8 +378,7 @@ public class TagTreeContextMenu extends JPopupMenu { configurePathResolvingMenuItem.addActionListener(this::configurePathResolvingActionPerformed); configurePathResolvingMenuItem.setIcon(View.getIcon("settings16")); add(configurePathResolvingMenuItem); - - + removeMenuItem = new JMenuItem(mainPanel.translate("contextmenu.remove") + " (DEL)"); removeMenuItem.addActionListener((ActionEvent e) -> { removeItemActionPerformed(e, false); @@ -458,7 +457,7 @@ public class TagTreeContextMenu extends JPopupMenu { setAsLinkageMenuItem.addActionListener(this::setAsLinkageActionPerformed); setAsLinkageMenuItem.setIcon(View.getIcon("asclass16")); add(setAsLinkageMenuItem); - + setAs3ClassLinkageMenuItem = new JMenuItem(mainPanel.translate("contextmenu.setAs3ClassLinkage")); setAs3ClassLinkageMenuItem.addActionListener(this::setAs3ClassLinkageActionPerformed); setAs3ClassLinkageMenuItem.setIcon(View.getIcon("asclass16")); @@ -2585,7 +2584,7 @@ public class TagTreeContextMenu extends JPopupMenu { New empty DefineSprite is created in frame 1, and its name in ExportAssets tag is set to "__Packages." + cls New DoInitAction for the DefineSprite in frame 1 is created and it's filled with new cls Class code The Exportassets tag is modified with the new linkage identifier - */ + */ private void setAsLinkageActionPerformed(ActionEvent evt) { CharacterTag ch = (CharacterTag) getCurrentItem(); SWF swf = ch.getSwf(); @@ -2597,7 +2596,7 @@ public class TagTreeContextMenu extends JPopupMenu { String className = d.getSelectedClass(); String classParent = d.getSelectedParentClass(); ExportAssetsTag ea = d.getSelectedExportAssetsTag(); - + if (ea == null) { ea = new ExportAssetsTag(swf); ea.setTimelined(swf); @@ -2607,7 +2606,7 @@ public class TagTreeContextMenu extends JPopupMenu { swf.addTag(swf.indexOfTag(d.getSelectedPosition()), ea); } } - + if (!className.isEmpty()) { int frame = 1; int eaFrame = -1; @@ -2616,7 +2615,7 @@ public class TagTreeContextMenu extends JPopupMenu { for (int i = 0; i < tags.size(); i++) { Tag t = tags.get(i); if (t == ea) { - eaFrame = frame; + eaFrame = frame; } if (t instanceof ShowFrameTag) { if (frame == eaFrame) { @@ -2626,29 +2625,29 @@ public class TagTreeContextMenu extends JPopupMenu { frame++; } } - + DoInitActionTag regDoInit = new DoInitActionTag(swf); regDoInit.spriteId = ch.getCharacterId(); regDoInit.setTimelined(swf); - + ActionScript2Parser regParser = new ActionScript2Parser(swf, regDoInit); String[] parts = className.contains(".") ? className.split("\\.") : new String[]{className}; DottedChain classDottedChain = new DottedChain(parts); - + try { List regActions = regParser.actionsFromString("Object.registerClass(\"" + Helper.escapePCodeString(identifier) + "\"," + classDottedChain.toPrintableString(false) + ");", swf.getCharset()); regDoInit.setActions(regActions); } catch (ActionParseException | IOException | CompilationException | InterruptedException ex) { //ignore } - + swf.addTag(regInsertPos, regDoInit); - + int insertPos = 0; - + tags = swf.getTags(); - + for (int i = 0; i < tags.size(); i++) { Tag t = tags.get(i); if (t instanceof ShowFrameTag) { @@ -2656,8 +2655,7 @@ public class TagTreeContextMenu extends JPopupMenu { break; } } - - + int classCharacterId = swf.getNextCharacterId(); DefineSpriteTag classSprite = new DefineSpriteTag(swf); classSprite.spriteId = classCharacterId; @@ -2678,10 +2676,10 @@ public class TagTreeContextMenu extends JPopupMenu { classDoInit.setTimelined(swf); ActionScript2Parser parser = new ActionScript2Parser(swf, classDoInit); - + String[] partsParent = classParent.contains(".") ? classParent.split("\\.") : new String[]{classParent}; DottedChain dcParent = new DottedChain(partsParent); - + try { List actions = parser.actionsFromString("class " + classDottedChain.toPrintableString(false) + (classParent.isEmpty() ? "" : " extends " + dcParent.toPrintableString(false)) + "{}", swf.getCharset()); classDoInit.setActions(actions); @@ -2690,13 +2688,13 @@ public class TagTreeContextMenu extends JPopupMenu { } classSprite.setExportName(exportName); - + swf.addTag(insertPos, classSprite); swf.addTag(insertPos + 1, classExportAssets); swf.addTag(insertPos + 2, classDoInit); - - } - + + } + boolean found = false; for (int i = ea.names.size() - 1; i >= 0; i--) { if (ea.tags.get(i) == ch.getCharacterId()) { @@ -2717,12 +2715,13 @@ public class TagTreeContextMenu extends JPopupMenu { if (ea.names.isEmpty()) { swf.removeTag(ea); } - + swf.clearAllCache(); swf.assignExportNamesToSymbols(); swf.setModified(true); mainPanel.refreshTree(swf); } + /* How set class to character mapping work in AS3: a) a character is selected @@ -2770,7 +2769,7 @@ public class TagTreeContextMenu extends JPopupMenu { SymbolClassTag selectedSymbolClass = d.getSelectedSymbolClassTag(); ABCContainerTag selectedAbcContainer = d.getSelectedAbcContainer(); String className = d.getSelectedClass(); - + if (className.isEmpty() && !ch.getClassNames().isEmpty()) { SymbolClassTag sct = d.getSelectedSymbolClassTag(); for (int i = sct.tags.size() - 1; i >= 0; i--) { @@ -2781,7 +2780,7 @@ public class TagTreeContextMenu extends JPopupMenu { } if (sct.names.isEmpty()) { swf.removeTag(sct); - } + } } else { String parentClassName = d.getSelectedParentClass(); @@ -5520,13 +5519,12 @@ public class TagTreeContextMenu extends JPopupMenu { mainPanel.repaintTree(); } - public void configurePathResolvingActionPerformed(ActionEvent evt) { - SWF item = (SWF) getCurrentItem(); + SWF item = (SWF) getCurrentItem(); PathResolvingDialog dialog = new PathResolvingDialog(item, Main.getDefaultDialogsOwner()); dialog.showDialog(); } - + public void changeCharsetActionPerformed(ActionEvent evt) { SWF item = (SWF) getCurrentItem(); String newCharset = ((JMenuItem) evt.getSource()).getText();