Mercurial > dive4elements > river
diff gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/MyWMSLoadHandler.java @ 9700:b2768f367dff
handler for wms theme legend
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 20 Jan 2021 19:06:57 +0100 |
parents | |
children |
line wrap: on
line diff
--- /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