set look and feel only when it is different from the previous

This commit is contained in:
honfika@gmail.com
2015-05-25 14:49:10 +02:00
parent 48b90ec8da
commit 134fd1558a
6 changed files with 229 additions and 195 deletions

View File

@@ -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);

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -168,4 +168,11 @@ public final class MainFrameRibbon extends AppRibbonFrame {
public Window getWindow() {
return this;
}
@Override
public void dispose() {
removeAll();
mainMenu.dispose();
super.dispose();
}
}

View File

@@ -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");
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<String> 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 <http://www.gnu.org/licenses/>.
*/
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<String> 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;
}
}
}