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

import cytoscape.Cytoscape;
import cytoscape.plugin.CytoscapePlugin;
import cytoscape.util.CytoscapeAction;
import it.cnr.iasi.giant.action.Action;
import it.cnr.iasi.giant.frame.GIANT_NT;
import it.cnr.iasi.giant.frame.GIANT_UNIX;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.UIManager;

/**
 *
 * @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 CytoscapePlugin {
    
    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 Application app;
    
    public Main() {
        CyMainPluginMenuAction menuAction = new CyMainPluginMenuAction();
	//Set Plugins Menu
	menuAction.setPreferredMenu(cyMenu);
	Cytoscape.getDesktop().getCyMenus().addAction(menuAction);
    }
    
    public class CyMainPluginMenuAction extends CytoscapeAction {

        private static final long serialVersionUID = 1L;

	public CyMainPluginMenuAction() {
            //Set Cytoscape Menu Entry Name
            super(pluginName);
	}

        @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 Application getApp() {
        return app;
    }
   
}
