/*
  The MIT License
  
  Copyright (c) 2009 Krzysztof Langner
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in
  all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  THE SOFTWARE.
*/
package eu.ydp.empiria.player.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.ComplexPanel;
import com.google.gwt.user.client.ui.RootPanel;

import eu.ydp.empiria.player.client.controller.communication.DisplayOptions;
import eu.ydp.empiria.player.client.controller.communication.FlowOptions;
import eu.ydp.empiria.player.client.controller.delivery.DeliveryEngine;
import eu.ydp.empiria.player.client.util.file.xml.XmlData;
import eu.ydp.empiria.player.client.version.Version;
import eu.ydp.empiria.player.client.view.ViewEngine;
/**
 * Main class with player API
 * @author Krzysztof Langner
 */
public class Player {

  /** JavaScript object representing this java object */
  private JavaScriptObject	jsObject;
  
  /** Delivery engine do manage the assessment content */
  public DeliveryEngine deliveryEngine;
  
  /** View engine maintains the view tasks */
  private ViewEngine viewEngine;
  
  {
	 logVersion();
  }

	/**
	 * constructor
	 * @param id
	 */
	public Player(String id){
		this.jsObject = JavaScriptObject.createFunction();
		PlayerGinjector injector = GWT.create( PlayerGinjector.class );
		viewEngine = injector.getViewEngine();
		RootPanel root = RootPanel.get(id);
		viewEngine.mountView(root);
		deliveryEngine = injector.getDeliveryEngine();
		deliveryEngine.init(jsObject);
	}

	public Player(ComplexPanel container){
		this.jsObject = JavaScriptObject.createFunction();		
		PlayerGinjector injector = GWT.create( PlayerGinjector.class );
		viewEngine = injector.getViewEngine();
		viewEngine.mountView(container);
		deliveryEngine = injector.getDeliveryEngine();
		deliveryEngine.init(jsObject);
	}

	public void loadExtension(JavaScriptObject extension){
		deliveryEngine.loadExtension(extension);
	}

	public void loadExtension(String extension){
		deliveryEngine.loadExtension(extension);
	}
	
	public void load(String url){
		deliveryEngine.load(url);
	}

	public void load(XmlData assessmentData, XmlData[] itemsData){
		deliveryEngine.load(assessmentData, itemsData);
	}
  
	 /**
	 * @return js object representing this player
	 */
	public JavaScriptObject getJavaScriptObject(){
	  return jsObject;
  }

	public void setFlowOptions(FlowOptions o){
		deliveryEngine.setFlowOptions(o);
	}
	
	public void setDisplayOptions(DisplayOptions o){
		deliveryEngine.setDisplayOptions(o);
	}
	
	public String getEngineMode(){
  		return deliveryEngine.getEngineMode();
	}
	
	private void logVersion(){
		 String version = Version.getVersion();
		 String versionMessage = "EmpiriaPlayer ver. " + version;
		 log(versionMessage);
		 System.out.println(versionMessage);
	}
	
	private native void log(String message)/*-{
		if (typeof console == 'object')
			console.log(message);
	 }-*/;

}

@@ -14,19 +14,17 @@
 License%0A
-  
 %0A
+
   Copyri
@@ -54,19 +54,17 @@
 Langner%0A
-  
 %0A
+
   Permis
@@ -500,19 +500,17 @@
 itions:%0A
-  
 %0A
+
   The ab
@@ -632,19 +632,17 @@
 ftware.%0A
-  
 %0A
+
   THE SO
@@ -1154,47 +1154,8 @@
 t;%0A%0A
-import com.google.gwt.core.client.GWT;%0A
 impo
@@ -1847,16 +1847,22 @@
 private 
+final 
 JavaScri
@@ -1880,18 +1880,16 @@
 Object;%0A
-  
 %0A  /** D
@@ -1979,19 +1979,17 @@
 Engine;%0A
-  
 %0A
+
   /** Vi
@@ -2036,16 +2036,22 @@
 private 
+final 
 ViewEngi
@@ -2065,18 +2065,16 @@
 Engine;%0A
-  
 %0A  %7B%0A%09 l
@@ -2235,36 +2235,24 @@
 r injector =
- GWT.create(
  PlayerGinje
@@ -2248,39 +2248,40 @@
 PlayerGinjector.
-class )
+INSTANCE
 ;%0A%09%09viewEngine =
@@ -2553,18 +2553,16 @@
 ction();
-%09%09
 %0A%09%09Playe
@@ -2586,20 +2586,8 @@
 or =
- GWT.create(
  Pla
@@ -2603,15 +2603,16 @@
 tor.
-class )
+INSTANCE
 ;%0A%09%09
@@ -2962,26 +2962,25 @@
 ension);%0A%09%7D%0A
-%09
 %0A
+
 %09public void
@@ -3151,11 +3151,9 @@
 %0A%09%7D%0A
-  
 %0A
+
 %09 /*
@@ -3354,34 +3354,33 @@
 wOptions(o);%0A%09%7D%0A
-%09
 %0A
+
 %09public void set
@@ -3455,18 +3455,17 @@
 (o);%0A%09%7D%0A
-%09
 %0A
+
 %09public 
@@ -3530,26 +3530,25 @@
 eMode();%0A%09%7D%0A
-%09
 %0A
+
 %09private voi
@@ -3731,17 +3731,16 @@
 ge);%0A%09%7D%0A
-%09
 %0A%09privat

Remove duplicate of gin instance