<commit_before>/*
* Copyright (C) 2005-2009 University of Deusto
* All rights reserved.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution.
*
* This software consists of contributions made by many individuals, 
* listed below:
*
* Author: <NAME> <<EMAIL>>
*
*/

package es.deusto.weblab.client.experiments.visir;

import java.util.List;

import com.google.gwt.http.client.URL;

import es.deusto.weblab.client.comm.exceptions.CommException;
import es.deusto.weblab.client.configuration.IConfigurationRetriever;
import es.deusto.weblab.client.dto.experiments.ResponseCommand;
import es.deusto.weblab.client.lab.comm.callbacks.IResponseCommandCallback;
import es.deusto.weblab.client.lab.experiments.IBoardBaseController;
import es.deusto.weblab.client.lab.experiments.util.applets.AbstractExternalAppBasedBoard;
import es.deusto.weblab.client.lab.experiments.util.applets.flash.FlashExperiment;

public class VisirExperiment extends FlashExperiment {
	
	private boolean teacher = false;
	private String cookie = null;
	private String url = null;
	private String savedata = null;
	
	private List<String> circuitsAvailable;

	/**
	 * Constructs a Board for the Visir client. It does not actually generate the
	 * full HTML code until the experiment is started (and hence Start called), as
	 * it uses the WebLabFlashAppBasedBoard's deferred mode.
	 * 
	 * @param configurationRetriever
	 * @param boardController
	 */
	public VisirExperiment(IConfigurationRetriever configurationRetriever,
			IBoardBaseController boardController) {
		super(configurationRetriever, boardController, "", 800, 500,
				 "",
				 "Visir Flash Experiment", true);
	}
	
	@Override
	public void end() {
		super.end();
	}

	@Override
	public void initialize() {
		super.initialize();
	}

	@Override
	public void setTime(int time) {
		super.setTime(time);
	}
	


	@Override
	public void start(final int time, final String initialConfiguration) {
		
		// Request the visir session "cookie" to the server.
		final VisirSetupDataRequestCommand reqData = new VisirSetupDataRequestCommand();
		AbstractExternalAppBasedBoard.staticBoardController.sendCommand(reqData, 
				new IResponseCommandCallback() {

					@Override
					public void onSuccess(ResponseCommand responseCommand) {
						
						// Use the command's helper method to parse the JSON response
						boolean success = reqData.parseResponse(responseCommand.getCommandString());
						
						if(success) {
							VisirExperiment.this.cookie   = reqData.getCookie();
							VisirExperiment.this.savedata = reqData.getSaveData();
							VisirExperiment.this.url      = reqData.getURL();
							VisirExperiment.this.teacher  = reqData.isTeacher(); 
							
							VisirExperiment.this.circuitsAvailable = reqData.getCircuitsAvailable();
							
							VisirExperiment.this.updateFlashVars();
							VisirExperiment.this.setSwfFile(VisirExperiment.this.url);
							
							VisirExperiment.super.start(time, initialConfiguration);
						} else {
							System.out.println("Could not parse response: " + responseCommand.getCommandString());
						}
						
					}

					@Override
					public void onFailure(CommException e) {
						System.out.println("Error: Could not retrieve data");
						VisirExperiment.super.start(time, initialConfiguration);
					}
				}
		);
		
		//super.start();
		
	}
	
	
	@Override
	public void onFlashReady() {
		initOnLoadCircuit();
		modFrame();
	}
	
	private static native void initOnLoadCircuit() /*-{
		$wnd.callOnLoadCircuit = function(id) {
			this.@es.deusto.weblab.client.experiments.visir.VisirExperiment::onLoadCircuit(I)(id);
		};
	}-*/;
	
	private static native void modFrame() /*-{
		
		var doc = $wnd.wl_iframe.contentDocument;
		if (doc == undefined || doc == null)
	    	doc = $wnd.wl_iframe.contentWindow.document;
	    	
	 	//$doc.getElementById('div_extra').innerHTML = "<div align='left'><font color='red'>HELLO WORLD</font></div>";
	    	
	}-*/;
	

	
	private void onLoadCircuit(int id) {
		System.out.println("Should load circuit number: " + id);
	}<commit_msg>[visir]: Minor changes. JS connection still not working.<commit_after>/*
* Copyright (C) 2005-2009 University of Deusto
* All rights reserved.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution.
*
* This software consists of contributions made by many individuals, 
* listed below:
*
* Author: <NAME> <<EMAIL>>
*
*/

package es.deusto.weblab.client.experiments.visir;

import java.util.List;

import com.google.gwt.http.client.URL;

import es.deusto.weblab.client.comm.exceptions.CommException;
import es.deusto.weblab.client.configuration.IConfigurationRetriever;
import es.deusto.weblab.client.dto.experiments.ResponseCommand;
import es.deusto.weblab.client.lab.comm.callbacks.IResponseCommandCallback;
import es.deusto.weblab.client.lab.experiments.IBoardBaseController;
import es.deusto.weblab.client.lab.experiments.util.applets.AbstractExternalAppBasedBoard;
import es.deusto.weblab.client.lab.experiments.util.applets.flash.FlashExperiment;

public class VisirExperiment extends FlashExperiment {
	
	private boolean teacher = false;
	private String cookie = null;
	private String url = null;
	private String savedata = null;
	
	private List<String> circuitsAvailable;

	/**
	 * Constructs a Board for the Visir client. It does not actually generate the
	 * full HTML code until the experiment is started (and hence Start called), as
	 * it uses the WebLabFlashAppBasedBoard's deferred mode.
	 * 
	 * @param configurationRetriever
	 * @param boardController
	 */
	public VisirExperiment(IConfigurationRetriever configurationRetriever,
			IBoardBaseController boardController) {
		super(configurationRetriever, boardController, "", 800, 500,
				 "",
				 "Visir Flash Experiment", true);
	}
	
	@Override
	public void end() {
		super.end();
	}

	@Override
	public void initialize() {
		super.initialize();
	}

	@Override
	public void setTime(int time) {
		super.setTime(time);
	}
	


	@Override
	public void start(final int time, final String initialConfiguration) {
		
		// Request the visir session "cookie" to the server.
		final VisirSetupDataRequestCommand reqData = new VisirSetupDataRequestCommand();
		AbstractExternalAppBasedBoard.staticBoardController.sendCommand(reqData, 
				new IResponseCommandCallback() {

					@Override
					public void onSuccess(ResponseCommand responseCommand) {
						
						// Use the command's helper method to parse the JSON response
						boolean success = reqData.parseResponse(responseCommand.getCommandString());
						
						if(success) {
							VisirExperiment.this.cookie   = reqData.getCookie();
							VisirExperiment.this.savedata = reqData.getSaveData();
							VisirExperiment.this.url      = reqData.getURL();
							VisirExperiment.this.teacher  = reqData.isTeacher(); 
							
							VisirExperiment.this.circuitsAvailable = reqData.getCircuitsAvailable();
							
							VisirExperiment.this.updateFlashVars();
							VisirExperiment.this.setSwfFile(VisirExperiment.this.url);
							
							VisirExperiment.super.start(time, initialConfiguration);
						} else {
							System.out.println("Could not parse response: " + responseCommand.getCommandString());
						}
						
					}

					@Override
					public void onFailure(CommException e) {
						System.out.println("Error: Could not retrieve data");
						VisirExperiment.super.start(time, initialConfiguration);
					}
				}
		);
		
		//super.start();
		
	}
	
	
	@Override
	public void onFlashReady() {
		initJavascriptAPI();
		modifyFrame();
	}
	
	private static native void initJavascriptAPI() /*-{
		$wnd.callOnLoadCircuit = function(id) {
			this.@es.deusto.weblab.client.experiments.visir.VisirExperiment::onLoadCircuit(I)(id);
		};
		
		$wnd.callRefresh = function() {
			$entry(this.@es.deusto.weblab.client.experiments.visir.VisirExperiment::refresh()());
		};
		
		alert('API loaded');
	}-*/;
	
	private static native void modifyFrame() /*-{
		
		var doc = $wnd.wl_iframe.contentDocument;
		if (doc == undefined || doc == null)
	    	doc = $wnd.wl_iframe.contentWindow.document;
	    	
	 	$doc.getElementById('div_extra').innerHTML = 
	 	"<div align='left'><font color='red'>HELLO WORLD</font></div>" +
	 	"<div align='left'><a href=\"javascript:callRefresh();\">REFRESH</a></div>";
	    	
	}-*/;
	

	private void refresh() {
		System.out.println("Doing REFRESH");
		initJavascriptAPI();
	}
	
	private void onLoadCircuit(int id) {
		System.out.println("Should load circuit number: " + id);
	}
{'fraction_non_alphanumeric': 0.10965116279069767, 'fraction_numerical': 0.0032558139534883722, 'mean_word_length': 3.8538374717832955, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6037376', 'n_tokens_mistral': 3112, 'n_tokens_neox': 2552, 'n_words': 567}