Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/client/ui/map/LegendWindow.java @ 4329:c9dcce9448f2
Added a new control 'show legend' to the map's toolbar. This control opens a window that displays the legends of all activated layers.
Currently, the row in that window has a fixed size of 400x150. The size is fixed, because there are problems with SmartGWT to build
panels with auto height/width :-/
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 30 Oct 2012 12:16:26 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/map/LegendWindow.java Tue Oct 30 12:16:26 2012 +0100 @@ -0,0 +1,100 @@ +package de.intevation.flys.client.client.ui.map; + +import java.util.List; + +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; + +import de.intevation.flys.client.shared.MapUtils; +import de.intevation.flys.client.shared.model.AttributedTheme; +import de.intevation.flys.client.shared.model.Theme; +import de.intevation.flys.client.shared.model.ThemeList; + + +public class LegendWindow extends Window { + + private ThemeList themeList; + + private VLayout legendContainer; + + public LegendWindow(ThemeList themeList) { + this.themeList = themeList; + this.legendContainer = new VLayout(); + + init(); + } + + public void update(ThemeList themeList) { + this.themeList = themeList; + + Canvas[] legends = legendContainer.getMembers(); + legendContainer.removeMembers(legends); + + addLegends(); + } + + private void addLegends() { + List<Theme> themes = themeList.getActiveThemes(); + + for (Theme theme : themes) { + if (theme.getActive() == 0) { + continue; + } + + if (theme instanceof AttributedTheme) { + legendContainer + .addMember(createLegendGraphicsRow((AttributedTheme) theme)); + } + } + } + + private Canvas createLegendGraphicsRow(AttributedTheme at) { + Label label = new Label(at.getDescription()); + Img img = createLegendGraphics(at); + + HLayout row = new HLayout(); + row.addMember(label); + row.addMember(img); + + row.setHeight(150); + row.setWidth(400); + + return row; + } + + private Img createLegendGraphics(AttributedTheme at) { + String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), + at.getAttr("layers")); + + Img img = new Img(imgUrl); + img.setImageType(ImageStyle.CENTER); + img.setAutoFit(true); + + return img; + } + + private void init() { + legendContainer.setAutoHeight(); + legendContainer.setLayoutAlign(VerticalAlignment.TOP); + legendContainer.setAlign(VerticalAlignment.CENTER); + + setTitle("WMS Legend"); + setAutoSize(true); + setCanDragResize(true); + setIsModal(false); + setShowModalMask(false); + setLayoutAlign(VerticalAlignment.TOP); + setAlign(VerticalAlignment.TOP); + + addItem(legendContainer); + addLegends(); + + centerInPage(); + } +}