From 1de608207f8be088e42096d6914ffdded59a2045 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 3 May 2015 10:29:05 +0200 Subject: [PATCH] action lsiteners converted to java 8 member references 2 --- .../flash/gui/ActionRedirector.java | 42 -- .../flash/gui/MainFrameClassicMenu.java | 355 ++---------- .../decompiler/flash/gui/MainFrameMenu.java | 303 ++++++++-- .../flash/gui/MainFrameRibbonMenu.java | 522 ++++-------------- .../decompiler/flash/gui/PreviewPanel.java | 3 +- .../flash/gui/ReplaceTraceDialog.java | 4 +- .../decompiler/flash/gui/abc/ABCPanel.java | 337 ++++++----- 7 files changed, 566 insertions(+), 1000 deletions(-) delete mode 100644 src/com/jpexs/decompiler/flash/gui/ActionRedirector.java diff --git a/src/com/jpexs/decompiler/flash/gui/ActionRedirector.java b/src/com/jpexs/decompiler/flash/gui/ActionRedirector.java deleted file mode 100644 index 86a9e7f8a..000000000 --- a/src/com/jpexs/decompiler/flash/gui/ActionRedirector.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2010-2015 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 java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -/** - * - * @author JPEXS - */ -public class ActionRedirector implements ActionListener { - - ActionListener target; - - String actionCommand; - - public ActionRedirector(ActionListener target, String actionCommand) { - this.target = target; - this.actionCommand = actionCommand; - } - - @Override - public void actionPerformed(ActionEvent e) { - e = new ActionEvent(e.getSource(), e.getID(), actionCommand); - target.actionPerformed(e); - } -} diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java index 9797b4010..5fb9d00bf 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java @@ -20,98 +20,19 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.console.ContextMenuTools; import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import com.jpexs.helpers.Cache; import com.sun.jna.Platform; import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; import javax.swing.JCheckBoxMenuItem; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; /** * * @author JPEXS */ -public class MainFrameClassicMenu extends MainFrameMenu implements ActionListener { - - private static final String ACTION_RELOAD = "RELOAD"; - - private static final String ACTION_ADVANCED_SETTINGS = "ADVANCEDSETTINGS"; - - private static final String ACTION_LOAD_MEMORY = "LOADMEMORY"; - - private static final String ACTION_LOAD_CACHE = "LOADCACHE"; - - private static final String ACTION_GOTO_DOCUMENT_CLASS_ON_STARTUP = "GOTODOCUMENTCLASSONSTARTUP"; - - private static final String ACTION_AUTO_RENAME_IDENTIFIERS = "AUTORENAMEIDENTIFIERS"; - - private static final String ACTION_CACHE_ON_DISK = "CACHEONDISK"; - - private static final String ACTION_SET_LANGUAGE = "SETLANGUAGE"; - - private static final String ACTION_DISABLE_DECOMPILATION = "DISABLEDECOMPILATION"; - - private static final String ACTION_ASSOCIATE = "ASSOCIATE"; - - private static final String ACTION_GOTO_DOCUMENT_CLASS = "GOTODOCUMENTCLASS"; - - private static final String ACTION_PARALLEL_SPEED_UP = "PARALLELSPEEDUP"; - - private static final String ACTION_INTERNAL_VIEWER_SWITCH = "INTERNALVIEWERSWITCH"; - - private static final String ACTION_SEARCH = "SEARCH"; - - private static final String ACTION_AUTO_DEOBFUSCATE = "AUTODEOBFUSCATE"; - - private static final String ACTION_EXIT = "EXIT"; - - private static final String ACTION_RENAME_ONE_IDENTIFIER = "RENAMEONEIDENTIFIER"; - - private static final String ACTION_ABOUT = "ABOUT"; - - private static final String ACTION_SHOW_PROXY = "SHOWPROXY"; - - private static final String ACTION_SUB_LIMITER = "SUBLIMITER"; - - private static final String ACTION_SAVE = "SAVE"; - - private static final String ACTION_SAVE_AS = "SAVEAS"; - - private static final String ACTION_SAVE_AS_EXE = "SAVEASEXE"; - - private static final String ACTION_OPEN = "OPEN"; - - private static final String ACTION_EXPORT_FLA = "EXPORTFLA"; - - private static final String ACTION_EXPORT_SEL = "EXPORTSEL"; - - private static final String ACTION_EXPORT = "EXPORT"; - - private static final String ACTION_CHECK_UPDATES = "CHECKUPDATES"; - - private static final String ACTION_HELP_US = "HELPUS"; - - private static final String ACTION_HOMEPAGE = "HOMEPAGE"; - - private static final String ACTION_RESTORE_CONTROL_FLOW = "RESTORECONTROLFLOW"; - - private static final String ACTION_RESTORE_CONTROL_FLOW_ALL = "RESTORECONTROLFLOWALL"; - - private static final String ACTION_RENAME_IDENTIFIERS = "RENAMEIDENTIFIERS"; - - private static final String ACTION_DEOBFUSCATE = "DEOBFUSCATE"; - - private static final String ACTION_DEOBFUSCATE_ALL = "DEOBFUSCATEALL"; - - private static final String ACTION_REMOVE_NON_SCRIPTS = "REMOVENONSCRIPTS"; - - private static final String ACTION_REFRESH_DECOMPILED = "REFRESHDECOMPILED"; +public class MainFrameClassicMenu extends MainFrameMenu { private final MainFrameClassic mainFrame; @@ -131,30 +52,6 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene private JCheckBoxMenuItem miAutoRenameIdentifiers; - private JMenuItem saveCommandButton; - - private JMenuItem saveasCommandButton; - - private JMenuItem saveasexeCommandButton; - - private JMenuItem exportAllCommandButton; - - private JMenuItem exportFlaCommandButton; - - private JMenuItem exportSelectionCommandButton; - - private JMenuItem reloadCommandButton; - - private JMenuItem renameInvalidCommandButton; - - private JMenuItem globalRenameCommandButton; - - private JMenuItem deobfuscationCommandButton; - - private JMenuItem searchCommandButton; - - private JMenuItem gotoDocumentClassCommandButton; - public MainFrameClassicMenu(MainFrameClassic mainFrame, boolean externalFlashPlayerUnavailable) { super(mainFrame); this.mainFrame = mainFrame; @@ -167,16 +64,6 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene return miInternalViewer.isSelected(); } - private void assignListener(JMenuItem b, final String command) { - final MainFrameClassicMenu t = this; - b.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - t.actionPerformed(new ActionEvent(e.getSource(), 0, command)); - } - }); - } - private String fixCommandTitle(String title) { if (title.length() > 2) { if (title.charAt(1) == ' ') { @@ -192,32 +79,25 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene JMenu menuFile = new JMenu(translate("menu.file")); JMenuItem miOpen = new JMenuItem(translate("menu.file.open")); miOpen.setIcon(View.getIcon("open16")); - miOpen.setActionCommand(ACTION_OPEN); - miOpen.addActionListener(this); + miOpen.addActionListener(this::open); JMenuItem miSave = new JMenuItem(translate("menu.file.save")); miSave.setIcon(View.getIcon("save16")); - miSave.setActionCommand(ACTION_SAVE); - miSave.addActionListener(this); + miSave.addActionListener(this::save); JMenuItem miSaveAs = new JMenuItem(translate("menu.file.saveas")); miSaveAs.setIcon(View.getIcon("saveas16")); - miSaveAs.setActionCommand(ACTION_SAVE_AS); - miSaveAs.addActionListener(this); + miSaveAs.addActionListener(this::saveAs); JMenuItem miSaveAsExe = new JMenuItem(translate("menu.file.saveasexe")); miSaveAsExe.setIcon(View.getIcon("saveas16")); - miSaveAsExe.setActionCommand(ACTION_SAVE_AS_EXE); - miSaveAsExe.addActionListener(this); + miSaveAsExe.addActionListener(this::saveAsExe); JMenuItem menuExportFla = new JMenuItem(translate("menu.file.export.fla")); - menuExportFla.setActionCommand(ACTION_EXPORT_FLA); - menuExportFla.addActionListener(this); + menuExportFla.addActionListener(this::exportFla); menuExportFla.setIcon(View.getIcon("flash16")); JMenuItem menuExportAll = new JMenuItem(translate("menu.file.export.all")); - menuExportAll.setActionCommand(ACTION_EXPORT); - menuExportAll.addActionListener(this); + menuExportAll.addActionListener(this::exportAll); JMenuItem menuExportSel = new JMenuItem(translate("menu.file.export.selection")); - menuExportSel.setActionCommand(ACTION_EXPORT_SEL); - menuExportSel.addActionListener(this); + menuExportSel.addActionListener(this::exportSelected); menuExportAll.setIcon(View.getIcon("export16")); menuExportSel.setIcon(View.getIcon("exportsel16")); @@ -231,42 +111,37 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene menuFile.addSeparator(); JMenuItem miClose = new JMenuItem(translate("menu.file.exit")); miClose.setIcon(View.getIcon("exit16")); - miClose.setActionCommand(ACTION_EXIT); - miClose.addActionListener(this); + miClose.addActionListener(this::exit); menuFile.add(miClose); menuBar.add(menuFile); JMenu menuDeobfuscation = new JMenu(translate("menu.tools.deobfuscation")); menuDeobfuscation.setIcon(View.getIcon("deobfuscate16")); JMenuItem miDeobfuscation = new JMenuItem(translate("menu.tools.deobfuscation.pcode")); - miDeobfuscation.setActionCommand(ACTION_DEOBFUSCATE); - miDeobfuscation.addActionListener(this); + miDeobfuscation.addActionListener(this::deobfuscate); miAutoDeobfuscation = new JCheckBoxMenuItem(translate("menu.settings.autodeobfuscation")); miAutoDeobfuscation.setSelected(Configuration.autoDeobfuscate.get()); - miAutoDeobfuscation.addActionListener(this); - miAutoDeobfuscation.setActionCommand(ACTION_AUTO_DEOBFUSCATE); + miAutoDeobfuscation.addActionListener(this::autoDeobfuscate); JMenuItem miRenameOneIdentifier = new JMenuItem(translate("menu.tools.deobfuscation.globalrename")); - miRenameOneIdentifier.setActionCommand(ACTION_RENAME_ONE_IDENTIFIER); - miRenameOneIdentifier.addActionListener(this); + miRenameOneIdentifier.addActionListener(this::renameOneIdentifier); JMenuItem miRenameIdentifiers = new JMenuItem(translate("menu.tools.deobfuscation.renameinvalid")); - miRenameIdentifiers.setActionCommand(ACTION_RENAME_IDENTIFIERS); - miRenameIdentifiers.addActionListener(this); + miRenameIdentifiers.addActionListener(this::renameIdentifiers); menuDeobfuscation.add(miRenameOneIdentifier); menuDeobfuscation.add(miRenameIdentifiers); menuDeobfuscation.add(miDeobfuscation); JMenu menuTools = new JMenu(translate("menu.tools")); JMenuItem miProxy = new JMenuItem(translate("menu.tools.proxy")); - miProxy.setActionCommand(ACTION_SHOW_PROXY); miProxy.setIcon(View.getIcon("proxy16")); - miProxy.addActionListener(this); + miProxy.addActionListener(this::showProxy); JMenuItem miSearchScript = new JMenuItem(translate("menu.tools.searchas")); - miSearchScript.addActionListener(this); - miSearchScript.setActionCommand(ACTION_SEARCH); + miSearchScript.addActionListener((ActionEvent e) -> { + search(e, null); + }); miSearchScript.setIcon(View.getIcon("search16")); menuTools.add(miSearchScript); @@ -276,42 +151,35 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene if (externalFlashPlayerUnavailable) { miInternalViewer.setEnabled(false); } - miInternalViewer.setActionCommand(ACTION_INTERNAL_VIEWER_SWITCH); - miInternalViewer.addActionListener(this); + miInternalViewer.addActionListener(this::internalViewerSwitch); miParallelSpeedUp = new JCheckBoxMenuItem(translate("menu.settings.parallelspeedup")); miParallelSpeedUp.setSelected(Configuration.parallelSpeedUp.get()); - miParallelSpeedUp.setActionCommand(ACTION_PARALLEL_SPEED_UP); - miParallelSpeedUp.addActionListener(this); + miParallelSpeedUp.addActionListener(this::parallelSpeedUp); menuTools.add(miProxy); menuTools.add(menuDeobfuscation); JMenuItem miGotoDocumentClass = new JMenuItem(translate("menu.tools.gotodocumentclass")); - miGotoDocumentClass.setActionCommand(ACTION_GOTO_DOCUMENT_CLASS); - miGotoDocumentClass.addActionListener(this); + miGotoDocumentClass.addActionListener(this::gotoDucumentClass); menuBar.add(menuTools); miDecompile = new JCheckBoxMenuItem(translate("menu.settings.disabledecompilation")); miDecompile.setSelected(!Configuration.decompile.get()); - miDecompile.setActionCommand(ACTION_DISABLE_DECOMPILATION); - miDecompile.addActionListener(this); + miDecompile.addActionListener(this::disableDecompilation); miCacheDisk = new JCheckBoxMenuItem(translate("menu.settings.cacheOnDisk")); miCacheDisk.setSelected(Configuration.cacheOnDisk.get()); - miCacheDisk.setActionCommand(ACTION_CACHE_ON_DISK); - miCacheDisk.addActionListener(this); + miCacheDisk.addActionListener(this::cacheOnDisk); miGotoMainClassOnStartup = new JCheckBoxMenuItem(translate("menu.settings.gotoMainClassOnStartup")); miGotoMainClassOnStartup.setSelected(Configuration.gotoMainClassOnStartup.get()); - miGotoMainClassOnStartup.setActionCommand(ACTION_GOTO_DOCUMENT_CLASS_ON_STARTUP); - miGotoMainClassOnStartup.addActionListener(this); + miGotoMainClassOnStartup.addActionListener(this::gotoDucumentClassOnStartup); miAutoRenameIdentifiers = new JCheckBoxMenuItem(translate("menu.settings.autoRenameIdentifiers")); miAutoRenameIdentifiers.setSelected(Configuration.autoRenameIdentifiers.get()); - miAutoRenameIdentifiers.setActionCommand(ACTION_AUTO_RENAME_IDENTIFIERS); - miAutoRenameIdentifiers.addActionListener(this); + miAutoRenameIdentifiers.addActionListener(this::autoRenameIdentifiers); JMenu menuSettings = new JMenu(translate("menu.settings")); menuSettings.add(miAutoDeobfuscation); @@ -323,13 +191,11 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene menuSettings.add(miAutoRenameIdentifiers); miAssociate = new JCheckBoxMenuItem(translate("menu.settings.addtocontextmenu")); - miAssociate.setActionCommand(ACTION_ASSOCIATE); - miAssociate.addActionListener(this); + miAssociate.addActionListener(this::associate); miAssociate.setSelected(ContextMenuTools.isAddedToContextMenu()); JMenuItem miLanguage = new JMenuItem(translate("menu.settings.language")); - miLanguage.setActionCommand(ACTION_SET_LANGUAGE); - miLanguage.addActionListener(this); + miLanguage.addActionListener(this::setLanguage); if (Platform.isWindows()) { menuSettings.add(miAssociate); @@ -337,33 +203,27 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene menuSettings.add(miLanguage); JMenuItem advancedSettingsCommandButton = new JMenuItem(translate("menu.advancedsettings.advancedsettings")); - advancedSettingsCommandButton.setActionCommand(ACTION_ADVANCED_SETTINGS); advancedSettingsCommandButton.setIcon(View.getIcon("settings16")); - advancedSettingsCommandButton.addActionListener(this); + advancedSettingsCommandButton.addActionListener(this::advancedSettings); menuSettings.add(advancedSettingsCommandButton); menuBar.add(menuSettings); JMenu menuHelp = new JMenu(translate("menu.help")); JMenuItem miAbout = new JMenuItem(translate("menu.help.about")); miAbout.setIcon(View.getIcon("about16")); - - miAbout.setActionCommand(ACTION_ABOUT); - miAbout.addActionListener(this); + miAbout.addActionListener(this::about); JMenuItem miCheckUpdates = new JMenuItem(translate("menu.help.checkupdates")); - miCheckUpdates.setActionCommand(ACTION_CHECK_UPDATES); miCheckUpdates.setIcon(View.getIcon("update16")); - miCheckUpdates.addActionListener(this); + miCheckUpdates.addActionListener(this::checkUpdates); JMenuItem miHelpUs = new JMenuItem(translate("menu.help.helpus")); - miHelpUs.setActionCommand(ACTION_HELP_US); miHelpUs.setIcon(View.getIcon("donate16")); - miHelpUs.addActionListener(this); + miHelpUs.addActionListener(this::helpUs); JMenuItem miHomepage = new JMenuItem(translate("menu.help.homepage")); - miHomepage.setActionCommand(ACTION_HOMEPAGE); miHomepage.setIcon(View.getIcon("homepage16")); - miHomepage.addActionListener(this); + miHomepage.addActionListener(this::homePage); menuHelp.add(miCheckUpdates); menuHelp.add(miHelpUs); @@ -401,157 +261,4 @@ public class MainFrameClassicMenu extends MainFrameMenu implements ActionListene gotoDocumentClassCommandButton.setEnabled(hasAbc); deobfuscationCommandButton.setEnabled(hasAbc);*/ } - - @Override - public void actionPerformed(ActionEvent e) { - switch (e.getActionCommand()) { - case ACTION_RELOAD: - reload(null); - break; - case ACTION_ADVANCED_SETTINGS: - advancedSettings(null); - break; - case ACTION_LOAD_MEMORY: - loadFromMemory(null); - break; - case ACTION_LOAD_CACHE: - loadFromCache(null); - break; - case ACTION_GOTO_DOCUMENT_CLASS_ON_STARTUP: - Configuration.gotoMainClassOnStartup.set(miGotoMainClassOnStartup.isSelected()); - break; - case ACTION_AUTO_RENAME_IDENTIFIERS: - Configuration.autoRenameIdentifiers.set(miAutoRenameIdentifiers.isSelected()); - break; - case ACTION_CACHE_ON_DISK: - Configuration.cacheOnDisk.set(miCacheDisk.isSelected()); - if (miCacheDisk.isSelected()) { - Cache.setStorageType(Cache.STORAGE_FILES); - } else { - Cache.setStorageType(Cache.STORAGE_MEMORY); - } - break; - case ACTION_SET_LANGUAGE: - setLanguage(); - break; - case ACTION_DISABLE_DECOMPILATION: - Configuration.decompile.set(!miDecompile.isSelected()); - mainFrame.getPanel().disableDecompilationChanged(); - break; - case ACTION_ASSOCIATE: - if (miAssociate.isSelected() == ContextMenuTools.isAddedToContextMenu()) { - return; - } - ContextMenuTools.addToContextMenu(miAssociate.isSelected(), false); - - // Update checkbox menuitem accordingly (User can cancel rights elevation) - new Timer().schedule(new TimerTask() { - @Override - public void run() { - miAssociate.setSelected(ContextMenuTools.isAddedToContextMenu()); - } - }, 1000); // It takes some time registry change to apply - break; - case ACTION_GOTO_DOCUMENT_CLASS: - mainFrame.getPanel().gotoDocumentClass(mainFrame.getPanel().getCurrentSwf()); - break; - case ACTION_PARALLEL_SPEED_UP: - String confStr = translate("message.confirm.parallel") + "\r\n"; - if (miParallelSpeedUp.isSelected()) { - confStr += " " + translate("message.confirm.on"); - } else { - confStr += " " + translate("message.confirm.off"); - } - if (View.showConfirmDialog(null, confStr, translate("message.parallel"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { - Configuration.parallelSpeedUp.set((Boolean) miParallelSpeedUp.isSelected()); - } else { - miParallelSpeedUp.setSelected(!miParallelSpeedUp.isSelected()); - } - break; - case ACTION_INTERNAL_VIEWER_SWITCH: - Configuration.internalFlashViewer.set(miInternalViewer.isSelected()); - mainFrame.getPanel().reload(true); - break; - case ACTION_SEARCH: - search(null); - break; - case ACTION_AUTO_DEOBFUSCATE: - if (View.showConfirmDialog(mainFrame.getPanel(), translate("message.confirm.autodeobfuscate") + "\r\n" + (miAutoDeobfuscation.isSelected() ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { - Configuration.autoDeobfuscate.set(miAutoDeobfuscation.isSelected()); - mainFrame.getPanel().autoDeobfuscateChanged(); - } else { - miAutoDeobfuscation.setSelected(!miAutoDeobfuscation.isSelected()); - } - break; - case ACTION_EXIT: - exit(); - break; - } - - if (Main.isWorking()) { - return; - } - - switch (e.getActionCommand()) { - case ACTION_RENAME_ONE_IDENTIFIER: - renameOneIdentifier(); - break; - case ACTION_SHOW_PROXY: - showProxy(); - break; - case ACTION_SUB_LIMITER: - setSubLimiter(((JCheckBoxMenuItem) e.getSource()).isSelected()); - break; - case ACTION_SAVE: - save(); - break; - case ACTION_SAVE_AS: - saveAs(); - break; - case ACTION_SAVE_AS_EXE: - saveAsExe(); - break; - case ACTION_OPEN: - open(); - break; - case ACTION_EXPORT_SEL: - case ACTION_EXPORT: - boolean onlySel = e.getActionCommand().equals(ACTION_EXPORT_SEL); - export(onlySel); - break; - case ACTION_EXPORT_FLA: - exportFla(); - break; - case ACTION_CHECK_UPDATES: - checkUpdates(); - break; - case ACTION_HELP_US: - helpUs(); - break; - case ACTION_HOMEPAGE: - homePage(); - break; - case ACTION_ABOUT: - about(); - break; - case ACTION_RESTORE_CONTROL_FLOW: - case ACTION_RESTORE_CONTROL_FLOW_ALL: - boolean all = e.getActionCommand().equals(ACTION_RESTORE_CONTROL_FLOW_ALL); - restoreControlFlow(all); - break; - case ACTION_RENAME_IDENTIFIERS: - renameIdentifiers(); - break; - case ACTION_DEOBFUSCATE: - case ACTION_DEOBFUSCATE_ALL: - deobfuscate(); - break; - case ACTION_REMOVE_NON_SCRIPTS: - removeNonScripts(); - break; - case ACTION_REFRESH_DECOMPILED: - refreshDecompiled(); - break; - } - } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index bda1b136e..e201fb817 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -20,9 +20,11 @@ import com.jpexs.decompiler.flash.ApplicationInfo; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SWFBundle; import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.console.ContextMenuTools; import com.jpexs.decompiler.flash.gui.debugger.DebuggerTools; import com.jpexs.decompiler.flash.gui.helpers.CheckResources; import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.Cache; import com.jpexs.helpers.utf8.Utf8Helper; import java.awt.BorderLayout; import java.awt.Container; @@ -37,8 +39,11 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.util.Timer; +import java.util.TimerTask; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.AbstractButton; import javax.swing.JDialog; import javax.swing.JEditorPane; import javax.swing.JFrame; @@ -65,12 +70,20 @@ public abstract class MainFrameMenu { return mainFrame.translate(key); } - protected boolean open() { + protected boolean open(ActionEvent evt) { + if (Main.isWorking()) { + return false; + } + Main.openFileDialog(); return true; } - protected boolean save() { + protected boolean save(ActionEvent evt) { + if (Main.isWorking()) { + return false; + } + if (swf != null) { boolean saved = false; if (swf.swfList != null && swf.swfList.isBundle()) { @@ -115,7 +128,11 @@ public abstract class MainFrameMenu { return false; } - protected boolean saveAs() { + protected boolean saveAs(ActionEvent evt) { + if (Main.isWorking()) { + return false; + } + if (swf != null) { if (saveAs(swf, SaveFileMode.SAVEAS)) { swf.clearModified(); @@ -136,13 +153,21 @@ public abstract class MainFrameMenu { return false; } - protected void saveAsExe() { + protected void saveAsExe(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + if (swf != null) { saveAs(swf, SaveFileMode.EXE); } } - protected void close() { + protected void close(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + if (swf == null) { return; } @@ -150,7 +175,11 @@ public abstract class MainFrameMenu { Main.closeFile(swf.swfList); } - protected boolean closeAll() { + protected boolean closeAll(ActionEvent evt) { + if (Main.isWorking()) { + return false; + } + if (swf != null) { Main.closeAll(); return true; @@ -159,18 +188,46 @@ public abstract class MainFrameMenu { return false; } - protected void importText() { + protected void importText(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + mainFrame.getPanel().importText(swf); } - protected void importScript() { + protected void importScript(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + mainFrame.getPanel().importScript(swf); } - protected void importSymbolClass() { + protected void importSymbolClass(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + mainFrame.getPanel().importSymbolClass(swf); } + protected void exportAll(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + + export(false); + } + + protected void exportSelected(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + + export(true); + } + protected boolean export(boolean onlySelected) { if (swf != null) { mainFrame.getPanel().export(onlySelected); @@ -180,11 +237,31 @@ public abstract class MainFrameMenu { return false; } - protected void exportFla() { + protected void exportFla(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + mainFrame.getPanel().exportFla(swf); } - protected boolean search(Boolean searchInText) { + protected void importSwfXml(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + + mainFrame.getPanel().importSwfXml(); + } + + protected void exportSwfXml(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + + mainFrame.getPanel().exportSwfXml(); + } + + protected boolean search(ActionEvent evt, Boolean searchInText) { if (swf != null) { mainFrame.getPanel().searchInActionScriptOrText(searchInText); return true; @@ -193,7 +270,7 @@ public abstract class MainFrameMenu { return false; } - protected boolean replace() { + protected boolean replace(ActionEvent evt) { if (swf != null) { mainFrame.getPanel().replaceText(); return true; @@ -202,11 +279,31 @@ public abstract class MainFrameMenu { return false; } + protected void restoreControlFlow(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + + restoreControlFlow(false); + } + + protected void restoreControlFlowAll(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + + restoreControlFlow(true); + } + protected void restoreControlFlow(boolean all) { mainFrame.getPanel().restoreControlFlow(all); } - protected void showProxy() { + protected void showProxy(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + Main.showProxy(); } @@ -215,32 +312,61 @@ public abstract class MainFrameMenu { return true; } - protected void renameOneIdentifier() { + protected void renameOneIdentifier(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + mainFrame.getPanel().renameOneIdentifier(swf); } - protected void renameIdentifiers() { + protected void renameIdentifiers(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + mainFrame.getPanel().renameIdentifiers(swf); } - protected void deobfuscate() { + protected void deobfuscate(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + mainFrame.getPanel().deobfuscate(); } - protected void setSubLimiter(boolean value) { - Main.setSubLimiter(value); + protected void setSubLimiter(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + Main.setSubLimiter(selected); } protected void switchDebugger() { DebuggerTools.switchDebugger(swf); } - protected void debuggerShowLog() { + protected void debuggerShowLog(ActionEvent evt) { DebuggerTools.debuggerShowLog(); } - protected void replaceTraceCalls(String fname) { - DebuggerTools.replaceTraceCalls(swf, fname); + protected void debuggerReplaceTraceCalls(ActionEvent evt) { + ReplaceTraceDialog rtd = new ReplaceTraceDialog(Configuration.lastDebuggerReplaceFunction.get()); + rtd.setVisible(true); + if (rtd.getValue() != null) { + String fname = rtd.getValue(); + DebuggerTools.replaceTraceCalls(swf, fname); + mainFrame.getPanel().refreshDecompiled(); + Configuration.lastDebuggerReplaceFunction.set(rtd.getValue()); + } + } + + protected void clearRecentFiles(ActionEvent evt) { + Configuration.recentFiles.set(null); } protected void removeNonScripts() { @@ -285,27 +411,43 @@ public abstract class MainFrameMenu { dialog.setVisible(true); } - protected void checkUpdates() { + protected void checkUpdates(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + if (!Main.checkForUpdates()) { View.showMessageDialog(null, translate("update.check.nonewversion"), translate("update.check.title"), JOptionPane.INFORMATION_MESSAGE); } } - protected void helpUs() { + protected void helpUs(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + String helpUsURL = ApplicationInfo.PROJECT_PAGE + "/help_us.html?utm_source=app&utm_medium=menu&utm_campaign=app"; if (!View.navigateUrl(helpUsURL)) { View.showMessageDialog(null, translate("message.helpus").replace("%url%", helpUsURL)); } } - protected void homePage() { + protected void homePage(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + String homePageURL = ApplicationInfo.PROJECT_PAGE + "?utm_source=app&utm_medium=menu&utm_campaign=app"; if (!View.navigateUrl(homePageURL)) { View.showMessageDialog(null, translate("message.homepage").replace("%url%", homePageURL)); } } - protected void about() { + protected void about(ActionEvent evt) { + if (Main.isWorking()) { + return; + } + Main.about(); } @@ -334,15 +476,108 @@ public abstract class MainFrameMenu { } protected void gotoDucumentClassOnStartup(ActionEvent evt) { - boolean selected = true; // todo: honfika: get from evt.getSource() + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + Configuration.gotoMainClassOnStartup.set(selected); } - protected void setLanguage() { + protected void autoRenameIdentifiers(ActionEvent evt) { + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + + Configuration.autoRenameIdentifiers.set(selected); + } + + protected void cacheOnDisk(ActionEvent evt) { + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + + Configuration.cacheOnDisk.set(selected); + if (selected) { + Cache.setStorageType(Cache.STORAGE_FILES); + } else { + Cache.setStorageType(Cache.STORAGE_MEMORY); + } + } + + protected void setLanguage(ActionEvent evt) { new SelectLanguageDialog().display(); } - protected void exit() { + protected void disableDecompilation(ActionEvent evt) { + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + + Configuration.decompile.set(!selected); + mainFrame.getPanel().disableDecompilationChanged(); + } + + protected void associate(ActionEvent evt) { + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + + if (selected == ContextMenuTools.isAddedToContextMenu()) { + return; + } + ContextMenuTools.addToContextMenu(selected, false); + + // Update checkbox menuitem accordingly (User can cancel rights elevation) + new Timer().schedule(new TimerTask() { + @Override + public void run() { + button.setSelected(ContextMenuTools.isAddedToContextMenu()); + } + }, 1000); // It takes some time registry change to apply + } + + protected void gotoDucumentClass(ActionEvent evt) { + mainFrame.getPanel().gotoDocumentClass(mainFrame.getPanel().getCurrentSwf()); + } + + protected void parallelSpeedUp(ActionEvent evt) { + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + + String confStr = translate("message.confirm.parallel") + "\r\n"; + if (selected) { + confStr += " " + translate("message.confirm.on"); + } else { + confStr += " " + translate("message.confirm.off"); + } + if (View.showConfirmDialog(null, confStr, translate("message.parallel"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { + Configuration.parallelSpeedUp.set(selected); + } else { + button.setSelected(Configuration.parallelSpeedUp.get()); + } + } + + protected void internalViewerSwitch(ActionEvent evt) { + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + + Configuration.internalFlashViewer.set(selected); + mainFrame.getPanel().reload(true); + } + + protected void autoDeobfuscate(ActionEvent evt) { + AbstractButton button = (AbstractButton) evt.getSource(); + boolean selected = button.isSelected(); + + if (View.showConfirmDialog(mainFrame.getPanel(), translate("message.confirm.autodeobfuscate") + "\r\n" + (selected ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { + Configuration.autoDeobfuscate.set(selected); + mainFrame.getPanel().autoDeobfuscateChanged(); + } else { + button.setSelected(Configuration.autoDeobfuscate.get()); + } + } + + protected void deobfuscationMode(ActionEvent evt, int mode) { + Configuration.deobfuscationMode.set(mode); + mainFrame.getPanel().autoDeobfuscateChanged(); + } + + protected void exit(ActionEvent evt) { JFrame frame = (JFrame) mainFrame; frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); } @@ -363,19 +598,19 @@ public abstract class MainFrameMenu { if (e.isControlDown() && e.isShiftDown()) { switch (code) { case KeyEvent.VK_O: - return open(); + return open(null); case KeyEvent.VK_S: - return save(); + return save(null); case KeyEvent.VK_A: - return saveAs(); + return saveAs(null); case KeyEvent.VK_F: - return search(false); + return search(null, false); case KeyEvent.VK_T: - return search(true); + return search(null, true); case KeyEvent.VK_R: return reload(null); case KeyEvent.VK_X: - return closeAll(); + return closeAll(null); case KeyEvent.VK_D: return clearLog(); case KeyEvent.VK_E: diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index 6be30eeb3..85364ff4c 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -21,7 +21,6 @@ import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.console.ContextMenuTools; import com.jpexs.decompiler.flash.gui.debugger.DebuggerTools; import com.jpexs.decompiler.flash.tags.ABCContainerTag; -import com.jpexs.helpers.Cache; import com.jpexs.helpers.Helper; import com.jpexs.process.ProcessTools; import com.sun.jna.Platform; @@ -30,13 +29,10 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; import javax.swing.JCheckBox; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.SwingUtilities; -import org.pushingpixels.flamingo.api.common.AbstractCommandButton; import org.pushingpixels.flamingo.api.common.CommandButtonDisplayState; import org.pushingpixels.flamingo.api.common.CommandToggleButtonGroup; import org.pushingpixels.flamingo.api.common.JCommandButton; @@ -61,113 +57,7 @@ import org.pushingpixels.flamingo.internal.ui.ribbon.AbstractBandControlPanel; * * @author JPEXS */ -public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener { - - private static final String ACTION_RELOAD = "RELOAD"; - - private static final String ACTION_ADVANCED_SETTINGS = "ADVANCEDSETTINGS"; - - private static final String ACTION_LOAD_MEMORY = "LOADMEMORY"; - - private static final String ACTION_LOAD_CACHE = "LOADCACHE"; - - private static final String ACTION_GOTO_DOCUMENT_CLASS_ON_STARTUP = "GOTODOCUMENTCLASSONSTARTUP"; - - private static final String ACTION_AUTO_RENAME_IDENTIFIERS = "AUTORENAMEIDENTIFIERS"; - - private static final String ACTION_CACHE_ON_DISK = "CACHEONDISK"; - - private static final String ACTION_SET_LANGUAGE = "SETLANGUAGE"; - - private static final String ACTION_DISABLE_DECOMPILATION = "DISABLEDECOMPILATION"; - - private static final String ACTION_ASSOCIATE = "ASSOCIATE"; - - private static final String ACTION_GOTO_DOCUMENT_CLASS = "GOTODOCUMENTCLASS"; - - private static final String ACTION_PARALLEL_SPEED_UP = "PARALLELSPEEDUP"; - - private static final String ACTION_INTERNAL_VIEWER_SWITCH = "INTERNALVIEWERSWITCH"; - - private static final String ACTION_SEARCH = "SEARCH"; - - private static final String ACTION_REPLACE = "REPLACE"; - - private static final String ACTION_TIMELINE = "TIMELINE"; - - private static final String ACTION_AUTO_DEOBFUSCATE = "AUTODEOBFUSCATE"; - - private static final String ACTION_EXIT = "EXIT"; - - private static final String ACTION_DEBUGGER_SWITCH = "DEBUGGER_SWITCH"; - - private static final String ACTION_DEBUGGER_REPLACE_TRACE = "DEBUGGER_REPLACE_TRACE"; - - private static final String ACTION_DEBUGGER_LOG = "DEBUGGER_LOG"; - - private static final String ACTION_RENAME_ONE_IDENTIFIER = "RENAMEONEIDENTIFIER"; - - private static final String ACTION_ABOUT = "ABOUT"; - - private static final String ACTION_SHOW_PROXY = "SHOWPROXY"; - - private static final String ACTION_SUB_LIMITER = "SUBLIMITER"; - - private static final String ACTION_SAVE = "SAVE"; - - private static final String ACTION_SAVE_AS = "SAVEAS"; - - private static final String ACTION_SAVE_AS_EXE = "SAVEASEXE"; - - private static final String ACTION_OPEN = "OPEN"; - - private static final String ACTION_CLOSE = "CLOSE"; - - private static final String ACTION_CLOSE_ALL = "CLOSEALL"; - - private static final String ACTION_EXPORT_FLA = "EXPORTFLA"; - - public static final String ACTION_EXPORT_SEL = "EXPORTSEL"; - - public static final String ACTION_EXPORT_JAVA_SOURCE = "EXPORTJAVASOURCE"; - - public static final String ACTION_EXPORT_SWF_XML = "EXPORTSWFXML"; - - public static final String ACTION_IMPORT_SWF_XML = "IMPORTSWFXML"; - - private static final String ACTION_EXPORT = "EXPORT"; - - private static final String ACTION_IMPORT_TEXT = "IMPORTTEXT"; - - private static final String ACTION_IMPORT_SCRIPT = "IMPORTSCRIPT"; - - private static final String ACTION_IMPORT_SYMBOL_CLASS = "IMPORTSYMBOLCLASS"; - - private static final String ACTION_CHECK_UPDATES = "CHECKUPDATES"; - - private static final String ACTION_HELP_US = "HELPUS"; - - private static final String ACTION_HOMEPAGE = "HOMEPAGE"; - - private static final String ACTION_RESTORE_CONTROL_FLOW = "RESTORECONTROLFLOW"; - - private static final String ACTION_RESTORE_CONTROL_FLOW_ALL = "RESTORECONTROLFLOWALL"; - - private static final String ACTION_RENAME_IDENTIFIERS = "RENAMEIDENTIFIERS"; - - private static final String ACTION_DEOBFUSCATE = "DEOBFUSCATE"; - - private static final String ACTION_DEOBFUSCATE_ALL = "DEOBFUSCATEALL"; - - private static final String ACTION_CLEAR_RECENT_FILES = "CLEARRECENTFILES"; - - private static final String ACTION_VIEWMODE_RESOURCES = "VIEWMODERESOURCES"; - - private static final String ACTION_VIEWMODE_HEX_DUMP = "VIEWMODEHEXDUMP"; - - private static final String ACTION_DEOBFUSCATION_MODE_OLD = "DEOBFUSCATIONMODEOLD"; - - private static final String ACTION_DEOBFUSCATION_MODE_NEW = "DEOBFUSCATIONMODENEW"; +public class MainFrameRibbonMenu extends MainFrameMenu { private final MainFrameRibbon mainFrame; @@ -282,16 +172,6 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener return miInternalViewer.isSelected(); } - private void assignListener(AbstractCommandButton b, final String command) { - final MainFrameRibbonMenu t = this; - b.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - t.actionPerformed(new ActionEvent(e.getSource(), 0, command)); - } - }); - } - private String fixCommandTitle(String title) { if (title.length() > 2) { if (title.charAt(1) == ' ') { @@ -303,16 +183,16 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener private RibbonApplicationMenu createMainMenu() { RibbonApplicationMenu mainMenu = new RibbonApplicationMenu(); - exportFlaMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("exportfla32"), translate("menu.file.export.fla"), new ActionRedirector(this, ACTION_EXPORT_FLA), JCommandButton.CommandButtonKind.ACTION_ONLY); - exportAllMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("export32"), translate("menu.file.export.all"), new ActionRedirector(this, ACTION_EXPORT), JCommandButton.CommandButtonKind.ACTION_ONLY); - exportSelMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("exportsel32"), translate("menu.file.export.selection"), new ActionRedirector(this, ACTION_EXPORT_SEL), JCommandButton.CommandButtonKind.ACTION_ONLY); - RibbonApplicationMenuEntryPrimary checkUpdatesMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("update32"), translate("menu.help.checkupdates"), new ActionRedirector(this, ACTION_CHECK_UPDATES), JCommandButton.CommandButtonKind.ACTION_ONLY); - RibbonApplicationMenuEntryPrimary aboutMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("about32"), translate("menu.help.about"), new ActionRedirector(this, ACTION_ABOUT), JCommandButton.CommandButtonKind.ACTION_ONLY); - RibbonApplicationMenuEntryPrimary openFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("open32"), translate("menu.file.open"), new ActionRedirector(this, ACTION_OPEN), JCommandButton.CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION); - saveFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("save32"), translate("menu.file.save"), new ActionRedirector(this, ACTION_SAVE), JCommandButton.CommandButtonKind.ACTION_ONLY); - saveAsFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("saveas32"), translate("menu.file.saveas"), new ActionRedirector(this, ACTION_SAVE_AS), JCommandButton.CommandButtonKind.ACTION_ONLY); - closeFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("close32"), translate("menu.file.close"), new ActionRedirector(this, ACTION_CLOSE), JCommandButton.CommandButtonKind.ACTION_ONLY); - closeAllFilesMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("close32"), translate("menu.file.closeAll"), new ActionRedirector(this, ACTION_CLOSE_ALL), JCommandButton.CommandButtonKind.ACTION_ONLY); + exportFlaMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("exportfla32"), translate("menu.file.export.fla"), this::exportFla, JCommandButton.CommandButtonKind.ACTION_ONLY); + exportAllMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("export32"), translate("menu.file.export.all"), this::exportAll, JCommandButton.CommandButtonKind.ACTION_ONLY); + exportSelMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("exportsel32"), translate("menu.file.export.selection"), this::exportSelected, JCommandButton.CommandButtonKind.ACTION_ONLY); + RibbonApplicationMenuEntryPrimary checkUpdatesMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("update32"), translate("menu.help.checkupdates"), this::checkUpdates, JCommandButton.CommandButtonKind.ACTION_ONLY); + RibbonApplicationMenuEntryPrimary aboutMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("about32"), translate("menu.help.about"), this::about, JCommandButton.CommandButtonKind.ACTION_ONLY); + RibbonApplicationMenuEntryPrimary openFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("open32"), translate("menu.file.open"), this::open, JCommandButton.CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION); + saveFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("save32"), translate("menu.file.save"), this::save, JCommandButton.CommandButtonKind.ACTION_ONLY); + saveAsFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("saveas32"), translate("menu.file.saveas"), this::saveAs, JCommandButton.CommandButtonKind.ACTION_ONLY); + closeFileMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("close32"), translate("menu.file.close"), this::close, JCommandButton.CommandButtonKind.ACTION_ONLY); + closeAllFilesMenu = new RibbonApplicationMenuEntryPrimary(View.getResizableIcon("close32"), translate("menu.file.closeAll"), this::closeAll, JCommandButton.CommandButtonKind.ACTION_ONLY); openFileMenu.setRolloverCallback(new RibbonApplicationMenuEntryPrimary.PrimaryRolloverCallback() { @Override public void menuEntryActivated(JPanel targetPanel) { @@ -348,7 +228,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener } }); - RibbonApplicationMenuEntryFooter exitMenu = new RibbonApplicationMenuEntryFooter(View.getResizableIcon("exit32"), translate("menu.file.exit"), new ActionRedirector(this, "EXIT")); + RibbonApplicationMenuEntryFooter exitMenu = new RibbonApplicationMenuEntryFooter(View.getResizableIcon("exit32"), translate("menu.file.exit"), this::exit); mainMenu.addMenuEntry(openFileMenu); mainMenu.addMenuEntry(saveFileMenu); @@ -412,17 +292,17 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener JRibbonBand editBand = new JRibbonBand(translate("menu.general"), null); editBand.setResizePolicies(getResizePolicies(editBand)); JCommandButton openCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.open")), View.getResizableIcon("open32")); - assignListener(openCommandButton, ACTION_OPEN); + openCommandButton.addActionListener(this::open); saveCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.save")), View.getResizableIcon("save32")); - assignListener(saveCommandButton, ACTION_SAVE); + saveCommandButton.addActionListener(this::save); saveasCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.saveas")), View.getResizableIcon("saveas16")); - assignListener(saveasCommandButton, ACTION_SAVE_AS); + saveasCommandButton.addActionListener(this::saveAs); reloadCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.reload")), View.getResizableIcon("reload16")); - assignListener(reloadCommandButton, ACTION_RELOAD); + reloadCommandButton.addActionListener(this::reload); saveasexeCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.saveasexe")), View.getResizableIcon("saveasexe16")); - assignListener(saveasexeCommandButton, ACTION_SAVE_AS_EXE); + saveasexeCommandButton.addActionListener(this::saveAsExe);; editBand.addCommandButton(openCommandButton, RibbonElementPriority.TOP); editBand.addCommandButton(saveCommandButton, RibbonElementPriority.TOP); @@ -433,14 +313,14 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener JRibbonBand exportBand = new JRibbonBand(translate("menu.export"), null); exportBand.setResizePolicies(getResizePolicies(exportBand)); exportFlaCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.export.fla")), View.getResizableIcon("exportfla32")); - assignListener(exportFlaCommandButton, ACTION_EXPORT_FLA); + exportFlaCommandButton.addActionListener(this::exportFla); exportAllCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.export.all")), View.getResizableIcon("export16")); - assignListener(exportAllCommandButton, ACTION_EXPORT); + exportAllCommandButton.addActionListener(this::exportAll); exportSelectionCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.export.selection")), View.getResizableIcon("exportsel16")); - assignListener(exportSelectionCommandButton, ACTION_EXPORT_SEL); + exportSelectionCommandButton.addActionListener(this::exportSelected); exportXmlCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.export.xml")), View.getResizableIcon("exportxml32")); - assignListener(exportXmlCommandButton, ACTION_EXPORT_SWF_XML); + exportXmlCommandButton.addActionListener(this::exportSwfXml); exportBand.addCommandButton(exportFlaCommandButton, RibbonElementPriority.TOP); exportBand.addCommandButton(exportAllCommandButton, RibbonElementPriority.MEDIUM); @@ -450,17 +330,17 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener JRibbonBand importBand = new JRibbonBand(translate("menu.import"), null); importBand.setResizePolicies(getResizePolicies(importBand)); importTextCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.import.text")), View.getResizableIcon("importtext32")); - assignListener(importTextCommandButton, ACTION_IMPORT_TEXT); + importTextCommandButton.addActionListener(this::importText); // todo: icon importScriptCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.import.script")), View.getResizableIcon("importtext32")); - assignListener(importScriptCommandButton, ACTION_IMPORT_SCRIPT); + importScriptCommandButton.addActionListener(this::importScript); importSymbolClassCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.import.symbolClass")), View.getResizableIcon("importsymbolclass32")); - assignListener(importSymbolClassCommandButton, ACTION_IMPORT_SYMBOL_CLASS); + importSymbolClassCommandButton.addActionListener(this::importSymbolClass); importXmlCommandButton = new JCommandButton(fixCommandTitle(translate("menu.file.import.xml")), View.getResizableIcon("importxml32")); - assignListener(importXmlCommandButton, ACTION_IMPORT_SWF_XML); + importXmlCommandButton.addActionListener(this::importSwfXml); importBand.addCommandButton(importXmlCommandButton, RibbonElementPriority.TOP); importBand.addCommandButton(importTextCommandButton, RibbonElementPriority.MEDIUM); @@ -473,10 +353,10 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener viewModeToggleGroup = new CommandToggleButtonGroup(); viewModeResourcesToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.view.resources")), View.getResizableIcon("viewresources16")); - assignListener(viewModeResourcesToggleButton, ACTION_VIEWMODE_RESOURCES); + viewModeResourcesToggleButton.addActionListener(this::viewModeResouresButtonActionPerformed); viewModeHexToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.view.hex")), View.getResizableIcon("viewhex16")); - assignListener(viewModeHexToggleButton, ACTION_VIEWMODE_HEX_DUMP); + viewModeHexToggleButton.addActionListener(this::viewModeHexDumpButtonActionPerformed);; viewModeToggleGroup.add(viewModeResourcesToggleButton); viewModeToggleGroup.add(viewModeHexToggleButton); @@ -499,15 +379,15 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener debuggerBand.setResizePolicies(getResizePolicies(debuggerBand)); debuggerSwitchCommandButton = new JCommandToggleButton(translate("menu.debugger.switch"), View.getResizableIcon("debugger32")); - assignListener(debuggerSwitchCommandButton, ACTION_DEBUGGER_SWITCH); + debuggerSwitchCommandButton.addActionListener(this::debuggerSwitchButtonActionPerformed); //debuggerDetachCommandButton = new JCommandButton("Detach debugger",View.getResizableIcon("debuggerremove16")); - //assignListener(debuggerDetachCommandButton, ACTION_DEBUGGER_DETACH); + //debuggerDetachCommandButton.addActionListener(this::debuggerDetach); debuggerReplaceTraceCommandButton = new JCommandButton(translate("menu.debugger.replacetrace"), View.getResizableIcon("debuggerreplace16")); - assignListener(debuggerReplaceTraceCommandButton, ACTION_DEBUGGER_REPLACE_TRACE); + debuggerReplaceTraceCommandButton.addActionListener(this::debuggerReplaceTraceCalls); debuggerLogCommandButton = new JCommandButton(translate("menu.debugger.showlog"), View.getResizableIcon("debuggerlog16")); - assignListener(debuggerLogCommandButton, ACTION_DEBUGGER_LOG); + debuggerLogCommandButton.addActionListener(this::debuggerShowLog); debuggerSwitchGroup = new CommandToggleButtonGroup(); debuggerSwitchGroup.add(debuggerSwitchCommandButton); @@ -525,28 +405,30 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener toolsBand.setResizePolicies(getResizePolicies(toolsBand)); searchCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.search")), View.getResizableIcon("search32")); - assignListener(searchCommandButton, ACTION_SEARCH); + searchCommandButton.addActionListener((ActionEvent e) -> { + search(e, null); + }); replaceCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.replace")), View.getResizableIcon("replace32")); - assignListener(replaceCommandButton, ACTION_REPLACE); + replaceCommandButton.addActionListener(this::replace); timeLineToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.tools.timeline")), View.getResizableIcon("timeline32")); - assignListener(timeLineToggleButton, ACTION_TIMELINE); + timeLineToggleButton.addActionListener(this::timelineButtonActionPerformed); timeLineToggleGroup = new CommandToggleButtonGroup(); timeLineToggleGroup.add(timeLineToggleButton); gotoDocumentClassCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.gotodocumentclass")), View.getResizableIcon("gotomainclass32")); - assignListener(gotoDocumentClassCommandButton, ACTION_GOTO_DOCUMENT_CLASS); + gotoDocumentClassCommandButton.addActionListener(this::gotoDucumentClass); JCommandButton proxyCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.proxy")), View.getResizableIcon("proxy16")); - assignListener(proxyCommandButton, ACTION_SHOW_PROXY); + proxyCommandButton.addActionListener(this::showProxy); JCommandButton loadMemoryCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.searchmemory")), View.getResizableIcon("loadmemory16")); - assignListener(loadMemoryCommandButton, ACTION_LOAD_MEMORY); + loadMemoryCommandButton.addActionListener(this::loadFromMemory); JCommandButton loadCacheCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.searchcache")), View.getResizableIcon("loadcache16")); - assignListener(loadCacheCommandButton, ACTION_LOAD_CACHE); + loadCacheCommandButton.addActionListener(this::loadFromCache); toolsBand.addCommandButton(searchCommandButton, RibbonElementPriority.TOP); toolsBand.addCommandButton(replaceCommandButton, RibbonElementPriority.TOP); @@ -562,11 +444,11 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener deobfuscationBand.setResizePolicies(getResizePolicies(deobfuscationBand)); deobfuscationCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.deobfuscation.pcode")), View.getResizableIcon("deobfuscate32")); - assignListener(deobfuscationCommandButton, ACTION_DEOBFUSCATE); + deobfuscationCommandButton.addActionListener(this::deobfuscate); globalRenameCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.deobfuscation.globalrename")), View.getResizableIcon("rename16")); - assignListener(globalRenameCommandButton, ACTION_RENAME_ONE_IDENTIFIER); + globalRenameCommandButton.addActionListener(this::renameOneIdentifier); renameInvalidCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.deobfuscation.renameinvalid")), View.getResizableIcon("renameall16")); - assignListener(renameInvalidCommandButton, ACTION_RENAME_IDENTIFIERS); + renameInvalidCommandButton.addActionListener(this::renameIdentifiers); deobfuscationBand.addCommandButton(deobfuscationCommandButton, RibbonElementPriority.TOP); deobfuscationBand.addCommandButton(globalRenameCommandButton, RibbonElementPriority.MEDIUM); @@ -585,46 +467,38 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener miAutoDeobfuscation = new JCheckBox(translate("menu.settings.autodeobfuscation")); miAutoDeobfuscation.setSelected(Configuration.autoDeobfuscate.get()); - miAutoDeobfuscation.addActionListener(this); - miAutoDeobfuscation.setActionCommand(ACTION_AUTO_DEOBFUSCATE); + miAutoDeobfuscation.addActionListener(this::autoDeobfuscate); miInternalViewer = new JCheckBox(translate("menu.settings.internalflashviewer")); miInternalViewer.setSelected(Configuration.internalFlashViewer.get() || externalFlashPlayerUnavailable); if (externalFlashPlayerUnavailable) { miInternalViewer.setEnabled(false); } - miInternalViewer.setActionCommand(ACTION_INTERNAL_VIEWER_SWITCH); - miInternalViewer.addActionListener(this); + miInternalViewer.addActionListener(this::internalViewerSwitch); miParallelSpeedUp = new JCheckBox(translate("menu.settings.parallelspeedup")); miParallelSpeedUp.setSelected(Configuration.parallelSpeedUp.get()); - miParallelSpeedUp.setActionCommand(ACTION_PARALLEL_SPEED_UP); - miParallelSpeedUp.addActionListener(this); + miParallelSpeedUp.addActionListener(this::parallelSpeedUp); miDecompile = new JCheckBox(translate("menu.settings.disabledecompilation")); miDecompile.setSelected(!Configuration.decompile.get()); - miDecompile.setActionCommand(ACTION_DISABLE_DECOMPILATION); - miDecompile.addActionListener(this); + miDecompile.addActionListener(this::disableDecompilation); miAssociate = new JCheckBox(translate("menu.settings.addtocontextmenu")); - miAssociate.setActionCommand(ACTION_ASSOCIATE); - miAssociate.addActionListener(this); + miAssociate.addActionListener(this::associate); miAssociate.setSelected(ContextMenuTools.isAddedToContextMenu()); miCacheDisk = new JCheckBox(translate("menu.settings.cacheOnDisk")); miCacheDisk.setSelected(Configuration.cacheOnDisk.get()); - miCacheDisk.setActionCommand(ACTION_CACHE_ON_DISK); - miCacheDisk.addActionListener(this); + miCacheDisk.addActionListener(this::cacheOnDisk); miGotoMainClassOnStartup = new JCheckBox(translate("menu.settings.gotoMainClassOnStartup")); miGotoMainClassOnStartup.setSelected(Configuration.gotoMainClassOnStartup.get()); - miGotoMainClassOnStartup.setActionCommand(ACTION_GOTO_DOCUMENT_CLASS_ON_STARTUP); - miGotoMainClassOnStartup.addActionListener(this); + miGotoMainClassOnStartup.addActionListener(this::gotoDucumentClassOnStartup); miAutoRenameIdentifiers = new JCheckBox(translate("menu.settings.autoRenameIdentifiers")); miAutoRenameIdentifiers.setSelected(Configuration.autoRenameIdentifiers.get()); - miAutoRenameIdentifiers.setActionCommand(ACTION_AUTO_RENAME_IDENTIFIERS); - miAutoRenameIdentifiers.addActionListener(this); + miAutoRenameIdentifiers.addActionListener(this::autoRenameIdentifiers); settingsBand.addRibbonComponent(new JRibbonComponent(miAutoDeobfuscation)); settingsBand.addRibbonComponent(new JRibbonComponent(miInternalViewer)); @@ -641,17 +515,17 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener List languageBandResizePolicies = getIconBandResizePolicies(languageBand); languageBand.setResizePolicies(languageBandResizePolicies); JCommandButton setLanguageCommandButton = new JCommandButton(fixCommandTitle(translate("menu.settings.language")), View.getResizableIcon("setlanguage32")); - assignListener(setLanguageCommandButton, ACTION_SET_LANGUAGE); + setLanguageCommandButton.addActionListener(this::setLanguage); languageBand.addCommandButton(setLanguageCommandButton, RibbonElementPriority.TOP); JRibbonBand advancedSettingsBand = new JRibbonBand(translate("menu.advancedsettings.advancedsettings"), null); advancedSettingsBand.setResizePolicies(getResizePolicies(advancedSettingsBand)); JCommandButton advancedSettingsCommandButton = new JCommandButton(fixCommandTitle(translate("menu.advancedsettings.advancedsettings")), View.getResizableIcon("settings32")); - assignListener(advancedSettingsCommandButton, ACTION_ADVANCED_SETTINGS); + advancedSettingsCommandButton.addActionListener(this::advancedSettings); advancedSettingsBand.addCommandButton(advancedSettingsCommandButton, RibbonElementPriority.TOP); clearRecentFilesCommandButton = new JCommandButton(fixCommandTitle(translate("menu.tools.otherTools.clearRecentFiles")), View.getResizableIcon("clearrecent16")); - assignListener(clearRecentFilesCommandButton, ACTION_CLEAR_RECENT_FILES); + clearRecentFilesCommandButton.addActionListener(this::clearRecentFiles); advancedSettingsBand.addCommandButton(clearRecentFilesCommandButton, RibbonElementPriority.MEDIUM); JRibbonBand deobfuscationBand = new JRibbonBand(translate("menu.deobfuscation"), null); @@ -660,10 +534,14 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener CommandToggleButtonGroup grpDeobfuscation = new CommandToggleButtonGroup(); deobfuscationModeOldToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.deobfuscation.old")), View.getResizableIcon("deobfuscateold16")); - assignListener(deobfuscationModeOldToggleButton, ACTION_DEOBFUSCATION_MODE_OLD); + deobfuscationModeOldToggleButton.addActionListener((ActionEvent e) -> { + deobfuscationMode(e, 0); + }); deobfuscationModeNewToggleButton = new JCommandToggleButton(fixCommandTitle(translate("menu.file.deobfuscation.new")), View.getResizableIcon("deobfuscatenew16")); - assignListener(deobfuscationModeNewToggleButton, ACTION_DEOBFUSCATION_MODE_NEW); + deobfuscationModeNewToggleButton.addActionListener((ActionEvent e) -> { + deobfuscationMode(e, 1); + }); grpDeobfuscation.add(deobfuscationModeOldToggleButton); grpDeobfuscation.add(deobfuscationModeNewToggleButton); @@ -691,13 +569,13 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener helpBand.setResizePolicies(getResizePolicies(helpBand)); JCommandButton checkForUpdatesCommandButton = new JCommandButton(fixCommandTitle(translate("menu.help.checkupdates")), View.getResizableIcon("update16")); - assignListener(checkForUpdatesCommandButton, ACTION_CHECK_UPDATES); + checkForUpdatesCommandButton.addActionListener(this::checkUpdates); JCommandButton helpUsUpdatesCommandButton = new JCommandButton(fixCommandTitle(translate("menu.help.helpus")), View.getResizableIcon("donate32")); - assignListener(helpUsUpdatesCommandButton, ACTION_HELP_US); + helpUsUpdatesCommandButton.addActionListener(this::helpUs); JCommandButton homepageCommandButton = new JCommandButton(fixCommandTitle(translate("menu.help.homepage")), View.getResizableIcon("homepage16")); - assignListener(homepageCommandButton, ACTION_HOMEPAGE); + homepageCommandButton.addActionListener(this::homePage); JCommandButton aboutCommandButton = new JCommandButton(fixCommandTitle(translate("menu.help.about")), View.getResizableIcon("about32")); - assignListener(aboutCommandButton, ACTION_ABOUT); + aboutCommandButton.addActionListener(this::about); helpBand.addCommandButton(aboutCommandButton, RibbonElementPriority.TOP); helpBand.addCommandButton(checkForUpdatesCommandButton, RibbonElementPriority.MEDIUM); @@ -810,245 +688,51 @@ public class MainFrameRibbonMenu extends MainFrameMenu implements ActionListener //debuggerSwitchCommandButton. //debuggerDetachCommandButton.setEnabled(hasDebugger); debuggerReplaceTraceCommandButton.setEnabled(hasAbc && hasDebugger); - } - @Override - public void actionPerformed(ActionEvent e) { - switch (e.getActionCommand()) { - case ACTION_DEBUGGER_SWITCH: - if (debuggerSwitchGroup.getSelected() == null || View.showConfirmDialog(mainFrame, translate("message.debugger"), translate("dialog.message.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, Configuration.displayDebuggerInfo, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) { - switchDebugger(); - mainFrame.getPanel().refreshDecompiled(); - } else { - if (debuggerSwitchGroup.getSelected() == debuggerSwitchCommandButton) { - debuggerSwitchGroup.setSelected(debuggerSwitchCommandButton, false); - } - } - debuggerReplaceTraceCommandButton.setEnabled(debuggerSwitchGroup.getSelected() == debuggerSwitchCommandButton); - break; - case ACTION_DEBUGGER_LOG: - debuggerShowLog(); - break; - case ACTION_DEBUGGER_REPLACE_TRACE: - ReplaceTraceDialog rtd = new ReplaceTraceDialog(mainFrame, Configuration.lastDebuggerReplaceFunction.get()); - rtd.setVisible(true); - if (rtd.getValue() != null) { - replaceTraceCalls(rtd.getValue()); - mainFrame.getPanel().refreshDecompiled(); - Configuration.lastDebuggerReplaceFunction.set(rtd.getValue()); - } - break; - case ACTION_RELOAD: - reload(null); - break; - case ACTION_ADVANCED_SETTINGS: - advancedSettings(null); - break; - case ACTION_LOAD_MEMORY: - loadFromMemory(null); - break; - case ACTION_LOAD_CACHE: - loadFromCache(null); - break; - case ACTION_GOTO_DOCUMENT_CLASS_ON_STARTUP: - Configuration.gotoMainClassOnStartup.set(miGotoMainClassOnStartup.isSelected()); - break; - case ACTION_AUTO_RENAME_IDENTIFIERS: - Configuration.autoRenameIdentifiers.set(miAutoRenameIdentifiers.isSelected()); - break; - case ACTION_CACHE_ON_DISK: - Configuration.cacheOnDisk.set(miCacheDisk.isSelected()); - if (miCacheDisk.isSelected()) { - Cache.setStorageType(Cache.STORAGE_FILES); - } else { - Cache.setStorageType(Cache.STORAGE_MEMORY); - } - break; - case ACTION_SET_LANGUAGE: - setLanguage(); - break; - case ACTION_DISABLE_DECOMPILATION: - Configuration.decompile.set(!miDecompile.isSelected()); - mainFrame.getPanel().disableDecompilationChanged(); - break; - case ACTION_ASSOCIATE: - if (miAssociate.isSelected() == ContextMenuTools.isAddedToContextMenu()) { - return; - } - ContextMenuTools.addToContextMenu(miAssociate.isSelected(), false); + private void debuggerSwitchButtonActionPerformed(ActionEvent evt) { + if (debuggerSwitchGroup.getSelected() == null || View.showConfirmDialog(mainFrame, translate("message.debugger"), translate("dialog.message.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, Configuration.displayDebuggerInfo, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) { + switchDebugger(); + mainFrame.getPanel().refreshDecompiled(); + } else { + if (debuggerSwitchGroup.getSelected() == debuggerSwitchCommandButton) { + debuggerSwitchGroup.setSelected(debuggerSwitchCommandButton, false); + } + } + debuggerReplaceTraceCommandButton.setEnabled(debuggerSwitchGroup.getSelected() == debuggerSwitchCommandButton); + } - // Update checkbox menuitem accordingly (User can cancel rights elevation) - new Timer().schedule(new TimerTask() { - @Override - public void run() { - miAssociate.setSelected(ContextMenuTools.isAddedToContextMenu()); - } - }, 1000); // It takes some time registry change to apply - break; - case ACTION_GOTO_DOCUMENT_CLASS: - mainFrame.getPanel().gotoDocumentClass(mainFrame.getPanel().getCurrentSwf()); - break; - case ACTION_PARALLEL_SPEED_UP: - String confStr = translate("message.confirm.parallel") + "\r\n"; - if (miParallelSpeedUp.isSelected()) { - confStr += " " + translate("message.confirm.on"); - } else { - confStr += " " + translate("message.confirm.off"); - } - if (View.showConfirmDialog(null, confStr, translate("message.parallel"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { - Configuration.parallelSpeedUp.set((Boolean) miParallelSpeedUp.isSelected()); - } else { - miParallelSpeedUp.setSelected(!miParallelSpeedUp.isSelected()); - } - break; - case ACTION_INTERNAL_VIEWER_SWITCH: - Configuration.internalFlashViewer.set(miInternalViewer.isSelected()); - mainFrame.getPanel().reload(true); - break; + private void viewModeResouresButtonActionPerformed(ActionEvent evt) { + Configuration.dumpView.set(false); + mainFrame.getPanel().showView(MainPanel.VIEW_RESOURCES); + timeLineToggleGroup.setSelected(timeLineToggleButton, false); + viewModeToggleGroup.setSelected(viewModeResourcesToggleButton, true); + } - case ACTION_VIEWMODE_RESOURCES: - Configuration.dumpView.set(false); - mainFrame.getPanel().showView(MainPanel.VIEW_RESOURCES); - timeLineToggleGroup.setSelected(timeLineToggleButton, false); - viewModeToggleGroup.setSelected(viewModeResourcesToggleButton, true); - break; - case ACTION_VIEWMODE_HEX_DUMP: - Configuration.dumpView.set(true); - mainFrame.getPanel().showView(MainPanel.VIEW_DUMP); + private void viewModeHexDumpButtonActionPerformed(ActionEvent evt) { + Configuration.dumpView.set(true); + mainFrame.getPanel().showView(MainPanel.VIEW_DUMP); + timeLineToggleGroup.setSelected(timeLineToggleButton, false); + viewModeToggleGroup.setSelected(viewModeHexToggleButton, true); + } + + private void timelineButtonActionPerformed(ActionEvent evt) { + timeLineToggleGroup.setSelected(timeLineToggleButton, timeLineToggleGroup.getSelected() == timeLineToggleButton); + if (timeLineToggleGroup.getSelected() == timeLineToggleButton) { + if (!mainFrame.getPanel().showView(MainPanel.VIEW_TIMELINE)) { timeLineToggleGroup.setSelected(timeLineToggleButton, false); + } else { + viewModeToggleGroup.setSelected(viewModeHexToggleButton, false); + viewModeToggleGroup.setSelected(viewModeResourcesToggleButton, false); + } + } else { + if (Configuration.dumpView.get()) { viewModeToggleGroup.setSelected(viewModeHexToggleButton, true); - break; - case ACTION_DEOBFUSCATION_MODE_OLD: - Configuration.deobfuscationMode.set(0); - mainFrame.getPanel().autoDeobfuscateChanged(); - break; - case ACTION_DEOBFUSCATION_MODE_NEW: - Configuration.deobfuscationMode.set(1); - mainFrame.getPanel().autoDeobfuscateChanged(); - break; - case ACTION_SEARCH: - search(null); - break; - case ACTION_REPLACE: - replace(); - break; - case ACTION_TIMELINE: - timeLineToggleGroup.setSelected(timeLineToggleButton, timeLineToggleGroup.getSelected() == timeLineToggleButton); - if (timeLineToggleGroup.getSelected() == timeLineToggleButton) { - if (!mainFrame.getPanel().showView(MainPanel.VIEW_TIMELINE)) { - timeLineToggleGroup.setSelected(timeLineToggleButton, false); - } else { - viewModeToggleGroup.setSelected(viewModeHexToggleButton, false); - viewModeToggleGroup.setSelected(viewModeResourcesToggleButton, false); - } - } else { - if (Configuration.dumpView.get()) { - viewModeToggleGroup.setSelected(viewModeHexToggleButton, true); - mainFrame.getPanel().showView(MainPanel.VIEW_DUMP); - } else { - viewModeToggleGroup.setSelected(viewModeResourcesToggleButton, true); - mainFrame.getPanel().showView(MainPanel.VIEW_RESOURCES); - } - - } - break; - case ACTION_AUTO_DEOBFUSCATE: - if (View.showConfirmDialog(mainFrame.getPanel(), translate("message.confirm.autodeobfuscate") + "\r\n" + (miAutoDeobfuscation.isSelected() ? translate("message.confirm.on") : translate("message.confirm.off")), translate("message.confirm"), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { - Configuration.autoDeobfuscate.set(miAutoDeobfuscation.isSelected()); - mainFrame.getPanel().autoDeobfuscateChanged(); - } else { - miAutoDeobfuscation.setSelected(!miAutoDeobfuscation.isSelected()); - } - break; - case ACTION_CLEAR_RECENT_FILES: - Configuration.recentFiles.set(null); - break; - case ACTION_EXIT: - exit(); - break; - } - - if (Main.isWorking()) { - return; - } - - switch (e.getActionCommand()) { - case ACTION_RENAME_ONE_IDENTIFIER: - renameOneIdentifier(); - break; - case ACTION_SHOW_PROXY: - showProxy(); - break; - case ACTION_SUB_LIMITER: - setSubLimiter(((JCheckBox) e.getSource()).isSelected()); - break; - case ACTION_SAVE: - save(); - break; - case ACTION_SAVE_AS: - saveAs(); - break; - case ACTION_SAVE_AS_EXE: - saveAsExe(); - break; - case ACTION_OPEN: - open(); - break; - case ACTION_CLOSE: - close(); - break; - case ACTION_CLOSE_ALL: - closeAll(); - break; - case ACTION_IMPORT_TEXT: - importText(); - break; - case ACTION_IMPORT_SCRIPT: - importScript(); - break; - case ACTION_IMPORT_SYMBOL_CLASS: - importSymbolClass(); - break; - - case ACTION_EXPORT_SWF_XML: - mainFrame.getPanel().exportSwfXml(); - break; - case ACTION_IMPORT_SWF_XML: - mainFrame.getPanel().importSwfXml(); - break; - case ACTION_EXPORT_SEL: - case ACTION_EXPORT: - boolean onlySel = e.getActionCommand().equals(ACTION_EXPORT_SEL); - export(onlySel); - break; - case ACTION_EXPORT_FLA: - exportFla(); - break; - case ACTION_CHECK_UPDATES: - checkUpdates(); - break; - case ACTION_HELP_US: - helpUs(); - break; - case ACTION_HOMEPAGE: - homePage(); - break; - case ACTION_ABOUT: - about(); - break; - case ACTION_RESTORE_CONTROL_FLOW: - case ACTION_RESTORE_CONTROL_FLOW_ALL: - boolean all = e.getActionCommand().equals(ACTION_RESTORE_CONTROL_FLOW_ALL); - restoreControlFlow(all); - break; - case ACTION_RENAME_IDENTIFIERS: - renameIdentifiers(); - break; - case ACTION_DEOBFUSCATE: - case ACTION_DEOBFUSCATE_ALL: - deobfuscate(); - break; + mainFrame.getPanel().showView(MainPanel.VIEW_DUMP); + } else { + viewModeToggleGroup.setSelected(viewModeResourcesToggleButton, true); + mainFrame.getPanel().showView(MainPanel.VIEW_RESOURCES); + } } } } diff --git a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java index a53b8f496..cf0b158df 100644 --- a/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/PreviewPanel.java @@ -340,8 +340,7 @@ public class PreviewPanel extends JSplitPane { /*JPanel bottomPanel = new JPanel(new BorderLayout()); JPanel buttonsPanel = new JPanel(new FlowLayout()); JButton selectColorButton = new JButton(View.getIcon("color16")); - selectColorButton.addActionListener(mainPanel); - selectColorButton.setActionCommand(MainPanel.ACTION_SELECT_BKCOLOR); + selectColorButton.addActionListener(mainPanel::selectBkColor); selectColorButton.setToolTipText(AppStrings.translate("button.selectbkcolor.hint")); buttonsPanel.add(selectColorButton); bottomPanel.add(buttonsPanel, BorderLayout.EAST); diff --git a/src/com/jpexs/decompiler/flash/gui/ReplaceTraceDialog.java b/src/com/jpexs/decompiler/flash/gui/ReplaceTraceDialog.java index 412683db7..ca3fde489 100644 --- a/src/com/jpexs/decompiler/flash/gui/ReplaceTraceDialog.java +++ b/src/com/jpexs/decompiler/flash/gui/ReplaceTraceDialog.java @@ -18,7 +18,6 @@ package com.jpexs.decompiler.flash.gui; import java.awt.Container; import java.awt.FlowLayout; -import java.awt.Window; import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import javax.swing.ButtonGroup; @@ -61,8 +60,7 @@ public class ReplaceTraceDialog extends AppDialog { return value; } - public ReplaceTraceDialog(Window owner, String defaultVal) { - super(owner); + public ReplaceTraceDialog(String defaultVal) { setTitle(translate("dialog.title")); Container cnt = getContentPane(); cnt.setLayout(new BoxLayout(cnt, BoxLayout.Y_AXIS)); diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index e5de9fe31..d9a1d56b2 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -111,7 +111,7 @@ import jsyntaxpane.SyntaxDocument; import jsyntaxpane.Token; import jsyntaxpane.TokenType; -public class ABCPanel extends JPanel implements ItemListener, ActionListener, SearchListener, Freed { +public class ABCPanel extends JPanel implements ItemListener, SearchListener, Freed { private MainPanel mainPanel; @@ -149,12 +149,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se public JLabel scriptNameLabel; - private static final String ACTION_SAVE_DECOMPILED = "SAVEDECOMPILED"; - - private static final String ACTION_EDIT_DECOMPILED = "EDITDECOMPILED"; - - private static final String ACTION_CANCEL_DECOMPILED = "CANCELDECOMPILED"; - public JLabel experimentalLabel = new JLabel(AppStrings.translate("action.edit.experimental")); public JButton editDecompiledButton = new JButton(AppStrings.translate("button.edit"), View.getIcon("edit16")); @@ -163,8 +157,6 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se public JButton cancelDecompiledButton = new JButton(AppStrings.translate("button.cancel"), View.getIcon("cancel16")); - private static final String ACTION_ADD_TRAIT = "ADDTRAIT"; - private static List modifiedPacks = new ArrayList<>(); public MainPanel getMainPanel() { @@ -354,8 +346,7 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se JButton newTraitButton = new JButton(View.getIcon("traitadd16")); newTraitButton.setMargin(new Insets(5, 5, 5, 5)); - newTraitButton.addActionListener(this); - newTraitButton.setActionCommand(ACTION_ADD_TRAIT); + newTraitButton.addActionListener(this::addTraitButtonActionPerformed); newTraitButton.setToolTipText(AppStrings.translate("button.addtrait")); iconsPanel.add(newTraitButton); @@ -378,13 +369,10 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se saveDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); cancelDecompiledButton.setMargin(new Insets(3, 3, 3, 10)); - saveDecompiledButton.addActionListener(this); - saveDecompiledButton.setActionCommand(ACTION_SAVE_DECOMPILED); - editDecompiledButton.addActionListener(this); - editDecompiledButton.setActionCommand(ACTION_EDIT_DECOMPILED); + saveDecompiledButton.addActionListener(this::saveDecompiledButtonActionPerformed); + editDecompiledButton.addActionListener(this::editDecompiledButtonActionPerformed); + cancelDecompiledButton.addActionListener(this::cancelDecompiledButtonActionPerformed); - cancelDecompiledButton.addActionListener(this); - cancelDecompiledButton.setActionCommand(ACTION_CANCEL_DECOMPILED); saveDecompiledButton.setVisible(false); cancelDecompiledButton.setVisible(false); decButtonsPan.setAlignmentX(0); @@ -762,171 +750,168 @@ public class ABCPanel extends JPanel implements ItemListener, ActionListener, Se decompiledTextArea.requestFocusInWindow(); } - @Override - public void actionPerformed(ActionEvent e) { - switch (e.getActionCommand()) { - case ACTION_EDIT_DECOMPILED: - File swc = Configuration.getPlayerSWC(); - final String adobePage = "http://www.adobe.com/support/flashplayer/downloads.html"; - if (swc == null) { - if (View.showConfirmDialog(this, AppStrings.translate("message.action.playerglobal.needed").replace("%adobehomepage%", adobePage), AppStrings.translate("message.action.playerglobal.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.OK_OPTION) { + private void editDecompiledButtonActionPerformed(ActionEvent evt) { + File swc = Configuration.getPlayerSWC(); + final String adobePage = "http://www.adobe.com/support/flashplayer/downloads.html"; + if (swc == null) { + if (View.showConfirmDialog(this, AppStrings.translate("message.action.playerglobal.needed").replace("%adobehomepage%", adobePage), AppStrings.translate("message.action.playerglobal.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.OK_OPTION) { - View.navigateUrl(adobePage); + View.navigateUrl(adobePage); - int ret; - do { - ret = View.showConfirmDialog(this, AppStrings.translate("message.action.playerglobal.place").replace("%libpath%", Configuration.getFlashLibPath().getAbsolutePath()), AppStrings.translate("message.action.playerglobal.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); - swc = Configuration.getPlayerSWC(); - } while (ret == JOptionPane.OK_OPTION && swc == null); - } - } - if (swc != null) { - if (View.showConfirmDialog(null, AppStrings.translate("message.confirm.experimental.function"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, Configuration.warningExperimentalAS3Edit, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) { - setDecompiledEditMode(true); - } - } - break; - case ACTION_CANCEL_DECOMPILED: - setDecompiledEditMode(false); - break; - case ACTION_SAVE_DECOMPILED: - ScriptPack pack = decompiledTextArea.getScriptLeaf(); - int oldIndex = pack.scriptIndex; - SWF.uncache(pack); - - try { - String oldSp = null; - List packs = abc.script_info.get(oldIndex).getPacks(abc, oldIndex, null); - if (!packs.isEmpty()) { - oldSp = packs.get(0).getClassPath().toString(); - } - - String as = decompiledTextArea.getText(); - abc.replaceScriptPack(pack, as); - lastDecompiled = as; - mainPanel.updateClassesList(); - - if (oldSp != null) { - hilightScript(getSwf(), oldSp); - } - setDecompiledEditMode(false); - reload(); - View.showMessageDialog(this, AppStrings.translate("message.action.saved"), AppStrings.translate("dialog.message.title"), JOptionPane.INFORMATION_MESSAGE, Configuration.showCodeSavedMessage); - } catch (AVM2ParseException ex) { - abc.script_info.get(oldIndex).delete(abc, false); - decompiledTextArea.gotoLine((int) ex.line); - decompiledTextArea.markError(); - View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); - } catch (CompilationException ex) { - abc.script_info.get(oldIndex).delete(abc, false); - decompiledTextArea.gotoLine((int) ex.line); - decompiledTextArea.markError(); - View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); - } catch (IOException | InterruptedException ex) { - //ignore - } - break; - case ACTION_ADD_TRAIT: - int class_index = decompiledTextArea.getClassIndex(); - if (class_index < 0) { - return; - } - if (newTraitDialog == null) { - newTraitDialog = new NewTraitDialog(); - } - int void_type = abc.constants.getPublicQnameId("void", true);//abc.constants.forceGetMultinameId(new Multiname(Multiname.QNAME, abc.constants.forceGetStringId("void"), abc.constants.forceGetNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.forceGetStringId("")), 0), -1, -1, new ArrayList())); - int int_type = abc.constants.getPublicQnameId("int", true); //abc.constants.forceGetMultinameId(new Multiname(Multiname.QNAME, abc.constants.forceGetStringId("int"), abc.constants.forceGetNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.forceGetStringId("")), 0), -1, -1, new ArrayList())); - - Trait t = null; - int kind; - int nskind; - String name = null; - boolean isStatic; - Multiname m; - - boolean again = false; - loopm: + int ret; do { - if (again) { - View.showMessageDialog(null, AppStrings.translate("error.trait.exists").replace("%name%", name), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); - } - again = false; - if (newTraitDialog.showDialog() != AppDialog.OK_OPTION) { - return; - } - kind = newTraitDialog.getTraitType(); - nskind = newTraitDialog.getNamespaceKind(); - name = newTraitDialog.getTraitName(); - isStatic = newTraitDialog.getStatic(); - m = new Multiname(Multiname.QNAME, abc.constants.getStringId(name, true), abc.constants.getNamespaceId(new Namespace(nskind, abc.constants.getStringId("", true)), 0, true), 0, 0, new ArrayList<>()); - int mid = abc.constants.getMultinameId(m); - if (mid == 0) { - break; - } - for (Trait tr : abc.class_info.get(class_index).static_traits.traits) { - if (tr.name_index == mid) { - again = true; - break; - } - } + ret = View.showConfirmDialog(this, AppStrings.translate("message.action.playerglobal.place").replace("%libpath%", Configuration.getFlashLibPath().getAbsolutePath()), AppStrings.translate("message.action.playerglobal.title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE); + swc = Configuration.getPlayerSWC(); + } while (ret == JOptionPane.OK_OPTION && swc == null); + } + } + if (swc != null) { + if (View.showConfirmDialog(null, AppStrings.translate("message.confirm.experimental.function"), AppStrings.translate("message.warning"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, Configuration.warningExperimentalAS3Edit, JOptionPane.OK_OPTION) == JOptionPane.OK_OPTION) { + setDecompiledEditMode(true); + } + } + } - for (Trait tr : abc.instance_info.get(class_index).instance_traits.traits) { - if (tr.name_index == mid) { - again = true; - break; - } - } - } while (again); - switch (kind) { - case Trait.TRAIT_GETTER: - case Trait.TRAIT_SETTER: - case Trait.TRAIT_METHOD: - TraitMethodGetterSetter tm = new TraitMethodGetterSetter(); - MethodInfo mi = new MethodInfo(new int[0], void_type, abc.constants.getStringId(name, true), 0, new ValueKind[0], new int[0]); - int method_info = abc.addMethodInfo(mi); - tm.method_info = method_info; - MethodBody body = new MethodBody(); - body.method_info = method_info; - body.init_scope_depth = 1; - body.max_regs = 1; - body.max_scope_depth = 1; - body.max_stack = 1; - body.exceptions = new ABCException[0]; - AVM2Code code = new AVM2Code(); - code.code.add(new AVM2Instruction(0, new GetLocal0Ins(), new int[0])); - code.code.add(new AVM2Instruction(0, new PushScopeIns(), new int[0])); - code.code.add(new AVM2Instruction(0, new ReturnVoidIns(), new int[0])); - body.setCode(code); - Traits traits = new Traits(); - traits.traits = new ArrayList<>(); - body.traits = traits; - abc.addMethodBody(body); - mi.setBody(body); - t = tm; - break; - case Trait.TRAIT_SLOT: - case Trait.TRAIT_CONST: - TraitSlotConst ts = new TraitSlotConst(); - ts.type_index = int_type; - ts.value_kind = ValueKind.CONSTANT_Int; - ts.value_index = abc.constants.getIntId(0, true); - t = ts; - break; - } - if (t != null) { - t.kindType = kind; - t.name_index = abc.constants.getMultinameId(m, true); - int traitId; - if (isStatic) { - traitId = abc.class_info.get(class_index).static_traits.addTrait(t); - } else { - traitId = abc.class_info.get(class_index).static_traits.traits.size() + abc.instance_info.get(class_index).instance_traits.addTrait(t); - } - reload(); - decompiledTextArea.gotoTrait(traitId); - } + private void cancelDecompiledButtonActionPerformed(ActionEvent evt) { + setDecompiledEditMode(false); + } + private void saveDecompiledButtonActionPerformed(ActionEvent evt) { + ScriptPack pack = decompiledTextArea.getScriptLeaf(); + int oldIndex = pack.scriptIndex; + SWF.uncache(pack); + + try { + String oldSp = null; + List packs = abc.script_info.get(oldIndex).getPacks(abc, oldIndex, null); + if (!packs.isEmpty()) { + oldSp = packs.get(0).getClassPath().toString(); + } + + String as = decompiledTextArea.getText(); + abc.replaceScriptPack(pack, as); + lastDecompiled = as; + mainPanel.updateClassesList(); + + if (oldSp != null) { + hilightScript(getSwf(), oldSp); + } + setDecompiledEditMode(false); + reload(); + View.showMessageDialog(this, AppStrings.translate("message.action.saved"), AppStrings.translate("dialog.message.title"), JOptionPane.INFORMATION_MESSAGE, Configuration.showCodeSavedMessage); + } catch (AVM2ParseException ex) { + abc.script_info.get(oldIndex).delete(abc, false); + decompiledTextArea.gotoLine((int) ex.line); + decompiledTextArea.markError(); + View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + } catch (CompilationException ex) { + abc.script_info.get(oldIndex).delete(abc, false); + decompiledTextArea.gotoLine((int) ex.line); + decompiledTextArea.markError(); + View.showMessageDialog(this, AppStrings.translate("error.action.save").replace("%error%", ex.text).replace("%line%", Long.toString(ex.line)), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + } catch (IOException | InterruptedException ex) { + //ignore + } + } + + private void addTraitButtonActionPerformed(ActionEvent evt) { + int class_index = decompiledTextArea.getClassIndex(); + if (class_index < 0) { + return; + } + if (newTraitDialog == null) { + newTraitDialog = new NewTraitDialog(); + } + int void_type = abc.constants.getPublicQnameId("void", true);//abc.constants.forceGetMultinameId(new Multiname(Multiname.QNAME, abc.constants.forceGetStringId("void"), abc.constants.forceGetNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.forceGetStringId("")), 0), -1, -1, new ArrayList())); + int int_type = abc.constants.getPublicQnameId("int", true); //abc.constants.forceGetMultinameId(new Multiname(Multiname.QNAME, abc.constants.forceGetStringId("int"), abc.constants.forceGetNamespaceId(new Namespace(Namespace.KIND_PACKAGE, abc.constants.forceGetStringId("")), 0), -1, -1, new ArrayList())); + + Trait t = null; + int kind; + int nskind; + String name = null; + boolean isStatic; + Multiname m; + + boolean again = false; + loopm: + do { + if (again) { + View.showMessageDialog(null, AppStrings.translate("error.trait.exists").replace("%name%", name), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); + } + again = false; + if (newTraitDialog.showDialog() != AppDialog.OK_OPTION) { + return; + } + kind = newTraitDialog.getTraitType(); + nskind = newTraitDialog.getNamespaceKind(); + name = newTraitDialog.getTraitName(); + isStatic = newTraitDialog.getStatic(); + m = new Multiname(Multiname.QNAME, abc.constants.getStringId(name, true), abc.constants.getNamespaceId(new Namespace(nskind, abc.constants.getStringId("", true)), 0, true), 0, 0, new ArrayList<>()); + int mid = abc.constants.getMultinameId(m); + if (mid == 0) { break; + } + for (Trait tr : abc.class_info.get(class_index).static_traits.traits) { + if (tr.name_index == mid) { + again = true; + break; + } + } + + for (Trait tr : abc.instance_info.get(class_index).instance_traits.traits) { + if (tr.name_index == mid) { + again = true; + break; + } + } + } while (again); + switch (kind) { + case Trait.TRAIT_GETTER: + case Trait.TRAIT_SETTER: + case Trait.TRAIT_METHOD: + TraitMethodGetterSetter tm = new TraitMethodGetterSetter(); + MethodInfo mi = new MethodInfo(new int[0], void_type, abc.constants.getStringId(name, true), 0, new ValueKind[0], new int[0]); + int method_info = abc.addMethodInfo(mi); + tm.method_info = method_info; + MethodBody body = new MethodBody(); + body.method_info = method_info; + body.init_scope_depth = 1; + body.max_regs = 1; + body.max_scope_depth = 1; + body.max_stack = 1; + body.exceptions = new ABCException[0]; + AVM2Code code = new AVM2Code(); + code.code.add(new AVM2Instruction(0, new GetLocal0Ins(), new int[0])); + code.code.add(new AVM2Instruction(0, new PushScopeIns(), new int[0])); + code.code.add(new AVM2Instruction(0, new ReturnVoidIns(), new int[0])); + body.setCode(code); + Traits traits = new Traits(); + traits.traits = new ArrayList<>(); + body.traits = traits; + abc.addMethodBody(body); + mi.setBody(body); + t = tm; + break; + case Trait.TRAIT_SLOT: + case Trait.TRAIT_CONST: + TraitSlotConst ts = new TraitSlotConst(); + ts.type_index = int_type; + ts.value_kind = ValueKind.CONSTANT_Int; + ts.value_index = abc.constants.getIntId(0, true); + t = ts; + break; + } + if (t != null) { + t.kindType = kind; + t.name_index = abc.constants.getMultinameId(m, true); + int traitId; + if (isStatic) { + traitId = abc.class_info.get(class_index).static_traits.addTrait(t); + } else { + traitId = abc.class_info.get(class_index).static_traits.traits.size() + abc.instance_info.get(class_index).instance_traits.addTrait(t); + } + reload(); + decompiledTextArea.gotoTrait(traitId); } } }