Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9695:9e0ee81a9b7e | 9696:e388db7fd72e |
---|---|
15 import org.dive4elements.river.client.shared.model.AttributedTheme; | 15 import org.dive4elements.river.client.shared.model.AttributedTheme; |
16 import org.dive4elements.river.client.shared.model.Theme; | 16 import org.dive4elements.river.client.shared.model.Theme; |
17 import org.dive4elements.river.client.shared.model.ThemeList; | 17 import org.dive4elements.river.client.shared.model.ThemeList; |
18 | 18 |
19 import com.google.gwt.core.client.GWT; | 19 import com.google.gwt.core.client.GWT; |
20 import com.google.gwt.event.dom.client.LoadHandler; | |
20 import com.google.gwt.http.client.URL; | 21 import com.google.gwt.http.client.URL; |
21 import com.google.gwt.user.client.ui.Image; | 22 import com.google.gwt.user.client.ui.Image; |
22 import com.google.gwt.user.client.ui.Widget; | 23 import com.google.gwt.user.client.ui.Widget; |
23 import com.smartgwt.client.types.ImageStyle; | 24 import com.smartgwt.client.types.ImageStyle; |
24 import com.smartgwt.client.types.VerticalAlignment; | 25 import com.smartgwt.client.types.VerticalAlignment; |
29 import com.smartgwt.client.widgets.layout.HLayout; | 30 import com.smartgwt.client.widgets.layout.HLayout; |
30 import com.smartgwt.client.widgets.layout.VLayout; | 31 import com.smartgwt.client.widgets.layout.VLayout; |
31 | 32 |
32 public class LegendWindow extends Window { | 33 public class LegendWindow extends Window { |
33 | 34 |
34 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | 35 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); |
35 | 36 |
36 private ThemeList themeList; | 37 private ThemeList themeList; |
37 | 38 |
38 private final VLayout legendContainer; | 39 private final VLayout legendContainer; |
39 | 40 |
40 public LegendWindow(final ThemeList themeList) { | 41 public LegendWindow(final ThemeList themeList) { |
41 this.themeList = themeList; | 42 this.themeList = themeList; |
42 this.legendContainer = new VLayout(); | 43 this.legendContainer = new VLayout(); |
43 | 44 |
44 init(); | 45 init(); |
45 } | 46 } |
46 | 47 |
47 public void update(final ThemeList themeList) { | 48 public void update(final ThemeList themeList) { |
48 this.themeList = themeList; | 49 this.themeList = themeList; |
49 | 50 |
50 final Canvas[] legends = this.legendContainer.getMembers(); | 51 final Canvas[] legends = this.legendContainer.getMembers(); |
51 this.legendContainer.removeMembers(legends); | 52 this.legendContainer.removeMembers(legends); |
52 | 53 |
53 addLegends(); | 54 addLegends(); |
54 } | 55 } |
55 | 56 |
56 private void addLegends() { | 57 private void addLegends() { |
57 final List<Theme> themes = this.themeList.getActiveThemes(); | 58 final List<Theme> themes = this.themeList.getActiveThemes(); |
58 com.smartgwt.client.util.SC.say("themescount " + themes.size()); | 59 com.smartgwt.client.util.SC.say("themescount " + themes.size()); |
59 | |
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 this.legendContainer.addMember(createLegendGraphicsRow((AttributedTheme) theme)); | |
69 } } catch (Exception e) { | |
70 com.smartgwt.client.util.SC.say("exception at index " + themes.size()); | |
71 continue; | |
72 } | |
73 } | |
74 } | |
75 | 60 |
76 private Canvas createLegendGraphicsRow(final AttributedTheme at) { | 61 for (int i = 0; i < themes.size(); i++) { |
77 com.smartgwt.client.util.SC.say("init"); | 62 final Theme theme = themes.get(i); |
78 final Label label = new Label(at.getDescription()); | 63 if (theme.getActive() == 0) { |
79 final Widget img = createLegendGraphics(at); | 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 } | |
80 | 77 |
81 final HLayout row = new HLayout(); | 78 private Canvas createLegendGraphicsRow(final AttributedTheme at) { |
82 row.addMember(label); | 79 com.smartgwt.client.util.SC.say("init"); |
83 row.addMember(img); | 80 final Label label = new Label(at.getDescription()); |
84 | 81 final Widget img = createLegendGraphics(at); |
85 String url = "url"; | |
86 | |
87 if (img instanceof Image) { | |
88 setDimensions( row, ((Image) img).getHeight(), ((Image) img).getWidth()); | |
89 url = " url " + ((Image) img).getUrl(); | |
90 } | |
91 else if (img instanceof Img) { | |
92 setDimensions( row, ((Img) img).getHeight(), ((Img) img).getWidth()); | |
93 url = " dataPath " + ((Img) img).getDataPath(); | |
94 } | |
95 else { | |
96 setDimensions( row, 150, 400); //not sure when this is executed | |
97 } | |
98 String labelText = at.getDescription() +", height: "+ row.getHeight()+"width: "+ row.getWidth()+" "+url; | |
99 // | |
100 // final HLayout row2= new HLayout(); | |
101 // row.addMember(new Label(labelText)); | |
102 | 82 |
103 com.smartgwt.client.util.SC.say(labelText); | 83 final HLayout row = new HLayout(); |
104 return row; | 84 row.addMember(label); |
105 } | 85 row.addMember(img); |
106 | 86 |
107 private void setDimensions(HLayout row, int height, int width ) { | 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) { | |
108 final int minHeight = 30; | 110 final int minHeight = 30; |
109 row.setHeight(height < minHeight ? minHeight : height); | 111 row.setHeight(height < minHeight ? minHeight : height); |
110 row.setWidth(width); | 112 row.setWidth(width); |
111 } | 113 } |
112 | 114 |
113 private Widget createLegendGraphics(final AttributedTheme at) { | 115 private Widget createLegendGraphics(final AttributedTheme at) { |
114 | 116 |
115 final String legend = at.getAttr("legend"); | 117 final String legend = at.getAttr("legend"); |
116 // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), ebenso FLYSResources.getTest(); | 118 // TEST: final Image img = new Image("/images/FLYS_Donau.png"); (funktioniert!), |
117 if (legend != null && !"".equals(legend)) { | 119 // ebenso FLYSResources.getTest(); |
120 if (legend != null && !"".equals(legend)) { | |
118 | 121 |
119 final String imgUrl = URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend); | 122 final String imgUrl = URL.encode(GWT.getHostPageBaseURL() + "images/wms_legend/" + legend); |
120 | 123 |
121 final Image image = new Image(imgUrl); | 124 final Image image = new Image(imgUrl); |
122 final int imageWidth = image.getWidth(); | 125 final int imageWidth = image.getWidth(); |
123 final int imageHeight = image.getHeight(); | 126 final int imageHeight = image.getHeight(); |
124 final double widthPercent = imageWidth / 400.; | 127 final double widthPercent = imageWidth / 400.; |
125 | 128 |
126 // removing the limit of 150px height (legend can have an infinite height now, | 129 // removing the limit of 150px height (legend can have an infinite height now, |
127 // as long as the width is less/eq 400px; if the width is >400, | 130 // as long as the width is less/eq 400px; if the width is >400, |
128 // the legend will be scaled to 400px width; the ratio will be kept) | 131 // the legend will be scaled to 400px width; the ratio will be kept) |
129 | 132 |
130 // final double heightPercent = imageHeight / 150.; | 133 // final double heightPercent = imageHeight / 150.; |
131 if (widthPercent > 1)// || heightPercent > 1) { | 134 if (widthPercent > 1)// || heightPercent > 1) { |
132 image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px"); | 135 image.setSize((int) (imageWidth / widthPercent) + "px", (int) (imageHeight / widthPercent) + "px"); |
133 | |
134 return image; | |
135 } | |
136 final String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), at.getAttr("layers")); | |
137 | 136 |
138 final Img img = new Img(imgUrl); | 137 return image; |
139 img.setImageType(ImageStyle.CENTER); | 138 } |
140 img.setAutoFit(true); | 139 final String imgUrl = MapUtils.getLegendGraphicUrl(at.getAttr("url"), at.getAttr("layers")); |
141 | 140 |
142 return img; | 141 final Img img = new Img(imgUrl); |
143 } | 142 img.setImageType(ImageStyle.CENTER); |
143 img.setAutoFit(true); | |
144 | 144 |
145 private void init() { | 145 return img; |
146 this.legendContainer.setAutoHeight(); | 146 } |
147 this.legendContainer.setLayoutAlign(VerticalAlignment.TOP); | |
148 this.legendContainer.setAlign(VerticalAlignment.CENTER); | |
149 | 147 |
150 setTitle(this.MSG.wms_legend()); | 148 private void init() { |
151 setAutoSize(true); | 149 this.legendContainer.setAutoHeight(); |
152 setCanDragResize(true); | 150 this.legendContainer.setLayoutAlign(VerticalAlignment.TOP); |
153 setIsModal(false); | 151 this.legendContainer.setAlign(VerticalAlignment.CENTER); |
154 setShowModalMask(false); | |
155 setLayoutAlign(VerticalAlignment.TOP); | |
156 setAlign(VerticalAlignment.TOP); | |
157 | 152 |
158 addItem(this.legendContainer); | 153 setTitle(this.MSG.wms_legend()); |
159 addLegends(); | 154 setAutoSize(true); |
155 setCanDragResize(true); | |
156 setIsModal(false); | |
157 setShowModalMask(false); | |
158 setLayoutAlign(VerticalAlignment.TOP); | |
159 setAlign(VerticalAlignment.TOP); | |
160 | 160 |
161 centerInPage(); | 161 addItem(this.legendContainer); |
162 } | 162 addLegends(); |
163 | |
164 centerInPage(); | |
165 } | |
163 } | 166 } |