package tmaestroplayer.actions;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
//import tmaestroplayer.GraphicalLoginFrame;
import tmaestroplayer.VentanaSCO;
import tmaestroplayer.VentanaSeleccionCurso;
import tmaestroplayer.VentanaSeleccionUnidad;

/**
 *
 * @author Gonzalo
 */
public class KeyboardAction extends AbstractAction {

    JDesktopPane jdp;

    public KeyboardAction(JDesktopPane jdp, String actionName) {
        super(actionName);
        this.jdp = jdp;
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        String eventName = (String) getValue(NAME);
        //System.out.println("se recibió un evento del mando");
        JInternalFrame selectedJIF = jdp.getSelectedFrame();
        
        if (selectedJIF instanceof VentanaSeleccionUnidad) {
            //System.out.println("Se pulsó la tecla '" + eventName + "' en la ventana '" + ((VentanaSeleccionUnidad) selectedJIF).unidadPrincipal.getName() + "'");
            if (eventName.equals("up")) {
                ((VentanaSeleccionUnidad)selectedJIF).upEvent();
            } else if (eventName.equals("down")) {
                ((VentanaSeleccionUnidad)selectedJIF).downEvent();
            } else if (eventName.equals("left")) {
                ((VentanaSeleccionUnidad)selectedJIF).leftEvent();
            } else if (eventName.equals("right")) {
                ((VentanaSeleccionUnidad)selectedJIF).rightEvent();
            } else if (eventName.equals("enter")) {
                ((VentanaSeleccionUnidad)selectedJIF).enterEvent();
            }
        } else if(selectedJIF instanceof VentanaSCO) {
            //System.out.println("Se pulsó la tecla '" + eventName + "' en el 'SCO'");
            if (eventName.equals("up")) {
                ((VentanaSCO)selectedJIF).upEvent();
            } else if (eventName.equals("down")) {
                ((VentanaSCO)selectedJIF).downEvent();
            } else if (eventName.equals("left")) {
                ((VentanaSCO)selectedJIF).leftEvent();
            } else if (eventName.equals("right")) {
                ((VentanaSCO)selectedJIF).rightEvent();
            } else if (eventName.equals("enter")) {
                ((VentanaSCO)selectedJIF).enterEvent();
            }
        }
        else  {
            //System.out.println("Se pulsó la tecla '" + eventName + "' en la ventana de seleccion de curso");
            if (eventName.equals("up")) {
                ((VentanaSeleccionCurso)selectedJIF).upEvent();
            } else if (eventName.equals("down")) {
                ((VentanaSeleccionCurso)selectedJIF).downEvent();
            } else if (eventName.equals("left")) {
                ((VentanaSeleccionCurso)selectedJIF).leftEvent();
            } else if (eventName.equals("right")) {
                ((VentanaSeleccionCurso)selectedJIF).rightEvent();
            } else if (eventName.equals("enter")) {
                ((VentanaSeleccionCurso)selectedJIF).enterEvent();
            }
        }
        /*else if (selectedJIF instanceof GraphicalLoginFrame) {
            if (eventName.equals("left")) {
                ((GraphicalLoginFrame)selectedJIF).leftEvent();
            } else if (eventName.equals("right")) {
                ((GraphicalLoginFrame)selectedJIF).rightEvent();
            } else if (eventName.equals("up")) {
                ((GraphicalLoginFrame)selectedJIF).upEvent();
            } else if (eventName.equals("down")) {
                ((GraphicalLoginFrame)selectedJIF).downEvent();
            } else if (eventName.equals("enter")) {
                ((GraphicalLoginFrame)selectedJIF).enterEvent();
            }
            
        }*/
    }
}
