diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-03-22 13:52:29 +0100 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-03-22 13:52:29 +0100 |
commit | 0953f7cde8a2c09850f398790adc983ebf7f1b8b (patch) | |
tree | 60215d314905a71c545ff637061bb945f2eeee5f /pdf-over-gui/src/main/java/at | |
parent | 5cc1081113429add3b70887b47b4be4b8da8cf69 (diff) | |
download | pdf-over-0953f7cde8a2c09850f398790adc983ebf7f1b8b.tar.gz pdf-over-0953f7cde8a2c09850f398790adc983ebf7f1b8b.tar.bz2 pdf-over-0953f7cde8a2c09850f398790adc983ebf7f1b8b.zip |
sanitize swt handling
Diffstat (limited to 'pdf-over-gui/src/main/java/at')
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java | 18 | ||||
-rw-r--r-- | pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java | 109 |
2 files changed, 0 insertions, 127 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java index c2528adc..6af00889 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java @@ -58,7 +58,6 @@ import at.asit.pdfover.gui.controls.MainBarRectangleButton; import at.asit.pdfover.gui.controls.MainBarStartButton; import at.asit.pdfover.gui.osx.CocoaUIEnhancer; import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.utils.SWTLoader; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.states.BKUSelectionState; import at.asit.pdfover.gui.workflow.states.ConfigurationUIState; @@ -212,23 +211,6 @@ public class MainWindow { if (System.getProperty("os.name").contains("OS X")) { //$NON-NLS-1$ //$NON-NLS-2$ hookupOSXMenu(); } - // Workaround for SWT bug on Mac: disable full screen mode - try { - Field field = Control.class.getDeclaredField("view"); //$NON-NLS-1$ - Object /*NSView*/ view = field.get(getShell()); - if (view != null) - { - Class<?> c = Class.forName("org.eclipse.swt.internal.cocoa.NSView"); //$NON-NLS-1$ - Object nswindow = c.getDeclaredMethod("window").invoke(view); //$NON-NLS-1$ - c = Class.forName("org.eclipse.swt.internal.cocoa.NSWindow"); //$NON-NLS-1$ - Method setCollectionBehavior = c.getDeclaredMethod( - "setCollectionBehavior", //$NON-NLS-1$ - (SWTLoader.getArchBits() == 64) ? long.class : int.class); - setCollectionBehavior.invoke(nswindow, 0); - } - } catch (Exception e) { - log.error("Error disabling full screen mode", e); //$NON-NLS-1$ - } } try { Display display = Display.getCurrent(); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java deleted file mode 100644 index 6184ebc7..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SWTLoader.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.gui.utils; - -// Imports -import java.io.File; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.URLDecoder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.gui.exceptions.InitializationException; - -/** - * - */ -@SuppressWarnings("nls") -public class SWTLoader { - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory.getLogger(SWTLoader.class); - - /** - * Load the SWT library for this OS - * @throws InitializationException Loading failed - */ - public static void loadSWT() throws InitializationException { - try { - URLClassLoader cl = (URLClassLoader)SWTLoader.class.getClassLoader(); - Method addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); - addUrlMethod.setAccessible(true); - - String swtLibPath = getSwtJarPath() + getSwtJarName(); - log.debug("loading " + swtLibPath); - File swtLib = new File(swtLibPath); - if (!swtLib.isFile()) - throw new SWTLoadFailedException("Library " + swtLibPath + " not found"); - log.debug("Adding " + swtLib + " to ClassLoader..."); - addUrlMethod.invoke(cl, swtLib.toURI().toURL()); - log.debug("Success."); - } catch (Exception e) { - throw new InitializationException("SWT loading failed", e); - } - } - - /** - * Get bit-ness of the JVM - * @return 32 or 64 - */ - public static int getArchBits() { - String arch = System.getProperty("os.arch"); - return arch.contains("64") ? 64 : 32; - } - - private static String getSwtJarName() throws SWTLoadFailedException { - String os = System.getProperty("os.name").toLowerCase(); - if (os.contains("win")) - os = "windows"; - else if (os.contains("mac")) - os = "mac"; - else if (os.contains("linux") || os.contains("nix")) - os = "linux"; - else { - log.error("Unknown OS: " + os); - throw new SWTLoadFailedException("Unknown OS: " + os); - } - return "swt-" + os + "-" + getArchBits() + ".jar"; - } - - private static String getSwtJarPath() { - String path = ""; - try { - path = URLDecoder.decode(SWTLoader.class.getProtectionDomain().getCodeSource().getLocation().getPath(), "UTF-8"); - int idx = path.lastIndexOf('/'); - idx = path.lastIndexOf('/', idx - 1); - path = path.substring(0, idx + 1); - } catch (UnsupportedEncodingException e) { - // Ignore - } - return path + "lib-swt/"; - } - - private static class SWTLoadFailedException extends Exception { - private static final long serialVersionUID = 1L; - - SWTLoadFailedException(String msg) { - super(msg); - } - } - -} |