/*****************************************************************************
 *
 * File     : ResultPanel.js
 * 
 * Project  : WMS Viewer Client
 * 
 * Contents : 
 *
 * Author: Milan Trninic
 *
 * Copyright 1999-2005 Galdos Systems, Inc.
 * All rights reserved.
 * 
 ***|***************************|***********************|*******************|*/

/************************************************************************
*
*	Global declarations
*
*
*************************************************************************/

/************************************************************************
*
*	function:	ResultPanel
*
*	purpose:	Constructor
*
*************************************************************************/
function ResultPanel()
{
	// method assignments
	this.init = ResultPanel.init;
	this.setSize = ResultPanel.setSize;
	this.getSize = ResultPanel.getSize;
	this.enableMapControls = ResultPanel.enableMapControls;
	this.activateMapControl = ResultPanel.activateMapControl;
	this.getMapPanel = ResultPanel.getMapPanel;
	this.onMapViewResult = ResultPanel.onMapViewResult;
	this.getMapSize = ResultPanel.getMapSize;
	this.changePanel = ResultPanel.changePanel;
	this.setActivePanel = ResultPanel.setActivePanel;
	this.getResultType = ResultPanel.getResultType;
	this.showLayer = ResultPanel.showLayer;
	
	// instance field declarations
	this._uiElement;
	this._toolbar;
	this._mapPanel;
	this._gmlPanel;
	this._panelMap;
	this._visiblePanel;

	// initialization
	this.init();
}

/************************************************************************
*
*	function:	init
*
*	purpose:	initializes the globals
*
*************************************************************************/
function ResultPanel.init()
{
	this._uiElement = document.getElementById("resultPanel");
	this._mapPanel = new MapPanel();
	this._gmlPanel = new GmlPanel();

	var toolbarUI = document.getElementById("resultTabToolbar");
	this._toolbar = new Toolbar(toolbarUI);
	
	var mapButton = this._toolbar.getButton("mapTabButton");
	var gmlButton = this._toolbar.getButton("gmlTabButton");
	
	this._uiElement.setAttribute("dataTransfer", this);
	mapButton.attachEvent("onclick", ResultPanel.changePanelAdapter);
	gmlButton.attachEvent("onclick", ResultPanel.changePanelAdapter);

	mapButton.setSelectedImagePath("images/mapTabActive.gif");
	gmlButton.setSelectedImagePath("images/gmlTabActive.gif");
	
	mapButton.setSelected(true);
	gmlButton.setSelected(false);
	this._toolbar.setEnabled(true);
	
	this._panelMap = new Hashtable();
	
	this._panelMap.put(mapButton, this._mapPanel);
	this._panelMap.put(gmlButton, this._gmlPanel);
	
	this._mapPanel.setVisible(true);
	this._visiblePanel = this._mapPanel;
}
	
/************************************************************************
*
*	function:	setSize
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.setSize(width, height)
{
	this._uiElement.width = width;
	this._uiElement.height = height;
	this._mapPanel.setSize(width, height * 0.8);
	this._gmlPanel.setSize(width, height * 0.92);
	//this._toolbar.setSize(width, height * 0.2);
}

/************************************************************************
*
*	function:	getSize
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.getSize()
{
	var result = new Point(this._uiElement.width, this._uiElement.height);
	return result;
}

/************************************************************************
*
*	function:	enableMapControls
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.enableMapControls(enable)
{
	this._mapPanel.setToolbarEnabled(enable);
}

/************************************************************************
*
*	function:	activateMapControl
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.activateMapControl(control)
{
	this._mapPanel.activateControl(control);
}

/************************************************************************
*
*	function:	getMapPanel
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.getMapPanel()
{
	return this._mapPanel;
}

/************************************************************************
*
*	function:	onMapViewResult
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.onMapViewResult(boundingBox, mapSize)
{
	this._mapPanel.onResultReceived(boundingBox, mapSize);
}

/************************************************************************
*
*	function:	getMapSize
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.getMapSize()
{
	return this._mapPanel.getMapSize();
}

/************************************************************************
*
*	function:	changePanel
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.changePanel()
{
	this._visiblePanel.setVisible(false);
	
	var button = this._toolbar.getSelectedButton();
	var panel = this._panelMap.get(button);
	panel.setVisible(true);
	this._visiblePanel = panel;
}

/************************************************************************
*
*	function:	setActivePanel
*
*	purpose:	Set the current panel to either "map" or "gml"
*
*************************************************************************/
function ResultPanel.setActivePanel(panel) {
	if (panel == "map") {
		this._toolbar.getButton("mapTabButton").setSelected(true);
		if (this._visiblePanel != this._mapPanel) {
			this.changePanel();
		}
	}
	else if (panel == "gml") {
		this._toolbar.getButton("gmlTabButton").setSelected(true);
		if (this._visiblePanel != this._gmlPanel) {
			this.changePanel();
		}
	}
}

/************************************************************************
*
*	function:	getResultType
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.getResultType()
{
	return this._mapPanel.getResultType();
}

/************************************************************************
*
*	function:	showLayer
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.showLayer(layerName, show)
{
	return this._mapPanel.showLayer(layerName, show);
}

/************************************************************************
*
*	function:	Event handler adapters
*
*	purpose:	
*
*************************************************************************/
function ResultPanel.changePanelAdapter(event){target(event, ResultPanel).changePanel();}

