changeset 9705:bfdf98529a66

cleanup
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Thu, 21 Jan 2021 15:05:24 +0100
parents ca9ed55d6f51
children 299c1c61d8ef
files gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MyLoadHandler.java
diffstat 2 files changed, 16 insertions(+), 75 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java	Thu Jan 21 14:08:03 2021 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java	Thu Jan 21 15:05:24 2021 +0100
@@ -65,7 +65,7 @@
 			try {
 				if (theme instanceof AttributedTheme) {
 					Canvas createLegendGraphicsRow = createLegendGraphicsRow((AttributedTheme) theme);
-					 this.legendContainer.addMember(createLegendGraphicsRow);
+					this.legendContainer.addMember(createLegendGraphicsRow);
 				}
 			} catch (Exception e) {
 				continue;
@@ -76,67 +76,39 @@
 	private Canvas createLegendGraphicsRow(final AttributedTheme at) {
 		final Label label = new Label(at.getDescription());
 		final HLayout row = new HLayout();
-		final Widget img = createLegendGraphics(row ,at);
+		final Widget img = createLegendGraphics(row, at);
 
 		row.addMember(label);
 		row.addMember(img);
 
-//		String url = "url";
-		if (img instanceof Image) {
-//			url = " url " + ((Image) img).getUrl();
-//			new MyLoadHandler(row, ((Image) img));
-
-//		} else if (img instanceof Img) {
-//			setDimensions(row, ((Img) img).getHeight(), ((Img) img).getWidth());
-//			url = " dataPath " + ((Img) img).getDataPath();
-		} else {
-			setDimensions(row, 150, 400); // not sure when this is executed
-		}
-//		String labelText = at.getDescription() + ", height: " + row.getHeight() + "width: " + row.getWidth() + " "
-//				+ url;
-
-//		com.smartgwt.client.util.SC.say(labelText);
+		// setDimensions(row, 150, 400);
 		return row;
 	}
 
-	private void setDimensions(HLayout row, int height, int width) {
-		final int minHeight = 30;
-		row.setHeight(height < minHeight ? minHeight : height);
-		row.setWidth(width);
-	}
-
 	private Widget createLegendGraphics(HLayout row, final AttributedTheme at) {
 
 		final String legend = at.getAttr("legend");
 		// TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!),
 		// ebenso FLYSResources.getTest();
-		String attr = at.getAttr("url");
-		String attr2 = at.getAttr("layers");
-		
-		if (legend != null && !"".equals(legend)) {
-
-			final String imgUrl = URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend);
-
-			final Image image = new Image(imgUrl);
-			new MyWMSLoadHandler(row, image);
+		String urlAttr = at.getAttr("url");
+		String layersAttr = at.getAttr("layers");
 
-			return image;
-		}
-	
-		final String imgUrl = MapUtils.getLegendGraphicUrl(attr, attr2);
+		final String imgUrl = getUrl(legend, urlAttr, layersAttr);
+
 		final Image image = new Image(imgUrl);
-		
-//		com.smartgwt.client.util.SC.say(imgUrl);
-		new MyLoadHandler(row, ((Image) image));
-//		Image image = new Image(imgUrl);
-//		Widget widget = image.asWidget();
-//		final Img img = new Img(imgUrl);
-//		img.setImageType(ImageStyle.CENTER);
-//		img.setAutoFit(true);
+		new MyWMSLoadHandler(row, image);
 
 		return image;
 	}
 
+	private String getUrl(final String legend, String urlAttr, String layersAttr) {
+		if (legend != null && !"".equals(legend)) {
+			return URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend);
+		} else {
+			return MapUtils.getLegendGraphicUrl(urlAttr, layersAttr);
+		}
+	}
+
 	private void init() {
 		this.legendContainer.setAutoHeight();
 		this.legendContainer.setLayoutAlign(VerticalAlignment.TOP);
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MyLoadHandler.java	Thu Jan 21 14:08:03 2021 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-package org.dive4elements.river.client.client.ui.map;
-
-import com.google.gwt.event.dom.client.LoadEvent;
-import com.google.gwt.event.shared.HandlerRegistration;
-import com.google.gwt.user.client.ui.Image;
-import com.smartgwt.client.widgets.layout.HLayout;
-
-public class MyLoadHandler implements com.google.gwt.event.dom.client.LoadHandler {
-	private Image m_image;
-	private HLayout m_row;
-	private HandlerRegistration m_handelReg;
-
-	public MyLoadHandler(HLayout row, Image image) {
-		m_image = image;
-		m_row = row;
-		m_handelReg = image.addLoadHandler(this);
-	}
-
-	@Override
-	public void onLoad(LoadEvent event) {
-		setDimensions(m_row, m_image.getHeight(), m_image.getWidth());
-		if (m_handelReg != null)
-			m_handelReg.removeHandler();
-	}
-
-	private void setDimensions(HLayout row, int height, int width) {
-		final int minHeight = 30;
-		row.setHeight(height < minHeight ? minHeight : height);
-		row.setWidth(width);
-	}
-}
\ No newline at end of file

http://dive4elements.wald.intevation.org