<commit_before>package org.lwjgl.opengl.awt;

import java.awt.AWTException;
import java.awt.Canvas;
import java.awt.Graphics;

public abstract class AWTGLCanvas extends Canvas {
    private static final long serialVersionUID = 1L;

    private PlatformGLCanvas platformGLCanvas = new PlatformWin32GLCanvas();
    protected long context;
    private final GLData data;
    private final GLData effective = new GLData();

    protected AWTGLCanvas(GLData data) {
        this.data = data;
    }

    protected AWTGLCanvas() {
        this(new GLData());
    }

    @Override
    public void paint(Graphics g) {
        boolean created = false;
        if (context == 0L) {
            try {
                context = platformGLCanvas.create(this, data, effective);
                created = true;
            } catch (AWTException e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }
        platformGLCanvas.makeCurrent(this, context);
        try {
            if (created)
                initGL();
            paintGL();
        } finally {
            platformGLCanvas.makeCurrent(null, 0L);
        }
    }

    /**
     * Will be called once after the OpenGL has been created.
     */
    public abstract void initGL();

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

    public final void swapBuffers() {
        platformGLCanvas.swapBuffers(this);
    }

}<commit_msg>Detect platform and reflectively instantiate platform implementation<commit_after>package org.lwjgl.opengl.awt;

import java.awt.AWTException;
import java.awt.Canvas;
import java.awt.Graphics;

import org.lwjgl.system.Platform;

public abstract class AWTGLCanvas extends Canvas {
    private static final long serialVersionUID = 1L;

    private static PlatformGLCanvas platformCanvas;
    static {
        String platformClassName;
        switch (Platform.get()) {
        case WINDOWS:
            platformClassName = "org.lwjgl.opengl.awt.PlatformWin32GLCanvas";
            break;
        default:
            throw new AssertionError("NYI");
        }
        try {
            @SuppressWarnings("unchecked")
            Class<? extends PlatformGLCanvas> clazz = (Class<? extends PlatformGLCanvas>) AWTGLCanvas.class.getClassLoader().loadClass(platformClassName);
            platformCanvas = clazz.newInstance();
        } catch (ClassNotFoundException e) {
            throw new AssertionError("Platform-specific GLCanvas class not found: " + platformClassName);
        } catch (InstantiationException e) {
            throw new AssertionError("Could not instantiate platform-specific GLCanvas class: " + platformClassName);
        } catch (IllegalAccessException e) {
            throw new AssertionError("Could not instantiate platform-specific GLCanvas class: " + platformClassName);
        }
    }

    protected long context;
    private final GLData data;
    private final GLData effective = new GLData();

    protected AWTGLCanvas(GLData data) {
        this.data = data;
    }

    protected AWTGLCanvas() {
        this(new GLData());
    }

    @Override
    public void paint(Graphics g) {
        boolean created = false;
        if (context == 0L) {
            try {
                context = platformCanvas.create(this, data, effective);
                created = true;
            } catch (AWTException e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }
        platformCanvas.makeCurrent(this, context);
        try {
            if (created)
                initGL();
            paintGL();
        } finally {
            platformCanvas.makeCurrent(null, 0L);
        }
    }

    /**
     * Will be called once after the OpenGL has been created.
     */
    public abstract void initGL();

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

    public final void swapBuffers() {
        platformCanvas.swapBuffers(this);
    }

}
{'fraction_non_alphanumeric': 0.08756993432254925, 'fraction_numerical': 0.0024324981756263684, 'mean_word_length': 2.1389312977099237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3942014', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1051, 'n_words': 300}