diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 776af2ada..0c480958a 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -861,10 +861,7 @@ public class Main { exit(); } if (Configuration.useRibbonInterface.get()) { - Stopwatch sw = Stopwatch.startNew(); View.setLookAndFeel(); - sw.stop(); - System.out.println("sw: " + sw.getElapsedMilliseconds()); } else { try { UIManager.put(SubstanceLookAndFeel.COLORIZATION_FACTOR, null); diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java index c16bf9dd9..703e83e3d 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java @@ -121,4 +121,11 @@ public final class MainFrameClassic extends AppFrame implements MainFrame { public Window getWindow() { return this; } + + @Override + public void dispose() { + removeAll(); + mainMenu.dispose(); + super.dispose(); + } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java index 0ceb9b15b..180c6963f 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameMenu.java @@ -34,6 +34,7 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; +import java.awt.KeyEventDispatcher; import java.awt.KeyboardFocusManager; import java.awt.ScrollPane; import java.awt.event.ActionEvent; @@ -63,6 +64,8 @@ public abstract class MainFrameMenu implements MenuBuilder { private final MainFrame mainFrame; + private KeyEventDispatcher keyEventDispatcher; + private SWF swf; public boolean isInternalFlashViewerSelected() { @@ -664,42 +667,7 @@ public abstract class MainFrameMenu implements MenuBuilder { private void registerHotKeys() { KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); - manager.addKeyEventDispatcher((KeyEvent e) -> { - if (((JFrame) mainFrame).isActive() && e.getID() == KeyEvent.KEY_PRESSED) { - int code = e.getKeyCode(); - if (e.isControlDown() && e.isShiftDown()) { - switch (code) { - case KeyEvent.VK_O: - return openActionPerformed(null); - case KeyEvent.VK_S: - return saveActionPerformed(null); - case KeyEvent.VK_A: - return saveAsActionPerformed(null); - case KeyEvent.VK_F: - return search(null, false); - case KeyEvent.VK_T: - return search(null, true); - case KeyEvent.VK_R: - return reloadActionPerformed(null); - case KeyEvent.VK_X: - return closeAllActionPerformed(null); - case KeyEvent.VK_D: - return clearLog(); - case KeyEvent.VK_E: - return export(false); - } - } else if (e.isControlDown() && !e.isShiftDown()) { - switch (code) { - case KeyEvent.VK_UP: - return previousTag(); - case KeyEvent.VK_DOWN: - return nextTag(); - } - } - } - - return false; - }); + manager.addKeyEventDispatcher(keyEventDispatcher = this::dispatchKeyEvent); } public void createMenuBar() { @@ -1014,4 +982,46 @@ public abstract class MainFrameMenu implements MenuBuilder { finishMenu("/file/" + (supportsMenuAction() ? "open" : "recent")); finishMenu("_/open"); } + + public void dispose() { + KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager(); + manager.removeKeyEventDispatcher(keyEventDispatcher); + } + + public boolean dispatchKeyEvent(KeyEvent e) { + if (((JFrame) mainFrame).isActive() && e.getID() == KeyEvent.KEY_PRESSED) { + int code = e.getKeyCode(); + if (e.isControlDown() && e.isShiftDown()) { + switch (code) { + case KeyEvent.VK_O: + return openActionPerformed(null); + case KeyEvent.VK_S: + return saveActionPerformed(null); + case KeyEvent.VK_A: + return saveAsActionPerformed(null); + case KeyEvent.VK_F: + return search(null, false); + case KeyEvent.VK_T: + return search(null, true); + case KeyEvent.VK_R: + return reloadActionPerformed(null); + case KeyEvent.VK_X: + return closeAllActionPerformed(null); + case KeyEvent.VK_D: + return clearLog(); + case KeyEvent.VK_E: + return export(false); + } + } else if (e.isControlDown() && !e.isShiftDown()) { + switch (code) { + case KeyEvent.VK_UP: + return previousTag(); + case KeyEvent.VK_DOWN: + return nextTag(); + } + } + } + + return false; + } } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java index 215d818f7..bf99d7cf5 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java @@ -168,4 +168,11 @@ public final class MainFrameRibbon extends AppRibbonFrame { public Window getWindow() { return this; } + + @Override + public void dispose() { + removeAll(); + mainMenu.dispose(); + super.dispose(); + } } diff --git a/src/com/jpexs/decompiler/flash/gui/View.java b/src/com/jpexs/decompiler/flash/gui/View.java index e699ef13d..f6a9ea3bf 100644 --- a/src/com/jpexs/decompiler/flash/gui/View.java +++ b/src/com/jpexs/decompiler/flash/gui/View.java @@ -69,6 +69,7 @@ import javax.swing.JRootPane; import javax.swing.JTable; import javax.swing.JTree; import javax.swing.KeyStroke; +import javax.swing.LookAndFeel; import javax.swing.SwingConstants; import javax.swing.SwingUtilities; import javax.swing.UIDefaults; @@ -91,6 +92,7 @@ import org.pushingpixels.substance.api.DecorationAreaType; import org.pushingpixels.substance.api.SubstanceColorScheme; import org.pushingpixels.substance.api.SubstanceConstants; import org.pushingpixels.substance.api.SubstanceLookAndFeel; +import org.pushingpixels.substance.api.SubstanceSkin; import org.pushingpixels.substance.api.fonts.FontPolicy; import org.pushingpixels.substance.api.fonts.FontSet; import org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel; @@ -158,9 +160,20 @@ public class View { } try { - UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel()); - SubstanceLookAndFeel.setSkin(Configuration.guiSkin.get()); - if (SubstanceLookAndFeel.getCurrentSkin() == null) { + LookAndFeel oldLookAndFeel = UIManager.getLookAndFeel(); + if (!(oldLookAndFeel instanceof SubstanceOfficeBlue2007LookAndFeel)) { + UIManager.setLookAndFeel(new SubstanceOfficeBlue2007LookAndFeel()); + oldLookAndFeel.uninitialize(); + } + + SubstanceSkin currentSkin = SubstanceLookAndFeel.getCurrentSkin(); + if (currentSkin != null) { + String currentSkinName = currentSkin.getClass().getName(); + String newSkinName = Configuration.guiSkin.get(); + if (!currentSkinName.equals(newSkinName)) { + SubstanceLookAndFeel.setSkin(newSkinName); + } + } else { Logger.getLogger(View.class.getName()).log(Level.SEVERE, "Current skin is null"); SubstanceLookAndFeel.setSkin("com.jpexs.decompiler.flash.gui.OceanicSkin"); } diff --git a/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java b/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java index 77436c646..81c96be34 100644 --- a/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java +++ b/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java @@ -1,153 +1,153 @@ -/* - * Copyright (C) 2015 Jindra - * - * 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.pipes; - -import com.jpexs.decompiler.flash.ApplicationInfo; -import com.jpexs.decompiler.flash.gui.Main; -import com.sun.jna.Platform; -import com.sun.jna.platform.win32.Kernel32; -import com.sun.jna.platform.win32.WinError; -import com.sun.jna.platform.win32.WinNT; -import java.awt.Window; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.util.List; - -/** - * - * @author JPEXS - */ -public class FirstInstance { - - private static final String MUTEX_NAME = "FFDEC_MUTEX"; - - private static WinNT.HANDLE mutex; - - public static final int PIPE_MAJOR = 1; - - public static final int PIPE_MINOR = 0; - - public static final String PIPE_NAME = "ffdec"; - - public static final String PIPE_APP_CODE = "ffdec"; - - private static boolean isRunning() { - if (Platform.isWindows()) { - mutex = Kernel32.INSTANCE.CreateMutex(null, false, MUTEX_NAME); - if (mutex == null) { - return false; - } - int er = Kernel32.INSTANCE.GetLastError(); - if (er == WinError.ERROR_ALREADY_EXISTS) { - return true; - } - - new Thread("OtherInstanceCommunicator") { - @Override - public void run() { - while (true) { - try (PipeInputStream pis = new PipeInputStream(PIPE_NAME, true)) { - ObjectInputStream ois = new ObjectInputStream(pis); - String app = ois.readUTF(); - if (app.equals(PIPE_APP_CODE)) { - int major = ois.readInt(); - int minor = ois.readInt(); - int release = ois.readInt(); - int build = ois.readInt(); - int pipeMajor = ois.readInt(); - int pipeMinor = ois.readInt(); - - if (pipeMajor == PIPE_MAJOR) { - String command = ois.readUTF(); - switch (command) { - case "open": - int cnt = ois.readInt(); - for (int i = 0; i < cnt; i++) { - Main.openFile(ois.readUTF(), null); - } - //no break - focus too - case "focus": - - java.awt.EventQueue.invokeLater(new Runnable() { - @Override - public void run() { - Window wnd = Main.getMainFrame().getWindow(); - wnd.setAlwaysOnTop(true); - wnd.toFront(); - wnd.requestFocus(); - wnd.setAlwaysOnTop(false); - wnd.repaint(); - } - }); - break; - } - } - - } - } catch (IOException ex) { - //ignore - } - } - } - }.start(); - - } - return false; - } - - private static ObjectOutputStream startCommand(String command) throws IOException { - PipeOutputStream pos = new PipeOutputStream(PIPE_NAME, false); - ObjectOutputStream oos = new ObjectOutputStream(pos); - oos.writeUTF(PIPE_APP_CODE); - oos.writeInt(ApplicationInfo.version_major); - oos.writeInt(ApplicationInfo.version_minor); - oos.writeInt(ApplicationInfo.version_release); - oos.writeInt(ApplicationInfo.version_build); - oos.writeInt(PIPE_MAJOR); - oos.writeInt(PIPE_MINOR); - oos.writeUTF(command); - return oos; - } - - public static boolean focus() { - if (!isRunning()) { - return false; - } - try { - ObjectOutputStream oos = startCommand("focus"); - oos.close(); - return true; - } catch (IOException ex) { - return false; - } - } - - public static boolean openFiles(List files) { - try { - ObjectOutputStream oos = startCommand("open"); - oos.writeInt(files.size()); - for (String s : files) { - oos.writeUTF(s); - } - oos.close(); - return true; - } catch (IOException ex) { - return false; - } - } -} +/* + * Copyright (C) 2015 Jindra + * + * 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.pipes; + +import com.jpexs.decompiler.flash.ApplicationInfo; +import com.jpexs.decompiler.flash.gui.Main; +import com.sun.jna.Platform; +import com.sun.jna.platform.win32.Kernel32; +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.platform.win32.WinNT; +import java.awt.Window; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.util.List; + +/** + * + * @author JPEXS + */ +public class FirstInstance { + + private static final String MUTEX_NAME = "FFDEC_MUTEX"; + + private static WinNT.HANDLE mutex; + + public static final int PIPE_MAJOR = 1; + + public static final int PIPE_MINOR = 0; + + public static final String PIPE_NAME = "ffdec"; + + public static final String PIPE_APP_CODE = "ffdec"; + + private static boolean isRunning() { + if (Platform.isWindows()) { + mutex = Kernel32.INSTANCE.CreateMutex(null, false, MUTEX_NAME); + if (mutex == null) { + return false; + } + int er = Kernel32.INSTANCE.GetLastError(); + if (er == WinError.ERROR_ALREADY_EXISTS) { + return true; + } + + new Thread("OtherInstanceCommunicator") { + @Override + public void run() { + while (true) { + try (PipeInputStream pis = new PipeInputStream(PIPE_NAME, true)) { + ObjectInputStream ois = new ObjectInputStream(pis); + String app = ois.readUTF(); + if (app.equals(PIPE_APP_CODE)) { + int major = ois.readInt(); + int minor = ois.readInt(); + int release = ois.readInt(); + int build = ois.readInt(); + int pipeMajor = ois.readInt(); + int pipeMinor = ois.readInt(); + + if (pipeMajor == PIPE_MAJOR) { + String command = ois.readUTF(); + switch (command) { + case "open": + int cnt = ois.readInt(); + for (int i = 0; i < cnt; i++) { + Main.openFile(ois.readUTF(), null); + } + //no break - focus too + case "focus": + + java.awt.EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + Window wnd = Main.getMainFrame().getWindow(); + wnd.setAlwaysOnTop(true); + wnd.toFront(); + wnd.requestFocus(); + wnd.setAlwaysOnTop(false); + wnd.repaint(); + } + }); + break; + } + } + + } + } catch (IOException ex) { + //ignore + } + } + } + }.start(); + + } + return false; + } + + private static ObjectOutputStream startCommand(String command) throws IOException { + PipeOutputStream pos = new PipeOutputStream(PIPE_NAME, false); + ObjectOutputStream oos = new ObjectOutputStream(pos); + oos.writeUTF(PIPE_APP_CODE); + oos.writeInt(ApplicationInfo.version_major); + oos.writeInt(ApplicationInfo.version_minor); + oos.writeInt(ApplicationInfo.version_release); + oos.writeInt(ApplicationInfo.version_build); + oos.writeInt(PIPE_MAJOR); + oos.writeInt(PIPE_MINOR); + oos.writeUTF(command); + return oos; + } + + public static boolean focus() { + if (!isRunning()) { + return false; + } + try { + ObjectOutputStream oos = startCommand("focus"); + oos.close(); + return true; + } catch (IOException ex) { + return false; + } + } + + public static boolean openFiles(List files) { + try { + ObjectOutputStream oos = startCommand("open"); + oos.writeInt(files.size()); + for (String s : files) { + oos.writeUTF(s); + } + oos.close(); + return true; + } catch (IOException ex) { + return false; + } + } +}