Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java @ 9704:ca9ed55d6f51
debug
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Thu, 21 Jan 2021 14:08:03 +0100 |
parents | 0c8374059484 |
children | bfdf98529a66 |
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; |
9698 | 20 import com.google.gwt.event.shared.HandlerRegistration; |
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 | |
60 for (int i = 0; i < themes.size(); i++) { | |
61 final Theme theme = themes.get(i); | |
62 if (theme.getActive() == 0) { | |
63 continue; | |
64 } | |
65 try { | |
66 if (theme instanceof AttributedTheme) { | |
67 Canvas createLegendGraphicsRow = createLegendGraphicsRow((AttributedTheme) theme); | |
9699 | 68 this.legendContainer.addMember(createLegendGraphicsRow); |
9696 | 69 } |
70 } catch (Exception e) { | |
71 continue; | |
72 } | |
73 } | |
74 } | |
75 | |
76 private Canvas createLegendGraphicsRow(final AttributedTheme at) { | |
77 final Label label = new Label(at.getDescription()); | |
9700
b2768f367dff
handler for wms theme legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9699
diff
changeset
|
78 final HLayout row = new HLayout(); |
b2768f367dff
handler for wms theme legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9699
diff
changeset
|
79 final Widget img = createLegendGraphics(row ,at); |
9696 | 80 |
81 row.addMember(label); | |
82 row.addMember(img); | |
83 | |
9699 | 84 // String url = "url"; |
9696 | 85 if (img instanceof Image) { |
9699 | 86 // url = " url " + ((Image) img).getUrl(); |
9702
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
87 // new MyLoadHandler(row, ((Image) img)); |
9699 | 88 |
9701
0caaca0df028
another try for river axis legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9700
diff
changeset
|
89 // } else if (img instanceof Img) { |
0caaca0df028
another try for river axis legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9700
diff
changeset
|
90 // setDimensions(row, ((Img) img).getHeight(), ((Img) img).getWidth()); |
9699 | 91 // url = " dataPath " + ((Img) img).getDataPath(); |
9696 | 92 } else { |
93 setDimensions(row, 150, 400); // not sure when this is executed | |
94 } | |
9699 | 95 // String labelText = at.getDescription() + ", height: " + row.getHeight() + "width: " + row.getWidth() + " " |
96 // + url; | |
9696 | 97 |
9699 | 98 // com.smartgwt.client.util.SC.say(labelText); |
9696 | 99 return row; |
100 } | |
101 | |
102 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
|
103 final int minHeight = 30; |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
104 row.setHeight(height < minHeight ? minHeight : height); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
105 row.setWidth(width); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
106 } |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
107 |
9700
b2768f367dff
handler for wms theme legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9699
diff
changeset
|
108 private Widget createLegendGraphics(HLayout row, final AttributedTheme at) { |
9619 | 109 |
9696 | 110 final String legend = at.getAttr("legend"); |
111 // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), | |
112 // ebenso FLYSResources.getTest(); | |
9703 | 113 String attr = at.getAttr("url"); |
114 String attr2 = at.getAttr("layers"); | |
115 | |
9702
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
116 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
|
117 |
9696 | 118 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
|
119 |
9696 | 120 final Image image = new Image(imgUrl); |
9700
b2768f367dff
handler for wms theme legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9699
diff
changeset
|
121 new MyWMSLoadHandler(row, image); |
9696 | 122 |
123 return image; | |
9702
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
124 } |
9703 | 125 |
126 final String imgUrl = MapUtils.getLegendGraphicUrl(attr, attr2); | |
9702
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
127 final Image image = new Image(imgUrl); |
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
128 |
9704 | 129 // com.smartgwt.client.util.SC.say(imgUrl); |
9702
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
130 new MyLoadHandler(row, ((Image) image)); |
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
131 // Image image = new Image(imgUrl); |
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
132 // Widget widget = image.asWidget(); |
9701
0caaca0df028
another try for river axis legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9700
diff
changeset
|
133 // final Img img = new Img(imgUrl); |
0caaca0df028
another try for river axis legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9700
diff
changeset
|
134 // img.setImageType(ImageStyle.CENTER); |
0caaca0df028
another try for river axis legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9700
diff
changeset
|
135 // img.setAutoFit(true); |
9696 | 136 |
9702
20456a3c92e2
Img -> Image; correct URL for WMS Legend
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9701
diff
changeset
|
137 return image; |
9696 | 138 } |
139 | |
140 private void init() { | |
141 this.legendContainer.setAutoHeight(); | |
142 this.legendContainer.setLayoutAlign(VerticalAlignment.TOP); | |
143 this.legendContainer.setAlign(VerticalAlignment.CENTER); | |
144 | |
145 setTitle(this.MSG.wms_legend()); | |
146 setAutoSize(true); | |
147 setCanDragResize(true); | |
148 setIsModal(false); | |
149 setShowModalMask(false); | |
150 setLayoutAlign(VerticalAlignment.TOP); | |
151 setAlign(VerticalAlignment.TOP); | |
152 | |
153 addItem(this.legendContainer); | |
154 addLegends(); | |
155 | |
156 centerInPage(); | |
157 } | |
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
|
158 } |