package nightcode;

import java.awt.*;
import java.lang.reflect.Method;
import java.util.Properties;

/**
 * This class handles loading of Nightcode namespaces while the splash image
 * is displayed on the screen. See entry point main() method in this class. How
 * it works:
 * 0. Assumes the splash screen is loaded (see project.clj - :manifest entry)
 * 1. Loads nightcode.core/-main using reflection (it takes time)
 * 2. Closes splash screen
 * 3. Invokes nightcode.core/-main
 */
public class Nightcode {

    private Method loadNightcodeMain() throws Exception {
        final String cn = "nightcode.core";
        Class<?> clazz = Class.forName(cn);
        if (clazz == null) {
            throw new RuntimeException("Cannot load class " + cn);
        }
        Method m = clazz.getMethod("main", String[].class);
        if (m == null) {
            throw new RuntimeException("Cannot obtain method 'main'");
        }
        return m;
    }

    private void invokeNightcodeMain(Method m, String[] args) throws Exception {
        m.invoke(null, (Object) args);
    }

    private void init(String[] args) throws Exception {
        final SplashScreen splash = SplashScreen.getSplashScreen();

        Method m = loadNightcodeMain();

        if (splash != null) {
            splash.close();
        }

        invokeNightcodeMain(m, args);
    }

    public static void main(String[] args) throws Exception {
        Properties props = System.getProperties();
        // properties to make font rendering smoother on Linux+OracleJVM/OpenJDK
        // should make no difference on other OSes and JVMs
        // set properties only if the user has not overidden them
        if (props.getProperty("awt.useSystemAAFontSettings") == null
                && props.getProperty("sun.java2d.xrender") == null) {
            props.setProperty("awt.useSystemAAFontSettings", "on");
            props.setProperty("sun.java2d.xrender", "true");
        }
        // initialize and launch Nightcode
        new Nightcode().init(args);
    }

}

@@ -93,16 +93,38 @@
 perties;
+%0Aimport javax.swing.*;
 %0A%0A/**%0A *
@@ -301,19 +301,13 @@
  0. 
-Assumes the
+Opens
  spl
@@ -322,52 +322,47 @@
 en i
-s loaded (see project.clj - :manifest entry)
+n a JWindow if it wasn't loaded via awt
 %0A * 
@@ -1206,25 +1206,24 @@
 shScreen();%0A
-%0A
         Meth
@@ -1230,62 +1230,579 @@
 od m
- = loadNightcodeMain();%0A%0A        if (splash != null) %7B
+;%0A%0A        if (splash == null) %7B%0A            JWindow window = new JWindow();%0A            ClassLoader cl = this.getClass().getClassLoader();%0A            Icon icon  = new ImageIcon(cl.getResource(%22logo_splash.png%22));%0A            window.add(new JLabel(icon));%0A            window.setSize(icon.getIconWidth(), icon.getIconHeight());%0A            window.setLocationRelativeTo(null);%0A            window.setVisible(true);%0A            m = loadNightcodeMain();%0A            window.setVisible(false);%0A            window.dispose();%0A        %7D else %7B%0A            m = loadNightcodeMain();
 %0A   

Support both splashscreen techniques