001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.gui.layer.geoimage; 003 004import java.net.MalformedURLException; 005import java.net.URL; 006import java.util.Objects; 007 008import org.openstreetmap.josm.data.coor.LatLon; 009import org.openstreetmap.josm.tools.Mediawiki; 010 011/** 012 * A geocoded image from <a href="https://commons.wikimedia.org/">Wikimedia Commons</a> 013 */ 014class WikimediaCommonsEntry extends ImageEntry { 015 private final String title; 016 017 WikimediaCommonsEntry(String title, LatLon latLon) { 018 this.title = title.replaceFirst("^File:", "").replace(" ", "_"); 019 setPos(latLon); 020 } 021 022 @Override 023 protected URL getImageUrl() throws MalformedURLException { 024 return new URL(Mediawiki.getImageUrl("https://upload.wikimedia.org/wikipedia/commons", title)); 025 } 026 027 @Override 028 public String getDisplayName() { 029 return "File:" + title; 030 } 031 032 @Override 033 public String toString() { 034 return "File:" + title; 035 } 036 037 @Override 038 public int hashCode() { 039 return 31 * super.hashCode() + Objects.hash(title); 040 } 041 042 @Override 043 public boolean equals(Object obj) { 044 if (this == obj) 045 return true; 046 if (!super.equals(obj) || getClass() != obj.getClass()) 047 return false; 048 WikimediaCommonsEntry other = (WikimediaCommonsEntry) obj; 049 return Objects.equals(title, other.title); 050 } 051}