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

import it.cnr.iasi.giant.action.Action;
import it.cnr.iasi.giant.util.ControllerMap;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @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 Controller implements ActionListener {
    
    private static HashMap<String, String> command2action;
    
    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            initMap();
            ControllerMap map = new ControllerMap();
            String commandKey = map.getMap().get(e.getSource());
            String actionClass = command2action.get(commandKey);
            Action action = (Action)Class.forName(actionClass).newInstance();
            action.execute();
            System.out.println(actionClass);
        } catch (InstantiationException e1) {
            Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, e1);
        } catch (IllegalAccessException e2) {
            Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, e2);
        } catch (ClassNotFoundException e3) {
            Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, e3);
        }
    }
    
    private void initMap() {
        command2action = new HashMap<String, String>();
        command2action.put("selectNet_button", "it.cnr.iasi.giant.action.SelectNetworkAction");
        command2action.put("selectClusters_button", "it.cnr.iasi.giant.action.SelectClustersAction");
        command2action.put("computePZ_button", "it.cnr.iasi.giant.action.ComputePZAction");
        command2action.put("loadCluster_radio", "it.cnr.iasi.giant.action.LoadClusterRadioAction");
        command2action.put("computeCluster_radio", "it.cnr.iasi.giant.action.ComputeClusterRadioAction");
        command2action.put("runClustering_button", "it.cnr.iasi.giant.action.RunClusteringAction");
        command2action.put("attrib_button", "it.cnr.iasi.giant.action.SelectAttributesAction");
        command2action.put("giantHelp_menu", "it.cnr.iasi.giant.action.GiantHelpAction");
        
        command2action.put("searchNodeR_button", "it.cnr.iasi.giant.action.SearchNodeRegionAction");
        command2action.put("saveResultsRegions_button", "it.cnr.iasi.giant.action.SaveRegionsResultsAction");
    }
    
}