Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java @ 9697:15404504ea9e
yet another attempt
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 20 Jan 2021 16:17:32 +0100 |
parents | e388db7fd72e |
children | 812a6a3eaaf5 |
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) { | |
9697 | 68 theme.setActive(0); |
9696 | 69 Canvas createLegendGraphicsRow = createLegendGraphicsRow((AttributedTheme) theme); |
9697 | 70 // this.legendContainer.addMember(createLegendGraphicsRow); |
71 theme.setActive(1); | |
72 Canvas createLegendGraphicsRow2 = createLegendGraphicsRow((AttributedTheme) theme); | |
73 this.legendContainer.addMember(createLegendGraphicsRow2); | |
9696 | 74 } |
75 } catch (Exception e) { | |
76 com.smartgwt.client.util.SC.say("exception at index " + themes.size()); | |
77 continue; | |
78 } | |
79 } | |
80 } | |
81 | |
82 private Canvas createLegendGraphicsRow(final AttributedTheme at) { | |
83 com.smartgwt.client.util.SC.say("init"); | |
84 final Label label = new Label(at.getDescription()); | |
85 final Widget img = createLegendGraphics(at); | |
86 | |
87 final HLayout row = new HLayout(); | |
88 row.addMember(label); | |
89 row.addMember(img); | |
90 | |
91 String url = "url"; | |
92 | |
93 if (img instanceof Image) { | |
94 Image.prefetch(((Image) img).getUrl()); | |
95 setDimensions(row, ((Image) img).getHeight(), ((Image) img).getWidth()); | |
96 url = " url " + ((Image) img).getUrl(); | |
97 } else if (img instanceof Img) { | |
98 setDimensions(row, ((Img) img).getHeight(), ((Img) img).getWidth()); | |
99 url = " dataPath " + ((Img) img).getDataPath(); | |
100 } else { | |
101 setDimensions(row, 150, 400); // not sure when this is executed | |
102 } | |
103 String labelText = at.getDescription() + ", height: " + row.getHeight() + "width: " + row.getWidth() + " " | |
104 + url; | |
105 // | |
106 // final HLayout row2= new HLayout(); | |
107 // row.addMember(new Label(labelText)); | |
108 | |
109 com.smartgwt.client.util.SC.say(labelText); | |
110 return row; | |
111 } | |
112 | |
113 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
|
114 final int minHeight = 30; |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
115 row.setHeight(height < minHeight ? minHeight : height); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
116 row.setWidth(width); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
117 } |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
118 |
9696 | 119 private Widget createLegendGraphics(final AttributedTheme at) { |
9619 | 120 |
9696 | 121 final String legend = at.getAttr("legend"); |
122 // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), | |
123 // ebenso FLYSResources.getTest(); | |
124 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
|
125 |
9696 | 126 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
|
127 |
9696 | 128 final Image image = new Image(imgUrl); |
129 final int imageWidth = image.getWidth(); | |
130 final int imageHeight = image.getHeight(); | |
131 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
|
132 |
9696 | 133 // removing the limit of 150px height (legend can have an infinite height now, |
134 // as long as the width is less/eq 400px; if the width is >400, | |
135 // the legend will be scaled to 400px width; the ratio will be kept) | |
136 | |
137 // final double heightPercent = imageHeight / 150.; | |
138 if (widthPercent > 1)// || heightPercent > 1) { | |
139 image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px"); | |
140 | |
141 return image; | |
142 } | |
143 final String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), at.getAttr("layers")); | |
144 | |
145 final Img img = new Img(imgUrl); | |
146 img.setImageType(ImageStyle.CENTER); | |
147 img.setAutoFit(true); | |
148 | |
149 return img; | |
150 } | |
151 | |
152 private void init() { | |
153 this.legendContainer.setAutoHeight(); | |
154 this.legendContainer.setLayoutAlign(VerticalAlignment.TOP); | |
155 this.legendContainer.setAlign(VerticalAlignment.CENTER); | |
156 | |
157 setTitle(this.MSG.wms_legend()); | |
158 setAutoSize(true); | |
159 setCanDragResize(true); | |
160 setIsModal(false); | |
161 setShowModalMask(false); | |
162 setLayoutAlign(VerticalAlignment.TOP); | |
163 setAlign(VerticalAlignment.TOP); | |
164 | |
165 addItem(this.legendContainer); | |
166 addLegends(); | |
167 | |
168 centerInPage(); | |
169 } | |
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
|
170 } |