/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.cnr.iasi.giant;

import it.cnr.iasi.giant.frame.GIANT_NT;
import it.cnr.iasi.giant.frame.GIANT_UNIX;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.UIManager;
import org.cytoscape.app.CyAppAdapter;
import org.cytoscape.app.swing.AbstractCySwingApp;
import org.cytoscape.app.swing.CySwingAppAdapter;
import org.cytoscape.application.swing.AbstractCyAction;

/**
 *
 * @author Fabio Cumbo
 * @info GIANT
 * @version v1.0
 * @organization IASI-CNR : Istituto di Analisi dei Sistemi ed Informatica 
 *                  "Antonio Ruberti" - Consiglio Nazionale delle Ricerche
 * 
 */
public class Main extends AbstractCySwingApp {
    
    private static final String pluginName = "GIANT";
    private static final String pluginExtName = "GuImerà Amaral NeTwork";
    private static final String pluginVersion = "v1.0";
    private static final String pluginAuthor = "Fabio Cumbo";
    private static final String cyMenu = "Plugins";
    private static CySwingAppAdapter giant_adapter;
    private static Application app;
    
    public Main(CySwingAppAdapter adapt) {
        super(adapt);
        giant_adapter = adapt;
        adapt.getCySwingApplication()
                    .addAction(new CyMainPluginMenuAction(giant_adapter));
        
    }
    
    public class CyMainPluginMenuAction extends AbstractCyAction {

        private static final long serialVersionUID = 1L;
        private final CyAppAdapter adapter;

	public CyMainPluginMenuAction(CyAppAdapter adapter) {
            super(pluginName,
                adapter.getCyApplicationManager(),
                "network",
                adapter.getCyNetworkViewManager());
            this.adapter = adapter;
            setPreferredMenu("Apps");
	}

        @Override
	public void actionPerformed(ActionEvent event) {
            
            final String lafWindows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            
            java.awt.EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    try {
                        String operatingSystem;
                        operatingSystem = System.getProperty("os.name");

                        if (operatingSystem.startsWith("Windows")) {
                            app = new GIANT_NT();
                            UIManager.setLookAndFeel(lafWindows);
                        }
                        else {
                            app = new GIANT_UNIX();
                            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                        }

                        app.setVisibleOverride(true);
                        app.setDefaultCloseOperationOverride(JFrame.DO_NOTHING_ON_CLOSE);

                    } catch (ClassNotFoundException e1) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e1);
                    } catch (InstantiationException e2) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e2);
                    } catch (IllegalAccessException e3) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e3);
                    } catch (javax.swing.UnsupportedLookAndFeelException e4) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e4);
                    }
                }
            });
            
	}
    }
    
    //ONLY FOR TEST IN IDE
    public static void main(String args[]) {
        final String lafWindows = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
            
            java.awt.EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    try {
                        String operatingSystem;
                        operatingSystem = System.getProperty("os.name");

                        if (operatingSystem.startsWith("Windows")) {
                            app = new GIANT_NT();
                            UIManager.setLookAndFeel(lafWindows);
                        }
                        else {
                            app = new GIANT_UNIX();
                            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
                        }

                        app.setVisibleOverride(true);
                        app.setDefaultCloseOperationOverride(JFrame.DO_NOTHING_ON_CLOSE);

                    } catch (ClassNotFoundException e1) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e1);
                    } catch (InstantiationException e2) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e2);
                    } catch (IllegalAccessException e3) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e3);
                    } catch (javax.swing.UnsupportedLookAndFeelException e4) {
                        java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, e4);
                    }
                }
            });
    }
    
    public static CySwingAppAdapter getGiantAdapter() {
        return giant_adapter;
    }
    
    public static Application getApp() {
        return app;
    }
    
}
