package org.twopm.laf;

import java.util.prefs.Preferences;
import javax.swing.SwingUtilities;
import org.openide.modules.ModuleInstall;
import org.openide.util.NbPreferences;
import org.openide.windows.WindowManager;

/**
 * @author Edward M. Kagan <pagan@tabor.one>
 */
public class Installer extends ModuleInstall 
{
    
    @Override
    public void restored() {
        
        SwingUtilities.invokeLater(new Runnable()
        {
            @Override
            public void run()
            {
                Kernel.load_kernel();
                
            }
        });

        Preferences prefs = NbPreferences.root().node( "laf" ); //NOI18N
        if( !prefs.getBoolean("twopm.titan.installed", false) ) //NOI18N
        {     
            prefs.putBoolean("twopm.titan.installed", true ); //NOI18N
            WindowManager.getDefault().invokeWhenUIReady( new Runnable() 
            {
                @Override
                public void run() {
                    TitanEditor.load_editor(true);
                }
            });
        }
        else
        {
            WindowManager.getDefault().invokeWhenUIReady( new Runnable() 
            {
                @Override
                public void run() {
                    TitanEditor.load_editor(false);
                }
            });
        }
        
        
        
      
        
    }
    
    @Override
    public void validate() throws IllegalStateException 
    {   
        if (TitanLookAndFeel.self_install())
        {
            System.out.print("Setting up anti-aliasing hints to conf file...");
            if (!Kernel.setup_font_antialiaing_hints())
            {
                System.err.println("FAIL");
                return;
            }
            System.out.println("OK");
        }   
    }
}
