package org.lwjgl.vulkan.awt;

import org.lwjgl.system.Platform;
import org.lwjgl.vulkan.VkPhysicalDevice;

import java.awt.*;

/**
 * An AWT {@link Canvas} that supports to be drawn on using Vulkan.
 * 
 * @author Kai Burjack
 */
public abstract class AWTVKCanvas extends Canvas {
    private static final long serialVersionUID = 1L;
    private static PlatformVKCanvas platformCanvas;
    static {
        String platformClassName;
        switch (Platform.get()) {
        case WINDOWS:
            platformClassName = "org.lwjgl.vulkan.awt.PlatformWin32VKCanvas";
            break;
        case LINUX:
            platformClassName = "org.lwjgl.vulkan.awt.PlatformX11VKCanvas";
            break;
        case MACOSX:
            platformClassName = "org.lwjgl.vulkan.awt.PlatformMacOSXVKCanvas";
            break;
        default:
            throw new AssertionError("NYI");
        }
        try {
            @SuppressWarnings("unchecked")
            Class<? extends PlatformVKCanvas> clazz = (Class<? extends PlatformVKCanvas>) AWTVKCanvas.class.getClassLoader().loadClass(platformClassName);
            platformCanvas = clazz.newInstance();
        } catch (ClassNotFoundException e) {
            throw new AssertionError("Platform-specific VKCanvas class not found: " + platformClassName);
        } catch (InstantiationException e) {
            throw new AssertionError("Could not instantiate platform-specific VKCanvas class: " + platformClassName);
        } catch (IllegalAccessException e) {
            throw new AssertionError("Could not instantiate platform-specific VKCanvas class: " + platformClassName);
        }
    }

    private final VKData data;
    public long surface;

    protected AWTVKCanvas(VKData data) {
        this.data = data;
    }

    @Override
    public void paint(Graphics g) {
        boolean created = false;
        if (surface == 0L) {
            try {
                surface = platformCanvas.create(this, data);
                created = true;
            } catch (AWTException e) {
                throw new RuntimeException("Exception while creating the Vulkan surface", e);
            }
        }
        if (created)
            initVK();
        paintVK();
    }

    /**
     * Determine whether there is presentation support for the given {@link VkPhysicalDevice} in a command queue of the specified <code>queueFamiliy</code>.
     * 
     * @param physicalDevice
     *            the Vulkan {@link VkPhysicalDevice}
     * @param queueFamily
     *            the command queue family
     * @return <code>true</code> of <code>false</code>
     */
    public boolean getPhysicalDevicePresentationSupport(VkPhysicalDevice physicalDevice, int queueFamily) {
        return platformCanvas.getPhysicalDevicePresentationSupport(physicalDevice, queueFamily);
    }

    /**
     * Will be called once after the Vulkan surface has been created.
     */
    public abstract void initVK();

    /**
     * Will be called whenever the {@link Canvas} needs to paint itself.
     */
    public abstract void paintVK();

}

@@ -347,16 +347,22 @@
  static 
+final 
 Platform
@@ -411,33 +411,47 @@
     
-String platformClassName;
+// Enhanced switch would work better :(
 %0A   
@@ -528,41 +528,20 @@
 ormC
-lassName = %22org.lwjgl.vulkan.awt.
+anvas = new 
 Plat
@@ -549,33 +549,34 @@
 ormWin32VKCanvas
-%22
+()
 ;%0A            br
@@ -625,41 +625,20 @@
 ormC
-lassName = %22org.lwjgl.vulkan.awt.
+anvas = new 
 Plat
@@ -644,33 +644,34 @@
 tformX11VKCanvas
-%22
+()
 ;%0A            br
@@ -721,41 +721,20 @@
 ormC
-lassName = %22org.lwjgl.vulkan.awt.
+anvas = new 
 Plat
@@ -751,17 +751,18 @@
 VKCanvas
-%22
+()
 ;%0A      
@@ -850,757 +850,8 @@
   %7D%0A
-        try %7B%0A            @SuppressWarnings(%22unchecked%22)%0A            Class%3C? extends PlatformVKCanvas%3E clazz = (Class%3C? extends PlatformVKCanvas%3E) AWTVKCanvas.class.getClassLoader().loadClass(platformClassName);%0A            platformCanvas = clazz.newInstance();%0A        %7D catch (ClassNotFoundException e) %7B%0A            throw new AssertionError(%22Platform-specific VKCanvas class not found: %22 + platformClassName);%0A        %7D catch (InstantiationException e) %7B%0A            throw new AssertionError(%22Could not instantiate platform-specific VKCanvas class: %22 + platformClassName);%0A        %7D catch (IllegalAccessException e) %7B%0A            throw new AssertionError(%22Could not instantiate platform-specific VKCanvas class: %22 + platformClassName);%0A        %7D%0A
     

Replace reflection instantiation with normal instantiation