Mercurial > dive4elements > river
annotate gwt-client/src/main/java/org/dive4elements/river/client/client/ui/map/LegendWindow.java @ 9698:812a6a3eaaf5
another try
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Wed, 20 Jan 2021 17:19:59 +0100 |
parents | 15404504ea9e |
children | 94362af5928e |
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.dom.client.LoadEvent; |
9696 | 21 import com.google.gwt.event.dom.client.LoadHandler; |
9698 | 22 import com.google.gwt.event.shared.EventBus; |
23 import com.google.gwt.event.shared.HandlerRegistration; | |
24 import com.google.gwt.event.shared.SimpleEventBus; | |
9644 | 25 import com.google.gwt.http.client.URL; |
9619 | 26 import com.google.gwt.user.client.ui.Image; |
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 |
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
|
37 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
|
38 |
9696 | 39 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
|
40 |
9696 | 41 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
|
42 |
9696 | 43 private final VLayout legendContainer; |
9694 | 44 |
9696 | 45 public LegendWindow(final ThemeList themeList) { |
46 this.themeList = themeList; | |
47 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
|
48 |
9696 | 49 init(); |
50 } | |
51 | |
52 public void update(final ThemeList themeList) { | |
53 this.themeList = themeList; | |
54 | |
55 final Canvas[] legends = this.legendContainer.getMembers(); | |
56 this.legendContainer.removeMembers(legends); | |
57 | |
58 addLegends(); | |
59 } | |
60 | |
61 private void addLegends() { | |
62 final List<Theme> themes = this.themeList.getActiveThemes(); | |
63 com.smartgwt.client.util.SC.say("themescount " + themes.size()); | |
64 | |
65 for (int i = 0; i < themes.size(); i++) { | |
66 final Theme theme = themes.get(i); | |
67 if (theme.getActive() == 0) { | |
68 continue; | |
69 } | |
70 try { | |
71 if (theme instanceof AttributedTheme) { | |
9697 | 72 theme.setActive(0); |
9696 | 73 Canvas createLegendGraphicsRow = createLegendGraphicsRow((AttributedTheme) theme); |
9697 | 74 // this.legendContainer.addMember(createLegendGraphicsRow); |
75 theme.setActive(1); | |
76 Canvas createLegendGraphicsRow2 = createLegendGraphicsRow((AttributedTheme) theme); | |
77 this.legendContainer.addMember(createLegendGraphicsRow2); | |
9696 | 78 } |
79 } catch (Exception e) { | |
80 com.smartgwt.client.util.SC.say("exception at index " + themes.size()); | |
81 continue; | |
82 } | |
83 } | |
84 } | |
85 | |
86 private Canvas createLegendGraphicsRow(final AttributedTheme at) { | |
87 final Label label = new Label(at.getDescription()); | |
88 final Widget img = createLegendGraphics(at); | |
89 | |
90 final HLayout row = new HLayout(); | |
91 row.addMember(label); | |
92 row.addMember(img); | |
93 | |
94 String url = "url"; | |
95 | |
96 if (img instanceof Image) { | |
97 Image.prefetch(((Image) img).getUrl()); | |
9698 | 98 |
9696 | 99 url = " url " + ((Image) img).getUrl(); |
9698 | 100 |
101 | |
102 MyLoadHandler handler = new MyLoadHandler(row, ((Image) img)); | |
103 | |
104 final HandlerRegistration handelReg = ((Image) img).addLoadHandler( handler); | |
105 handler.setHandelReg(handelReg); | |
106 | |
9696 | 107 } else if (img instanceof Img) { |
108 setDimensions(row, ((Img) img).getHeight(), ((Img) img).getWidth()); | |
109 url = " dataPath " + ((Img) img).getDataPath(); | |
110 } else { | |
111 setDimensions(row, 150, 400); // not sure when this is executed | |
112 } | |
113 String labelText = at.getDescription() + ", height: " + row.getHeight() + "width: " + row.getWidth() + " " | |
114 + url; | |
115 // | |
116 // final HLayout row2= new HLayout(); | |
117 // row.addMember(new Label(labelText)); | |
118 | |
119 com.smartgwt.client.util.SC.say(labelText); | |
120 return row; | |
121 } | |
122 | |
123 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
|
124 final int minHeight = 30; |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
125 row.setHeight(height < minHeight ? minHeight : height); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
126 row.setWidth(width); |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
127 } |
2197a7ccb4a8
LegendWindow zu 3.1. + 3.2 DEBUG
dnt_bjoernsen <d.tironi@bjoernsen.de>
parents:
9644
diff
changeset
|
128 |
9696 | 129 private Widget createLegendGraphics(final AttributedTheme at) { |
9619 | 130 |
9696 | 131 final String legend = at.getAttr("legend"); |
132 // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), | |
133 // ebenso FLYSResources.getTest(); | |
134 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
|
135 |
9696 | 136 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
|
137 |
9696 | 138 final Image image = new Image(imgUrl); |
139 final int imageWidth = image.getWidth(); | |
140 final int imageHeight = image.getHeight(); | |
141 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
|
142 |
9696 | 143 // removing the limit of 150px height (legend can have an infinite height now, |
144 // as long as the width is less/eq 400px; if the width is >400, | |
145 // the legend will be scaled to 400px width; the ratio will be kept) | |
146 | |
147 // final double heightPercent = imageHeight / 150.; | |
148 if (widthPercent > 1)// || heightPercent > 1) { | |
149 image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px"); | |
150 | |
151 return image; | |
152 } | |
153 final String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), at.getAttr("layers")); | |
154 | |
155 final Img img = new Img(imgUrl); | |
156 img.setImageType(ImageStyle.CENTER); | |
157 img.setAutoFit(true); | |
158 | |
159 return img; | |
160 } | |
161 | |
162 private void init() { | |
163 this.legendContainer.setAutoHeight(); | |
164 this.legendContainer.setLayoutAlign(VerticalAlignment.TOP); | |
165 this.legendContainer.setAlign(VerticalAlignment.CENTER); | |
166 | |
167 setTitle(this.MSG.wms_legend()); | |
168 setAutoSize(true); | |
169 setCanDragResize(true); | |
170 setIsModal(false); | |
171 setShowModalMask(false); | |
172 setLayoutAlign(VerticalAlignment.TOP); | |
173 setAlign(VerticalAlignment.TOP); | |
174 | |
175 addItem(this.legendContainer); | |
176 addLegends(); | |
177 | |
178 centerInPage(); | |
179 } | |
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
|
180 } |