From 5204b5a52a279406bc1b8a5b6625d59c0c2fcedb Mon Sep 17 00:00:00 2001 From: Honfika Date: Sun, 19 Jan 2014 15:53:17 +0100 Subject: [PATCH] Move tag from one swf to another --- .../jpexs/decompiler/flash/gui/MainPanel.java | 53 +++++++++++++++---- .../flash/gui/locales/MainFrame.properties | 1 + .../flash/gui/locales/MainFrame_hu.properties | 1 + .../com/jpexs/decompiler/flash/tags/Tag.java | 4 ++ 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java index 71ad6da3e..44ce96834 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java +++ b/trunk/src/com/jpexs/decompiler/flash/gui/MainPanel.java @@ -159,6 +159,7 @@ import javax.swing.JColorChooser; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; +import javax.swing.JMenu; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -300,27 +301,36 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec private void createContextMenu() { final JPopupMenu contextPopupMenu = new JPopupMenu(); + final JMenuItem removeMenuItem = new JMenuItem(translate("contextmenu.remove")); removeMenuItem.addActionListener(this); removeMenuItem.setActionCommand(ACTION_REMOVE_ITEM); + contextPopupMenu.add(removeMenuItem); + final JMenuItem exportSelectionMenuItem = new JMenuItem(translate("menu.file.export.selection")); exportSelectionMenuItem.setActionCommand(MainFrameRibbonMenu.ACTION_EXPORT_SEL); exportSelectionMenuItem.addActionListener(this); contextPopupMenu.add(exportSelectionMenuItem); + final JMenuItem replaceImageSelectionMenuItem = new JMenuItem(translate("button.replace")); replaceImageSelectionMenuItem.setActionCommand(ACTION_REPLACE_IMAGE); replaceImageSelectionMenuItem.addActionListener(this); contextPopupMenu.add(replaceImageSelectionMenuItem); + final JMenuItem replaceBinarySelectionMenuItem = new JMenuItem(translate("button.replace")); replaceBinarySelectionMenuItem.setActionCommand(ACTION_REPLACE_BINARY); replaceBinarySelectionMenuItem.addActionListener(this); contextPopupMenu.add(replaceBinarySelectionMenuItem); + final JMenuItem closeSelectionMenuItem = new JMenuItem(translate("contextmenu.closeSwf")); closeSelectionMenuItem.setActionCommand(ACTION_CLOSE_SWF); closeSelectionMenuItem.addActionListener(this); contextPopupMenu.add(closeSelectionMenuItem); - contextPopupMenu.add(removeMenuItem); + final JMenu moveTagMenu = new JMenu(translate("contextmenu.moveTag")); + moveTagMenu.addActionListener(this); + contextPopupMenu.add(moveTagMenu); + tagTree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { @@ -354,24 +364,45 @@ public final class MainPanel extends JPanel implements ActionListener, TreeSelec replaceImageSelectionMenuItem.setVisible(false); replaceBinarySelectionMenuItem.setVisible(false); closeSelectionMenuItem.setVisible(false); + moveTagMenu.setVisible(false); if (paths.length == 1) { - Object tagObj = paths[0].getLastPathComponent(); + TreeNode treeNode = (TreeNode) paths[0].getLastPathComponent(); - if (tagObj instanceof TreeNode) { - TreeItem tag = ((TreeNode) tagObj).getItem(); + TreeItem item = ((TreeNode) treeNode).getItem(); - if (tag instanceof ImageTag && ((ImageTag) tag).importSupported()) { - replaceImageSelectionMenuItem.setVisible(true); - } - if (tag instanceof DefineBinaryDataTag) { - replaceBinarySelectionMenuItem.setVisible(true); - } + if (item instanceof ImageTag && ((ImageTag) item).importSupported()) { + replaceImageSelectionMenuItem.setVisible(true); + } + if (item instanceof DefineBinaryDataTag) { + replaceBinarySelectionMenuItem.setVisible(true); } - if (tagObj instanceof SWFRoot) { + if (treeNode instanceof SWFRoot) { closeSelectionMenuItem.setVisible(true); } + + if (item instanceof Tag && swfs.size() > 1) { + final Tag tag = (Tag) item; + moveTagMenu.removeAll(); + for (final SWF targetSwf : swfs) { + if (targetSwf != tag.getSwf()) { + JMenuItem swfItem = new JMenuItem(targetSwf.getShortFileName()); + swfItem.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent ae) { + tag.getSwf().tags.remove(tag); + tag.setSwf(targetSwf); + targetSwf.tags.add(tag); + refreshTree(); + } + }); + moveTagMenu.add(swfItem); + } + } + moveTagMenu.setVisible(true); + } } removeMenuItem.setVisible(allSelectedIsTag); diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties index d91fac279..20bca5a73 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame.properties @@ -423,3 +423,4 @@ decompilation.unsupported = Unsupported by decompiler decompilerMark = decompiler mark fontNotFound = Font with id=%fontId% was not found. +contextmenu.moveTag = Move tag to diff --git a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties index 50bbc9d38..68b4fb73c 100644 --- a/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties +++ b/trunk/src/com/jpexs/decompiler/flash/gui/locales/MainFrame_hu.properties @@ -423,3 +423,4 @@ decompilation.unsupported = Visszaford\u00edt\u00e1s nem t\u00e1mogatott decompilerMark = visszaford\u00edt\u00e1si jel fontNotFound = Bet\u0171t\u00edpus (id=%fontId%) nem tal\u00e1lhat\u00f3. +contextmenu.moveTag = \u00c1thelyez\u00e9s ide \ No newline at end of file diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java index 596030e83..f8809a8d3 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -75,6 +75,10 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem { return swf; } + public void setSwf(SWF swf) { + this.swf = swf; + } + /** * Constructor *