source: josm/trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java@ 3720

Last change on this file since 3720 was 3720, checked in by bastiK, 13 years ago

added missing svn:eol-style

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