changeset 9700:b2768f367dff

handler for wms theme legend
author dnt_bjoernsen <d.tironi@bjoernsen.de>
date Wed, 20 Jan 2021 19:06:57 +0100
parents 94362af5928e
children 0caaca0df028
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/MyWMSLoadHandler.java
diffstat 2 files changed, 48 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java	Wed Jan 20 18:30:26 2021 +0100
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java	Wed Jan 20 19:06:57 2021 +0100
@@ -75,9 +75,9 @@
 
 	private Canvas createLegendGraphicsRow(final AttributedTheme at) {
 		final Label label = new Label(at.getDescription());
-		final Widget img = createLegendGraphics(at);
+		final HLayout row = new HLayout();
+		final Widget img = createLegendGraphics(row ,at);
 
-		final HLayout row = new HLayout();
 		row.addMember(label);
 		row.addMember(img);
 
@@ -105,7 +105,7 @@
 		row.setWidth(width);
 	}
 
-	private Widget createLegendGraphics(final AttributedTheme at) {
+	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!),
@@ -115,17 +115,7 @@
 			final String imgUrl = URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend);
 
 			final Image image = new Image(imgUrl);
-			final int imageWidth = image.getWidth();
-			final int imageHeight = image.getHeight();
-			final double widthPercent = imageWidth / 400.;
-
-			// removing the limit of 150px height (legend can have an infinite height now,
-			// as long as the width is less/eq 400px; if the width is >400,
-			// the legend will be scaled to 400px width; the ratio will be kept)
-
-			// final double heightPercent = imageHeight / 150.;
-			if (widthPercent > 1)// || heightPercent > 1) {
-				image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px");
+			new MyWMSLoadHandler(row, image);
 
 			return image;
 		}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MyWMSLoadHandler.java	Wed Jan 20 19:06:57 2021 +0100
@@ -0,0 +1,44 @@
+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 MyWMSLoadHandler implements com.google.gwt.event.dom.client.LoadHandler {
+	private Image m_image;
+	private HLayout m_row;
+	private HandlerRegistration m_handelReg;
+
+	public MyWMSLoadHandler(HLayout row, Image image) {
+		m_image = image;
+		m_row = row;
+		m_handelReg = image.addLoadHandler(this);
+	}
+
+	@Override
+	public void onLoad(LoadEvent event) {
+		setDimensions( );
+		if (m_handelReg != null)
+			m_handelReg.removeHandler();
+	}
+
+	private void setDimensions() {
+		final int imageWidth = m_image.getWidth();
+		final int imageHeight = m_image.getHeight();
+		final double widthPercent = imageWidth / 400.;
+
+		// removing the limit of 150px height (legend can have an infinite height now,
+		// as long as the width is less/eq 400px; if the width is >400,
+		// the legend will be scaled to 400px width; the ratio will be kept)
+
+		// final double heightPercent = imageHeight / 150.;
+		if (widthPercent > 1)// || heightPercent > 1) {
+			m_image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px");
+		
+		
+		final int minHeight = 30;
+		m_row.setHeight( m_image.getHeight() < minHeight ? minHeight :  m_image.getHeight());
+		m_row.setWidth( m_image.getWidth());
+	}
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org