// Copyright 2008 ProjectWizards GmbH. All rights reserved.

//console.log("Style.js");

var  Style = Base.extend({
	constructor: function(dictionary, environment)
	{
		if(dictionary)
			for (var property in dictionary) 
				this[property] = dictionary[property];	
		if(this.contentType == "FlagStatus")
			this.contentFormatter = new FlagStatusFormatter(environment);
		else if(this.contentType == "Date")
			this.contentFormatter = new DateFormatter(environment.format.dateAndTimeFormat.date, environment.format.dateAndTimeFormat.time, true, environment);
		else if(this.contentType == "Percent")
			this.contentFormatter = new PercentFormatter();
		else if(this.contentType == "Currency")
			this.contentFormatter = new CurrencyFormatter(environment);
		else if(this.contentType == "Boolean")
			this.contentFormatter = new BooleanFormatter(environment);
		else if(this.contentType == "Duration")
			this.contentFormatter = new DurationFormatter(environment);
		else if(this.contentType == "Utilisation")
			this.contentFormatter = new UtilisationFormatter(environment);
		else
			this.contentFormatter = new Formatter();
	},
	
	log: function()
	{
		
		console.log("----------------------------------------------------");
		console.log("fontFamily           : "+this.fontFamily);
		console.log("fontSize             : "+this.fontSize);
		console.log("fontWeight           : "+this.fontWeight);
		console.log("fontStyle            : "+this.fontStyle);
		console.log("fontStretch          : "+this.fontStretch);
		console.log("contentKey           : "+this.contentKey);
		console.log("contentKeyTitle      : "+this.contentKeyTitle);
		console.log("contentValueWithTimes: "+this.contentValueWithTimes);
		console.log("color                : "+this.color);
		console.log("backgroundColor      : "+this.backgroundColor);
		console.log("borderStyle          : "+this.borderStyle);
		console.log("hasShadow            : "+this.hasShadow);
		console.log("hasGradient          : "+this.hasGradient);
		console.log("height               : "+this.height);

		
	}, 
	
	mergeWithStyle: function(style)
	{
		if(style.fontFamily)
			this.fontFamily = style.fontFamily;
		if(style.fontSize)
			this.fontSize = style.fontSize;
		if(style.fontWeight)
			this.fontWeight = style.fontWeight;
		if(style.fontStyle)
			this.fontStyle = style.fontStyle;
		if(style.fontStretch)
			this.fontStretch = style.fontStretch;
		if(style.contentKey){
			if(style.contentKey == "-"){
				this.contentKey = null;
				this.contentType = null;
				this.contentFormatter = null;
			}else{
				this.contentKey = style.contentKey;
				this.contentType = style.contentType;
				this.contentFormatter = style.contentFormatter;
			}
		}
		if(style.contentKeyTitle)
		{
			if(style.contentKeyTitle == "-")
				this.contentKeyTitle = null;
			else
				this.contentKeyTitle = style.contentKeyTitle;
		}
		if(style.contentValueWithTimes)
			this.contentValueWithTimes = style.contentValueWithTimes;
		if(style.color)
			this.color = style.color;
		if(style.backgroundColor)
			this.backgroundColor = style.backgroundColor;
		if(style.borderStyle)
			this.borderStyle = style.borderStyle;
		if(style.hasShadow)
			this.hasShadow = style.hasShadow;
		if(style.hasGradient)
			this.hasGradient = style.hasGradient;
		if(style.height)
			this.height = style.height;
	}
});

var  StyleList = Base.extend({
	constructor: function(dictionary, environment)
	{
		this.cachedStyles = [];
		this.targets = [];
		for (var target in dictionary){
			var flatStyles = dictionary[target];
			var styles = {};
			for (var condition in flatStyles){
				styles[condition] = new Style(flatStyles[condition], environment);			
			}
			this.targets[target] = styles;
		}
	},
	
	flattenedStyleForTarget: function(target, conditionMask)
	{
		var key = conditionMask + 1234*target;
		var result = this.cachedStyles[key];				
		if(!result){
			result = new Style();
			for(var condition=0; condition<=29; condition++){
				if((conditionMask & (1<<condition))>0){
					var style = this.targets[target][condition];
					if(style)
						result.mergeWithStyle(style);
				}
			}
			this.cachedStyles[key] = result;
		}
		return result;
	}
}, 
// Klassenmethoden:
{
	activityViewStyleTargets: {
		MEStyleTargetRow: 0,
		MEStyleTargetOutline: 1,
		MEStyleTargetBar: 2,
		MEStyleTargetLabelLeft: 3,
		MEStyleTargetLabelMiddle: 4,
		MEStyleTargetLabelRight: 5
	},
	
	styleConditions: {
		MEActivityStyleConditionGeneral: 0,
		MEActivityStyleConditionGreenFlag: 1,
		MEActivityStyleConditionYellowFlag: 2,
		MEActivityStyleConditionRedFlag: 3,
		MEActivityStyleConditionLevel1: 4,
		MEActivityStyleConditionLevel2: 5,
		MEActivityStyleConditionLevel3: 6,
		MEActivityStyleConditionLevel4: 7,
		MEActivityStyleConditionLevel5: 8,
		MEActivityStyleConditionLevel6: 9,
		MEActivityStyleConditionLevel7: 10,
		MEActivityStyleConditionLevel8: 11,
		MEActivityStyleConditionActivity: 12,
		MEActivityStyleConditionActivityWithAssignments: 13,
		MEActivityStyleConditionGroup: 14,
		MEActivityStyleConditionProject: 15,
		MEActivityStyleConditionAssignment: 16,
		MEActivityStyleConditionMilestone: 17,
		MEActivityStyleConditionVeryLowPriority: 18,
		MEActivityStyleConditionLowPriority: 19,
		MEActivityStyleConditionNormalPriority: 20,
		MEActivityStyleConditionHighPriority: 21,
		MEActivityStyleConditionVeryHighPriority: 22,
		MEActivityStyleConditionCritical: 23,
		MEActivityStyleConditionWarning: 24,
		MEActivityStyleConditionConflict: 25,
		MEActivityStyleConditionCollapsed: 26,
		MEActivityStyleConditionExpanded: 27,
		MEActivityStyleConditionFiltered: 28,
		MEActivityStyleConditionChanged: 29
	}
});
