package me.coley.recaf;

import java.awt.EventQueue;
import java.io.File;
import java.io.IOException;

import javax.swing.UIManager;

import org.objectweb.asm.tree.ClassNode;

import me.coley.recaf.asm.AsmUtil;
import me.coley.recaf.asm.JarData;
import me.coley.recaf.ui.FilePrompt;
import me.coley.recaf.ui.Gui;

public enum Recaf {
	/**
	 * Singleton instance.
	 */
	INSTANCE;
	/**
	 * The gui.
	 */
	public Gui gui;
	/**
	 * The current jar file being modified.
	 */
	public File currentJar;
	/**
	 * Data about the {@link #currentJar current jar file}.
	 */
	public JarData jarData;
	/**
	 * The file selection manager.
	 */
	public final FilePrompt filePrompts;
	/**
	 * The options.
	 */
	public final Options options;
	/**
	 * The utility instance handling a variety of ASM duties <i>(Bytecode loading, parsing, exporting)</i>.
	 */
	public final AsmUtil asm;

	private Recaf() {
		filePrompts = new FilePrompt();
		options = new Options();
		options.load();
		asm = new AsmUtil(this);
	}

	public void openFile(File file) throws IOException {
		this.currentJar = file;
		this.jarData = new JarData(file);
		this.gui.updateTree();
		this.gui.getFrame().setTitle("Recaf: " + file.getName());
	}

	public void saveFile(File file) throws IOException {
		this.jarData.save(file);
	}

	public void selectClass(ClassNode node) {
		this.gui.addClassView(node);
	}

	public void showGui() {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					gui = new Gui();
					gui.getFrame().setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch (Exception e) {
			e.printStackTrace();
		}
		INSTANCE.showGui();
	}
}

@@ -125,16 +125,68 @@
 Manager;
+%0Aimport javax.swing.UnsupportedLookAndFeelException;
 %0A%0Aimport
@@ -1693,99 +1693,780 @@
 %7B%0A%09%09
-try %7B%0A%09%09%09UIManager.setLookAndFeel(%22javax.swing.plaf.nimbus.NimbusLookAndFeel%22);%0A%09%09%7D catch (
+String laf = System.getenv(%22COL_RECAF_LAF%22);%0A%09%09try %7B%0A%09%09%09setLookAndFeel(laf);%0A%09%09%7D catch (ClassNotFoundException%7CClassCastException%7CUnsupportedLookAndFeelException ex) %7B%0A%09%09%09System.out.println(%22The specified Look and Feel '%22 + laf + %22' could not be loaded.%22);%0A%09%09%09try %7B%0A%09%09%09%09setLookAndFeel(null);%0A%09%09%09%7D catch(Exception ex2) %7B%0A%09%09%09%09//If this exception is thrown we are truly insane%E2%80%A6%0A%09%09%09%09throw new RuntimeException(ex2);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09INSTANCE.showGui();%0A%09%7D%0A%0A%09public static void setLookAndFeel(String laf) throws ClassNotFoundException, ClassCastException, UnsupportedLookAndFeelException %7B%0A%09%09if (laf == null) %7B%0A%09%09%09//Default Look & Feel%0A%09%09%09laf = %22javax.swing.plaf.nimbus.NimbusLookAndFeel%22;%0A%09%09%7D%0A%09%09try %7B%0A%09%09%09UIManager.setLookAndFeel(laf);%0A%09%09%7D catch (InstantiationException%7CIllegalAccess
 Exce
@@ -2476,61 +2476,107 @@
 on e
+x
 ) %7B%0A%09%09%09
-e.printStackTrace();%0A%09%09%7D%0A%09%09INSTANCE.showGui();
+//As far as I know, these errors are not recoverable%0A%09%09%09throw new RuntimeException(ex);%0A%09%09%7D
 %0A%09%7D%0A

Add ability to set Look & Feel via environment variable.