package cavm;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.lang.InterruptedException;
import javax.imageio.ImageIO;
import javax.swing.JDialog;
import java.awt.EventQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Splash {
    static final Logger LOG = LoggerFactory.getLogger(Splash.class);
    private static JDialog dialog;

    public static void close() {
	if (dialog != null) {
	    dialog.dispose();
	}
    }

    static void splash() {
	try {
	    final BufferedImage img = ImageIO.read(Splash.class.getResourceAsStream("/battle_slug_splash.png"));
	    dialog = new JDialog() {

		@Override
		public void paint(Graphics g) {
		    g.drawImage(img, 0, 0, null);
		}
	    };
	    // use the same size as your image
	    dialog.setPreferredSize(new Dimension(500, 548)); 
	    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
	    dialog.setUndecorated(true);
	    dialog.pack();
	    dialog.setLocationRelativeTo(null);
	    dialog.setVisible(true);
	    dialog.repaint();
//	    try {
		Class<?> uim = Class.forName("javax.swing.UIManager");
		uim.getDeclaredMethod("setLookAndFeel", String.class).invoke(null, (String) uim.getDeclaredMethod("getSystemLookAndFeelClassName").invoke(null));
//	    } catch (Exception ex) {
//		ex.printStackTrace(); // XXX better logging
//	    }
	} catch (Exception ex) {
	    LOG.error("Unable to open splash screen.", ex);
	}
    }

    static void runMain(String[] args) {
	// Invoke loader method
	try {
	    Class<?> clazz = Class.forName("cavm.core");
	    Class<?>[] argClass = new Class<?>[1];
	    argClass[0] = Class.forName("[Ljava.lang.String;");
	    Object[] argObj = new Object[] {args};

	    clazz.getDeclaredMethod("main", argClass).invoke(null, argObj);
	} catch (Exception ex) {
	    LOG.error("Unable to launch main application.", ex);
	}
    }

    public static void main(final String[] args) throws InterruptedException {
	EventQueue.invokeLater(new Runnable() {
	    public void run() {
		splash();
	    }
	});
	runMain(args);
    }
}

@@ -1105,23 +1105,13 @@
 ();%0A
-//
 %09    
-try %7B%0A%09%09
 Clas
@@ -1160,19 +1160,46 @@
 nager%22);
-%0A%09%09
+ // XXX do we need this?%0A%09    
 uim.getD
@@ -1340,97 +1340,8 @@
 ));%0A
-//%09    %7D catch (Exception ex) %7B%0A//%09%09ex.printStackTrace(); // XXX better logging%0A//%09    %7D%0A
 %09%7D c

Drop some comments.