Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java @ 9696:e388db7fd72e
another attempt
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 20 Jan 2021 15:55:08 +0100 |
parents | 94b976204a0a |
children | 15404504ea9e |
rev | line source |
---|---|
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
2 * Software engineering by Intevation GmbH |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
3 * |
5993
ea9eef426962
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5861
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
5993
ea9eef426962
Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5861
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
5861
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
7 */ |
172338b1407f
GWT client: Added copyright header.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5838
diff
changeset
|
8 |
5835
821a02bbfb4e
Fixed internal java dependencies
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5834
diff
changeset
|
9 package org.dive4elements.river.client.client.ui.map; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import java.util.List; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
9619 | 13 import org.dive4elements.river.client.client.FLYSConstants; |
14 import org.dive4elements.river.client.shared.MapUtils; | |
15 import org.dive4elements.river.client.shared.model.AttributedTheme; | |
16 import org.dive4elements.river.client.shared.model.Theme; | |
17 import org.dive4elements.river.client.shared.model.ThemeList; | |
18 | |
7958
632c724fed2d
i18n for WMS legend window title.
Tom Gottfried <tom@intevation.de>
parents:
5993
diff
changeset
|
19 import com.google.gwt.core.client.GWT; |
9696 | 20 import com.google.gwt.event.dom.client.LoadHandler; |
9644 | 21 import com.google.gwt.http.client.URL; |
9619 | 22 import com.google.gwt.user.client.ui.Image; |
23 import com.google.gwt.user.client.ui.Widget; | |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 import com.smartgwt.client.types.ImageStyle; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 import com.smartgwt.client.types.VerticalAlignment; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 import com.smartgwt.client.widgets.Canvas; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 import com.smartgwt.client.widgets.Img; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 import com.smartgwt.client.widgets.Label; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 import com.smartgwt.client.widgets.Window; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 import com.smartgwt.client.widgets.layout.HLayout; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 import com.smartgwt.client.widgets.layout.VLayout; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 public class LegendWindow extends Window { |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
9696 | 35 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 |
9696 | 37 private ThemeList themeList; |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 |
9696 | 39 private final VLayout legendContainer; |
9694 | 40 |
9696 | 41 public LegendWindow(final ThemeList themeList) { |
42 this.themeList = themeList; | |
43 this.legendContainer = new VLayout(); | |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 |
9696 | 45 init(); |
46 } | |
47 | |
48 public void update(final ThemeList themeList) { | |
49 this.themeList = themeList; | |
50 | |
51 final Canvas[] legends = this.legendContainer.getMembers(); | |
52 this.legendContainer.removeMembers(legends); | |
53 | |
54 addLegends(); | |
55 } | |
56 | |
57 private void addLegends() { | |
58 final List<Theme> themes = this.themeList.getActiveThemes(); | |
59 com.smartgwt.client.util.SC.say("themescount " + themes.size()); | |
60 | |
61 for (int i = 0; i < themes.size(); i++) { | |
62 final Theme theme = themes.get(i); | |
63 if (theme.getActive() == 0) { | |
64 continue; | |
65 } | |
66 try { | |
67 if (theme instanceof AttributedTheme) { | |
68 Canvas createLegendGraphicsRow = createLegendGraphicsRow((AttributedTheme) theme); | |
69 this.legendContainer.addMember(createLegendGraphicsRow); | |
70 } | |
71 } catch (Exception e) { | |
72 com.smartgwt.client.util.SC.say("exception at index " + themes.size()); | |
73 continue; | |
74 } | |
75 } | |
76 } | |
77 | |
78 private Canvas createLegendGraphicsRow(final AttributedTheme at) { | |
79 com.smartgwt.client.util.SC.say("init"); | |
80 final Label label = new Label(at.getDescription()); | |
81 final Widget img = createLegendGraphics(at); | |
82 | |
83 final HLayout row = new HLayout(); | |
84 row.addMember(label); | |
85 row.addMember(img); | |
86 | |
87 String url = "url"; | |
88 | |
89 if (img instanceof Image) { | |
90 Image.prefetch(((Image) img).getUrl()); | |
91 setDimensions(row, ((Image) img).getHeight(), ((Image) img).getWidth()); | |
92 url = " url " + ((Image) img).getUrl(); | |
93 } else if (img instanceof Img) { | |
94 setDimensions(row, ((Img) img).getHeight(), ((Img) img).getWidth()); | |
95 url = " dataPath " + ((Img) img).getDataPath(); | |
96 } else { | |
97 setDimensions(row, 150, 400); // not sure when this is executed | |
98 } | |
99 String labelText = at.getDescription() + ", height: " + row.getHeight() + "width: " + row.getWidth() + " " | |
100 + url; | |
101 // | |
102 // final HLayout row2= new HLayout(); | |
103 // row.addMember(new Label(labelText)); | |
104 | |
105 com.smartgwt.client.util.SC.say(labelText); | |
106 return row; | |
107 } | |
108 | |
109 private void setDimensions(HLayout row, int height, int width) { | |
9693
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
110 final int minHeight = 30; |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
111 row.setHeight(height < minHeight ? minHeight : height); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
112 row.setWidth(width); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
113 } |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
114 |
9696 | 115 private Widget createLegendGraphics(final AttributedTheme at) { |
9619 | 116 |
9696 | 117 final String legend = at.getAttr("legend"); |
118 // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), | |
119 // ebenso FLYSResources.getTest(); | |
120 if (legend != null && !"".equals(legend)) { | |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 |
9696 | 122 final String imgUrl = URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend); |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
123 |
9696 | 124 final Image image = new Image(imgUrl); |
125 final int imageWidth = image.getWidth(); | |
126 final int imageHeight = image.getHeight(); | |
127 final double widthPercent = imageWidth / 400.; | |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
128 |
9696 | 129 // removing the limit of 150px height (legend can have an infinite height now, |
130 // as long as the width is less/eq 400px; if the width is >400, | |
131 // the legend will be scaled to 400px width; the ratio will be kept) | |
132 | |
133 // final double heightPercent = imageHeight / 150.; | |
134 if (widthPercent > 1)// || heightPercent > 1) { | |
135 image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px"); | |
136 | |
137 return image; | |
138 } | |
139 final String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), at.getAttr("layers")); | |
140 | |
141 final Img img = new Img(imgUrl); | |
142 img.setImageType(ImageStyle.CENTER); | |
143 img.setAutoFit(true); | |
144 | |
145 return img; | |
146 } | |
147 | |
148 private void init() { | |
149 this.legendContainer.setAutoHeight(); | |
150 this.legendContainer.setLayoutAlign(VerticalAlignment.TOP); | |
151 this.legendContainer.setAlign(VerticalAlignment.CENTER); | |
152 | |
153 setTitle(this.MSG.wms_legend()); | |
154 setAutoSize(true); | |
155 setCanDragResize(true); | |
156 setIsModal(false); | |
157 setShowModalMask(false); | |
158 setLayoutAlign(VerticalAlignment.TOP); | |
159 setAlign(VerticalAlignment.TOP); | |
160 | |
161 addItem(this.legendContainer); | |
162 addLegends(); | |
163 | |
164 centerInPage(); | |
165 } | |
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.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
166 } |