diff --git a/source/net/yacy/gui/Toolkits.java b/source/net/yacy/gui/Toolkits.java deleted file mode 100644 index 052b2fa87..000000000 --- a/source/net/yacy/gui/Toolkits.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Toolkits - * Copyright 2015 by Michael Peter Christen; mc@yacy.net, Frankfurt a. M., Germany - * First released 22.01.2015 at http://yacy.net - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program in the file lgpl21.txt - * If not, see . - */ - -package net.yacy.gui; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import net.yacy.cora.util.ConcurrentLog; - -public class Toolkits { - - public static Object applicationInstance; - public static Method setDockIconImage, setQuitHandler; - - static { - Class applicationClass = null; - try { - applicationClass = Class.forName("com.apple.eawt.Application"); - final Method applicationGetApplication = applicationClass.getMethod("getApplication"); - applicationInstance = applicationGetApplication.invoke(null); - setDockIconImage = applicationClass.getMethod("setDockIconImage", Class.forName("java.awt.Image")); - } catch (ClassNotFoundException|NoSuchMethodException|SecurityException|IllegalAccessException|IllegalArgumentException|InvocationTargetException e) { - ConcurrentLog.logException(e); - } - if (applicationClass != null) try { - final Class quitHandlerClass = Class.forName("com.apple.eawt.QuitHandler"); - setQuitHandler = applicationClass.getMethod("setQuitHandler", quitHandlerClass); - } catch (ClassNotFoundException|NoSuchMethodException|SecurityException|IllegalArgumentException e) { - ConcurrentLog.logException(e); - } - } -} diff --git a/source/net/yacy/gui/Tray.java b/source/net/yacy/gui/Tray.java index d4451925a..b585639d5 100644 --- a/source/net/yacy/gui/Tray.java +++ b/source/net/yacy/gui/Tray.java @@ -38,6 +38,8 @@ import java.awt.event.ActionListener; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import javax.imageio.ImageIO; @@ -145,11 +147,30 @@ public final class Tray { Tray.this.progressIcons = null; } } + + private static Object applicationInstance; + private static Method setDockIconImage; + + static { + Class applicationClass = null; + try { + applicationClass = Class.forName("com.apple.eawt.Application"); + final Method applicationGetApplication = applicationClass.getMethod("getApplication"); + applicationInstance = applicationGetApplication.invoke(null); + } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + ConcurrentLog.logException(e); + } + if (applicationClass != null) try { + setDockIconImage = applicationClass.getMethod("setDockIconImage", Class.forName("java.awt.Image")); + } catch (ClassNotFoundException | SecurityException | IllegalArgumentException | NoSuchMethodException e) { + ConcurrentLog.logException(e); + } + } private static void setDockIcon(Image icon) { - if (!OS.isMacArchitecture || Toolkits.setDockIconImage == null || Toolkits.applicationInstance == null) return; + if (!OS.isMacArchitecture || setDockIconImage == null || applicationInstance == null) return; try { - Toolkits.setDockIconImage.invoke(Toolkits.applicationInstance, icon); + setDockIconImage.invoke(applicationInstance, icon); } catch (final Throwable e) {} // same as: Application.getApplication().setDockIconImage(i); }