/**
 * Copyright (c) 2014-2017 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.eclipse.smarthome.ui.classic.internal.render;

import org.apache.commons.lang.StringUtils;
import org.eclipse.emf.common.util.EList;
import org.eclipse.smarthome.core.library.types.PointType;
import org.eclipse.smarthome.core.types.State;
import org.eclipse.smarthome.model.sitemap.Mapview;
import org.eclipse.smarthome.model.sitemap.Widget;
import org.eclipse.smarthome.ui.classic.render.RenderException;

/**
 * This is an implementation of the {@link WidgetRenderer} interface, which
 * can produce HTML code for Text widgets.
 * 
 * @author Gaël L'hopital - Initial contribution
 *
 */
public class MapviewRenderer extends AbstractWidgetRenderer {

	public boolean canRender(Widget w) {
		return w instanceof Mapview;
	}
	
	public EList<Widget> renderWidget(Widget w, StringBuilder sb) throws RenderException {
		Mapview mapview = (Mapview) w;
		String snippet = getSnippet("mapview");
		
		State state = itemUIRegistry.getState(mapview);
		if(state instanceof PointType) {
			PointType pointState = (PointType) state;
			double latitude = pointState.getLatitude().doubleValue();
			double longitude = pointState.getLongitude().doubleValue();
			snippet = StringUtils.replace(snippet, "%lat%", Double.toString(latitude));
			snippet = StringUtils.replace(snippet, "%lon%", Double.toString(longitude));
			snippet = StringUtils.replace(snippet, "%lonminus%", Double.toString(longitude-0.01));
			snippet = StringUtils.replace(snippet, "%lonplus%", Double.toString(longitude+0.01));
			snippet = StringUtils.replace(snippet, "%latminus%", Double.toString(latitude-0.01));
			snippet = StringUtils.replace(snippet, "%latplus%", Double.toString(latitude+0.01));
		}
		
		int height = mapview.getHeight();
		if(height==0) {
			height = 4;	// set default height to something viewable
		}
		height = height * 36;
		snippet = StringUtils.replace(snippet, "%height%", Integer.toString(height));
		
		sb.append(snippet);
		return null;
	}
}
@@ -859,10 +859,9 @@
 .%0A *
- 
 %0A
+
  * @
@@ -975,17 +975,34 @@
 erer %7B%0A%0A
-%09
+    @Override%0A    
 public b
@@ -1030,18 +1030,24 @@
 et w) %7B%0A
-%09%09
+        
 return w
@@ -1071,14 +1071,33 @@
 ew;%0A
-%09%7D%0A%09%0A%09
+    %7D%0A%0A    @Override%0A    
 publ
@@ -1179,18 +1179,24 @@
 ption %7B%0A
-%09%09
+        
 Mapview 
@@ -1218,18 +1218,24 @@
 iew) w;%0A
-%09%09
+        
 String s
@@ -1266,21 +1266,25 @@
 view%22);%0A
-%09%09%0A%09%09
+%0A        
 State st
@@ -1323,20 +1323,27 @@
 pview);%0A
-%09%09
+        
 if
+ 
 (state i
@@ -1365,19 +1365,28 @@
 Type) %7B%0A
-%09%09%09
+            
 PointTyp
@@ -1419,19 +1419,28 @@
  state;%0A
-%09%09%09
+            
 double l
@@ -1489,19 +1489,28 @@
 alue();%0A
-%09%09%09
+            
 double l
@@ -1561,19 +1561,28 @@
 alue();%0A
-%09%09%09
+            
 snippet 
@@ -1641,35 +1641,44 @@
 ing(latitude));%0A
-%09%09%09
+            
 snippet = String
@@ -1734,27 +1734,36 @@
 ongitude));%0A
-%09%09%09
+            
 snippet = St
@@ -1824,33 +1824,35 @@
 ng(longitude
--
+ - 
 0.01));%0A
 %09%09%09snippet =
@@ -1831,35 +1831,44 @@
 itude - 0.01));%0A
-%09%09%09
+            
 snippet = String
@@ -1928,25 +1928,27 @@
 ongitude
-+
+ + 
 0.01));%0A
 %09%09%09snipp
@@ -1931,35 +1931,44 @@
 itude + 0.01));%0A
-%09%09%09
+            
 snippet = String
@@ -2032,17 +2032,19 @@
 tude
--
+ - 
 0.01));%0A
 %09%09%09s
@@ -2039,19 +2039,28 @@
 0.01));%0A
-%09%09%09
+            
 snippet 
@@ -2131,17 +2131,19 @@
 tude
-+
+ + 
 0.01));%0A
 %09%09%7D%0A
@@ -2142,17 +2142,27 @@
 ));%0A
-%09%09%7D%0A%09%09%0A%09%09
+        %7D%0A%0A        
 int 
@@ -2195,29 +2195,47 @@
 ();%0A
-%09%09
+        
 if
+ 
 (height
+ 
 ==
+ 
 0) %7B%0A
-%09%09%09
+            
 heig
@@ -2241,17 +2241,17 @@
 ght = 4;
-%09
+ 
 // set d
@@ -2290,14 +2290,26 @@
 ble%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 heig
@@ -2326,18 +2326,24 @@
 t * 36;%0A
-%09%09
+        
 snippet 
@@ -2416,13 +2416,17 @@
 ));%0A
-%09%09%0A%09%09
+%0A        
 sb.a
@@ -2445,10 +2445,16 @@
 t);%0A
-%09%09
+        
 retu
@@ -2466,8 +2466,12 @@
 ll;%0A
-%09
+    
 %7D%0A%7D
+%0A

Apply ESH code formatter (#3992)