1 | package org.openstreetmap.josm.data.imagery;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collection;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Class that stores info about a WMS server.
|
---|
8 | *
|
---|
9 | * @author Frederik Ramm <frederik@remote.org>
|
---|
10 | */
|
---|
11 | public class ImageryInfo implements Comparable<ImageryInfo> {
|
---|
12 | public enum ImageryType {
|
---|
13 | WMS("wms"),
|
---|
14 | TMS("tms"),
|
---|
15 | HTML("html"),
|
---|
16 | BING("bing");
|
---|
17 |
|
---|
18 | private String urlString;
|
---|
19 | ImageryType(String urlString) {
|
---|
20 | this.urlString = urlString;
|
---|
21 | }
|
---|
22 | public String getUrlString() {
|
---|
23 | return urlString;
|
---|
24 | }
|
---|
25 | }
|
---|
26 |
|
---|
27 | String name;
|
---|
28 | String url=null;
|
---|
29 | String cookies = null;
|
---|
30 | public final String eulaAcceptanceRequired;
|
---|
31 | ImageryType imageryType = ImageryType.WMS;
|
---|
32 | double pixelPerDegree = 0.0;
|
---|
33 | int maxZoom = 0;
|
---|
34 |
|
---|
35 | public ImageryInfo(String name) {
|
---|
36 | this.name=name;
|
---|
37 | this.eulaAcceptanceRequired = null;
|
---|
38 | }
|
---|
39 |
|
---|
40 | public ImageryInfo(String name, String url) {
|
---|
41 | this.name=name;
|
---|
42 | setURL(url);
|
---|
43 | this.eulaAcceptanceRequired = null;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public ImageryInfo(String name, String url, String eulaAcceptanceRequired) {
|
---|
47 | this.name=name;
|
---|
48 | setURL(url);
|
---|
49 | this.eulaAcceptanceRequired = eulaAcceptanceRequired;
|
---|
50 | }
|
---|
51 |
|
---|
52 | public ImageryInfo(String name, String url, String eulaAcceptanceRequired, String cookies) {
|
---|
53 | this.name=name;
|
---|
54 | setURL(url);
|
---|
55 | this.cookies=cookies;
|
---|
56 | this.eulaAcceptanceRequired = eulaAcceptanceRequired;
|
---|
57 | }
|
---|
58 |
|
---|
59 | public ImageryInfo(String name, String url, String cookies, double pixelPerDegree) {
|
---|
60 | this.name=name;
|
---|
61 | setURL(url);
|
---|
62 | this.cookies=cookies;
|
---|
63 | this.pixelPerDegree=pixelPerDegree;
|
---|
64 | this.eulaAcceptanceRequired = null;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public ArrayList<String> getInfoArray() {
|
---|
68 | String e2 = null;
|
---|
69 | String e3 = null;
|
---|
70 | String e4 = null;
|
---|
71 | if(url != null && !url.isEmpty()) {
|
---|
72 | e2 = getFullURL();
|
---|
73 | }
|
---|
74 | if(cookies != null && !cookies.isEmpty()) {
|
---|
75 | e3 = cookies;
|
---|
76 | }
|
---|
77 | if(imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) {
|
---|
78 | if(pixelPerDegree != 0.0) {
|
---|
79 | e4 = String.valueOf(pixelPerDegree);
|
---|
80 | }
|
---|
81 | } else {
|
---|
82 | if(maxZoom != 0) {
|
---|
83 | e4 = String.valueOf(maxZoom);
|
---|
84 | }
|
---|
85 | }
|
---|
86 | if(e4 != null && e3 == null) {
|
---|
87 | e3 = "";
|
---|
88 | }
|
---|
89 | if(e3 != null && e2 == null) {
|
---|
90 | e2 = "";
|
---|
91 | }
|
---|
92 |
|
---|
93 | ArrayList<String> res = new ArrayList<String>();
|
---|
94 | res.add(name);
|
---|
95 | if(e2 != null) {
|
---|
96 | res.add(e2);
|
---|
97 | }
|
---|
98 | if(e3 != null) {
|
---|
99 | res.add(e3);
|
---|
100 | }
|
---|
101 | if(e4 != null) {
|
---|
102 | res.add(e4);
|
---|
103 | }
|
---|
104 | return res;
|
---|
105 | }
|
---|
106 |
|
---|
107 | public ImageryInfo(Collection<String> list) {
|
---|
108 | ArrayList<String> array = new ArrayList<String>(list);
|
---|
109 | this.name=array.get(0);
|
---|
110 | if(array.size() >= 2) {
|
---|
111 | setURL(array.get(1));
|
---|
112 | }
|
---|
113 | if(array.size() >= 3) {
|
---|
114 | this.cookies=array.get(2);
|
---|
115 | }
|
---|
116 | if(array.size() >= 4) {
|
---|
117 | if (imageryType == ImageryType.WMS || imageryType == ImageryType.HTML) {
|
---|
118 | this.pixelPerDegree=Double.valueOf(array.get(3));
|
---|
119 | } else {
|
---|
120 | this.maxZoom=Integer.valueOf(array.get(3));
|
---|
121 | }
|
---|
122 | }
|
---|
123 | this.eulaAcceptanceRequired = null;
|
---|
124 | }
|
---|
125 |
|
---|
126 | public ImageryInfo(ImageryInfo i) {
|
---|
127 | this.name=i.name;
|
---|
128 | this.url=i.url;
|
---|
129 | this.cookies=i.cookies;
|
---|
130 | this.imageryType=i.imageryType;
|
---|
131 | this.pixelPerDegree=i.pixelPerDegree;
|
---|
132 | this.eulaAcceptanceRequired = null;
|
---|
133 | }
|
---|
134 |
|
---|
135 | @Override
|
---|
136 | public int compareTo(ImageryInfo in)
|
---|
137 | {
|
---|
138 | int i = name.compareTo(in.name);
|
---|
139 | if(i == 0) {
|
---|
140 | i = url.compareTo(in.url);
|
---|
141 | }
|
---|
142 | if(i == 0) {
|
---|
143 | i = Double.compare(pixelPerDegree, in.pixelPerDegree);
|
---|
144 | }
|
---|
145 | return i;
|
---|
146 | }
|
---|
147 |
|
---|
148 | public boolean equalsBaseValues(ImageryInfo in)
|
---|
149 | {
|
---|
150 | return url.equals(in.url);
|
---|
151 | }
|
---|
152 |
|
---|
153 | public void setPixelPerDegree(double ppd) {
|
---|
154 | this.pixelPerDegree = ppd;
|
---|
155 | }
|
---|
156 |
|
---|
157 | public void setMaxZoom(int maxZoom) {
|
---|
158 | this.maxZoom = maxZoom;
|
---|
159 | }
|
---|
160 |
|
---|
161 | public void setURL(String url) {
|
---|
162 | for (ImageryType type : ImageryType.values()) {
|
---|
163 | if (url.startsWith(type.getUrlString() + ":")) {
|
---|
164 | this.url = url.substring(type.getUrlString().length() + 1);
|
---|
165 | this.imageryType = type;
|
---|
166 | return;
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | // Default imagery type is WMS
|
---|
171 | this.url = url;
|
---|
172 | this.imageryType = ImageryType.WMS;
|
---|
173 | }
|
---|
174 |
|
---|
175 | public String getName() {
|
---|
176 | return this.name;
|
---|
177 | }
|
---|
178 |
|
---|
179 | public void setName(String name) {
|
---|
180 | this.name = name;
|
---|
181 | }
|
---|
182 |
|
---|
183 | public String getURL() {
|
---|
184 | return this.url;
|
---|
185 | }
|
---|
186 |
|
---|
187 | public String getCookies() {
|
---|
188 | return this.cookies;
|
---|
189 | }
|
---|
190 |
|
---|
191 | public double getPixelPerDegree() {
|
---|
192 | return this.pixelPerDegree;
|
---|
193 | }
|
---|
194 |
|
---|
195 | public int getMaxZoom() {
|
---|
196 | return this.maxZoom;
|
---|
197 | }
|
---|
198 |
|
---|
199 | public String getFullURL() {
|
---|
200 | return imageryType.getUrlString() + ":" + url;
|
---|
201 | }
|
---|
202 |
|
---|
203 | public String getToolbarName()
|
---|
204 | {
|
---|
205 | String res = name;
|
---|
206 | if(pixelPerDegree != 0.0) {
|
---|
207 | res += "#PPD="+pixelPerDegree;
|
---|
208 | }
|
---|
209 | return res;
|
---|
210 | }
|
---|
211 |
|
---|
212 | public String getMenuName()
|
---|
213 | {
|
---|
214 | String res = name;
|
---|
215 | if(pixelPerDegree != 0.0) {
|
---|
216 | res += " ("+pixelPerDegree+")";
|
---|
217 | } else if(maxZoom != 0) {
|
---|
218 | res += " (z"+maxZoom+")";
|
---|
219 | }
|
---|
220 | return res;
|
---|
221 | }
|
---|
222 |
|
---|
223 | public ImageryType getImageryType() {
|
---|
224 | return imageryType;
|
---|
225 | }
|
---|
226 |
|
---|
227 | public static boolean isUrlWithPatterns(String url) {
|
---|
228 | return url != null && url.contains("{") && url.contains("}");
|
---|
229 | }
|
---|
230 | }
|
---|