/**********************************************************************
* Copyright (C) 2007 Kyoto University
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* 
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-
* 1301  USA
***********************************************************************/
/*
 * This file is the component controller file for translation log.
 */
var TranslationLogDisplay = Class.create();

TranslationLogDisplay.prototype = {
	initialize: function(id,fontSizeMenuId,loadButtonId,storeButtonId){
		this.id = id;
		this.element = $(this.id);
		this.fontSizeMenuElement = $(fontSizeMenuId);
		this.loadButtonElement = $(loadButtonId);
		this.storeButtonElement = $(storeButtonId);
		this.log = [];
		
		this.setEvent();
	},
	
	addLog: function(logObject){
		this.log.push(logObject);
	},
	
	clear: function(){
		this.element.innerHTML = '';
	},
	
	getFontSize: function(){
		if(this.fontSizeMenuElement.value == 'small') return 13;
		if(this.fontSizeMenuElement.value == 'medium') return 16;
		if(this.fontSizeMenuElement.value == 'large') return 20;
		return 16;
	},
	
	draw: function(){
		this.clear();
		for(var i=0;i<this.log.length;i++){
			var dl = document.createElement("dl");
			var dt = document.createElement("dt");
			dt.innerHTML = this.log[i].source;
			dl.appendChild(dt);
			
			for(var j=0;j<this.log[i].translationResults.length;j++){
				for(var k=0;k<this.log[i].translationResults[j].length;k++){
					var dd = document.createElement("dd");
					dd.innerHTML = this.log[i].translationResults[j][k].language+ ": "+this.log[i].translationResults[j][k].text;
					dl.appendChild(dd);
				}
			}
			
			this.element.appendChild(dl);
		}
		this.element.setStyle({fontSize:this.getFontSize()+'pt'});
		var count = 0;
		this.element.descendants().each(function(e){
			if(e.nodeName != 'dl') count++;
		});
		this.element.scrollTop = this.getFontSize()*count+'pt';
	},
	
	setEvent: function(){
		this.fontSizeMenuElement.observe('change',this.onChangeFontMenu.bindAsEventListener(0,this));
	},
	
	onChangeFontMenu: function(event){
		$A(arguments)[1].draw();
	}
}

