Mercurial > dive4elements > river
changeset 9696:e388db7fd72e
another attempt
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 20 Jan 2021 15:55:08 +0100 (2021-01-20) |
parents | 9e0ee81a9b7e |
children | 15404504ea9e |
files | gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java |
diffstat | 1 files changed, 119 insertions(+), 116 deletions(-) [+] |
line wrap: on
line diff
--- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java Wed Jan 20 11:35:59 2021 +0100 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java Wed Jan 20 15:55:08 2021 +0100 @@ -17,6 +17,7 @@ import org.dive4elements.river.client.shared.model.ThemeList; import com.google.gwt.core.client.GWT; +import com.google.gwt.event.dom.client.LoadHandler; import com.google.gwt.http.client.URL; import com.google.gwt.user.client.ui.Image; import com.google.gwt.user.client.ui.Widget; @@ -31,133 +32,135 @@ 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(); - } + protected FLYSConstants MSG = GWT.create(FLYSConstants.class); - private void addLegends() { - final List<Theme> themes = this.themeList.getActiveThemes(); - com.smartgwt.client.util.SC.say("themescount " + themes.size()); - - - for (int i = 0; i< themes.size() ; i++) { - final Theme theme = themes.get(i); - if (theme.getActive() == 0) { - continue; - } - try { - if (theme instanceof AttributedTheme) { - this.legendContainer.addMember(createLegendGraphicsRow((AttributedTheme) theme)); - } } catch (Exception e) { - com.smartgwt.client.util.SC.say("exception at index " + themes.size()); - continue; - } - } - } - - private Canvas createLegendGraphicsRow(final AttributedTheme at) { - com.smartgwt.client.util.SC.say("init"); - final Label label = new Label(at.getDescription()); - final Widget img = createLegendGraphics(at); + private ThemeList themeList; - final HLayout row = new HLayout(); - row.addMember(label); - row.addMember(img); - - String url = "url"; - - if (img instanceof Image) { - setDimensions( row, ((Image) img).getHeight(), ((Image) img).getWidth()); - url = " url " + ((Image) img).getUrl(); - } - 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; - // -// final HLayout row2= new HLayout(); -// row.addMember(new Label(labelText)); + private final VLayout legendContainer; - com.smartgwt.client.util.SC.say(labelText); - return row; - } + public LegendWindow(final ThemeList themeList) { + this.themeList = themeList; + this.legendContainer = new VLayout(); - private void setDimensions(HLayout row, int height, int width ) { + 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(); + com.smartgwt.client.util.SC.say("themescount " + themes.size()); + + 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) { + com.smartgwt.client.util.SC.say("exception at index " + themes.size()); + continue; + } + } + } + + private Canvas createLegendGraphicsRow(final AttributedTheme at) { + com.smartgwt.client.util.SC.say("init"); + final Label label = new Label(at.getDescription()); + final Widget img = createLegendGraphics(at); + + final HLayout row = new HLayout(); + row.addMember(label); + row.addMember(img); + + String url = "url"; + + if (img instanceof Image) { + Image.prefetch(((Image) img).getUrl()); + setDimensions(row, ((Image) img).getHeight(), ((Image) img).getWidth()); + url = " url " + ((Image) img).getUrl(); + } 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; + // + // final HLayout row2= new HLayout(); + // row.addMember(new Label(labelText)); + + com.smartgwt.client.util.SC.say(labelText); + 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(final AttributedTheme at) { - - final String legend = at.getAttr("legend"); - // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), ebenso FLYSResources.getTest(); - if (legend != null && !"".equals(legend)) { - - 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"); - - return image; - } - final String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), at.getAttr("layers")); + private Widget createLegendGraphics(final AttributedTheme at) { - final Img img = new Img(imgUrl); - img.setImageType(ImageStyle.CENTER); - img.setAutoFit(true); - - return img; - } - - private void init() { - this.legendContainer.setAutoHeight(); - this.legendContainer.setLayoutAlign(VerticalAlignment.TOP); - this.legendContainer.setAlign(VerticalAlignment.CENTER); + final String legend = at.getAttr("legend"); + // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), + // ebenso FLYSResources.getTest(); + if (legend != null && !"".equals(legend)) { - setTitle(this.MSG.wms_legend()); - setAutoSize(true); - setCanDragResize(true); - setIsModal(false); - setShowModalMask(false); - setLayoutAlign(VerticalAlignment.TOP); - setAlign(VerticalAlignment.TOP); + final String imgUrl = URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend); - addItem(this.legendContainer); - addLegends(); + final Image image = new Image(imgUrl); + final int imageWidth = image.getWidth(); + final int imageHeight = image.getHeight(); + final double widthPercent = imageWidth / 400.; - centerInPage(); - } + // 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"); + + return image; + } + final String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), at.getAttr("layers")); + + final Img img = new Img(imgUrl); + img.setImageType(ImageStyle.CENTER); + img.setAutoFit(true); + + return img; + } + + 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(); + } }