







































Module('ca.carleton.gcrc.atlas.widgets.focus','$Revision: 3685 $',function(mod){

var modObservable=imprt('ca.carleton.gcrc.mvc.observable');
var modDisplayWidget=imprt('ca.carleton.gcrc.atlas.displayWidget');
var modDomUtil=imprt('ca.carleton.gcrc.dom.util');

var modDynamicText=imprt('ca.carleton.gcrc.atlas.dynamicText');









mod.FocusWidgetFactory=Class(modDisplayWidget.WidgetFactory,function(publ,priv,supr){




publ.__init__=function(
layerName_
){

supr.__init__.call(this);

this.layerName=layerName_;

this.dynamicText=null;

this.imageDir='./';
this.imageTopLeft='bubble.png';
this.imageTopCenter='bubble_h.png';
this.imageTopRight='bubble.png';
this.imageBottomLeft='bubble.png';
this.imageBottomCenter='bubble_h.png';
this.imageBottomRight='bubble.png';
this.imageCenterLeft='bubble_v.png';
this.imageCenterRight='bubble_v.png';
this.topMargin=25;
this.bottomMargin=45;
this.leftMargin=25;
this.rightMargin=45;
}





publ.Width=function()
{
return 0;
}





publ.Height=function()
{
return 0;
}













publ.Create=function(
svgParent_,
dataModel_,
x_,
y_,
width_,
height_,
topic_
)
{
var widget=new mod.FocusWidget(this,dataModel_,topic_);

return widget;
}






publ.GetStyle=function(
){
var style={};

style.imageTopLeft=this.imageDir+'/'+this.imageTopLeft;
style.imageTopCenter=this.imageDir+'/'+this.imageTopCenter;
style.imageTopRight=this.imageDir+'/'+this.imageTopRight;
style.imageBottomLeft=this.imageDir+'/'+this.imageBottomLeft;
style.imageBottomCenter=this.imageDir+'/'+this.imageBottomCenter;
style.imageBottomRight=this.imageDir+'/'+'bubble.png';
style.imageCenterLeft=this.imageDir+'/'+this.imageCenterLeft;
style.imageCenterRight=this.imageDir+'/'+this.imageCenterRight;
style.topMargin=this.topMargin;
style.bottomMargin=this.bottomMargin;
style.leftMargin=this.leftMargin;
style.rightMargin=this.rightMargin;

return style
}

});






mod.FocusWidget=Class(modObservable.Observer,function(publ,priv,supr){






publ.__init__=function(
factory_
,dataModel_
,topic_
){

supr.__init__.call(this);


this.factory=factory_;


this.dataModel=dataModel_;


this.topic=topic_;


this.dynamicText=this.factory.dynamicText;


this.style=this.factory.GetStyle();


this.active=true;


this.htmlParent=this.topic.htmlParent;
this.htmlDoc=this.htmlParent.ownerDocument;
this.htmlTopDiv=this.htmlDoc.createElement('div');
this.htmlParent.appendChild(this.htmlTopDiv);


this.htmlX=1*this.topic.htmlX;
this.htmlY=1*this.topic.htmlY;
this.htmlWidth=1*this.topic.htmlWidth;
this.htmlHeight=1*this.topic.htmlHeight;




this.featureInfos={};


this.currentPopUpWindow=null;


var layer=dataModel_.LayerFromName(factory_.layerName);
this.Observe(layer,'display_state',this.DisplayStateChanged,null);
}




publ.Remove=function(){
this.active=false;


this.Terminate();


this.ClosePopUp();

if(null!=this.htmlTopDiv){
this.htmlParent.removeChild(this.htmlTopDiv);
this.htmlTopDiv=null;
}
}





publ.DisplayStateChanged=function(mvcEvent){
var feature=mvcEvent.originator;


var featureInfo=this.FeatureInfo(feature);

if(feature.IsInFocus()){
featureInfo.inFocus=true;


if(false==featureInfo.scheduled&&null!=feature.mouseEvent){
featureInfo.scheduled=true;

var receiver=this;
setTimeout(function(){
if(true==featureInfo.scheduled){
receiver.PopUp(featureInfo,feature.mouseEvent);
}
},0);
}

}else{
featureInfo.inFocus=false;
featureInfo.scheduled=false;


this.ClosePopUp();
}
}




publ.PopUp=function(featureInfo,mouseEvent){
if(null!=this.currentPopUpWindow){

if(this.currentPopUpWindow.feature.id==featureInfo.feature.id){

return;
}


this.ClosePopUp();
}


if(false==this.active){
return;
}


this.currentPopUpWindow=new mod.PopUpWindow(featureInfo.feature,this,mouseEvent);
}




publ.ClosePopUp=function(){
if(null!=this.currentPopUpWindow){
modDomUtil.RemoveChildren(this.htmlTopDiv);

this.currentPopUpWindow=null;

this.dynamicText.Terminate();
}
}







publ.FeatureInfo=function(feature_){
var featureInfo=this.featureInfos[feature_.id];
if(null==featureInfo){
featureInfo={};
this.featureInfos[feature_.id]=featureInfo;

featureInfo.feature=feature_;

featureInfo.inFocus=false;
featureInfo.scheduled=false;
}

return featureInfo;
}
});





mod.PopUpWindow=Class(function(publ,priv){






publ.__init__=function(
feature_
,focusWidget_
,mouseEvent_
){

this.feature=feature_;


this.focusWidget=focusWidget_;


var centerX=this.focusWidget.htmlWidth/2;
var centerY=this.focusWidget.htmlHeight/2;


var mouseX=mouseEvent_.pageX-this.focusWidget.htmlX;
var mouseY=mouseEvent_.pageY-this.focusWidget.htmlY;




var hAlign;
if(mouseX>centerX){
hAlign='right:'+(this.focusWidget.htmlWidth-mouseX+10)+'px;';
}else{
hAlign='left:'+(mouseX+10)+'px;';
}


var vAlign;
if(mouseY>centerY){
vAlign='bottom:'+(this.focusWidget.htmlHeight-mouseY+10)+'px;';
}else{
vAlign='top:'+(mouseY+10)+'px;';
}

var outerDiv=this.focusWidget.htmlDoc.createElement('div');
outerDiv.setAttribute('style',
'position:absolute;'
+'visibility:hidden;'
+'top:'+this.focusWidget.htmlY+'px;'
+'left:'+this.focusWidget.htmlX+'px;'
+'width:'+this.focusWidget.htmlWidth+'px;'
+'height:'+this.focusWidget.htmlHeight+'px;'
);

var div=this.focusWidget.htmlDoc.createElement('div');
div.setAttribute('style',
'position:absolute;'
+'visibility:visible;'
+vAlign
+hAlign
+'z-index:1;'
);
outerDiv.appendChild(div);


var table=this.focusWidget.htmlDoc.createElement('table');
div.appendChild(table);
table.setAttribute('border',0);
table.setAttribute('cellspacing',0);
table.setAttribute('cellpadding',0);


var row1=this.focusWidget.htmlDoc.createElement('tr');
table.appendChild(row1);
var row2=this.focusWidget.htmlDoc.createElement('tr');
table.appendChild(row2);
var row3=this.focusWidget.htmlDoc.createElement('tr');
table.appendChild(row3);

var style=this.focusWidget.style;


var td=this.focusWidget.htmlDoc.createElement('td');
row1.appendChild(td);
td.setAttribute('style',
'width:'+style.leftMargin+'px;height:'+style.topMargin+'px;background-image:url("'+style.imageTopLeft+'");background-repeat:no-repeat;background-position:top left;');


td=this.focusWidget.htmlDoc.createElement('td');
row1.appendChild(td);
td.setAttribute('style',
'height:'+style.topMargin+'px;background-image:url("'+style.imageTopCenter+'");background-repeat:repeat-x;background-position:top left;');


td=this.focusWidget.htmlDoc.createElement('td');
row1.appendChild(td);
td.setAttribute('style',
'width:'+style.rightMargin+'px;height:'+style.topMargin+'px;background-image:url("'+style.imageTopRight+'");background-repeat:no-repeat;background-position:top right;');


td=this.focusWidget.htmlDoc.createElement('td');
row2.appendChild(td);
td.setAttribute('style',
'width:'+style.leftMargin+'px;background-image:url("'+style.imageCenterLeft+'");background-repeat:repeat-y;background-position:top left;');


contentTd=this.focusWidget.htmlDoc.createElement('td');
row2.appendChild(contentTd);


td=this.focusWidget.htmlDoc.createElement('td');
row2.appendChild(td);
td.setAttribute('style',
'width:'+style.rightMargin+'px;background-image:url("'+style.imageCenterRight+'");background-repeat:repeat-y;background-position:top right;');


td=this.focusWidget.htmlDoc.createElement('td');
row3.appendChild(td);
td.setAttribute('style',
'width:'+style.leftMargin+'px;height:'+style.bottomMargin+'px;background-image:url("'+style.imageBottomLeft+'");background-repeat:no-repeat;background-position:bottom left;');


td=this.focusWidget.htmlDoc.createElement('td');
row3.appendChild(td);
td.setAttribute('style',
'height:'+style.bottomMargin+'px;background-image:url("'+style.imageBottomCenter+'");background-repeat:repeat-x;background-position:bottom left;');


td=this.focusWidget.htmlDoc.createElement('td');
row3.appendChild(td);
td.setAttribute('style',
'width:'+style.rightMargin+'px;height:'+style.bottomMargin+'px;background-image:url("'+style.imageBottomRight+'");background-repeat:no-repeat;background-position:bottom right;');


var contentDiv=this.focusWidget.htmlDoc.createElement('div');
contentTd.appendChild(contentDiv);
contentDiv.setAttribute('style',
'max-width:500px;max-height:350px;overflow:hidden;background-color:#121212;color:#eaf7fb;');

this.focusWidget.dynamicText.RenderHTML(this.focusWidget.dataModel,contentDiv,this.feature);


this.focusWidget.htmlTopDiv.appendChild(outerDiv);
}
});
});