Created
October 1, 2018 13:20
-
-
Save RChehowski/c59b292c9f15db922c178c0303e91024 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.vizor.unreal.platform.mac; | |
import com.vizor.unreal.platform.FrameDecorator; | |
import javax.swing.ImageIcon; | |
import java.awt.Image; | |
import java.lang.invoke.MethodHandle; | |
import java.net.URL; | |
import static java.lang.invoke.MethodHandles.lookup; | |
import static java.lang.invoke.MethodType.methodType; | |
public class MacFrameDecorator extends FrameDecorator | |
{ | |
// Root application class | |
private final Object application; | |
// Methods: | |
private final MethodHandle setDockIconImage; | |
public MacFrameDecorator() | |
{ | |
try { | |
final Class<?> applicationClass = Class.forName("com.apple.eawt.Application"); | |
application = applicationClass.getMethod("getApplication").invoke(null); | |
// setDockIconImage method handle | |
setDockIconImage = lookup().findVirtual(applicationClass, "setDockIconImage", | |
methodType(void.class, Image.class)); | |
} | |
catch (Throwable t) { | |
throw new RuntimeException(t); | |
} | |
} | |
@Override | |
protected void setApplicationIconImpl(URL iconUrl) | |
{ | |
final Image image = new ImageIcon(iconUrl).getImage(); | |
try { | |
setDockIconImage.invoke(application, image); | |
} | |
catch (Throwable t) { | |
throw new RuntimeException(t); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment