Mercurial > dive4elements > river
view gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java @ 9705:bfdf98529a66
cleanup
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Thu, 21 Jan 2021 15:05:24 +0100 |
parents | ca9ed55d6f51 |
children |
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde * Software engineering by Intevation GmbH * * This file is Free Software under the GNU AGPL (>=v3) * and comes with ABSOLUTELY NO WARRANTY! Check out the * documentation coming with Dive4Elements River for details. */ package org.dive4elements.river.client.client.ui.map; import java.util.List; import org.dive4elements.river.client.client.FLYSConstants; import org.dive4elements.river.client.shared.MapUtils; import org.dive4elements.river.client.shared.model.AttributedTheme; import org.dive4elements.river.client.shared.model.Theme; import org.dive4elements.river.client.shared.model.ThemeList; import com.google.gwt.core.client.GWT; import com.google.gwt.event.shared.HandlerRegistration; import com.google.gwt.http.client.URL; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Widget; import com.smartgwt.client.types.ImageStyle; import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.Window; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; public class LegendWindow extends Window { protected FLYSConstants MSG = GWT.create(FLYSConstants.class); private ThemeList themeList; private final VLayout legendContainer; public LegendWindow(final ThemeList themeList) { this.themeList = themeList; this.legendContainer = new VLayout(); init(); } public void update(final ThemeList themeList) { this.themeList = themeList; final Canvas[] legends = this.legendContainer.getMembers(); this.legendContainer.removeMembers(legends); addLegends(); } private void addLegends() { final List<Theme> themes = this.themeList.getActiveThemes(); for (int i = 0; i < themes.size(); i++) { final Theme theme = themes.get(i); if (theme.getActive() == 0) { continue; } try { if (theme instanceof AttributedTheme) { Canvas createLegendGraphicsRow = createLegendGraphicsRow((AttributedTheme) theme); this.legendContainer.addMember(createLegendGraphicsRow); } } catch (Exception e) { continue; } } } private Canvas createLegendGraphicsRow(final AttributedTheme at) { final Label label = new Label(at.getDescription()); final HLayout row = new HLayout(); final Widget img = createLegendGraphics(row, at); row.addMember(label); row.addMember(img); // setDimensions(row, 150, 400); return row; } 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 urlAttr = at.getAttr("url"); String layersAttr = at.getAttr("layers"); final String imgUrl = getUrl(legend, urlAttr, layersAttr); final Image image = new Image(imgUrl); 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); this.legendContainer.setAlign(VerticalAlignment.CENTER); setTitle(this.MSG.wms_legend()); setAutoSize(true); setCanDragResize(true); setIsModal(false); setShowModalMask(false); setLayoutAlign(VerticalAlignment.TOP); setAlign(VerticalAlignment.TOP); addItem(this.legendContainer); addLegends(); centerInPage(); } }