##
## OpenRemote, the Home of the Digital Home. Copyright 2008-2012, OpenRemote Inc.
## 
## See the contributors.txt file in the distribution for a full listing of individual contributors.
## 
## This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General
## Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
## later version.
## 
## This program 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 Affero General Public License for more
## details.
## 
## You should have received a copy of the GNU Affero General Public License along with this program. If not, see
## <http://www.gnu.org/licenses/>.
##
##*****************************
##******@author Javen**********
##*****************************
<?xml version="1.0" encoding="UTF-8"?>
<openremote xmlns="http://www.openremote.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.openremote.org http://www.openremote.org/schemas/panel.xsd">
  ##-----------------------------------------------------------------panels---------------------------------------------------------------------------
  <panels>
  #foreach ($panel in $panels)
  	<panel id="${panel.getOid()}" name="${stringUtils.escapeXml($panel.getName())}">
  		##<-------tabbar---------->##
		#if($panel.getTabbar())
	  		#getTabbarXML($panel.getTabbar())
  		#end
  		##<-------tabbar---------->##
  		
  		##<-----include groups--->##
		#if($panel.getGroupRefs().size()>0)
			#foreach($groupnRef in $panel.getGroupRefs())
				<include type="group" ref="${groupnRef.getGroupId()}"/>
			#end
		#end
		##<-----include groups--->##
		
  	</panel>
  #end
  </panels> 
  ##-----------------------------------------------------------------screens---------------------------------------------------------------------------
  <screens>
  	#foreach($screen in $screens)
  		<screen id="${screen.getOid()}" name="${stringUtils.escapeXml($screen.getName())}"
  		#if($screen.isLandscape())
  		  landscape="true"
  		#end
  		#if($screen.getInverseScreenId()!=0)
  		  inverseScreenId="${screen.getInverseScreenId()}"
  		#end
  		>
  		##-----------------------------------------------------------------background---------------------------------------------------------------------------
  		#if($screen.getBackground().getImageSource().getSrc().length()!=0)
  			<background
	  			#if(!$screen.getBackground().isFillScreen())
	  				#if($screen.getBackground().isAbsolute())
	  					absolute="${screen.getBackground().getLeft()},${screen.getBackground().getTop()}">
	  				#else
	  					relative="${screen.getBackground().getRelatedType()}">
	  				#end
	  			#else
	  				fillScreen="true">
	  			#end
  				<image src="${screen.getBackground().getImageSource().getImageFileName()}"/>
  			</background>
  		#end
  		##--------------------------------------------------------------------grid---------------------------------------------------------------------------
  		#foreach($grid in $screen.getGrids())
  			<grid left="${grid.getLeft()}" top="${grid.getTop()}" width="${grid.getWidth()}" height="${grid.getHeight()}" rows="${grid.getRowCount()}" cols="${grid.getColumnCount()}">
  				#foreach($cell in $grid.getCells())
  					<cell x="${cell.getPosX()}" y="${cell.getPosY()}" rowspan="${cell.getRowspan()}" colspan="${cell.getColspan()}">
  						${cell.getUiComponent().getPanelXml()}
  					</cell>
  				#end
  			</grid>
  		#end
  		##-----------------------------------------------------------------absolute---------------------------------------------------------------------------
  		#foreach($absolute in $screen.getAbsolutes())
  			<absolute left="${absolute.getLeft()}" top="${absolute.getTop()}" width="${absolute.getWidth()}" height="${absolute.getHeight()}">
  				${absolute.getUiComponent().getPanelXml()}
  			</absolute>
  		#end
  		##-----------------------------------------------------------------gesture---------------------------------------------------------------------------
  		#foreach($gesture in $screen.getGestures())
  			${gesture.getPanelXml()}
  		#end
  		</screen>
  	#end
  </screens>
  ##-----------------------------------------------------------------groups---------------------------------------------------------------------------
  	<groups>
  		#foreach($group in $groups)
  			<group id="${group.getOid()}" name="${stringUtils.escapeXml($group.getName())}">
  				##<-------tabbar---------->##
				#if($group.getTabbar())
					#getTabbarXML($group.getTabbar())
		  		#end
  				##<-------tabbar---------->##
				
				##<-----include screens--->##
				#if($group.getScreenRefs().size()>0)
					#foreach($screenRef in $group.getScreenRefs())
					 ${screenRef.getScreen().getPanelXml()}
					#end
				#end
				##<-----include screens--->##
  			</group>
  		#end
  	</groups>
</openremote>
##----------------------------------------------------------------------------Methods-------------------------------------------------------------------------------------
#*
*	===================get the xml string for tabbar .===================
*#
#macro(getTabbarXML,$tabbar)
	<tabbar>
		#foreach($tabbarItem in $tabbar.getTabbarItems())
			<item name="$tabbarItem.getName()">
				#set($navigate = $tabbarItem.getNavigate())
				#getNavigateXML($navigate)
				#if($!{tabbarItem.getImage()})
					<image src="${tabbarItem.getImage().getImageFileName()}" #*state="$!{tabbarItem.getImage().getState()}"*#/>
				#end
			</item>
		#end
	</tabbar>
#end

#*
*	===================get the xml string for navigate .===================
*#
#macro(getNavigateXML,$navigate)
   #if($navigate.isSet())
   	<navigate 
   		#if($navigate.getToGroup()!=-1)
   			toGroup="${navigate.getToGroup()}"
   			#if($navigate.getToScreen()!=-1)
   				toScreen="${navigate.getToScreen()}"
   			#end
   		#else
   			to="${navigate.getToLogical().toString()}"
   		#end
   		/>
	#end
#end
##----------------------------------------------------------------------------Methods-------------------------------------------------------------------------------------