1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.geoimage;
|
---|
3 |
|
---|
4 | import java.net.MalformedURLException;
|
---|
5 | import java.net.URI;
|
---|
6 | import java.net.URISyntaxException;
|
---|
7 | import java.net.URL;
|
---|
8 | import java.util.Objects;
|
---|
9 |
|
---|
10 | import org.openstreetmap.josm.data.coor.LatLon;
|
---|
11 | import org.openstreetmap.josm.tools.JosmRuntimeException;
|
---|
12 | import org.openstreetmap.josm.tools.Mediawiki;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * A geocoded image from <a href="https://commons.wikimedia.org/">Wikimedia Commons</a>
|
---|
16 | */
|
---|
17 | class WikimediaCommonsEntry extends ImageEntry {
|
---|
18 | private final String title;
|
---|
19 |
|
---|
20 | WikimediaCommonsEntry(String title, LatLon latLon) {
|
---|
21 | this.title = title.replaceFirst("^File:", "").replace(" ", "_");
|
---|
22 | setPos(latLon);
|
---|
23 | }
|
---|
24 |
|
---|
25 | @Override
|
---|
26 | protected URL getImageUrl() throws MalformedURLException {
|
---|
27 | return new URL(Mediawiki.getImageUrl("https://upload.wikimedia.org/wikipedia/commons", title));
|
---|
28 | }
|
---|
29 |
|
---|
30 | @Override
|
---|
31 | public URI getImageURI() {
|
---|
32 | try {
|
---|
33 | return new URI(Mediawiki.getImageUrl("https://upload.wikimedia.org/wikipedia/commons", this.title));
|
---|
34 | } catch (URISyntaxException e) {
|
---|
35 | // This should never happen.
|
---|
36 | throw new JosmRuntimeException(this.toString(), e);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | @Override
|
---|
41 | public String getDisplayName() {
|
---|
42 | return "File:" + title;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public String toString() {
|
---|
47 | return "File:" + title;
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public int hashCode() {
|
---|
52 | return 31 * super.hashCode() + Objects.hash(title);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public boolean equals(Object obj) {
|
---|
57 | if (this == obj)
|
---|
58 | return true;
|
---|
59 | if (!super.equals(obj) || getClass() != obj.getClass())
|
---|
60 | return false;
|
---|
61 | WikimediaCommonsEntry other = (WikimediaCommonsEntry) obj;
|
---|
62 | return Objects.equals(title, other.title);
|
---|
63 | }
|
---|
64 | }
|
---|