/*
 * ARX: Efficient, Stable and Optimal Data Anonymization
 * Copyright (C) 2012 - 2014 Florian Kohlmayer, Fabian Prasser
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package org.deidentifier.arx.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintWriter;
import java.io.StringWriter;

import javax.swing.JOptionPane;
import javax.swing.Timer;

import org.deidentifier.arx.gui.view.impl.MainWindow;
import org.deidentifier.arx.gui.view.impl.MainSplash;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;

/**
 * Main entry point
 * 
 * @author Prasser, Kohlmayer
 */
public class Main {

    private static Splash splash = null;
    private static MainSplash splash;
    
    public static void main(final String[] args) {
        
        try {
            if (!isOSX()){
                splash =  new Splash();
                splash.setVisible(true);
            }
            splash = new MainSplash();
            splash.setVisible(true);
            
            System.setProperty("sun.awt.noerasebackground", "true"); //$NON-NLS-1$ //$NON-NLS-2$
            
            MainWindow main = new MainWindow();
            main.addShellListener(new ShellAdapter(){
                @Override
                public void shellActivated(ShellEvent arg0) {
                    hideSplash();
                }
            });
            main.show();
            
        } catch (Throwable e){
            hideSplash();
    		StringWriter sw = new StringWriter();
    		PrintWriter pw = new PrintWriter(sw);
    		e.printStackTrace(pw);
    		final String trace = sw.toString();

            JOptionPane.showMessageDialog(null, trace, "Unexpected error", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
            
        }
    }
    
    private static void hideSplash() {
        new Timer(1000, new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent arg0) {
                if (splash != null) splash.setVisible(false);
            }
        }).start(); 
    }
    
    private static boolean isOSX() {
        String osName = System.getProperty("os.name");
        return osName.contains("OS X");
    }
}

@@ -1293,16 +1293,20 @@
  static 
+Main
 Splash s
@@ -1323,50 +1323,8 @@
 ll;%0A
-    private static MainSplash splash;%0A    
 %0A   
@@ -1371,24 +1371,16 @@
 args) %7B%0A
-        
 %0A       
@@ -1386,16 +1386,17 @@
   try %7B%0A
+%0A
         
@@ -1412,16 +1412,17 @@
 isOSX())
+ 
 %7B%0A      
@@ -1439,22 +1439,25 @@
 splash =
- 
  new 
+Main
 Splash()
@@ -1517,96 +1517,8 @@
   %7D%0A
-            splash = new MainSplash();%0A            splash.setVisible(true);%0A            
 %0A   
@@ -1611,28 +1611,16 @@
 -NLS-2$%0A
-            
 %0A       
@@ -1708,24 +1708,25 @@
 ellAdapter()
+ 
 %7B%0A          
@@ -1896,28 +1896,16 @@
 show();%0A
-            
 %0A       
@@ -1926,18 +1926,32 @@
 wable e)
+ 
 %7B%0A
+            %0A
         
@@ -1972,18 +1972,24 @@
 ();%0A    
-%09%09
+        
 StringWr
@@ -2022,18 +2022,24 @@
 ();%0A    
-%09%09
+        
 PrintWri
@@ -2072,18 +2072,24 @@
 w);%0A    
-%09%09
+        
 e.printS
@@ -2111,10 +2111,16 @@
     
-%09%09
+        
 fina
@@ -2283,28 +2283,16 @@
 xit(1);%0A
-            
 %0A       
@@ -2296,28 +2296,24 @@
     %7D%0A    %7D%0A
-    
 %0A    private
@@ -2384,16 +2384,17 @@
 stener()
+ 
 %7B%0A      
@@ -2568,20 +2568,15 @@
 t();
- 
 %0A    %7D%0A
-    
 %0A   

Resolve merge artifacts