package tmaestroplayer;

import edutainmentclient.Main;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.image.ImageObserver;
import java.awt.image.PixelGrabber;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import java.util.Vector;

import javax.swing.*;

import javax.media.Time;

import org.w3c.dom.Element;

import tmaestroplayer.navigation.ButtonNavigation;
import tmaestroplayer.navigation.Navigation;
import tmaestroplayer.template.ImageButton;
import tmaestroplayer.template.TemplateComponent;
import tmaestroplayer.template.TemplateComponentsJavaXML;

public class AppletTemplateComponentsXML extends TemplateComponentsJavaXML {

    //variable para mostrar msg de depuracion
    boolean OUT = true;
    //SSS 26102009 Boton de siguiente
    String nextButton;
    // Botón de salida
    String exitButton;
    // Controles reproducción video
    String playButton, pauseButton, stopButton, subtitlesButton;
    // Panel donde se sitúan todos los componentes de un SCO
    JLayeredPane p = new JLayeredPane();
    // Componentes relacionados con los los reproductores multimedia
    HashMap playercomponents = new HashMap();
    // Componentes de tipo MediaPanel
    public HashMap players = new HashMap();
    // Vector que almacena el nombre de los reproductores
    public Vector playersName = new Vector();
    // Componentes relacionados con los paneles de desplazamiento
    HashMap scrollPanel = new HashMap();
    // Componentes de la plantilla 
    HashMap components = new HashMap();
    // Componentes de tipo HAnimated 
    HashMap componentsAnimated = new HashMap();
    // Sellos temporales de los reproductores
    HashMap timestamp = new HashMap();
    // Instantes temporales de los subtitulos reproductor
    HashMap timestampPlayer = new HashMap();
    //Componentes de tipo HScrollPane
    HashMap ListScrollPane = new HashMap();
    // Imagenes que forman una imagen animada (primer elemento de tipo JLabel)
    HashMap imageAnimated = new HashMap();
    // Elemento que contiene los elementos que componen una opción de reproducción
    Element eoption = null;
    // Componentes de la plantilla test de preguntas
    HashMap asocTest = new HashMap();
    // Componentes multimedia de test
    Vector playersTest = new Vector();
    // Temporizador asociado al MediaPlayer de inactividad de una pregunta de test
    Timer timerInactivity = new Timer(0, new TimerListenerInac("", null));
    // Reproductor de inactividad
    MediaPanel playerInactivity = null;
    // Componente donde se muestran los subtitulos
    //SSS 26102009 antes eran JTextArea
    //JTextArea subtitles = new JTextArea();
    JLabel subtitles = new JLabel();
    // Componente donde se muestran las secuencias de imagenes
    public JLabel image = new JLabel();
    // Temporizador de un reproductor que controla el instante de los subtitulos
    Timer timer = new Timer(0, new TimerListener("", null));
    // Indice de controla los sellos temporales
    int indexTimer = 1;
    // Direcci�n del servidorWeb donde se alojan los recursos del SCO (http://~/tMaestro/Cursos/nameCourse/)	
    String ruta;
    // Nombre del SCO
    String nameSCO;
    // Ultimo reproductor ejecutado
    MediaPanel lastPlayer = null;
    JRadioButton playbu = null;
    //SSS 26102009 para los delayed
    public VentanaSeleccionUnidad vsup = null;
    // components q aparecen tras seleccionar pregunta ok en test
    public static HashMap okcomponents = new HashMap();
    // components que aparecen tras errar una pregunta
    public static HashMap wrongcomponents = new HashMap();
    public static boolean ESTEST = false;
    public static int ANSWEROK = -1;
    /**
     * navigation controls
     */
    public Navigation navigation;
    /**
     * HashMap containing the buttons
     */
    public HashMap<String, ImageButton> buttons = new HashMap<String, ImageButton>();
    /**
     * botón que está seleccionado, por lo tanto en estado focused
     */
    String currentSelected = null;
    /**
     * variable usada para depuración
     */
    long instantePlay = 0;
    /**
     * Nombre del reproductor que contiene los subtítulos
     */
    String subtitlesPlayerComponentName;
    /**
     * coordenadas de la plantilla
     */
    public static int x = 0, y = 0, w = 0, h = 0;
    /**
     * Reproductores asociados a las respuestas
     */
    public HashMap<String, String> answersPlayers = new HashMap<String, String>();

    public AppletTemplateComponentsXML(String xmlfile, String tmp, String option, VentanaSeleccionUnidad vsup) {
        super(xmlfile + "/" + tmp + "TEMPLATE/TemplateComponents.xml");
        //System.out.println("se ejecutó super");

        this.vsup = vsup;
        ruta = xmlfile + tmp;
        nameSCO = xmlfile + tmp;

        // para rutas relativas del applet=> sin ruta
        exitButton = getExitButton(ruta + "TEMPLATE/ExitButton.xml");
        //System.out.println("Obtuvimos el exitButton: " + exitButton);
        //SSS 26102009 control boton next
        nextButton = getNextButton(ruta + "TEMPLATE/NextButton.xml");
        //System.out.println("Obtuvimos el nextButton: " + nextButton);
        playercomponents = getPlayerButtons(ruta + "TEMPLATE/MediaPlayersControl.xml");
        //System.out.println("Obtuvimos playercomponents");
        eoption = readOption(ruta + "OPTIONS/" + option);
        //System.out.println("Leímos la opción");
        Vector nameScroll = new Vector();
        scrollPanel = getScrollPanel(ruta + "TEMPLATE/ScrollPanelBar.xml", nameScroll);
        if (nameScroll.size() > 0) {
            for (int i = 0; i < nameScroll.size(); i++) {
                String name = (String) nameScroll.get(i);
                ListScrollPane.put(name, new JScrollPane());
            }
        }
        int resul = readTest(ruta + "TEMPLATE/test.xml", asocTest, playersTest);

        //SSS 26102009
        if (resul != 0) {
            ESTEST = true;
            ANSWEROK = resul;
            // if (TMAppletI.OUT) System.out.println(resul);
        } else {
            ESTEST = false;
        }
        navigation = new Navigation(xmlfile + "/" + tmp + "/TEMPLATE/Navigation.xml");

    }

    public void up() {
        ButtonNavigation bn = navigation.getNavigations().get(currentSelected);
        String nextSelected = null;
        if (currentSelected != null) {
            if (!(nextSelected = bn.getUp()).equals("")) {
                if (components.get(nextSelected) != null) {
                    ((ImageButton) components.get(currentSelected)).setNormalIcon();
                    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
                    currentSelected = nextSelected;
                    String answerPlayer;
                    if ((answerPlayer = answersPlayers.get(currentSelected)) != null) {
                        jButtonPlayTest(answerPlayer, false);
                    }
                }
            }
        } else {
            currentSelected = navigation.getInitiallySelected();
            ((ImageButton) components.get(currentSelected)).setFocusedIcon();
        }
    }

    public void down() {
        ButtonNavigation bn = navigation.getNavigations().get(currentSelected);
        String nextSelected = null;
        if (currentSelected != null) {
            if (!(nextSelected = bn.getDown()).equals("")) {
                if (components.get(nextSelected) != null) {
                    ((ImageButton) components.get(currentSelected)).setNormalIcon();
                    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
                    currentSelected = nextSelected;
                    String answerPlayer;
                    if ((answerPlayer = answersPlayers.get(currentSelected)) != null) {
                        jButtonPlayTest(answerPlayer, false);
                    }
                }
            }
        } else {
            currentSelected = navigation.getInitiallySelected();
            ((ImageButton) components.get(currentSelected)).setFocusedIcon();
        }
    }

    public void left() {
        ButtonNavigation bn = navigation.getNavigations().get(currentSelected);
        String nextSelected = null;
        if (currentSelected != null) {
            if (!(nextSelected = bn.getLeft()).equals("")) {
                if (components.get(nextSelected) != null) {
                    ((ImageButton) components.get(currentSelected)).setNormalIcon();
                    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
                    currentSelected = nextSelected;
                    String answerPlayer;
                    if ((answerPlayer = answersPlayers.get(currentSelected)) != null) {
                        jButtonPlayTest(answerPlayer, false);
                    }
                }
            }
        } else {
            currentSelected = navigation.getInitiallySelected();
            ((ImageButton) components.get(currentSelected)).setFocusedIcon();
        }
    }

    public void right() {
        ButtonNavigation bn = navigation.getNavigations().get(currentSelected);
        String nextSelected = null;
        if (currentSelected != null) {
            if (!(nextSelected = bn.getRight()).equals("")) {
                if (components.get(nextSelected) != null) {
                    ((ImageButton) components.get(currentSelected)).setNormalIcon();
                    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
                    currentSelected = nextSelected;
                    String answerPlayer;
                    if ((answerPlayer = answersPlayers.get(currentSelected)) != null) {
                        jButtonPlayTest(answerPlayer, false);
                    }
                }
            }
        } else {
            currentSelected = navigation.getInitiallySelected();
            ((ImageButton) components.get(currentSelected)).setFocusedIcon();
        }
    }

    public void enter() {
        ButtonNavigation bn = navigation.getNavigations().get(currentSelected);
        String nextSelected = null;
        if (currentSelected != null) {
            ImageButton currentButton = (ImageButton) components.get(currentSelected);
            currentButton.setActionedIcon();
            if (currentButton.getButtonName().equals(exitButton)) {
                //Es el exitButton
                jButtonExitActionPerformed();
            } else if (currentButton.getButtonName().equals(nextButton)) {
                //Es el nextButton
                jButtonNextActionPerformed(nextButton);
            } else {//Es o play, o pause, o stop o un botón de test
                //Un mediaButton puede ser play, pause o stop
                //mediaButtonPlayers es una cadena que contiene los reproductores
                //sobre los que actúa separados por un espacio
                String mediaButtonPlayers;
                //Comprobamos si se pulsó un botón de play (podría haber más de uno)
                if ((mediaButtonPlayers = (String) playercomponents.get("play" + currentButton.getButtonName())) != null) {
                    jButtonPlayActionPerformed(mediaButtonPlayers);
                } //Comprobamos si se pulsó un botón de pause (podría haber más de uno)
                else if ((mediaButtonPlayers = (String) playercomponents.get("pause" + currentButton.getButtonName())) != null) {
                    jButtonPauseActionPerformed(mediaButtonPlayers);
                } //Comprobamos si se pulsó un botón de stop (podría haber más de uno)
                else if ((mediaButtonPlayers = (String) playercomponents.get("stop" + currentButton.getButtonName())) != null) {
                    jButtonStopActionPerformed(mediaButtonPlayers);
                }//Comprobamos si es un botón de test
                else if (asocTest.size() > 0) {
                    if (playersTest.size() != 0) {
                        String nameplayerButton = (String) playersTest.get(4);
                        if (currentButton.getButtonName().equals(nameplayerButton)) {
                            jButtonPlayTest((String) playersTest.get(0), false);
                        }
                    }
                    for (int key = 1; key < asocTest.size(); key++) {//Comprobamos si es uno de los botones de respuesta
                        String asoc = (String) asocTest.get(key);
                        String buttonName = asoc.substring(0, asoc.indexOf(" "));
                        asoc = asoc.substring(asoc.indexOf(" ") + 1);
                        String labelName = asoc.substring(0, asoc.indexOf(" "));
                        String playerName = asoc.substring(asoc.indexOf(" "));
                        //Comprobamos si el botón de test que estamos procesando es el botón que generó el evento
                        if (currentButton.getButtonName().equals(buttonName)) {
                            Vector trueAnswers = (Vector) asocTest.get("answerTrue");
                            boolean isTrue = false;
                            for (int i = 0; i < trueAnswers.size(); i++) {
                                //Integer currentId = Integer.parseInt((String) trueAnswers.get(i));
                                Integer currentId = (Integer) trueAnswers.get(i);
                                if (key == currentId.intValue()) {//Si se cumple es una respuesta correcta
                                    isTrue = true;
                                    break;
                                }
                            }
                            if (isTrue) {//Es un botón de respuesta correcta
                                String playerRight = "";
                                if (playersTest.size() != 0) {
                                    playerRight = (String) playersTest.get(1);
                                    if (!playerRight.equals("")) {
                                        jButtonPlayTest(playerRight, false);
                                    }
                                }
                            } else {//Es un botón de respuesta incorrecta
                                String playerWrong = "";
                                if (playersTest.size() != 0) {
                                    playerWrong = (String) playersTest.get(2);
                                    if (!playerWrong.equals("")) {
                                        jButtonPlayTest(playerWrong, false);
                                    }
                                }
                            }
                            jButtonOkWrong(buttonName);
                            break;
                        }
                    }
                }
            }
        }
    }

    /*public void keyPressed(java.awt.event.KeyEvent evt) {
    ButtonNavigation bn = navigation.getNavigations().get(currentSelected);
    String nextSelected = null;
    switch (evt.getKeyCode()) {
    case KeyEvent.VK_UP:
    if (currentSelected != null) {
    if (!(nextSelected = bn.getUp()).equals("")) {
    ((ImageButton) components.get(currentSelected)).setNormalIcon();
    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
    currentSelected = nextSelected;
    }
    } else {
    currentSelected = navigation.getInitiallySelected();
    ((ImageButton) components.get(currentSelected)).setFocusedIcon();
    }
    break;
    case KeyEvent.VK_DOWN:
    if (currentSelected != null) {
    if (!(nextSelected = bn.getDown()).equals("")) {
    ((ImageButton) components.get(currentSelected)).setNormalIcon();
    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
    currentSelected = nextSelected;
    }
    } else {
    currentSelected = navigation.getInitiallySelected();
    ((ImageButton) components.get(currentSelected)).setFocusedIcon();
    }
    break;
    case KeyEvent.VK_LEFT:
    if (currentSelected != null) {
    if (!(nextSelected = bn.getLeft()).equals("")) {
    ((ImageButton) components.get(currentSelected)).setNormalIcon();
    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
    currentSelected = nextSelected;
    }
    } else {
    currentSelected = navigation.getInitiallySelected();
    ((ImageButton) components.get(currentSelected)).setFocusedIcon();
    }
    break;
    case KeyEvent.VK_RIGHT:
    if (currentSelected != null) {
    if (!(nextSelected = bn.getRight()).equals("")) {
    ((ImageButton) components.get(currentSelected)).setNormalIcon();
    ((ImageButton) components.get(nextSelected)).setFocusedIcon();
    currentSelected = nextSelected;
    }
    } else {
    currentSelected = navigation.getInitiallySelected();
    ((ImageButton) components.get(currentSelected)).setFocusedIcon();
    }
    break;
    case KeyEvent.VK_ENTER:
    if (currentSelected != null) {
    ImageButton currentButton = (ImageButton) components.get(currentSelected);
    currentButton.setActionedIcon();
    if (currentButton.getButtonName().equals(exitButton)) {
    //Es el exitButton
    jButtonExitActionPerformed();
    } else if (currentButton.getButtonName().equals(nextButton)) {
    //Es el nextButton
    jButtonNextActionPerformed(nextButton);
    } else {//Es o play, o pause, o stop o un botón de test
    //Un mediaButton puede ser play, pause o stop
    //mediaButtonPlayers es una cadena que contiene los reproductores
    //sobre los que actúa separados por un espacio
    String mediaButtonPlayers;
    //Comprobamos si se pulsó un botón de play (podría haber más de uno)
    if ((mediaButtonPlayers = (String) playercomponents.get("play" + currentButton.getButtonName())) != null) {
    jButtonPlayActionPerformed(mediaButtonPlayers);
    } //Comprobamos si se pulsó un botón de pause (podría haber más de uno)
    else if ((mediaButtonPlayers = (String) playercomponents.get("pause" + currentButton.getButtonName())) != null) {
    jButtonPauseActionPerformed(mediaButtonPlayers);
    } //Comprobamos si se pulsó un botón de stop (podría haber más de uno)
    else if ((mediaButtonPlayers = (String) playercomponents.get("stop" + currentButton.getButtonName())) != null) {
    jButtonStopActionPerformed(mediaButtonPlayers);
    }
    }
    }
    break;
    }
    }*/
    public Component getVisualTemplateComponent() {
        return getVisualTemplateComponent(mainComponent);
    }

    private Component getComponentsScrollPane(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getComponentsScrollPane");
        }
        Component c = null;

        if (tc.componentClass.equalsIgnoreCase("TextPanel")) {

            JEditorPane textArea = new JEditorPane();

            HashMap valuesTextPanel = readValuesOption(eoption, "com.uvigo.mhp.textPanel.TextPanel", tc.componentName);
            if (valuesTextPanel != null) {

                if (valuesTextPanel.containsKey("background")) {
                    String background = (String) valuesTextPanel.get("background");
                    if (valuesTextPanel.containsKey("opaque")) {
                        String opaque = (String) valuesTextPanel.get("opaque");
                        if (opaque.equals("true")) { // Se pinta color de fondo
                            textArea.setOpaque(true);
                            String r = background.substring(0, background.indexOf(" "));
                            String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                            String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());
                            int rv = Integer.parseInt(r);
                            int vv = Integer.parseInt(v);
                            int av = Integer.parseInt(a);
                            textArea.setBackground(new java.awt.Color(rv, vv, av));
                        }
                    }
                }

                if (valuesTextPanel.containsKey("foreground")) {
                    String foreground = (String) valuesTextPanel.get("foreground");
                    String r = foreground.substring(0, foreground.indexOf(" "));
                    String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                    String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());
                    int rv = Integer.parseInt(r);
                    int vv = Integer.parseInt(v);
                    int av = Integer.parseInt(a);
                    textArea.setForeground(new java.awt.Color(rv, vv, av));
                }

                if (valuesTextPanel.containsKey("configurationFile")) {
                    String configurationFile = ruta + (String) valuesTextPanel.get("configurationFile");

                    //lectura TEMP/COMPONENTS/...
                    final HashMap iconsTextPanel = readValuesTextPanel(configurationFile);
                    if (iconsTextPanel.containsKey("locator")) {
                        String location = ruta + "COMPONENTS/" + ((String) iconsTextPanel.get("locator"));
                        URL dirURL = null;
                        try {
                            dirURL = new URL(location);
                        } catch (MalformedURLException e1) {
                            e1.printStackTrace();
                        }
                        try {
                            textArea.setPage(dirURL);
                        } catch (IOException e) {
                        }
                    }

                    textArea.setEditable(false);
                    textArea.setBounds(tc.x, tc.y, tc.w, tc.h);
                }
            }
            components.put(tc.componentName, textArea);
            c = textArea;
            c.setBounds(tc.x, tc.y, tc.w, tc.h);
        }

        return c;
    }

    private Component getButton(final TemplateComponent tc) {
        if (OUT) {
            System.out.println("getButton");
        }
        Component c = null;
        int x = tc.x;
        int y = tc.y;
        int w = tc.w;
        int h = tc.h;
        String playTest = "";
        String playerRight1 = "";
        String playerWrong1 = "";
        String labelQ = "";
        int id = 0;
        boolean isTest = false;
        //final JRadioButton b = new JRadioButton();
        final ImageButton b = new ImageButton();

        //Almacenamos el nombre del botón
        b.setButtonName(tc.componentName);

        //System.out.println(tc.componentName + " isFocusable: " + b.isFocusable());
        b.setFocusable(false);
        //System.out.println(tc.componentName + " new isFocusable: " + b.isFocusable());

        final String vplay = (String) playercomponents.get("play" + tc.componentName);
        final String vstop = (String) playercomponents.get("stop" + tc.componentName);
        final String vpause = (String) playercomponents.get("pause" + tc.componentName);

        //es test
        if ((vplay == null) && (vstop == null) && (vpause == null) && (asocTest.size() > 0)) {
            //SSS 26102009 cambio, debe ser para corregir error
            String namelabel = null;
            String namebutton = null;
            String nameplayer = null;
            for (int k = 0; k < asocTest.size() - 1; k++) {
                int key = k + 1;
                String cadena = (String) asocTest.get(key);
                namebutton = cadena.substring(0, cadena.indexOf(" "));
                String subcad = cadena.substring(namebutton.length() + 1);
                namelabel = subcad.substring(0, subcad.indexOf(" "));
                nameplayer = subcad.substring(namelabel.length() + 1);

                // con esta comparacion se que pregunta de test es
                if (tc.componentName.equals(namebutton)) {
                    //adivino el nombre del player
                    playTest = nameplayer;
                    //Guardamos los reproductores asociados a las respuestas en un HashMap
                    //para poder recuperarlos cuando navegamos por los botones con el mando
                    if (!nameplayer.equals("")) {
                        answersPlayers.put(namebutton, nameplayer);
                    }
                    id = key;
                    isTest = true;
                    labelQ = namelabel;
                    break;
                    //cuando coincide salgo
                }
            }
            // pq puede ser no play, no stop, no pause, el test distinto de cero
            // pero no ser pregunta de test (boton exit)
            if (isTest) { // Verificar si se trata de una respuesta correcta
                Vector answers = (Vector) asocTest.get("answerTrue");
                if (answers != null) {
                    boolean isTrue = false;
                    for (int j = 0; j < answers.size(); j++) {
                        int index = Integer.parseInt(answers.get(j).toString());
                        if (index == id) {
                            // si es la correcta se le asigna el player de correcta
                            //SSS 26102009 debe ser para corregir error
                            if (playersTest.size() != 0) {
                                playerRight1 = (String) playersTest.get(1);
                            }
                            isTrue = true;
                        }
                    }
                    if (!isTrue) {
                        // si no se le asocia el player de incorrecto
                        //SSS 26102009 debe ser para corregir error
                        if (playersTest.size() != 0) {
                            playerWrong1 = (String) playersTest.get(2);
                        }
                    }
                }
            }
        }
        final String playerAnswer = playTest;
        final String playerRight = playerRight1;
        final String playerWrong = playerWrong1;

        String contentFile = "";
        HashMap vButton = new HashMap();
        System.out.println("valuesbutton en getbutton " + eoption + " " + tc.componentName);
        vButton = readValuesOption(eoption, "com.uvigo.mhp.ui.HButton", tc.componentName);
//System.out.println("readValuesOption "+vButton);
        final HashMap valuesButton = vButton;

        if (vButton != null) {
            if (valuesButton.containsKey("X")) {
                x = Integer.parseInt((String) valuesButton.get("X"));
            }
            if (valuesButton.containsKey("Y")) {
                y = Integer.parseInt((String) valuesButton.get("Y"));
            }
            if (valuesButton.containsKey("Width")) {
                w = Integer.parseInt((String) valuesButton.get("Width"));
            }
            if (valuesButton.containsKey("Height")) {
                h = Integer.parseInt((String) valuesButton.get("Height"));
            }
            b.setBorderPainted(false);
            b.setContentAreaFilled(false);

            if (valuesButton.containsKey("background")) {
                String background = (String) valuesButton.get("background");
                if (valuesButton.containsKey("backgroundMode")) {
                    String backgroundMode = (String) valuesButton.get("backgroundMode");
                    if (backgroundMode.equals("1")) { // Se pinta color de fondo
                        String r = background.substring(0, background.indexOf(" "));
                        String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                        String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());
                        int rv = Integer.parseInt(r);
                        int vv = Integer.parseInt(v);
                        int av = Integer.parseInt(a);
                        b.setBorderPainted(true);
                        b.setContentAreaFilled(true);
                        b.setBackground(new java.awt.Color(rv, vv, av));
                    }
                }
            }

            if (valuesButton.containsKey("foreground")) {
                String foreground = (String) valuesButton.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());
                int rv = Integer.parseInt(r);
                int vv = Integer.parseInt(v);
                int av = Integer.parseInt(a);
                b.setForeground(new java.awt.Color(rv, vv, av));
            }

            if (valuesButton.containsKey("font")) {
                //SSS 26102009 se ha cambiado pq cuando tenia dos palabras font, lo hacia mal
                String texto = (String) valuesButton.get("font");
                String auxiliar = "";
                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));
                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(auxiliar.lastIndexOf(" ") + 1, auxiliar.length());
                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0, auxiliar.lastIndexOf("") - 1);

                b.setFont(new Font(font, formato, size));
            } else {
                b.setFont(new Font("Dialog", Font.PLAIN, 12));
            }
            //SSS 26102009 se ha cambiado pq lo hacia mal
            if (valuesButton.containsKey("horizontalAlignment")) {
                int hAlign = Integer.parseInt((String) valuesButton.get("horizontalAlignment"));

                switch (hAlign) {
                    case 0:
                        b.setHorizontalAlignment(JRadioButton.LEFT);
                        break;
                    case 1:
                        b.setHorizontalAlignment(JRadioButton.CENTER);
                        break;
                    case 2:
                        b.setHorizontalAlignment(JRadioButton.RIGHT);
                        break;
                }
                /*
                int hor = Integer.parseInt((String) valuesButton.get("horizontalAlignment"));
                if (hor == 0) {
                b.setHorizontalAlignment(SwingConstants.LEFT);
                } else if (hor == 2) {
                b.setHorizontalAlignment(SwingConstants.RIGHT);
                } else if (hor == 1) {
                b.setHorizontalAlignment(SwingConstants.CENTER);
                }*/
            } else {
                //b.setHorizontalAlignment((int) SwingConstants.CENTER);
                b.setHorizontalAlignment(JRadioButton.CENTER);
            }
            if (valuesButton.containsKey("verticalAlignment")) {
                int vAlign = Integer.parseInt((String) valuesButton.get("verticalAlignment"));

                switch (vAlign) {
                    case 0:
                        b.setVerticalAlignment(JRadioButton.LEFT);
                        break;
                    case 4:
                        b.setVerticalAlignment(JRadioButton.CENTER);
                        break;
                    case 8:
                        b.setVerticalAlignment(JRadioButton.RIGHT);
                        break;
                }

                /*
                int ver = Integer.parseInt((String) valuesButton.get("verticalAlignment"));
                if (ver == 0) {
                b.setVerticalAlignment(SwingConstants.LEFT);
                } else if (ver == 2) {
                b.setVerticalAlignment(SwingConstants.RIGHT);
                } else if (ver == 1) {
                b.setVerticalAlignment(SwingConstants.CENTER);
                }
                 */

            } else {
                //b.setVerticalAlignment((int) SwingConstants.CENTER);
                b.setVerticalAlignment(JRadioButton.CENTER);
            }
            if (valuesButton.containsKey("contentFile")) {
                contentFile = ruta + (String) valuesButton.get("contentFile");
                final HashMap iconsButton = readValuesComponents(contentFile);
                //SSS 26102009 por si no lo defines...
                if (iconsButton != null) {

                    if (iconsButton.containsKey("normalStateContent")) {
                        HashMap properButton = (HashMap) iconsButton.get("normalStateContent");
                        if (properButton.containsKey("graphicContent")) {
                            try {
                                javax.swing.ImageIcon ic = new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent"))));
                                b.setNormalStateIcon(ic);
                                b.setNormalIcon();
                                //b.setIcon(ic);
                            } catch (MalformedURLException ex) {
                                System.err.println(ex);
                            }
                        }
                        if (properButton.containsKey("textContent")) {
                            String buttonText = (String) properButton.get("textContent");
                            buttonText = buttonText.trim();
                            if (!buttonText.equals("")) {
                                //b.setText((String) properButton.get("textContent"));
                                b.setText(buttonText);
                            } /*else {
                            System.out.println("no se incluye texto en el botón");
                            }
                            System.out.println("********textContent *" + buttonText + "*");*/
                        }
                    }
                    if (iconsButton.containsKey("actionedStateContent")) {
                        HashMap properButton = (HashMap) iconsButton.get("actionedStateContent");
                        if (properButton.containsKey("graphicContent")) {
                            try {
                                javax.swing.ImageIcon ic = new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent"))));
                                b.setActionedStateIcon(ic);
                            } catch (MalformedURLException ex) {
                                ex.printStackTrace();
                            }
                        }
                    }
                    if (iconsButton.containsKey("focusedStateContent")) {
                        HashMap properButton = (HashMap) iconsButton.get("focusedStateContent");
                        if (properButton.containsKey("graphicContent")) {
                            try {
                                javax.swing.ImageIcon ic = new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent"))));
                                b.setFocusedStateIcon(ic);
                            } catch (MalformedURLException ex) {
                                ex.printStackTrace();
                            }
                        }
                    }

                    b.addMouseListener(new java.awt.event.MouseListener() {

                        public void actionPerformed(java.awt.event.ActionEvent evt) {
                        }

                        public void mouseEntered(MouseEvent arg0) {

                            if (valuesButton.containsKey("actionedWhenFocused")) {
                                if (iconsButton.containsKey("actionedStateContent")) {
                                    try {
                                        HashMap properButton = (HashMap) iconsButton.get("actionedStateContent");
                                        if (properButton.containsKey("graphicContent")) {
                                            b.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));
                                        }
                                        if (properButton.containsKey("textContent")) {
                                            String buttonText = (String) properButton.get("textContent");
                                            buttonText = buttonText.trim();
                                            if (!buttonText.equals("")) {
                                                //b.setText((String) properButton.get("textContent"));
                                                b.setText(buttonText);
                                            } /*else {
                                            System.out.println("no se incluye texto en el botón");
                                            }*/
                                        }
                                    } catch (MalformedURLException ex) {
                                        System.err.println(ex);
                                    }
                                }
                                if (tc.componentName.equals(exitButton)) {
                                    //SSS 26102009 control de los hilos
                                    HILOS.clear();
                                    System.exit(0);
                                }
                                //SSS 26102009 control de los Next
                                if (tc.componentName.equals(nextButton)) {
                                    jButtonNextActionPerformed(nextButton);
                                }
                                if (vplay != null) {
                                    jButtonPlayActionPerformed(vplay);
                                }
                                if (vstop != null) {
                                    jButtonStopActionPerformed(vstop);
                                }
                                if (vpause != null) {
                                    jButtonPauseActionPerformed(vpause);
                                }
                                //SSS 26102009 estaba mal
                                if (playerAnswer.compareTo("") != 0) {
                                    jButtonPlayTest(playerAnswer, false);
                                }

                            } else if (iconsButton.containsKey("focusedStateContent")) {
                                //try {
                                if (currentSelected != null) {
                                    if (!currentSelected.equals(b.getButtonName())) {
                                        ((ImageButton) components.get(currentSelected)).setNormalIcon();
                                        currentSelected = b.getButtonName();
                                        //System.out.println("cambiamos el seleccionado con el ratón");
                                    }
                                } else {
                                    currentSelected = b.getButtonName();
                                }
                                HashMap properButton = (HashMap) iconsButton.get("focusedStateContent");
                                /*if (properButton.containsKey("graphicContent")) {
                                b.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));
                                }*/
                                b.setFocusedIcon();
                                if (properButton.containsKey("textContent")) {
                                    String buttonText = (String) properButton.get("textContent");
                                    buttonText = buttonText.trim();
                                    if (!buttonText.equals("")) {
                                        //b.setText((String) properButton.get("textContent"));
                                        b.setText(buttonText);
                                    } /*else {
                                    System.out.println("no se incluye texto en el botón");
                                    }*/
                                }
                                //SSS 26102009 estaba mal
                                if (playerAnswer.compareTo("") != 0) {
                                    jButtonPlayTest(playerAnswer, false);
                                }
                                //} catch (MalformedURLException ex) {
                                //  System.out.println(ex);
                                //}

                            }

                        }

                        public void mouseExited(MouseEvent arg0) {
                            if (iconsButton.containsKey("normalStateContent")) {
                                //En el caso del que el botón seleccionado sea el botón del que acaba de salir
                                //el ratón dejamos "null" como seleccionado, esto no se va a cumplir siempre
                                //ya que si teniendo el ratón encima de un botón movemos el foco de los botones
                                //con el mando al salir el ratón del botón estará como currentSelected otro botón
                                if (currentSelected.equals(b.getButtonName())) {
                                    currentSelected = null;
                                }
                                //try {
                                HashMap properButton = (HashMap) iconsButton.get("normalStateContent");
                                /*if (properButton.containsKey("graphicContent")) {
                                b.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));
                                }*/
                                b.setNormalIcon();
                                if (properButton.containsKey("textContent")) {
                                    String buttonText = (String) properButton.get("textContent");
                                    buttonText = buttonText.trim();
                                    if (!buttonText.equals("")) {
                                        //b.setText((String) properButton.get("textContent"));
                                        b.setText(buttonText);
                                    }/* else {
                                    System.out.println("no se incluye texto en el botón");
                                    }*/
                                }
                                //} catch (MalformedURLException ex) {
                                //System.err.println(ex);
                                //}
                            }
                        }

                        public void mousePressed(MouseEvent arg0) {
                            //System.out.println(tc.componentName);
                            if (iconsButton.containsKey("actionedStateContent")) {
                                //try {
                                HashMap properButton = (HashMap) iconsButton.get("actionedStateContent");
                                /*if (properButton.containsKey("graphicContent")) {
                                b.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));
                                }*/
                                b.setActionedIcon();
                                if (properButton.containsKey("textContent")) {
                                    String buttonText = (String) properButton.get("textContent");
                                    buttonText = buttonText.trim();
                                    if (!buttonText.equals("")) {
                                        //b.setText((String) properButton.get("textContent"));
                                        b.setText(buttonText);
                                    } /*else {
                                    System.out.println("no se incluye texto en el botón");
                                    }*/
                                }
                                //} catch (MalformedURLException ex) {
                                //System.err.println(ex);
                                //}
                            }
                            if (tc.componentName.equals(exitButton)) {
                                //SSS 26102009 para controlar los hilos
                                okcomponents.clear();
                                wrongcomponents.clear();
                                HILOS.clear();

                                System.out.println("vamos a salir");
                                for (int d = 0; d < playersName.size(); d++) {
                                    String mediaPanel = (String) playersName.get(d);
                                    //SSS 26102009 esto no lo tengo pero parece que no lo usa
                                    MediaPanel mp = (MediaPanel) players.get(mediaPanel);

                                    jButtonStopActionPerformed(mediaPanel);
                                }
                                //SSS 26102009 para controlar el next
                                NEXT = false;
                                //System.out.println("vamos a ocultar el applet");
                                p.setVisible(false);
                                //18-11-2010
                               // Main.started = false;
                                System.out.println("Se pulso el botón de EXIT");
                                //SSS 26102009 para controlar el next
                            } else if (tc.componentName.equals(nextButton)) {
                                System.out.println("pulse el nextButton en contentFile");
                                jButtonNextActionPerformed(nextButton);
                            } else if (vplay != null) {
                                jButtonPlayActionPerformed(vplay);
                            } else if (vstop != null) {
                                jButtonStopActionPerformed(vstop);
                            } else if (vpause != null) {
                                jButtonPauseActionPerformed(vpause);
                                //SSS 26102009 estaban mal las comparaciones
                            } else if (playerRight.compareTo("") != 0) {
                                jButtonPlayTest(playerRight, false);
                            } else if (playerWrong.compareTo("") != 0) {
                                jButtonPlayTest(playerWrong, false);
                            } else if (playersTest.size() != 0) {
                                String nameplayerButton = (String) playersTest.get(4);
                                if (tc.componentName.equals(nameplayerButton)) {
                                    jButtonPlayTest((String) playersTest.get(0), false);
                                }
                                //26102009 para controlar los ok wrong
                            } else if (ESTEST) {
                                //System.out.println(tc.componentName);
                                jButtonOkWrong(tc.componentName);
                            }
                        }

                        public void mouseClicked(MouseEvent arg0) {
                        }

                        public void mouseReleased(MouseEvent arg0) {
                        }
                    });
                }
            } else { // no hay imagen asociada al bot�n

                b.setText(tc.componentName);

                b.addMouseListener(new java.awt.event.MouseListener() {

                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                    }

                    public void mouseEntered(MouseEvent arg0) {
                        if (valuesButton.containsKey("actionedWhenFocused")) {
                            if (tc.componentName.equals(exitButton)) {
                                //SSS 26102009 para controlar hilos
                                HILOS.clear();
                                System.exit(0);
                            }
                            //SSS26102009 para controlar next
                            if (tc.componentName.equals(nextButton)) {
                                jButtonNextActionPerformed(nextButton);
                            }
                            if (vplay != null) {
                                jButtonPlayActionPerformed(vplay);
                            }
                            if (vstop != null) {
                                jButtonStopActionPerformed(vstop);
                            }
                            if (vpause != null) {
                                jButtonPauseActionPerformed(vpause);
                            }
                        }
                        if (playerAnswer.compareTo("") != 0) {
                            jButtonPlayTest(playerAnswer, false);
                        }
                    }

                    public void mouseExited(MouseEvent arg0) {
                    }

                    public void mousePressed(MouseEvent arg0) {
                        if (tc.componentName.equals(exitButton)) {
                            
                            HILOS.clear();
                            System.out.println("vamos a salir");
                            for (int d = 0; d < playersName.size(); d++) {
                                String mediaPanel = (String) playersName.get(d);
                                MediaPanel mp = (MediaPanel) players.get(mediaPanel);

                                jButtonStopActionPerformed(mediaPanel);
                            }
                            //System.out.println("vamos a ocultar el applet");
                            p.setVisible(false);
                            //18-11-2010
                           // Main.started = false;
                            System.out.println("Se pulso el botón de EXIT");
                            //26102009 para controlar el next
                        } else if (tc.componentName.equals(nextButton)) {
                            System.out.println("pulse nextButton en no contentFile");
                            jButtonNextActionPerformed(nextButton);
                        } else if (vplay != null) {
                            jButtonPlayActionPerformed(vplay);
                        } else if (vstop != null) {
                            jButtonStopActionPerformed(vstop);
                        } else if (vpause != null) {
                            jButtonPauseActionPerformed(vpause);
                        } else if (playerRight != "") {
                            jButtonPlayTest(playerRight, false);
                        } else if (playerWrong != "") {
                            jButtonPlayTest(playerWrong, false);
                        } else if (playersTest != null) {
                            String nameplayerButton = (String) playersTest.get(4);
                            if (tc.componentName.equals(nameplayerButton)) {
                                jButtonPlayTest((String) playersTest.get(0), false);
                            }
                        }
                    }

                    public void mouseClicked(MouseEvent arg0) {
                    }

                    public void mouseReleased(MouseEvent arg0) {
                    }
                });
            }
        } else { // no hay imagen asociada al bot�n

            if (tc.componentName.equals(exitButton)) {
                b.setText("EXIT");
                //SSS 26102009 para controlar next
            } else if (tc.componentName.equals(nextButton)) {
                b.setText("NEXT");
            } else if (vplay != null) {
                b.setText("PLAY");
            } else if (vstop != null) {
                b.setText("STOP");
            } else if (vpause != null) {
                b.setText("PAUSE");
            }
            b.addMouseListener(new java.awt.event.MouseListener() {

                public void actionPerformed(java.awt.event.ActionEvent evt) {
                }

                public void mouseEntered(MouseEvent arg0) {
                    if (playerAnswer != "") {
                        //SSS 26102009 lo tengo comentado...
                        // jButtonPlayTest(playerAnswer, false);
                    }
                }

                public void mouseExited(MouseEvent arg0) {
                }

                public void mousePressed(MouseEvent arg0) {
                    if (tc.componentName.equals(exitButton)) {
                     
                        //SSS 26102009 para controlar los hilos
                        HILOS.clear();
                        System.out.println("vamos a salir");
                        for (int d = 0; d < playersName.size(); d++) {
                            String mediaPanel = (String) playersName.get(d);
                            MediaPanel mp = (MediaPanel) players.get(mediaPanel);

                            jButtonStopActionPerformed(mediaPanel);
                        }
                        //System.out.println("vamos a ocultar el applet");
                        p.setVisible(false);
                        //18-11-2011
                       // Main.started = false;
                        System.out.println("Se pulso el botón de EXIT");
                        //SSS 26102009 para controlar el next
                    } else if (tc.componentName.equals(nextButton)) {
                        jButtonNextActionPerformed(nextButton);
                    } else if (vplay != null) {
                        jButtonPlayActionPerformed(vplay);
                    } else if (vstop != null) {
                        jButtonStopActionPerformed(vstop);
                    } else if (vpause != null) {
                        jButtonPauseActionPerformed(vpause);
                        //SSS 26102009 cambiado
                        /*
                        } else if (playerRight != "") {
                        jButtonPlayTest(playerRight, false);
                        } else if (playerWrong != "") {
                        jButtonPlayTest(playerWrong, false);
                         * */
                    } else if (playersTest.size() != 0) {
                        String nameplayerButton = (String) playersTest.get(4);
                        if (tc.componentName.equals(nameplayerButton)) {
                            jButtonPlayTest((String) playersTest.get(0), false);
                        }
                    }
                }

                public void mouseClicked(MouseEvent arg0) {
                }

                public void mouseReleased(MouseEvent arg0) {
                }
            });

        }
        if (valuesButton != null) {
            final int TIME_ALWAYS = 0;
            final int TIME_OK = 1;
            final int TIME_WRONG = 2;
            final int TIME_TIME = 4;
            if (valuesButton.containsKey("delayedTimeMode")) {
                b.setVisible(false);
                String delayedTimeMode = (String) valuesButton.get("delayedTimeMode");
                // if (TMAppletI.OUT) System.out.println(tc.componentName);
                if (delayedTimeMode.equals("1")) {
                    //System.out.println("entro aqui en button ok");

                    // t.setVisible(false);
                    int i = okcomponents.size();
                    okcomponents.put(new Integer(i + 1), (JRadioButton) b);
                } else if (delayedTimeMode.equals("2")) {

                    //System.out.println("entro aqui en button wrong");

                    int i = wrongcomponents.size();
                    wrongcomponents.put(new Integer(i + 1), (JRadioButton) b);
                    // t.setVisible(false);
                    // t.setEnabled(false);
                } else if (delayedTimeMode.equals("4")) {

                    //System.out.println("entro aqui label en delayed");

                    if (valuesButton.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesButton.get("delayedTime");
                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,true);
                        elHilo.inicia((String) valuesButton.get("name"),
                                delayedTime, (JRadioButton) b, true, false,
                                tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();
                    }
                } else if (delayedTimeMode.equals("6")) {

                    //System.out.println("entro aqui label en limited");
                    b.setVisible(true);

                    if (valuesButton.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesButton.get("delayedTime");
                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,false);
                        elHilo.inicia((String) valuesButton.get("name"),
                                delayedTime, (JRadioButton) b, false, false,
                                tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();
                    }
                }

                // c = null;
            } else {
                // result.add(t);
                // c = l;
                b.setVisible(true);

            }

            b.setBounds(x, y, w, h);

            components.put(tc.componentName, b);
            c = b;
        }
        if (vplay != null) {
            playbu = b;
            c = playbu;

            return c;
        }
        return c;
    }

    /**
     * Este método devuelve el índice del timestamp de los subtítulos que tiene que ser mostrado a continuación
     * en función del instante de reproducción guardado en el LMS.
     * @param tiempo instante de tiempo recuperado del LMS
     * //Silvia
     * //considero que hay q poner el q corresponda, no el siguiente...
     * @return el índice del subtítulo
     */
    private int getIndexTimerFromTime(double tiempo, String locator) {

        double timestampTime = 0.0;
        int indice = 0;

        while (timestampTime <= tiempo) {
            Vector vTimestamp = (Vector) timestamp.get(locator + ++indice);
            //System.out.println(vTimestamp);
            timestampTime = Float.parseFloat((String) vTimestamp.get(1));
            //timestampTime = Float.parseFloat((String) ((Vector) timestamp.get(locator + ++indice)).get(0));
        }

        //Silvia
        indice = indice - 1;
        if (indice < 0) {
            indice = 0;
        }
        return indice;
    }

    private Component getLabel(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getLabel");
        }
        Component c = null;
        int x = tc.x;
        int y = tc.y;
        int w = tc.w;
        int h = tc.h;
        final String vsubtitles = (String) playercomponents.get("subtitles" + tc.componentName);

        components.put(tc.componentName, "HLabel");
        //SSS 26102009 cambia el tipo de subtitulos
        final JLabel l = new JLabel();
        // final JTextArea l = new JTextArea();
        HashMap valuesLabel = readValuesOption(eoption, "com.uvigo.mhp.ui.HLabel", tc.componentName);

        //Si no se han definido valores para la etiqueta no la mostramos
        if (valuesLabel == null) {
            return null;
        }

        if (valuesLabel.containsKey("Visible")) {
            //Si no es visible
            if (((String) valuesLabel.get("Visible")).equals("false")) {
                System.out.println("*****************El componente " + tc.componentName + " no es visible");
                return null;
            }
        }

        //SSS 26102009
        //l.setEditable(false);
        l.setOpaque(false);
        l.setVisible(true);

        boolean labelTest = false;

        for (int k = 0; k < asocTest.size() - 1; k++) {
            int key = k + 1;
            String cadena = (String) asocTest.get(key);
            String namebutton = cadena.substring(0, cadena.indexOf(" "));
            String subcad = cadena.substring(namebutton.length() + 1);
            String namelabel = subcad.substring(0, subcad.indexOf(" "));
            final String nameplayer = subcad.substring(namelabel.length() + 1);

            if (tc.componentName.equals(namelabel)) {
                labelTest = true;
                l.addMouseListener(new java.awt.event.MouseListener() {

                    public void mousePressed(MouseEvent arg0) {
                        //SSS 26102009
                        //l.setEditable(false);
                        l.setOpaque(false);
                        l.setVisible(true);
                        l.setForeground(new java.awt.Color(0, 255, 0));
                        l.setFont(new Font("SansSerif", 1, 30));
                    }

                    public void mouseClicked(MouseEvent arg0) {
                    }

                    public void mouseReleased(MouseEvent arg0) {
                    }

                    public void mouseEntered(MouseEvent arg0) {
                        //SSS 26102009
                        //l.setEditable(false);
                        l.setOpaque(false);
                        l.setVisible(true);
                        l.setForeground(new java.awt.Color(0, 255, 0));
                        l.setFont(new Font("SansSerif", 1, 30));
                        jButtonPlayTest(nameplayer, false);
                    }

                    public void mouseExited(MouseEvent arg0) {
                        //SSS 26102009
                        //l.setEditable(false);
                        l.setOpaque(false);
                        l.setVisible(true);
                        l.setForeground(new java.awt.Color(255, 255, 255));
                        l.setFont(new Font("SansSerif", 0, 30));
                    }
                });
                break;
            }

        }

        if (valuesLabel != null) {

            if (valuesLabel.containsKey("X")) {
                x = Integer.parseInt((String) valuesLabel.get("X"));
            }
            if (valuesLabel.containsKey("Y")) {
                y = Integer.parseInt((String) valuesLabel.get("Y"));
            }
            if (valuesLabel.containsKey("Width")) {
                w = Integer.parseInt((String) valuesLabel.get("Width"));
            }
            if (valuesLabel.containsKey("Height")) {
                h = Integer.parseInt((String) valuesLabel.get("Height"));
            }
            if (valuesLabel.containsKey("background")) {
                String background = (String) valuesLabel.get("background");
                if (valuesLabel.containsKey("backgroundMode")) {
                    //System.out.println("cojo el background del label");
                    String backgroundMode = (String) valuesLabel.get("backgroundMode");
                    if (backgroundMode.equals("1")) {
                        l.setOpaque(true);
                        String r = background.substring(0, background.indexOf(" "));
                        String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                        String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());
                        int rv = Integer.parseInt(r);
                        int vv = Integer.parseInt(v);
                        int av = Integer.parseInt(a);
                        l.setBackground(new java.awt.Color(rv, vv, av));
                        //System.out.println("*******Cambiamos el color");
                    }
                }
            }
            //-------------
            //SSS 26102009 hacia todo mal, cambiado

            if (valuesLabel.get("label") != null) {
                String textLabel = new String((String) valuesLabel.get("label"));

                //System.out.println(textLabel);

                int index;
                String texto = "<html><body>";
                while ((index = textLabel.indexOf("\\n")) != -1) {
                    texto += textLabel.substring(0, index) + "<br/>";
                    textLabel = textLabel.substring(index + 2);
                }
                texto += textLabel + "</body></html>";

                l.setText(texto);

                /*
                String name = "";
                String total = "<html><body>";
                int j = 0;
                for (int i = 0; i < textLabel.length(); i++) {
                Character car = new Character(textLabel.charAt(i));
                if (i < textLabel.length() - 1) {
                Character carI = new Character(textLabel.charAt(i + 1));
                if ((car.hashCode() == 92) && (carI.hashCode() == 110)) {
                name = textLabel.substring(j, i);
                j = i + 2;
                total = total + name + "<br/>";
                }
                }
                }
                if (j > 0) {
                total = total + textLabel.substring(j) + "</body></html>";
                l.setText(total);
                // l.append(name);
                } else {
                l.setText(textLabel);
                }
                 */
            }

            /*
            if (valuesLabel.get("label") != null) {
            String textLabel = new String((String) valuesLabel.get("label"));
            String name = "";
            int j = 0;
            for (int i = 0; i < textLabel.length(); i++) {
            Character car = textLabel.charAt(i);
            if (i < textLabel.length() - 1) {
            Character carI = textLabel.charAt(i + 1);
            if ((car.hashCode() == 92) && (carI.hashCode() == 110)) {
            name = textLabel.substring(j, i);
            j = i + 2;
            l.append(name + "\n");

            }
            }
            }
            if (j > 0) {
            name = textLabel.substring(j);
            l.append(name);
            } else {
            l.setText(textLabel);
            }
            }
             */
            //-------------

            if (valuesLabel.containsKey("foreground")) {
                String foreground = (String) valuesLabel.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());
                int rv = Integer.parseInt(r);
                int vv = Integer.parseInt(v);
                int av = Integer.parseInt(a);
                l.setForeground(new java.awt.Color(rv, vv, av));
            }

            if (valuesLabel.containsKey("font")) {
                //SSS 26102009 lo hacia mal
                String texto = (String) valuesLabel.get("font");
                String auxiliar = "";
                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));
                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(auxiliar.lastIndexOf(" ") + 1, auxiliar.length());
                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0, auxiliar.lastIndexOf("") - 1);
                //System.out.println("Fuente del HLabel: " + font);

                l.setFont(new Font(font, formato, size));
                //System.out.println("Fuente del JLabel:" + l.getFont().toString());
            }

        }
        //SSS 26102009 se olvido de comprobar esto
        if (valuesLabel != null) {

            // problemas con el alineamiento, en SCOCreator:
			/*
             * LEFT=0 RIGHT=1 CENTER=2
             *
             * en JLabel y en general en cq compoenent de Swing
             *
             * CENTER=0 LEFT=2 RIGHT=4
             */
            if (valuesLabel.containsKey("horizontalAlignment")) {
                int hAlign = Integer.parseInt((String) valuesLabel.get("horizontalAlignment"));
                switch (hAlign) {
                    case 0:
                        l.setHorizontalAlignment(JLabel.LEFT);
                        break;
                    case 1:
                        l.setHorizontalAlignment(JLabel.CENTER);
                        break;
                    case 2:
                        l.setHorizontalAlignment(JLabel.RIGHT);
                        break;
                }
                /*int hor = Integer.parseInt((String) valuesLabel.get("horizontalAlignment"));
                if (hor == 0) {
                l.setHorizontalAlignment(SwingConstants.LEFT);
                System.out.println("JLabel.LEFT: "+JLabel.LEFT);
                } else if (hor == 2) {
                l.setHorizontalAlignment(SwingConstants.RIGHT);
                System.out.println("JLabel.RIGHT: "+JLabel.RIGHT);
                } else if (hor == 1) {
                l.setHorizontalAlignment(SwingConstants.CENTER);
                System.out.println("JLabel.CENTER: "+JLabel.CENTER);
                }*/
                // l.setHorizontalAlignment(Integer.parseInt((String)
                // valuesLabel.get("horizontalAlignment")));

            } else {
                l.setHorizontalAlignment(SwingConstants.CENTER);
            }

            if (valuesLabel.containsKey("verticalAlignment")) {
                int vAlign = Integer.parseInt((String) valuesLabel.get("verticalAlignment"));
                switch (vAlign) {
                    case 0:
                        l.setVerticalAlignment(JLabel.TOP);
                        break;
                    case 4:
                        l.setVerticalAlignment(JLabel.CENTER);
                        break;
                    case 8:
                        l.setVerticalAlignment(JLabel.BOTTOM);
                        break;
                }
            } else {
                l.setVerticalAlignment(JLabel.CENTER);
            }
        } else {
            l.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
            l.setVerticalAlignment(JLabel.CENTER);
        }
        l.setBounds(x, y, w, h);
        //SSS 26102009 aqui igual cambiar lo de light_grey
        if (vsubtitles != null) {
            //SSS 26102009 nuevo
            l.setOpaque(true);
            if (!valuesLabel.containsKey("backgroundMode")) {
                l.setBackground(java.awt.Color.LIGHT_GRAY);
                //System.out.println("lo ponemos a light_gray");
            }
            l.setBorder(javax.swing.BorderFactory.createEtchedBorder());
            subtitles = l;
        }

        //SSS 26102009 nuevo
        if (valuesLabel != null) {
            final int TIME_ALWAYS = 0;
            final int TIME_OK = 1;
            final int TIME_WRONG = 2;
            final int TIME_TIME = 4;
            if (valuesLabel.containsKey("delayedTimeMode")) {
                l.setVisible(false);
                String delayedTimeMode = (String) valuesLabel.get("delayedTimeMode");
                // if (TMAppletI.OUT) System.out.println(tc.componentName);
                if (delayedTimeMode.equals("1")) {

                    //System.out.println("entro aqui en button ok");
                    // t.setVisible(false);
                    int i = okcomponents.size();
                    okcomponents.put(new Integer(i + 1), (JLabel) l);
                } else if (delayedTimeMode.equals("2")) {

                    //System.out.println("entro aqui en button wrong");
                    int i = wrongcomponents.size();
                    wrongcomponents.put(new Integer(i + 1), (JLabel) l);
                    // t.setVisible(false);
                    // t.setEnabled(false);
                } else if (delayedTimeMode.equals("4")) {


                    //System.out.println("entro aqui label en delayed");

                    if (valuesLabel.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesLabel.get("delayedTime");
                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,true);
                        elHilo.inicia((String) valuesLabel.get("name"),
                                delayedTime, (JLabel) l, true, false,
                                tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();
                    }
                } else if (delayedTimeMode.equals("6")) {


                    //System.out.println("entro aqui label en limited");
                    l.setVisible(true);

                    if (valuesLabel.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesLabel.get("delayedTime");
                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,false);
                        elHilo.inicia((String) valuesLabel.get("name"),
                                delayedTime, (JLabel) l, false, false,
                                tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();
                    }
                }
            }
            // c = null;
        } else {
            // result.add(t);
            // c = l;
            l.setVisible(true);

        }

        c = (Component) l;
        return c;
    }

    private Component getPanel(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getPanel");
        }
        Component c = null;
        //SSS 26102009 estaba mal
        // cambio para pintarla relativa al panel
        x = tc.x;
        y = tc.y;
        w = tc.w;
        h = tc.h;
        /*
        int x = tc.x;
        int y = tc.y;
        int w = tc.w;
        int h = tc.h;
         * */
        components.put(tc.componentName, "HPanel");
        JLayeredPane panel = new JLayeredPane();

        HashMap valuesPanel = readValuesOption(eoption, "com.uvigo.mhp.ui.HPanel", tc.componentName);
        if (valuesPanel != null) {
            if (valuesPanel.containsKey("X")) {
                x = Integer.parseInt((String) valuesPanel.get("X"));
            }
            if (valuesPanel.containsKey("Y")) {
                y = Integer.parseInt((String) valuesPanel.get("Y"));
            }
            if (valuesPanel.containsKey("Width")) {
                w = Integer.parseInt((String) valuesPanel.get("Width"));
            }
            if (valuesPanel.containsKey("Height")) {
                h = Integer.parseInt((String) valuesPanel.get("Height"));
            }
            if (valuesPanel.containsKey("background")) {
                String background = (String) valuesPanel.get("background");
                String r = background.substring(0, background.indexOf(" "));
                String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());
                int rv = Integer.parseInt(r);
                int vv = Integer.parseInt(v);
                int av = Integer.parseInt(a);
                if (valuesPanel.containsKey("opaque")) {
                    panel.setOpaque(true);
                    panel.setBackground(new java.awt.Color(rv, vv, av));

                } else {
                    panel.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(rv, vv, av)));
                }

            }

            if (valuesPanel.containsKey("backgroundImageURL")) {

                String urlImage = ruta + (String) valuesPanel.get("backgroundImageURL");
                JLabel img = new JLabel();

                ImageIcon image = null;
                try {
                    URL dirURL = new URL(urlImage);
                    image = new ImageIcon(dirURL);
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }

                img.setIcon(image);
                //Esto estaba mal ya que aquí hay que poner las coordenadas relativas al panel
                //en este caso x e y valen 0 (borde superior izquierdo del panel)
                //y w y h valen lo mismo que el tamaño del panel
                //img.setBounds(x, y, w, h);
                img.setBounds(0, 0, w, h);
                //Gonzalo: lo pongo a false para admitir imágenes con transparencias
                //img.setOpaque(true);
                img.setOpaque(false);
                panel.add(img, 0);

            }

            if (valuesPanel.containsKey("foreground")) {
                String foreground = (String) valuesPanel.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());
                int rv = Integer.parseInt(r);
                int vv = Integer.parseInt(v);
                int av = Integer.parseInt(a);
                panel.setForeground(new java.awt.Color(rv, vv, av));
            }

            if (valuesPanel.containsKey("font")) {
                //SSS 26102009 estaba mal
                String texto = (String) valuesPanel.get("font");
                String auxiliar = "";
                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));
                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(auxiliar.lastIndexOf(" ") + 1, auxiliar.length());
                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0, auxiliar.lastIndexOf("") - 1);

                panel.setFont(new Font(font, formato, size));
            }
            //SSS 26102009 estaba mal
            if (valuesPanel.containsKey("horizontalAlignment")) {
                int hor = Integer.parseInt((String) valuesPanel.get("horizontalAlignment"));
                if (hor == 0) {
                    panel.setAlignmentX(JLayeredPane.LEFT_ALIGNMENT);
                } else if (hor == 2) {
                    panel.setAlignmentX(JLayeredPane.RIGHT_ALIGNMENT);
                } else if (hor == 1) {
                    panel.setAlignmentX(JLayeredPane.CENTER_ALIGNMENT);
                }

            } else {
                panel.setAlignmentX(JLayeredPane.CENTER_ALIGNMENT);
            }
            if (valuesPanel.containsKey("verticalAlignment")) {
                int ver = Integer.parseInt((String) valuesPanel.get("verticalAlignment"));
                if (ver == 0) {
                    panel.setAlignmentY(JLayeredPane.LEFT_ALIGNMENT);
                } else if (ver == 2) {
                    panel.setAlignmentY(JLayeredPane.RIGHT_ALIGNMENT);
                } else if (ver == 1) {
                    panel.setAlignmentY(JLayeredPane.CENTER_ALIGNMENT);
                }

            } else {
                panel.setAlignmentY(JLayeredPane.CENTER_ALIGNMENT);
            }
        }
        /*
        if (valuesPanel.containsKey("horizontalAlignment")) {
        panel.setAlignmentX(Integer.parseInt((String) valuesPanel.get("horizontalAlignment")));
        }
        if (valuesPanel.containsKey("verticalAlignment")) {
        panel.setAlignmentY(Integer.parseInt((String) valuesPanel.get("verticalAlignment")));
        }
         * */

        if (tc.containedcomponents.size() > 0) {
            for (TemplateComponent tcc : tc.containedcomponents) {
                //System.out.println("silviaaaa " + tc.containedcomponents.size());
                System.out.println("nombre: " + tcc.componentName + ", clase: " + tcc.componentClass);
                Component cp = getVisualTemplateComponent(tcc);
                //SSS 26102009 agrego

                if (cp != null) {
                    panel.add(cp, 0);
                }
            }
        }

        panel.setLayout(null);
        panel.setVisible(true);
        panel.setBounds(x, y, w, h);
        c = panel;
        return c;
    }

    private Component getMediaPlayer(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getmediaPlayer");
        }
        Component c = null;
        //SSS 26102009 para controlar la secuencia
        boolean secuencia = false;
        int x = tc.x;
        int y = tc.y;
        int w = tc.w;
        int h = tc.h;
        MediaPanel mediaPanel = null;
        HashMap valuesPanel = readValuesOption(eoption, "com.uvigo.mhp.mediaPlayer.MediaPlayer", tc.componentName);
        if (valuesPanel != null) {
            if (valuesPanel.containsKey("X")) {
                x = Integer.parseInt((String) valuesPanel.get("X"));
            }
            if (valuesPanel.containsKey("Y")) {
                y = Integer.parseInt((String) valuesPanel.get("Y"));
            }
            if (valuesPanel.containsKey("Width")) {
                w = Integer.parseInt((String) valuesPanel.get("Width"));
            }
            if (valuesPanel.containsKey("Height")) {
                h = Integer.parseInt((String) valuesPanel.get("Height"));
            }
            String configurationFile = "";
            String locator = "";

            if (valuesPanel.containsKey("configurationFile")) {
                configurationFile = ruta + (String) valuesPanel.get("configurationFile");
                locator = getLocatorPlayer(configurationFile);
                timestamp = getTimestamp(configurationFile, locator);
                timestampPlayer.put(tc.componentName, timestamp);

                URL dirURL = null;
                try {
                    dirURL = new URL(ruta + "COMPONENTS/" + locator);
                } catch (MalformedURLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                if (components.containsKey(tc.componentName)) {
                    mediaPanel = new MediaPanel(dirURL, "");
                    mediaPanel.setVisible(false);
                    c = mediaPanel;
                } else {
                    components.put(tc.componentName, "MediaPlayer");
                    playersName.add(tc.componentName);

                    playButton = getPlayButton(ruta + "TEMPLATE/MediaPlayersControl.xml", tc.componentName);
                    pauseButton = getPauseButton(ruta + "TEMPLATE/MediaPlayersControl.xml", tc.componentName);
                    stopButton = getStopButton(ruta + "TEMPLATE/MediaPlayersControl.xml", tc.componentName);

                    mediaPanel = new MediaPanel(dirURL, locator);

                    //SSS 26102009 depende de si es mp2
                    //mediaPanel.setVisible(true);

                    //Si no es un test y hay punto a recuperar lo introducimos en el mediaplayer
                    System.out.println("ESTEST: " + ESTEST);
                    System.out.println("restored: " + vsup.frame.oCL.restored);


                    if (!ESTEST && vsup.frame.oCL.restored) {
                        //Gonzalo 26032010: ESTO NO ESTÁ COMPROBADO AL 100% QUE FUNCIONA BIEN
                        System.out.println("Restaurando los instantes de tiempo!!!!!!!!!!");

                        double tiempo;

                        try {
                            tiempo = Double.parseDouble(vsup.frame.oCL.scoPoint);
                        } catch (NumberFormatException nfe) {
                            tiempo = -1;
                        }

                        if (tiempo > 0) {//Si había un tiempo almacenado se lo asignamos al reproductor

                            mediaPanel.setTime(tiempo);
                            //System.out.println("Vamos a empezar la reproducción en el instante " + tiempo);
                            //Aquí recuperamos el instante de los subtítulos
                            if (timestamp.size() > 0) {//Obtenemos el índice del siguiente subtítulo a reproducir y inicializamos el temporizador que controla los subtítulos
                                //Silvia
                                //ahora indexTimer no es el índice del siguiente subtitulo, sino, del que toca
                                indexTimer = getIndexTimerFromTime(tiempo, locator);//Recuperamos el indice del siguiente subtitulo

                                float tiempo1;
                                float tiempo2;
                                //Silvia
                                //aqui daba error pq salia nombreplayer.avi0 y tendría que ser nombreplayer.avi
                                if (indexTimer == 0) {
                                    tiempo1 = (float) 0.0;
                                    tiempo2 = Float.parseFloat((String) ((Vector) timestamp.get(locator + 1)).get(1));
                                } else {
                                    tiempo1 = Float.parseFloat((String) ((Vector) timestamp.get(locator + (indexTimer))).get(1));
                                    tiempo2 = Float.parseFloat((String) ((Vector) timestamp.get(locator + (indexTimer + 1))).get(1));
                                }
                                //Silvia
                                //Para poner el tiempo que le falta el subtitulo y a la imagen actual
                                // float delay = tiempo2 - tiempo1;
                                float delay = (float) (tiempo2 - tiempo);
                                int dly = (int) (delay * 1000);
                                timer = new Timer(dly, new TimerListener(locator, tc.componentName));
                            }
                        }
                    }

                    players.put(tc.componentName, mediaPanel);

                    mediaPanel.setBounds(x, y, w, h);
                    //SSS 26102009 para ver si es secuencia
                    //System.out.println("ver si el locator es mp2 " + locator);
                    String extension = locator.substring(locator.lastIndexOf("."), locator.length());
                    if ((extension.compareTo(".mp2") == 0)||(extension.compareTo(".mp3")==0)) {
                        for (int i = 1; i < timestamp.size() + 1; i++) {
                            Vector aux = (Vector) timestamp.get(locator + i);
                            if (aux.get(0) != "") {

                                System.out.println("es secuencia de imagenes");
                                secuencia = true;
                                break;
                            } else {
                            }

                        }
                        if (secuencia) {
                            ImageIcon auxi = null;
                            URL dirURL1 = null;
                            String carpeta = locator.substring(0, locator.lastIndexOf("."));
                            System.out.println("indexTimer " + indexTimer);
                            Vector vvv = (Vector) timestamp.get(locator + indexTimer);//"1");
                            System.out.println(vvv.get(0) + " " + vvv.get(1) + " " + vvv.get(2));

                            //System.out.println("hasta aqui bien " + vvv);
                            String img1 = (String) vvv.get(0);

                            String im = ruta + "COMPONENTS/" + carpeta +"/"+ img1;

                            //System.out.println(im);
                            try {
                                dirURL1 = new URL(im);
                                System.out.println("silviapi "+dirURL1.getPath());
                            } catch (MalformedURLException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            Image original = Toolkit.getDefaultToolkit().createImage(dirURL1);
                            // falta, problema
                            Image scaled = original.getScaledInstance(w, h,
                                    Image.SCALE_FAST);
                            auxi = new ImageIcon(scaled);
                            image.setIcon(auxi);

                            image = new JLabel();
                            image.setBounds(x, y, w, h);
                            // image.setVisible(true);
                            image.setOpaque(true);
                            image.setHorizontalAlignment(SwingConstants.CENTER);
                            image.setVerticalAlignment(SwingConstants.CENTER);
                        }

                    }

                    if ((playersTest != null) && (playersTest.size() > 0) && (tc.componentName.equals((String) playersTest.get(3)))) {
                        jButtonPlayTest((String) playersTest.get(3), true);
                    }

// Reproducci�n autom�tica del reproductor:
                    String autoplay = getAutoplay(ruta + "TEMPLATE/MediaPlayersControl.xml", tc.componentName);

                    if (autoplay != null) {
                        if (autoplay.equals("true")) {
                            mediaPanel.start();

                            if (timestamp.size() > 0) {
                                Vector time = (Vector) timestamp.get(locator + 1);
                                String cant = (String) time.get(0);
                                String sub = (String) time.get(1);
                                float cc = Float.parseFloat(cant);
                                int ca = (int) (cc * 1000);
                                timer = new Timer(ca, new TimerListener(locator, tc.componentName));
                                timer.start();
                            }

                        }
                    }
                }
            }
        }
        //SSS 26102009 nuevo
        final int TIME_ALWAYS = 0;
        final int TIME_OK = 1;
        final int TIME_WRONG = 2;
        final int TIME_TIME = 4;
        if (valuesPanel != null) {
            if (valuesPanel.containsKey("delayedTimeMode")) {
                mediaPanel.setVisible(false);
                c = null;
                // mediaPanel = new MediaPanel(dirURL, locator);
                String delayedTimeMode = (String) valuesPanel.get("delayedTimeMode");
                // if (TMAppletI.OUT) System.out.println(tc.componentName);
                if (delayedTimeMode.equals("1")) {

                    //System.out.println("entro aqui label en ok");
                    // t.setVisible(false);
                    int i = okcomponents.size();
                    okcomponents.put(new Integer(i + 1),
                            (MediaPanel) mediaPanel);
                } else if (delayedTimeMode.equals("2")) {

                    //System.out.println("entro aqui label en wrong");
                    int i = wrongcomponents.size();
                    wrongcomponents.put(new Integer(i + 1),
                            (MediaPanel) mediaPanel);
                    // t.setVisible(false);
                    // t.setEnabled(false);
                } else if (delayedTimeMode.equals("4")) {


                    //System.out.println("entro aqui label en delayed");

                    if (valuesPanel.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesPanel.get("delayedTime");
                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,true);
                        elHilo.inicia((String) valuesPanel.get("name"),
                                delayedTime, (MediaPanel) mediaPanel, true,
                                false, tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();
                    }
                } else if (delayedTimeMode.equals("6")) {


                    //System.out.println("entro aqui label en limited");
                    mediaPanel.setVisible(true);
                    c = mediaPanel;
                    if (valuesPanel.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesPanel.get("delayedTime");
                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,false);
                        elHilo.inicia((String) valuesPanel.get("name"),
                                delayedTime, (MediaPanel) mediaPanel, false,
                                false, tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();
                    }
                }

            } else if (components.containsKey(tc.componentName)) {
                mediaPanel.setVisible(true);
            }
        }
        if (secuencia) {
            c = image;
        } else {
            c = mediaPanel;
        }
//SSS 26102009 cambia
        // c = mediaPanel;




        return c;
    }

    private Component getSwitch(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getSwitch");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        components.put(tc.componentName, "HSwitch");
        final JRadioButton rb = new JRadioButton();

        final HashMap valuesSwitch = readValuesOption(eoption, "com.uvigo.mhp.ui.HSwitch", tc.componentName);


        if (valuesSwitch != null) {
            if (valuesSwitch.containsKey("X")) {
                x = Integer.parseInt((String) valuesSwitch.get("X"));


            }
            if (valuesSwitch.containsKey("Y")) {
                y = Integer.parseInt((String) valuesSwitch.get("Y"));


            }
            if (valuesSwitch.containsKey("Width")) {
                w = Integer.parseInt((String) valuesSwitch.get("Width"));


            }
            if (valuesSwitch.containsKey("Height")) {
                h = Integer.parseInt((String) valuesSwitch.get("Height"));


            }

            if (valuesSwitch.containsKey("background")) {
                String background = (String) valuesSwitch.get("background");


                if (valuesSwitch.containsKey("backgroundMode")) {
                    rb.setOpaque(true);
                    String r = background.substring(0, background.indexOf(" "));
                    String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                    String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                    int rv = Integer.parseInt(r);


                    int vv = Integer.parseInt(v);


                    int av = Integer.parseInt(a);
                    rb.setBackground(new java.awt.Color(rv, vv, av));


                }
            }

            if (valuesSwitch.containsKey("foreground")) {
                String foreground = (String) valuesSwitch.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                rb.setForeground(new java.awt.Color(rv, vv, av));


            }

            if (valuesSwitch.containsKey("font")) {
                ///SSS 26102009 cambia
                String texto = (String) valuesSwitch.get("font");
                String auxiliar = "";


                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));
                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(
                        auxiliar.lastIndexOf(" ") + 1, auxiliar.length());


                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0,
                        auxiliar.lastIndexOf("") - 1);
                rb.setFont(new Font(font, formato, size));


            } //SSS 26102009 estaba mal
            if (valuesSwitch.containsKey("horizontalAlignment")) {
                int hor = Integer.parseInt((String) valuesSwitch.get("horizontalAlignment"));


                if (hor == 0) {
                    rb.setHorizontalAlignment(SwingConstants.LEFT);


                } else if (hor == 2) {
                    rb.setHorizontalAlignment(SwingConstants.RIGHT);


                } else if (hor == 1) {
                    rb.setHorizontalAlignment(SwingConstants.CENTER);


                }

            } else {
                rb.setHorizontalAlignment(SwingConstants.CENTER);


            }
            if (valuesSwitch.containsKey("verticalAlignment")) {
                int ver = Integer.parseInt((String) valuesSwitch.get("verticalAlignment"));


                if (ver == 0) {
                    rb.setVerticalAlignment(SwingConstants.LEFT);


                } else if (ver == 2) {
                    rb.setVerticalAlignment(SwingConstants.RIGHT);


                } else if (ver == 1) {
                    rb.setVerticalAlignment(SwingConstants.CENTER);


                }
            } else {
                rb.setVerticalAlignment(SwingConstants.CENTER);


            }
            if (valuesSwitch.containsKey("contentFile")) {

                String contentFile = ruta + (String) valuesSwitch.get("contentFile");
                // lectura TEMP/COMPONENTS/...
                final HashMap iconsButton = readValuesComponents(contentFile);



                if (valuesSwitch.containsKey("switchableState")) {
                    rb.setSelected(true);


                    if (iconsButton.containsKey("actionedStateContent")) {
                        try {
                            HashMap properButton = (HashMap) iconsButton.get("actionedStateContent");


                            if (properButton.containsKey("graphicContent")) {
                                rb.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));


                            }
                            if (properButton.containsKey("textContent")) {
                                rb.setText((String) properButton.get("textContent"));


                            }
                            String aaaa = nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent"));


                        } catch (MalformedURLException ex) {
                            System.err.println(ex);


                        }
                    }
                } else {
                    rb.setSelected(false);


                    if (iconsButton.containsKey("normalStateContent")) {
                        try {
                            HashMap properButton = (HashMap) iconsButton.get("normalStateContent");


                            if (properButton.containsKey("graphicContent")) {
                                rb.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));


                            }
                            if (properButton.containsKey("textContent")) {
                                rb.setText((String) properButton.get("textContent"));


                            }
                            String aaaa = nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent"));


                        } catch (MalformedURLException ex) {
                            System.err.println(ex);


                        }
                    }
                }

                rb.addMouseListener(new java.awt.event.MouseListener() {

                    public void actionPerformed(java.awt.event.ActionEvent evt) {
                    }

                    public void mouseEntered(MouseEvent arg0) {
                        if (rb.isSelected()) {
                        } else {
                            if (iconsButton.containsKey("focusedStateContent")) {
                                try {
                                    HashMap properButton = (HashMap) iconsButton.get("focusedStateContent");


                                    if (properButton.containsKey("graphicContent")) {
                                        rb.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));


                                    }
                                    if (properButton.containsKey("textContent")) {
                                        rb.setText((String) properButton.get("textContent"));


                                    }
                                } catch (MalformedURLException ex) {
                                    System.err.println(ex);


                                }
                            }
                        }
                    }

                    public void mouseExited(MouseEvent arg0) {
                        if (rb.isSelected()) {
                        } else {
                            if (iconsButton.containsKey("normalStateContent")) {
                                try {
                                    HashMap properButton = (HashMap) iconsButton.get("normalStateContent");


                                    if (properButton.containsKey("graphicContent")) {
                                        rb.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));


                                    }
                                    if (properButton.containsKey("textContent")) {
                                        rb.setText((String) properButton.get("textContent"));


                                    }
                                } catch (MalformedURLException ex) {
                                    System.err.println(ex);


                                }
                            }
                        }
                    }

                    public void mousePressed(MouseEvent arg0) {
                        if (rb.isSelected()) {
                            if (iconsButton.containsKey("normalStateContent")) {
                                try {
                                    HashMap properButton = (HashMap) iconsButton.get("normalStateContent");


                                    if (properButton.containsKey("graphicContent")) {
                                        rb.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));


                                    }
                                    if (properButton.containsKey("textContent")) {
                                        rb.setText((String) properButton.get("textContent"));


                                    }
                                } catch (MalformedURLException ex) {
                                    System.err.println(ex);


                                }
                            }
                        } else {
                            if (iconsButton.containsKey("actionedStateContent")) {
                                try {
                                    HashMap properButton = (HashMap) iconsButton.get("actionedStateContent");


                                    if (properButton.containsKey("graphicContent")) {
                                        rb.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) properButton.get("graphicContent")))));


                                    }
                                    if (properButton.containsKey("textContent")) {
                                        rb.setText((String) properButton.get("textContent"));


                                    }
                                } catch (MalformedURLException ex) {
                                    System.err.println(ex);


                                }
                            }
                        }
                    }

                    public void mouseClicked(MouseEvent arg0) {
                    }

                    public void mouseReleased(MouseEvent arg0) {
                    }
                });


            } else {
                if (valuesSwitch.containsKey("switchableState")) {
                    rb.setSelected(true);


                } else {
                    rb.setSelected(false);


                }
            }
        }
        rb.setBounds(x, y, w, h);
        c = rb;


        return c;


    }

    private Component getScrollPane(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getScrollPane");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        components.put(tc.componentName, "HScrollPane");
        JScrollPane areaScrollPane = (JScrollPane) ListScrollPane.get(tc.componentName);



        if (tc.containedcomponents.size() > 0) {
            for (TemplateComponent tcc : tc.containedcomponents) {
                Component textarea = getComponentsScrollPane(tcc);
                areaScrollPane = new JScrollPane(textarea);
                areaScrollPane.setViewportView(textarea);


            }
        }
        final HashMap valuesScrollPane = readValuesOption(eoption, "com.uvigo.mhp.ui.HScrollPane", tc.componentName);


        if (valuesScrollPane != null) {
            if (valuesScrollPane.containsKey("X")) {
                x = Integer.parseInt((String) valuesScrollPane.get("X"));


            }
            if (valuesScrollPane.containsKey("Y")) {
                y = Integer.parseInt((String) valuesScrollPane.get("Y"));


            }
            if (valuesScrollPane.containsKey("Width")) {
                w = Integer.parseInt((String) valuesScrollPane.get("Width"));


            }
            if (valuesScrollPane.containsKey("Height")) {
                h = Integer.parseInt((String) valuesScrollPane.get("Height"));


            }
        }

        areaScrollPane.setPreferredSize(new Dimension(w, h));
        areaScrollPane.setBounds(x, y, w, h);
        c = areaScrollPane;
        ListScrollPane.put(tc.componentName, areaScrollPane);
        c = areaScrollPane;


        return c;


    }

    private Component getScrollBar(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getScrollBar");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        String vscrollBarH = null;
        String vscrollBarV = null;



        if (scrollPanel != null) {
            vscrollBarH = (String) scrollPanel.get("horizontal" + tc.componentName);
            vscrollBarV = (String) scrollPanel.get("vertical" + tc.componentName);


        }
        components.put(tc.componentName, "HScrollBar");
        JScrollBar bar = new JScrollBar();


        if (vscrollBarH != null) {
            bar = new JScrollBar(JScrollBar.HORIZONTAL);
            JScrollPane areaScrollPane = (JScrollPane) ListScrollPane.get(vscrollBarH);
            areaScrollPane.setHorizontalScrollBar(bar);


        }
        if (vscrollBarV != null) {
            bar = new JScrollBar(JScrollBar.VERTICAL);
            JScrollPane areaScrollPane = (JScrollPane) ListScrollPane.get(vscrollBarV);
            areaScrollPane.setVerticalScrollBar(bar);


        }

        final HashMap valuesScrollBar = readValuesOption(eoption, "com.uvigo.mhp.ui.HScrollBar", tc.componentName);


        if (valuesScrollBar.containsKey("X")) {
            x = Integer.parseInt((String) valuesScrollBar.get("X"));


        }
        if (valuesScrollBar.containsKey("Y")) {
            y = Integer.parseInt((String) valuesScrollBar.get("Y"));


        }
        if (valuesScrollBar.containsKey("Width")) {
            w = Integer.parseInt((String) valuesScrollBar.get("Width"));


        }
        if (valuesScrollBar.containsKey("Height")) {
            h = Integer.parseInt((String) valuesScrollBar.get("Height"));


        }

        if (valuesScrollBar.containsKey("background")) {
            String background = (String) valuesScrollBar.get("background");


            if (valuesScrollBar.containsKey("backgroundMode")) {
                bar.setOpaque(true);
                String r = background.substring(0, background.indexOf(" "));
                String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                bar.setBackground(new java.awt.Color(rv, vv, av));


            }
        }

        if (valuesScrollBar.containsKey("unitIncrement")) {
            bar.setBlockIncrement(Integer.parseInt((String) valuesScrollBar.get("unitIncrement")));


        }

        if (valuesScrollBar.containsKey("maxValue")) {
            bar.setMaximum(Integer.parseInt((String) valuesScrollBar.get("maxValue")));


        }

        if (valuesScrollBar.containsKey("minValue")) {
            bar.setMinimum(Integer.parseInt((String) valuesScrollBar.get("minValue")));


        }

        if (valuesScrollBar.containsKey("value")) {
            bar.setValue(Integer.parseInt((String) valuesScrollBar.get("value")));


        }
        bar.setBounds(x, y, w, h);
        c = bar;


        return c;


    }

    private Component getTextPanel(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getTextPanel");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;


        if (components.containsKey(tc.componentName)) {
            JTextArea textArea = new JTextArea();
            textArea.setVisible(false);
            c = textArea;


        } else {
            components.put(tc.componentName, "TextPanel");
            JEditorPane textArea = new JEditorPane();

            HashMap valuesTextPanel = readValuesOption(eoption, "com.uvigo.mhp.textPanel.TextPanel", tc.componentName);


            if (valuesTextPanel != null) {
                if (valuesTextPanel.containsKey("X")) {
                    x = Integer.parseInt((String) valuesTextPanel.get("X"));


                }
                if (valuesTextPanel.containsKey("Y")) {
                    y = Integer.parseInt((String) valuesTextPanel.get("Y"));


                }
                if (valuesTextPanel.containsKey("Width")) {
                    w = Integer.parseInt((String) valuesTextPanel.get("Width"));


                }
                if (valuesTextPanel.containsKey("Height")) {
                    h = Integer.parseInt((String) valuesTextPanel.get("Height"));


                }

                if (valuesTextPanel.containsKey("background")) {
                    String background = (String) valuesTextPanel.get("background");


                    if (valuesTextPanel.containsKey("opaque")) {
                        String opaque = (String) valuesTextPanel.get("opaque");


                        if (opaque.equals("true")) { // Se pinta color de fondo
                            textArea.setOpaque(true);
                            String r = background.substring(0, background.indexOf(" "));
                            String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                            String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                            int rv = Integer.parseInt(r);


                            int vv = Integer.parseInt(v);


                            int av = Integer.parseInt(a);
                            textArea.setBackground(new java.awt.Color(rv, vv, av));


                        }
                    }
                }

                if (valuesTextPanel.containsKey("foreground")) {
                    String foreground = (String) valuesTextPanel.get("foreground");
                    String r = foreground.substring(0, foreground.indexOf(" "));
                    String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                    String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                    int rv = Integer.parseInt(r);


                    int vv = Integer.parseInt(v);


                    int av = Integer.parseInt(a);
                    textArea.setForeground(new java.awt.Color(rv, vv, av));


                }

                if (valuesTextPanel.containsKey("configurationFile")) {
                    String configurationFile = ruta + (String) valuesTextPanel.get("configurationFile");

                    //lectura TEMP/COMPONENTS/...
                    final HashMap iconsTextPanel = readValuesTextPanel(configurationFile);


                    if (iconsTextPanel.containsKey("locator")) {
                        String location = ruta + "COMPONENTS/" + ((String) iconsTextPanel.get("locator"));
                        URL dirURL = null;


                        try {
                            dirURL = new URL(location);


                        } catch (MalformedURLException e1) {
                            e1.printStackTrace();


                        }
                        try {
                            textArea.setPage(dirURL);


                        } catch (IOException e) {
                        }
                    }

                    textArea.setEditable(false);
                    textArea.setBounds(x, y, w, h);


                }
            }

            c = textArea;


        }
        return c;


    }

    private Component getImage(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getImage");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        JLabel image = new JLabel();

        HashMap valuesImage = readValuesOption(eoption, "com.uvigo.mhp.ui.HImage", tc.componentName);


        if (valuesImage != null) {
            if (valuesImage.containsKey("X")) {
                x = Integer.parseInt((String) valuesImage.get("X"));


            }
            if (valuesImage.containsKey("Y")) {
                y = Integer.parseInt((String) valuesImage.get("Y"));


            }
            if (valuesImage.containsKey("Width")) {
                w = Integer.parseInt((String) valuesImage.get("Width"));


            }
            if (valuesImage.containsKey("Height")) {
                h = Integer.parseInt((String) valuesImage.get("Height"));


            }

            if (valuesImage.containsKey("background")) {
                String background = (String) valuesImage.get("background");


                if (valuesImage.containsKey("backgroundMode")) {
                    String backgroundMode = (String) valuesImage.get("backgroundMode");


                    if (backgroundMode.equals("1")) { // Se pinta color de fondo
                        image.setOpaque(true);
                        String r = background.substring(0, background.indexOf(" "));
                        String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                        String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                        int rv = Integer.parseInt(r);


                        int vv = Integer.parseInt(v);


                        int av = Integer.parseInt(a);
                        image.setBackground(new java.awt.Color(rv, vv, av));


                    }
                }
            }

            if (valuesImage.containsKey("foreground")) {
                String foreground = (String) valuesImage.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                image.setForeground(new java.awt.Color(rv, vv, av));


            }

//SSS 26102009 estaba mal
            // por defecto es la izq
            image.setHorizontalAlignment(SwingConstants.CENTER);
            image.setVerticalAlignment(SwingConstants.CENTER);


            if (valuesImage.containsKey("horizontalAlignment")) {
                int hor = Integer.parseInt((String) valuesImage.get("horizontalAlignment"));


                if (hor == 0) {
                    image.setHorizontalAlignment(SwingConstants.LEFT);


                } else if (hor == 2) {
                    image.setHorizontalAlignment(SwingConstants.RIGHT);


                } else if (hor == 1) {
                    image.setHorizontalAlignment(SwingConstants.CENTER);


                }

            }
            if (valuesImage.containsKey("verticalAlignment")) {
                int ver = Integer.parseInt((String) valuesImage.get("verticalAlignment"));


                if (ver == 0) {
                    image.setVerticalAlignment(SwingConstants.LEFT);


                } else if (ver == 2) {
                    image.setVerticalAlignment(SwingConstants.RIGHT);


                } else if (ver == 1) {
                    image.setVerticalAlignment(SwingConstants.CENTER);


                }
            }
            if (valuesImage.containsKey("imageURL")) {
                try {
                    String im = ruta + (String) valuesImage.get("imageURL");
                    URL dirURL = new URL(im);
                    image.setIcon(new javax.swing.ImageIcon(dirURL));


                } catch (MalformedURLException e) {
                    e.printStackTrace();


                }
            }
        }
        //SSS 26102009 la imagen relativa al panel
        //image.setBounds(x, y, w, h);
        image.setBounds(x + AppletTemplateComponentsXML.x, y + AppletTemplateComponentsXML.y, w, h);
        //SSS 26102009 agrego
        final int TIME_ALWAYS = 0;
        final int TIME_OK = 1;
        final int TIME_WRONG = 2;
        final int TIME_DELAYED = 4;
        final int TIME_LIMITED = 6;


        if (valuesImage != null) {
            if (valuesImage.containsKey("delayedTimeMode")) {
                image.setVisible(false);
                String delayedTimeMode = (String) valuesImage.get("delayedTimeMode");
                // if (TMAppletI.OUT) System.out.println(tc.componentName);


                if (delayedTimeMode.equals("1")) {

                    //System.out.println("entro aqui en image ok");
                    // t.setVisible(false);
                    int i = okcomponents.size();
                    okcomponents.put(new Integer(i + 1), (JLabel) image);


                } else if (delayedTimeMode.equals("2")) {

                    //System.out.println("entro aqui en image wrong");
                    int i = wrongcomponents.size();
                    wrongcomponents.put(new Integer(i + 1), (JLabel) image);
                    // t.setVisible(false);
                    // t.setEnabled(false);


                } else if (delayedTimeMode.equals("4")) {


                    //System.out.println("entro aqui label en delayed");

                    if (valuesImage.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesImage.get("delayedTime");


                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,true);
                        elHilo.inicia((String) valuesImage.get("name"),
                                delayedTime, (JLabel) image, true, false,
                                tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();


                    }
                } else if (delayedTimeMode.equals("6")) {


                    //System.out.println("entro aqui label en limited");
                    image.setVisible(true);



                    if (valuesImage.containsKey("delayedTime")) {
                        String delayedTimestr = (String) valuesImage.get("delayedTime");


                        long delayedTime = Long.parseLong(delayedTimestr);
                        DelayedTime elHilo = new DelayedTime();// (String)valuesLabel.get("name"),a,
                        // (HVisible)t,false);
                        elHilo.inicia((String) valuesImage.get("name"),
                                delayedTime, (JLabel) image, false, false,
                                tc.componentName, vsup);
                        HILOS.add(elHilo);
                        // elHilo.start();


                    }
                }
                // c = null;
            }
        } else {

            image.setVisible(true);


        }
        c = image;


        return c;


    }

    private Component getAnimatedImage(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getAnimatedImage");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        JLabel image = new JLabel();


        boolean content = false;
        Vector images = new Vector();
        HashMap valuesImage = readValuesOption(eoption, "com.uvigo.mhp.ui.HAnimated", tc.componentName);


        if (valuesImage != null) {
            if (valuesImage.containsKey("X")) {
                x = Integer.parseInt((String) valuesImage.get("X"));


            }
            if (valuesImage.containsKey("Y")) {
                y = Integer.parseInt((String) valuesImage.get("Y"));


            }
            if (valuesImage.containsKey("Width")) {
                w = Integer.parseInt((String) valuesImage.get("Width"));


            }
            if (valuesImage.containsKey("Height")) {
                h = Integer.parseInt((String) valuesImage.get("Height"));


            } // Esta propiedad permite elegir las im�genes que constituir�n
            //la animaci�n.
            if (valuesImage.containsKey("contentFile")) {

                String contentFile = ruta + (String) valuesImage.get("contentFile");


                int position = 0;


                int repeatCount = 0;
                images = readValuesImageAnimated(contentFile);


                int delay = 1;


                if (valuesImage.containsKey("delay")) {
                    delay = Integer.parseInt((String) valuesImage.get("delay"));


                }
                if (valuesImage.containsKey("position")) {
                    position = Integer.parseInt((String) valuesImage.get("position"));


                }
                if (valuesImage.containsKey("repeatCount")) {
                    repeatCount = Integer.parseInt((String) valuesImage.get("repeatCount"));


                }

                if (images.size() > 0) {
                    try {
                        String imagen = (String) images.get(position);
                        String dirImage = ruta + "COMPONENTS/" + imagen;
                        URL dirURL = new URL(dirImage);
                        image.setIcon(new javax.swing.ImageIcon(dirURL));


                    } catch (MalformedURLException e) {
                        e.printStackTrace();


                    }
                }
                if (images.size() > 1) {
                    content = true;
                    imageAnimated.put(tc.componentName, images);
                    timer = new Timer(delay * 100, new TimerListenerImageAnimated(tc.componentName, position, repeatCount));
                    timer.setInitialDelay(delay * 100);
                    timer.start();


                }

            }

            // Color de fondo del HAnimated (del area visible no ocupada por la animaci�n)
            if (valuesImage.containsKey("background")) {
                String background = (String) valuesImage.get("background");


                if (valuesImage.containsKey("backgroundMode")) {
                    String backgroundMode = (String) valuesImage.get("backgroundMode");


                    if (backgroundMode.equals("1")) { // Se pinta color de fondo
                        image.setOpaque(true);
                        String r = background.substring(0, background.indexOf(" "));
                        String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                        String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                        int rv = Integer.parseInt(r);


                        int vv = Integer.parseInt(v);


                        int av = Integer.parseInt(a);
                        image.setBackground(new java.awt.Color(rv, vv, av));


                    }
                }
            }

            if (valuesImage.containsKey("foreground")) {
                String foreground = (String) valuesImage.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                image.setForeground(new java.awt.Color(rv, vv, av));


            } //SSS 26102009 estaba mal
            // Como se alinea la animaci�n en la dimensi�n horizontal
            if (valuesImage.containsKey("horizontalAlignment")) {
                int hor = Integer.parseInt((String) valuesImage.get("horizontalAlignment"));


                if (hor == 0) {
                    image.setHorizontalAlignment(SwingConstants.LEFT);


                } else if (hor == 2) {
                    image.setHorizontalAlignment(SwingConstants.RIGHT);


                } else if (hor == 1) {
                    image.setHorizontalAlignment(SwingConstants.CENTER);


                }
            } else {
                image.setHorizontalAlignment(SwingConstants.CENTER);


            } // Como se alinea la animaci�n en la dimensi�n vertical
            if (valuesImage.containsKey("verticalAlignment")) {
                int ver = Integer.parseInt((String) valuesImage.get("verticalAlignment"));


                if (ver == 0) {
                    image.setVerticalAlignment(SwingConstants.LEFT);


                } else if (ver == 2) {
                    image.setVerticalAlignment(SwingConstants.RIGHT);


                } else if (ver == 1) {
                    image.setVerticalAlignment(SwingConstants.CENTER);


                }
            } else {
                image.setVerticalAlignment(SwingConstants.CENTER);


            }

        } else {
            image.setHorizontalAlignment(SwingConstants.CENTER);
            image.setVerticalAlignment(SwingConstants.CENTER);


        }
        image.setBounds(x, y, w, h);

        componentsAnimated.put(tc.componentName, image);
        c = image;


        return c;



    }

    private Component getInternalFrame(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getInternalFrame");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        JPanel internalFrame = new JPanel();
        HashMap valuesInternalFrame = readValuesOption(eoption, "com.uvigo.mhp.ui.HInternalFrame", tc.componentName);


        if (valuesInternalFrame != null) {
            if (valuesInternalFrame.containsKey("X")) {
                x = Integer.parseInt((String) valuesInternalFrame.get("X"));


            }
            if (valuesInternalFrame.containsKey("Y")) {
                y = Integer.parseInt((String) valuesInternalFrame.get("Y"));


            }
            if (valuesInternalFrame.containsKey("Width")) {
                w = Integer.parseInt((String) valuesInternalFrame.get("Width"));


            }
            if (valuesInternalFrame.containsKey("Height")) {
                h = Integer.parseInt((String) valuesInternalFrame.get("Height"));


            }

            if (valuesInternalFrame.containsKey("background")) {
                String background = (String) valuesInternalFrame.get("background");


                if (valuesInternalFrame.containsKey("opaque")) {
                    String backgroundMode = (String) valuesInternalFrame.get("opaque");


                    if (backgroundMode.equals("true")) { // Se pinta color de fondo

                        internalFrame.setOpaque(true);
                        String r = background.substring(0, background.indexOf(" "));
                        String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                        String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                        int rv = Integer.parseInt(r);


                        int vv = Integer.parseInt(v);


                        int av = Integer.parseInt(a);
                        internalFrame.setBackground(new java.awt.Color(rv, vv, av));


                    }
                }
            }

            if (valuesInternalFrame.containsKey("foreground")) {
                String foreground = (String) valuesInternalFrame.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                internalFrame.setForeground(new java.awt.Color(rv, vv, av));


            }

            if (valuesInternalFrame.containsKey("font")) {
                //SSS 26102009 estaba mal
                String texto = (String) valuesInternalFrame.get("font");
                String auxiliar = "";


                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));
                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(auxiliar.lastIndexOf(" ") + 1, auxiliar.length());


                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0, auxiliar.lastIndexOf("") - 1);

                internalFrame.setFont(new Font(font, formato, size));


            }

            if (valuesInternalFrame.containsKey("label")) {
                internalFrame.setToolTipText((String) valuesInternalFrame.get("label"));


            } //SSS 26102009 estaba mal
            if (valuesInternalFrame.containsKey("horizontalAlignment")) {
                int hor = Integer.parseInt((String) valuesInternalFrame.get("horizontalAlignment"));


                if (hor == 0) {
                    internalFrame.setAlignmentX(JLayeredPane.LEFT_ALIGNMENT);


                } else if (hor == 2) {
                    internalFrame.setAlignmentX(JLayeredPane.RIGHT_ALIGNMENT);


                } else if (hor == 1) {
                    internalFrame.setAlignmentX(JLayeredPane.CENTER_ALIGNMENT);


                }

            } else {
                internalFrame.setAlignmentX(JPanel.CENTER_ALIGNMENT);


            }
            if (valuesInternalFrame.containsKey("verticalAlignment")) {
                int ver = Integer.parseInt((String) valuesInternalFrame.get("verticalAlignment"));


                if (ver == 0) {
                    internalFrame.setAlignmentY(JLayeredPane.LEFT_ALIGNMENT);


                } else if (ver == 2) {
                    internalFrame.setAlignmentY(JLayeredPane.RIGHT_ALIGNMENT);


                } else if (ver == 1) {
                    internalFrame.setAlignmentY(JLayeredPane.CENTER_ALIGNMENT);


                }
            } else {
                internalFrame.setAlignmentY(JPanel.CENTER_ALIGNMENT);


            }

        }

        internalFrame.setBounds(x, y, w, h);

        internalFrame.setVisible(true);

        c = internalFrame;


        return c;



    }

    private Component getMultiPanel(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getMultiPanel");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        JPanel internalFrame = new JPanel();
        HashMap valuesInternalFrame = readValuesOption(eoption, "com.uvigo.mhp.ui.HMultiPanel", tc.componentName);


        if (valuesInternalFrame != null) {
            if (valuesInternalFrame.containsKey("X")) {
                x = Integer.parseInt((String) valuesInternalFrame.get("X"));


            }
            if (valuesInternalFrame.containsKey("Y")) {
                y = Integer.parseInt((String) valuesInternalFrame.get("Y"));


            }
            if (valuesInternalFrame.containsKey("Width")) {
                w = Integer.parseInt((String) valuesInternalFrame.get("Width"));


            }
            if (valuesInternalFrame.containsKey("Height")) {
                h = Integer.parseInt((String) valuesInternalFrame.get("Height"));


            }

            if (valuesInternalFrame.containsKey("background")) {
                String background = (String) valuesInternalFrame.get("background");


                if (valuesInternalFrame.containsKey("opaque")) {
                    String backgroundMode = (String) valuesInternalFrame.get("opaque");


                    if (backgroundMode.equals("true")) { // Se pinta color de fondo

                        internalFrame.setOpaque(true);
                        String r = background.substring(0, background.indexOf(" "));
                        String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                        String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                        int rv = Integer.parseInt(r);


                        int vv = Integer.parseInt(v);


                        int av = Integer.parseInt(a);
                        internalFrame.setBackground(new java.awt.Color(rv, vv, av));


                    }
                }
            }

            if (valuesInternalFrame.containsKey("foreground")) {
                String foreground = (String) valuesInternalFrame.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                internalFrame.setForeground(new java.awt.Color(rv, vv, av));


            }

            if (valuesInternalFrame.containsKey("font")) {
                //SSS 26102009 estaba mal
                String texto = (String) valuesInternalFrame.get("font");
                String auxiliar = "";


                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));
                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(auxiliar.lastIndexOf(" ") + 1, auxiliar.length());


                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0, auxiliar.lastIndexOf("") - 1);

                internalFrame.setFont(new Font(font, formato, size));


            }

            if (valuesInternalFrame.containsKey("label")) {
                internalFrame.setToolTipText((String) valuesInternalFrame.get("label"));


            }
            if (valuesInternalFrame.containsKey("horizontalAlignment")) {
                internalFrame.setAlignmentX(Integer.parseInt((String) valuesInternalFrame.get("horizontalAlignment")));


            }
            if (valuesInternalFrame.containsKey("verticalAlignment")) {
                internalFrame.setAlignmentY(Integer.parseInt((String) valuesInternalFrame.get("verticalAlignment")));


            }
        }
        if (tc.containedcomponents.size() > 0) {
            for (TemplateComponent tcc : tc.containedcomponents) {
                Component cp = getVisualTemplateComponent(tcc);
                internalFrame.add(cp);


            }
        }

        internalFrame.setBounds(x, y, w, h);
        c = internalFrame;


        return c;


    }

    private Component getMenu(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getMenu");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        JPanel pmenu = new JPanel();

        java.awt.Color backgroundColor = null;
        java.awt.Color foregroundColor = null;
        final HashMap valuesMenu = readValuesOption(eoption, "com.uvigo.mhp.ui.HMenu", tc.componentName);


        if (valuesMenu != null) {
            if (valuesMenu.containsKey("X")) {
                x = Integer.parseInt((String) valuesMenu.get("X"));


            }
            if (valuesMenu.containsKey("Y")) {
                y = Integer.parseInt((String) valuesMenu.get("Y"));


            }
            if (valuesMenu.containsKey("Width")) {
                w = Integer.parseInt((String) valuesMenu.get("Width"));


            }
            if (valuesMenu.containsKey("Height")) {
                h = Integer.parseInt((String) valuesMenu.get("Height"));


            }

            if (valuesMenu.containsKey("background")) {
                String background = (String) valuesMenu.get("background");


                if (valuesMenu.containsKey("backgroundMode")) {
                    pmenu.setOpaque(true);
                    String r = background.substring(0, background.indexOf(" "));
                    String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                    String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                    int rv = Integer.parseInt(r);


                    int vv = Integer.parseInt(v);


                    int av = Integer.parseInt(a);
                    backgroundColor = new java.awt.Color(rv, vv, av);
                    pmenu.setBackground(new java.awt.Color(rv, vv, av));


                }
            }

            if (valuesMenu.containsKey("foreground")) {
                String foreground = (String) valuesMenu.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                foregroundColor = new java.awt.Color(rv, vv, av);
                pmenu.setForeground(new java.awt.Color(rv, vv, av));


            }

            String texto = "";



            if (valuesMenu.containsKey("font")) {
                //SSS 26102009 estaba mal
                texto = (String) valuesMenu.get("font");
                String auxiliar = "";


                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));

                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(auxiliar.lastIndexOf(" ") + 1, auxiliar.length());


                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0, auxiliar.lastIndexOf("") - 1);

                pmenu.setFont(new Font(font, formato, size));


            }

            if (valuesMenu.containsKey("configurationFile")) {

                String contentFile = ruta + (String) valuesMenu.get("configurationFile");
                // lectura TEMP/COMPONENTS/...
                final HashMap iconsButton = readValuesComponentsMenu(contentFile);


                for (int k = 0; k
                        < iconsButton.size(); k++) {
                    try {
                        final HashMap propiedades = (HashMap) iconsButton.get("menuElement" + k);
                        final JRadioButton option = new JRadioButton();


                        if (propiedades.containsKey("notSelectedImage")) {
                            option.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) propiedades.get("notSelectedImage")))));


                        } else {
                            option.setSelected(false);


                        }
                        option.setVisible(true);


                        if (texto == "") {
                            option.setFont(new Font(Font.DIALOG, Font.BOLD, 12));
                            option.setText((String) propiedades.get("label"));


                            if (foregroundColor != null) {
                                option.setForeground(foregroundColor);


                            }
                        }
                        if (backgroundColor != null) {
                            option.setBackground(backgroundColor);


                        }
                        //--------------------
                        final java.awt.Color backgroundColor2 = backgroundColor;
                        final java.awt.Color foregroundColor2 = foregroundColor;
                        java.awt.Color selectionBackground = null;
                        java.awt.Color selectionForeground = null;



                        if (valuesMenu.containsKey("selectionBackground")) {
                            String backgroundS = (String) valuesMenu.get("selectionBackground");
                            String r = backgroundS.substring(0, backgroundS.indexOf(" "));
                            String v = backgroundS.substring(r.length() + 1, backgroundS.indexOf(" ", r.length() + 1));
                            String a = backgroundS.substring(backgroundS.indexOf(" ", r.length() + 1) + 1, backgroundS.length());


                            int rv = Integer.parseInt(r);


                            int vv = Integer.parseInt(v);


                            int av = Integer.parseInt(a);
                            selectionBackground = new java.awt.Color(rv, vv, av);


                        }

                        if (valuesMenu.containsKey("selectionForeground")) {
                            String foreground = (String) valuesMenu.get("selectionForeground");
                            String r = foreground.substring(0, foreground.indexOf(" "));
                            String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                            String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                            int rv = Integer.parseInt(r);


                            int vv = Integer.parseInt(v);


                            int av = Integer.parseInt(a);
                            selectionForeground = new java.awt.Color(rv, vv, av);


                        }

                        final java.awt.Color selectionBackground2 = selectionBackground;
                        final java.awt.Color selectionForeground2 = selectionForeground;

                        option.addMouseListener(new java.awt.event.MouseListener() {

                            public void actionPerformed(java.awt.event.ActionEvent evt) {
                            }

                            public void mousePressed(MouseEvent arg0) {
                                if (valuesMenu.containsKey("enable")) {
                                } else {
                                    if (option.isSelected()) {
                                        if (propiedades.containsKey("notSelectedImage")) {
                                            try {
                                                option.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) propiedades.get("notSelectedImage")))));
                                                option.setBackground(backgroundColor2);
                                                option.setForeground(foregroundColor2);


                                            } catch (MalformedURLException ex) {
                                                System.err.println(ex);


                                            }
                                        }
                                    } else {
                                        if (propiedades.containsKey("selectedImage")) {
                                            try {
                                                option.setIcon(new javax.swing.ImageIcon(new URL(nameSCO + "COMPONENTS/" + ((String) propiedades.get("selectedImage")))));
                                                option.setBackground(selectionBackground2);
                                                option.setForeground(selectionForeground2);


                                            } catch (MalformedURLException ex) {
                                                System.err.println(ex);


                                            }
                                        }
                                    }
                                }
                            }

                            public void mouseClicked(MouseEvent arg0) {
                            }

                            public void mouseReleased(MouseEvent arg0) {
                            }

                            public void mouseEntered(MouseEvent arg0) {
                            }

                            public void mouseExited(MouseEvent arg0) {
                            }
                        });

                        pmenu.add(option);


                    } catch (MalformedURLException ex) {
                        System.err.println(ex);


                    }
                }

            }
            if (valuesMenu.containsKey("layoutOrientation")) {
                if (((String) valuesMenu.get("layoutOrientation")).equals("HORIZONTAL_WRAP")) {
                    if (valuesMenu.containsKey("visibleRowCount")) {
                        int size = Integer.parseInt((String) valuesMenu.get("visibleRowCount"));
                        pmenu.setLayout(new GridLayout(size, size));


                    } else {
                        pmenu.setLayout(new BoxLayout(pmenu, BoxLayout.X_AXIS));


                    }
                }
            } else {
                pmenu.setLayout(new BoxLayout(pmenu, BoxLayout.Y_AXIS));


            }
        }

        pmenu.setBounds(x, y, w, h);
        c = pmenu;



        return c;



    }

    private Component getActiveImage(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getActiveImage");


        }
        Component c = null;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;

        final JLayeredPane layeredPane = new JLayeredPane();
        final JLabel picture1 = new JLabel();

        final HashMap valuesMenu = readValuesOption(eoption, "com.uvigo.mhp.activeImage.ActiveImage", tc.componentName);


        if (valuesMenu != null) {
            if (valuesMenu.containsKey("X")) {
                x = Integer.parseInt((String) valuesMenu.get("X"));


            }
            if (valuesMenu.containsKey("Y")) {
                y = Integer.parseInt((String) valuesMenu.get("Y"));


            }
            if (valuesMenu.containsKey("Width")) {
                w = Integer.parseInt((String) valuesMenu.get("Width"));


            }
            if (valuesMenu.containsKey("Height")) {
                h = Integer.parseInt((String) valuesMenu.get("Height"));


            }

            if (valuesMenu.containsKey("configurationFile")) {

                String contentFile = ruta + (String) valuesMenu.get("configurationFile");
                final HashMap iconsImage = readValuesComponentsImageAct(contentFile);
                String backgroundImage = readBackgroundImageAct(contentFile);



                if (backgroundImage != null) {
                    backgroundImage = ruta + "COMPONENTS/" + backgroundImage;

                    ImageIcon image = null;
                    URL dirURL = null;


                    try {
                        dirURL = new URL(backgroundImage);
                        image = new ImageIcon(dirURL);


                    } catch (MalformedURLException e) {
                        e.printStackTrace();


                    }
                    picture1.setIcon(image);
                    picture1.setSize(image.getIconWidth(), image.getIconHeight());
                    picture1.setHorizontalAlignment(JLabel.CENTER);
                    picture1.setVerticalAlignment(JLabel.CENTER);


                }

                final int ww = w;
                final int hh = h;
                final int xx = x;
                final int yy = y;

                layeredPane.setAlignmentX(Component.CENTER_ALIGNMENT);
                layeredPane.setAlignmentY(Component.CENTER_ALIGNMENT);

                layeredPane.setBounds(x, y, w, h);
                layeredPane.setSize(w, h);
                picture1.setOpaque(true);
                layeredPane.add(picture1, new Integer(0));


                boolean enable = true;



                if (valuesMenu.containsKey("mouseEnabled")) {
                    String enabled = (String) valuesMenu.get("mouseEnabled");


                    if (enabled.equals("false")) {
                        enable = false;


                    }
                }
                if (enable) {
                    if (valuesMenu.containsKey("mouseBehaviour")) {

                        picture1.addMouseListener(new java.awt.event.MouseListener() {

                            public void actionPerformed(java.awt.event.ActionEvent evt) {
                            }

                            public void mouseEntered(MouseEvent event) {
                            }

                            public void mouseExited(MouseEvent arg0) {
                            }

                            public void mousePressed(MouseEvent event) {
                                int[] temp = new int[1];


                                int[] temp1 = new int[ww * hh];
                                ImageIcon imag = null;


                                int alpha;


                                for (int k = 0; k
                                        < iconsImage.size(); k++) {
                                    String nameimg = "activeZone" + k;


                                    if (iconsImage.containsKey(nameimg)) {
                                        HashMap propiedades = (HashMap) iconsImage.get(nameimg);


                                        if (propiedades.containsKey("locator")) {
                                            String locator = ruta + "COMPONENTS/" + propiedades.get("locator");


                                            try {
                                                URL dirURL = new URL(locator);
                                                imag = new ImageIcon(dirURL);


                                            } catch (MalformedURLException e) {
                                                e.printStackTrace();


                                            }

                                            ImageIcon mapimage = imag;

                                            PixelGrabber pg = new PixelGrabber(mapimage.getImage(), event.getX(), event.getY(), 1, 1, temp, 0, 0);



                                            try {
                                                pg.grabPixels();


                                            } catch (Exception ex) {
                                                ex.printStackTrace();


                                            }

                                            if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                                                new Exception().printStackTrace();


                                            }

                                            alpha = temp[0] & 0xff000000;


                                            if (alpha != 0) {
                                                JLabel imageActive = new JLabel();
                                                imageActive.setOpaque(false);
                                                imageActive.setIcon(mapimage);
                                                imageActive.setSize(mapimage.getIconWidth(), mapimage.getIconHeight());
                                                layeredPane.add(imageActive, 0);


                                            }
                                        }
                                    }

                                }
                            }

                            public void mouseClicked(MouseEvent arg0) {
                            }

                            public void mouseReleased(MouseEvent arg0) {
                            }
                        });



                    } else {
                        picture1.addMouseMotionListener(new java.awt.event.MouseMotionListener() {

                            public void mouseDragged(MouseEvent event) {
                            }

                            public void mouseMoved(MouseEvent event) {
                                int[] temp = new int[1];


                                int[] temp1 = new int[ww * hh];
                                ImageIcon imag = null;


                                int alpha;


                                for (int k = 0; k
                                        < iconsImage.size(); k++) {
                                    String nameimg = "activeZone" + k;



                                    if (iconsImage.containsKey(nameimg)) {
                                        HashMap propiedades = (HashMap) iconsImage.get(nameimg);


                                        if (propiedades.containsKey("locator")) {
                                            String locator = ruta + "COMPONENTS/" + propiedades.get("locator");


                                            try {
                                                URL dirURL = new URL(locator);
                                                imag = new ImageIcon(dirURL);


                                            } catch (MalformedURLException e) {
                                                e.printStackTrace();


                                            }

                                            ImageIcon mapimage = imag;

                                            PixelGrabber pg = new PixelGrabber(mapimage.getImage(), event.getX(), event.getY(), 1, 1, temp, 0, 0);



                                            try {
                                                pg.grabPixels();


                                            } catch (Exception ex) {
                                                ex.printStackTrace();


                                            }

                                            if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
                                                new Exception().printStackTrace();


                                            }

                                            alpha = temp[0] & 0xff000000;


                                            if (alpha != 0) {
                                                JLabel imageActive = new JLabel();
                                                imageActive.setOpaque(false);
                                                imageActive.setIcon(mapimage);
                                                layeredPane.add(imageActive, 0);



                                            }
                                        }
                                    }

                                }
                            }
                        });


                    }
                }
            }

            c = layeredPane;


        }
        return c;



    }

    private Component getTemplate(TemplateComponent tc) {
        if (OUT) {
            System.out.println("getTemplate");


        }
        Component c = null;


        boolean isImage = false;


        int x = tc.x;


        int y = tc.y;


        int w = tc.w;


        int h = tc.h;
        HashMap valuesPanel = readValuesOption(eoption, "com.uvigo.tMaestro.SCOCreator.tool.Template", tc.componentName);


        if (valuesPanel != null) {
            if (valuesPanel.containsKey("X")) {
                x = Integer.parseInt((String) valuesPanel.get("X"));


            }
            if (valuesPanel.containsKey("Y")) {
                y = Integer.parseInt((String) valuesPanel.get("Y"));


            }
            if (valuesPanel.containsKey("Width")) {
                w = Integer.parseInt((String) valuesPanel.get("Width"));


            }
            if (valuesPanel.containsKey("Height")) {
                h = Integer.parseInt((String) valuesPanel.get("Height"));


            }

            if (valuesPanel.containsKey("background")) {
                String background = (String) valuesPanel.get("background");
                String r = background.substring(0, background.indexOf(" "));
                String v = background.substring(r.length() + 1, background.indexOf(" ", r.length() + 1));
                String a = background.substring(background.indexOf(" ", r.length() + 1) + 1, background.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);


                if (valuesPanel.containsKey("opaque")) {
                    p.setOpaque(true);
                    p.setBackground(new java.awt.Color(rv, vv, av));


                } else {
                    p.setBorder(javax.swing.BorderFactory.createMatteBorder(4, 4, 4, 4, new java.awt.Color(rv, vv, av)));


                }
            }

            if (valuesPanel.containsKey("backgroundImageURL")) {

                String urlImage = ruta + (String) valuesPanel.get("backgroundImageURL");

                JLabel img = new JLabel();

                ImageIcon image = null;


                try {
                    URL dirURL = new URL(urlImage);
                    image = new ImageIcon(dirURL);


                } catch (MalformedURLException e) {
                    e.printStackTrace();


                }
                img.setIcon(image);
                img.setBounds(x, y, w, h);
                img.setOpaque(true);
                p.add(img, -1);
                isImage = true;


            }

            if (valuesPanel.containsKey("foreground")) {
                String foreground = (String) valuesPanel.get("foreground");
                String r = foreground.substring(0, foreground.indexOf(" "));
                String v = foreground.substring(r.length() + 1, foreground.indexOf(" ", r.length() + 1));
                String a = foreground.substring(foreground.indexOf(" ", r.length() + 1) + 1, foreground.length());


                int rv = Integer.parseInt(r);


                int vv = Integer.parseInt(v);


                int av = Integer.parseInt(a);
                p.setForeground(new java.awt.Color(rv, vv, av));


            }

            if (valuesPanel.containsKey("font")) {
                //SS 26102009 estaba mal
                String texto = (String) valuesPanel.get("font");
                String auxiliar = "";


                int size = Integer.parseInt(texto.substring(texto.lastIndexOf(" ") + 1, texto.length()));
                auxiliar = texto.substring(0, texto.lastIndexOf(" "));
                String format = auxiliar.substring(auxiliar.lastIndexOf(" ") + 1, auxiliar.length());


                int formato = Integer.parseInt(format);
                String font = auxiliar.substring(0, auxiliar.lastIndexOf("") - 1);

                p.setFont(new Font(font, formato, size));


            }

            if (valuesPanel.containsKey("horizontalAlignment")) {
                p.setAlignmentX(Integer.parseInt((String) valuesPanel.get("horizontalAlignment")));


            }

            if (valuesPanel.containsKey("verticalAlignment")) {
                p.setAlignmentY(Integer.parseInt((String) valuesPanel.get("verticalAlignment")));


            }

        }

        if (tc.containedcomponents.size() > 0) {

            for (TemplateComponent tcc : tc.containedcomponents) {

                int z = tcc.z;
                Component cp = getVisualTemplateComponent(tcc);


                if (cp != null) {
                    if (isImage) {
                        p.add(cp, z);


                    } else {
                        if (z == 0) {
                            p.add(cp, -1);


                        } else {
                            p.add(cp, z);


                        }
                    }
                }
            }
        }
        p.setVisible(true);
        p.setBounds(x, y, w, h);

        c = p;


        return c;


    }

    private Component getVisualTemplateComponent(final TemplateComponent tc) {
        Component c = null;



        if (tc.componentClass.equalsIgnoreCase("HButton")) {
            c = getButton(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HLabel")) {
            c = getLabel(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HPanel")) {
            c = getPanel(tc);


        } else if (tc.componentClass.equalsIgnoreCase("MediaPlayer")) {
            c = getMediaPlayer(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HSwitch")) {
            c = getSwitch(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HScrollPane")) {
            c = getScrollPane(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HScrollBar")) {
            c = getScrollBar(tc);


        } else if (tc.componentClass.equalsIgnoreCase("TextPanel")) {
            c = getTextPanel(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HImage")) {
            c = getImage(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HAnimated")) {
            c = getAnimatedImage(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HInternalFrame")) {
            c = getInternalFrame(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HMultiPanel")) {
            c = getMultiPanel(tc);


        } else if (tc.componentClass.equalsIgnoreCase("HMenu")) {
            c = getMenu(tc);


        } else if (tc.componentClass.equalsIgnoreCase("ActiveImage")) {
            c = getActiveImage(tc);


        } else {
            c = getTemplate(tc);
            //Vamos a dar el focus al botón por defecto


            if ((currentSelected = navigation.getInitiallySelected()) != null) {
                //System.out.println("currentSelected: "+currentSelected);
                //System.out.println("silvia " + components);
                //System.out.println("silvia " + currentSelected);
                Iterator it = components.entrySet().iterator();
                while (it.hasNext()) {
                    Map.Entry e = (Map.Entry) it.next();
                    //System.out.println(e.getKey() + " " + e.getValue());
                }

                ((ImageButton) components.get(currentSelected)).setFocusedIcon();


            }


        }

        return c;


    }

    public void setUp() {
        playbu.doClick();


    }

//SSS 26102009 nuevo controlar okywrong
    private void jButtonOkWrong(String nam) {

        //System.out.println("jButtonOkWrong");
        String cadena = (String) asocTest.get(new Integer(ANSWEROK));

        //System.out.println(cadena);
        String namebutton = cadena.substring(0, cadena.indexOf(" "));
        // if (TMAppletI.OUT) System.out.println("tama�o de okcomponents " +
        // okcomponents.size());


        if (nam.compareTo(namebutton) == 0) {

            System.out.println("pulse  la correcta");


            for (int i = 0; i
                    < okcomponents.size(); i++) {
                if (okcomponents.get(new Integer(i + 1)) instanceof MediaPanel) {
                    // if (TMAppletI.OUT)
                    // System.out.println("es un mediaPanel");
                    // primero tengo q parar todos (reset)
                    // los dos tipos por si le doy dos veces al mismo
					/*
                    for (int j = 0; j < okcomponents.size(); j++) {
                    if (okcomponents.get(new Integer(j + 1)) instanceof MediaPanel) {
                    MediaPanel aux = (MediaPanel) okcomponents
                    .get(new Integer(j + 1));
                    if (aux != null){

                    System.out.println("okcomponent "+aux.locator);
                    aux.mediaPlayer.setMediaTime(new Time(0));
                    aux.stop();
                    }

                    }
                    }
                     */
                    for (int j = 0; j
                            < wrongcomponents.size(); j++) {
                        if (wrongcomponents.get(new Integer(j + 1)) instanceof MediaPanel) {
                            //System.out.println("b");
                            MediaPanel aux = (MediaPanel) wrongcomponents.get(new Integer(j + 1));



                            if (aux != null) {
                                //System.out.println("wrongcomponent " + aux.locator);
                                aux.mediaPlayer.setMediaTime(new Time(0));
                                aux.stop();


                            }
                        }
                    }

                    //System.out.println("es un mediaPanel");
                    MediaPanel aux = (MediaPanel) okcomponents.get(new Integer(
                            i + 1));

                    //System.out.println("inicio en ok " + aux.locator);
                    aux.mediaPlayer.setMediaTime(new Time(0));
                    aux.start();


                } else if (okcomponents.get(new Integer(i + 1)) instanceof Component) {

                    for (int j = 0; j
                            < wrongcomponents.size(); j++) {
                        if (wrongcomponents.get(new Integer(j + 1)) instanceof Component) {
                            Component aux = (Component) wrongcomponents.get(new Integer(j + 1));
                            aux.setVisible(false);



                        }
                    }

                    Component aux = (Component) okcomponents.get(new Integer(
                            i + 1));

                    //System.out.println(aux);
                    aux.setVisible(true);



                } else {
                    //System.out.println("que co�o es " + wrongcomponents.get(new Integer(i + 1)));
                }
            }
        } else {

            //System.out.println("pulse la incorrecta");
            for (int i = 0; i
                    < wrongcomponents.size(); i++) {
                if (wrongcomponents.get(new Integer(i + 1)) instanceof MediaPanel) {
                    // primero tengo q parar todos (reset)
                    for (int j = 0; j
                            < okcomponents.size(); j++) {
                        if (okcomponents.get(new Integer(j + 1)) instanceof MediaPanel) {
                            MediaPanel aux = (MediaPanel) okcomponents.get(new Integer(j + 1));
                            //System.out.println("c");


                            if (aux != null) {
                                //System.out.println("okcomponent " + aux.locator);
                                aux.mediaPlayer.setMediaTime(new Time(0));
                                aux.stop();


                            }

                        }
                    }
                    /*
                    for (int j = 0; j < wrongcomponents.size(); j++) {
                    if (wrongcomponents.get(new Integer(j + 1)) instanceof MediaPanel) {
                    MediaPanel aux = (MediaPanel) wrongcomponents
                    .get(new Integer(j + 1));
                    //System.out.println("d");
                    if (aux != null){
                    System.out.println("wrongcomponent "+aux.locator);
                    aux.mediaPlayer.setMediaTime(new Time(0));
                    aux.stop();
                    }

                    }
                    }
                     */

                    //System.out.println("es un mediaPanel");
                    MediaPanel aux = (MediaPanel) wrongcomponents.get(new Integer(i + 1));

                    //System.out.println("inicio en wrong " + aux.locator);
                    aux.mediaPlayer.setMediaTime(new Time(0));
                    aux.start();


                } else if (wrongcomponents.get(new Integer(i + 1)) instanceof Component) {
                    // if (TMAppletI.OUT)
                    // System.out.println("entro en compoennt "+wrongcomponents.get(new
                    // Integer()));
                    for (int j = 0; j
                            < okcomponents.size(); j++) {
                        if (okcomponents.get(new Integer(j + 1)) instanceof Component) {
                            Component aux = (Component) okcomponents.get(new Integer(j + 1));
                            aux.setVisible(false);



                        }
                        Component aux = (Component) wrongcomponents.get(new Integer(i + 1));
                        aux.setVisible(true);


                    }
                } else {
                    //System.out.println("que cono es " + wrongcomponents.get(new Integer(i + 1)));
                }

            }
        }
    }

    private void jButtonExitActionPerformed() {
        okcomponents.clear();
        wrongcomponents.clear();
        HILOS.clear();

        System.out.println("vamos a salir");


        for (int d = 0; d
                < playersName.size(); d++) {
            String mediaPanel = (String) playersName.get(d);
            //SSS 26102009 esto no lo tengo pero parece que no lo usa
            MediaPanel mp = (MediaPanel) players.get(mediaPanel);

            jButtonStopActionPerformed(
                    mediaPanel);
            mp.mediaPlayer.close();


        }
        //SSS 26102009 para controlar el next
        NEXT = false;
        //System.out.println("vamos a ocultar el applet");
        p.setVisible(false);
        //18-11-2010
       // Main.started = false;
        System.out.println("Se pulso el botón de EXIT");



    } //SSS 26102009 nuevo controlar next

    private void jButtonNextActionPerformed(String nam) {

        System.out.println("jButtonNextActionPerformed");


        for (int d = 0; d
                < playersName.size(); d++) {
            String mediaPanel = (String) playersName.get(d);
            //SSS 26102009 esto no lo tengo pero parece que no lo usa
            MediaPanel mp = (MediaPanel) players.get(mediaPanel);

            jButtonStopActionPerformed(
                    mediaPanel);
            mp.mediaPlayer.close();


        }
        NEXT = false;
        // borramos los wrong y los ok



        for (int i = 0; i
                < HILOS.size(); i++) {
            DelayedTime aux = (DelayedTime) HILOS.get(i);
            //if (TMAppletI.OUT) System.out.println("entro para "+aux.name);


            if (aux != null) {
                if (aux.component instanceof MediaPanel) {
                    MediaPanel mediaPanel = (MediaPanel) aux.component;
                    mediaPanel.stop();


                }
                aux.norep = true;


            }

        }
        HILOS.clear();
        okcomponents.clear();
        wrongcomponents.clear();
        // significa que no hay siguiente y tengo q salir al ppal
        newfocused = -1;

        //System.out.println(vsup.unidadPrincipal);

        //System.out.println();
        Unit[] subunidades = vsup.unidadPrincipal.getSubUnits();


        for (int i = vsup.focused + 1; i
                < subunidades.length; i++) {
            if (subunidades[i].getSubUnits() == null || subunidades[i].getSubUnits().length == 0) {
                if (subunidades[i].getResources() != null && subunidades[i].getResources().length != 0) {
                    newfocused = i;


                    break;


                }
            }
        }
        if (newfocused == -1) {
            p.setVisible(false);


        } // if (TMAppletI.OUT)
        // System.out.println(TMAppletI.atcjx.panel.getComponentCount());
        // if (TMAppletI.OUT) System.out.println(newfocused);
        else {
            NEXT = true;
            p.setVisible(false);

            // p.setVisible(true);



        }
        //
    }

    private void jButtonPlayActionPerformed(String nam) {
        instantePlay = System.currentTimeMillis();
        System.out.println("jButtonPlayActionPerformed ");


        boolean fin = true;
        String name;
        String namePlayer = nam;


        int i = 0;


        while (fin) {
            if (namePlayer.indexOf(" ") > 0) {
                name = namePlayer.substring(i, namePlayer.indexOf(" "));
                i = namePlayer.indexOf(" ") + 1;
                namePlayer = namePlayer.substring(i);


            } else {
                name = namePlayer;
                fin = false;


            }

            MediaPanel mediaPanel = (MediaPanel) players.get(name);
            mediaPanel.start();


            if (players.containsKey(name)) {
                //System.out.println("obtengo los timestamp " + name);
                timestamp = (HashMap) timestampPlayer.get(name);


                if (timestamp.size() > 0) {
                    if (timer.getDelay() > 0) {
                        int del = timer.getDelay();


                        float mdi = (float) (mediaPanel.getTime() * 1000);


                        float suma = 0;


                        if (indexTimer > 1) {
                            int aux = indexTimer - 1;
                            Vector time = (Vector) timestamp.get(mediaPanel.locator + aux);
                            //SSS 26102009 cambia pq tb imagenes secuencia
                            String cant = (String) time.get(1);
                            suma = Float.parseFloat(cant);


                        }
                        float rr = ((float) mediaPanel.getTime()) - suma;


                        float au = (float) rr * 1000;


                        int au2 = (int) au;


                        int cc = del - au2;
                        timer = new Timer(cc, new TimerListener(mediaPanel.locator, nam));
                        timer.start();


                    } else if (timestamp.size() > 0) {
                        Vector time = (Vector) timestamp.get(mediaPanel.locator + 1);
                        //SSS 26102009 cambia pq añado tb imagenes secuencia
                        String cant = (String) time.get(1);
                        String sub = (String) time.get(2);


                        float cc = Float.parseFloat(cant);


                        int ca = (int) (cc * 1000);
                        timer = new Timer(ca, new TimerListener(mediaPanel.locator, nam));
                        timer.start();


                    }
                }
            }
        }
        return;


    }

    public void jButtonStopActionPerformed(String nam) {

        System.out.println("jButtonStopActionPerformed " + nam);


        boolean fin = true;
        String name;
        String namePlayer = nam;


        int i = 0;


        while (fin) {
            if (namePlayer.indexOf(" ") > 0) {
                name = namePlayer.substring(i, namePlayer.indexOf(" "));
                i = namePlayer.indexOf(" ") + 1;
                namePlayer = namePlayer.substring(i);


            } else {
                name = namePlayer;
                fin = false;


            }
            if (players.containsKey(name)) {
                MediaPanel mediaPanel = (MediaPanel) players.get(name);
                System.out.println(name + ": " + mediaPanel.getTime());
                System.out.println(name + " duration: " + mediaPanel.getDuration());
                mediaPanel.stop();
                timestamp = (HashMap) timestampPlayer.get(name);


                if (timestamp.size() > 0) {
                    timer.stop();
                    subtitles.setText("");
                    timer.setDelay(0);
                    indexTimer = 1;


                }
            }
        }
        return;


    }

    private void jButtonPauseActionPerformed(String nam) {
        System.out.println("duracion de la reproducción: " + (System.currentTimeMillis() - instantePlay));



        boolean fin = true;
        String name;
        String namePlayer = nam;


        int i = 0;


        while (fin) {
            if (namePlayer.indexOf(" ") > 0) {
                name = namePlayer.substring(i, namePlayer.indexOf(" "));
                i = namePlayer.indexOf(" ") + 1;
                namePlayer = namePlayer.substring(i);


            } else {
                name = namePlayer;
                fin = false;


            }
            if (players.containsKey(name)) {
                MediaPanel mediaPanel = (MediaPanel) players.get(name);
                mediaPanel.pause();
                timestamp = (HashMap) timestampPlayer.get(name);


                if (timestamp.size() > 0) {
                    timer.stop();


                }
            }
        }
        return;


    }

    private void initTimer(String name, String nameComp) {

        Vector vvv = (Vector) timestamp.get(name + indexTimer);
        //SSS 26102009 cambia pq secuencia imagenes

        //Silvia
        //para indexTimer=0 no funcionaba
        String cant = "0.0";
        String sub = "";
        String img = "";

        if (indexTimer != 0) {
            cant = (String) vvv.get(1);
            sub = (String) vvv.get(2);
            img = (String) vvv.get(0);


        }
        /*
        String cant = (String) vvv.get(0);
        String sub = (String) vvv.get(1);
         * */

        float cc = Float.parseFloat(cant);
        //Gonzalo: esta línea la introduzco para ajustar el desfase que se produce entre el vídeo y los subtítulos
        cc = (float) ((MediaPanel) players.get(subtitlesPlayerComponentName)).getTime();



        float cc1 = 0;


        float rc = 0;


        if (indexTimer < timestamp.size()) {
            int idx = indexTimer + 1;
            Vector vvv1 = (Vector) timestamp.get(name + idx);
            //SSS 26102009 cambia pq secuencia imagenes
            String cant1 = (String) vvv1.get(1);
            cc1 = Float.parseFloat(cant1);
            rc = cc1 - cc;


        }
        int ca;


        if (rc > 0) {
            ca = (int) (rc * 1000);


        } else {
            ca = (int) (cc * 1000);
            //-------------


        }

        subtitles.repaint();
        //SSS 26102009 cambia
        //subtitles.setOpaque(true);
        subtitles.setText("");


        if (img.compareTo("") != 0) {

            String carpeta = name.substring(0, name.lastIndexOf("."));

            Vector aux = (Vector) timestamp.get(name + "1");
            // String img1 = (String) aux.get(0);

            String im = ruta + "COMPONENTS/" + carpeta + "/" + img;

            //System.out.println(im);

            ImageIcon auxi = null;

            Image original = null;
            try {

                URL dirURL1 = new URL(im);

                original = Toolkit.getDefaultToolkit().createImage(
                        dirURL1);
            } catch (MalformedURLException e) {
                e.printStackTrace();


            }
            // falta, problema
            System.out.println(image.getWidth());
                  System.out.println(image.getHeight());
            Image scaled = original.getScaledInstance(image.getWidth(),
                    image.getHeight(), Image.SCALE_FAST);
            auxi = new ImageIcon(scaled);

            image.setVisible(true);
            image.setIcon(auxi);
            image.repaint();


        }






        if (sub.compareTo("") != 0) {// Esto est� mal, si el sub no contiene ningun salto de linea no se muestra

            //SSS 26102009 cambia pq staba
            //System.out.println("Sub: " + sub);

            int index;
            String texto = "<html><body>";


            while ((index = sub.indexOf("\\n")) != -1) {
                texto += sub.substring(0, index) + "<br/>";
                sub = sub.substring(index + 2);


            }
            texto += sub + "</body></html>";

            subtitles.setText(texto);

            // System.out.println("instante del subtítulo: " + cant + ", instante del vídeo: " + ((MediaPanel) players.get(subtitlesPlayerComponentName)).getTime());

            //System.out.println(texto);


            /*String nameS = "<html><body>";
            int j = 0;
            for (int i = 0; i < sub.length(); i++) {
            Character car = sub.charAt(i);
            if (i < sub.length() - 1) {
            Character carI = sub.charAt(i + 1);
            if ((car.hashCode() == 92) && (carI.hashCode() == 110)) {
            nameS = nameS + sub.substring(j, i) + "<br/>";
            j = i + 2;
            // subtitles.append(nameS + "\n");
            // subtitles.setAlignmentX(JLabel.CENTER_ALIGNMENT);
            }
            }
            }
            // if (j > 0) {
            nameS = nameS + sub.substring(j) + "</body></html>";
            
            subtitles.setText(nameS);*/
            // subtitles.setAlignmentX(JLabel.CENTER_ALIGNMENT);
            // }


            /*
            System.out.println("Sub: " + sub);
            String nameS = "";
            int j = 0;
            for (int i = 0; i < sub.length(); i++) {
            Character car = sub.charAt(i);
            if (i < sub.length() - 1) {
            Character carI = sub.charAt(i + 1);
            if ((car.hashCode() == 92) && (carI.hashCode() == 110)) {
            nameS = sub.substring(j, i);
            j =  i + 2;
            subtitles.append(nameS + "\n");
            subtitles.setAlignmentX(JLabel.CENTER_ALIGNMENT);
            }

            }
            }
            //if (j > 0) {
            nameS = sub.substring(j);
            subtitles.append(nameS);
            subtitles.setAlignmentX(JLabel.CENTER_ALIGNMENT);
            //}
             * */


        }

//-------------
        indexTimer++;
        timer = new Timer(ca, new TimerListener(name, nameComp));
        timer.start();




    }

    public class TimerListener implements ActionListener {

        String namePlayer = "";
        String nameComponent = "";

        public TimerListener(String name, String nameComp) {
            namePlayer = name;
            nameComponent = nameComp;
        }

        public void actionPerformed(ActionEvent evt) {

            timer.stop();
            //SSS 26102009 estaba mal
            timestamp = (HashMap) timestampPlayer.get(nameComponent);
            String component = "";
            String nameComponentaux = nameComponent;

            for (int i = 0; i < timestampPlayer.size(); i++) {

                //System.out.println(nameComponentaux);
                int longitud = nameComponentaux.indexOf(" ");
                if (longitud == -1) {
                    longitud = nameComponentaux.length();
                }
                component = nameComponentaux.substring(0, longitud);
                nameComponentaux = nameComponentaux.substring(nameComponentaux.indexOf(" ") + 1, nameComponentaux.length());
                //System.out.println(component);
                timestamp = (HashMap) (timestampPlayer.get(component));
                if (timestamp.size() != 0) {
                    //System.out.println("lo encontre " + timestamp);
                    subtitlesPlayerComponentName = component;
                    break;
                } else {
                    //System.out.println("este no es");
                }
            }
            /*System.out.println("timestampPlayer " + timestampPlayer);*/

            if (timestamp == null) {
                //System.out.println("es el timestamp " + nameComponent);
            }
            if (timestamp != null) {
                if (indexTimer <= timestamp.size()) {
                    initTimer(namePlayer, nameComponent);
                }
            }



            //SSS 26102009 estaba mal
            /*
            timestamp = (HashMap) timestampPlayer.get("playerPeque");
            if (indexTimer <= timestamp.size()) {
            initTimer(namePlayer, nameComponent);
            }
             * */
        }
    }

    public class TimerListenerInac implements ActionListener {

        String namePlayer = "";
        String nameComponent = "";

        public TimerListenerInac(String name, String nameComp) {
            namePlayer = name;
            nameComponent = nameComp;
        }

        public void actionPerformed(ActionEvent evt) {
            timerInactivity.stop();
            initPlayInactivity(nameComponent);

        }
    }

    public class TimerListenerImageAnimated implements ActionListener {

        int index = 0;
        int repeatCount = 0;
        int images = 0;
        String nameimage; // nombre del elemento HAnimated
        JLabel picture = new JLabel();

        public TimerListenerImageAnimated(String name, int position, int repeat) {
            nameimage = name;
            index = position;
            repeatCount = repeat;
        }

        public void actionPerformed(ActionEvent arg0) {
            Vector lista = (Vector) imageAnimated.get(nameimage);
            if (index < lista.size() - 1) {
                index++;
            } else {
                index = 0;
            }
            if (repeatCount > 0) {
                images++;
                if (images / lista.size() == repeatCount) {
                    timer.stop();
                }
            }
            try {
                String image = (String) lista.get(index);
                String dirImage = ruta + "COMPONENTS/" + image;
                URL dirURL = new URL(dirImage);
                picture = (JLabel) componentsAnimated.get(nameimage);
                picture.setIcon(new javax.swing.ImageIcon(dirURL));
            } catch (MalformedURLException e) {
                e.printStackTrace();
            }
        }
    }

    private void jButtonPlayTest(String nam, boolean inactivity) {
        if (!inactivity) {
            timerInactivity.stop();
            playerInactivity.stop();


        }
        if (lastPlayer != null) {
            lastPlayer.stop();


        }
        MediaPanel mediaPanel = (MediaPanel) players.get(nam);
        lastPlayer = mediaPanel;
        mediaPanel.start();


        if (inactivity) {
            playerInactivity = mediaPanel;


        }
        double ca = mediaPanel.getDuration();


        double au = (double) ca * 1000;


        int au2 = (int) au;
        timerInactivity = new Timer(au2, new TimerListenerInac(mediaPanel.locator, nam));
        timerInactivity.start();



    }

    private void initPlayInactivity(String nam) {
        playerInactivity.stop();
        playerInactivity.start();


        double ca = playerInactivity.getDuration();


        double au = (double) ca * 1000;


        int au2 = (int) au;
        timerInactivity = new Timer(au2, new TimerListenerInac(playerInactivity.locator, nam));
        timerInactivity.start();

    }
}
