package com.redpois0n.gscrot;

import gscrot.api.Plugin;

import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.image.BufferedImage;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.UIManager;

import org.jnativehook.GlobalScreen;

import pluginlib.PluginLoader;

import com.redpois0n.gscrot.ui.MainFrame;
import com.redpois0n.gscrot.ui.RegionCapture;

public class Main {
	
	private static PluginLoader<Plugin> loader;

	public static void main(String[] args) {
		Runtime.getRuntime().addShutdownHook(new ShutdownHook());
		
		try {
			loader = new PluginLoader<Plugin>();
			loader.loadPlugins();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		try {
			Config.load();
		} catch (FileNotFoundException e) {

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		try {
			if (!SystemTray.isSupported()) {
				System.err.println("SystemTray is not supported");
			} else {
				TrayIconHelper.initialize();
			}
			
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
			
			MainFrame.INSTANCE.setVisible(true);
			
			registerNativeHook();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	/**
	 * Disable JNativeHook logging and enable
	 * 
	 * @throws Exception
	 */
	private static void registerNativeHook() throws Exception {
		Logger logger = Logger.getLogger(GlobalScreen.class.getPackage().getName());
		logger.setLevel(Level.OFF);

		GlobalScreen.registerNativeHook();
	}

	public static void createBackground() throws Exception {
		Rectangle rect = ScreenshotHelper.getWholeDesktop();
		BufferedImage screenShot = ScreenshotHelper.capture(rect);
		
		RegionCapture frame = new RegionCapture(rect, screenShot);
		frame.setVisible(true);
	}
}

@@ -606,24 +606,159 @@
 Hook());%0A%09%09%0A
+%09%09try %7B%0A%09%09%09UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%0A
 %09%09try %7B%0A%09%09%09l
@@ -1153,81 +1153,8 @@
 %0A%09%09%09
-%0A%09%09%09UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());%0A
 %09%09%09%0A

set LAF earlier