    001// License: GPL. For details, see LICENSE file.
    002package org.openstreetmap.josm.plugins.streetside.model;
    003
    004import javax.swing.ImageIcon;
    005
    006import org.openstreetmap.josm.data.coor.LatLon;
    007import org.openstreetmap.josm.plugins.streetside.cache.Caches.MapObjectIconCache;
    008import org.openstreetmap.josm.tools.ImageProvider;
    009
    010public class MapObject extends KeyIndexedObject {
    011  private static final ImageIcon ICON_UNKNOWN_TYPE = ImageProvider.get("unknown-mapobject-type");
    012  //private static Function<String, URL> iconUrlGen = MainWebsite::mapObjectIcon;
    013
    014  private final LatLon coordinate;
    015  private final String objPackage;
    016  private final String value;
    017  private final long firstSeenTime;
    018  private final long lastSeenTime;
    019  private final long updatedTime;
    020
    021  public MapObject(
    022    final LatLon coordinate, final String key, final String objPackage, final String value,
    023    long firstSeenTime, long lastSeenTime, long updatedTime
    024  ) {
    025    super(key);
    026    if (objPackage == null || value == null || coordinate == null) {
    027      throw new IllegalArgumentException("The fields of a MapObject must not be null!");
    028    }
    029    this.coordinate = coordinate;
    030    this.objPackage = objPackage;
    031    this.value = value;
    032    this.firstSeenTime = firstSeenTime;
    033    this.lastSeenTime = lastSeenTime;
    034    this.updatedTime = updatedTime;
    035  }
    036
    037  public LatLon getCoordinate() {
    038    return coordinate;
    039  }
    040
    041  /**
    042   * @param objectTypeID the {@link String} representing the type of map object. This ID can be retrieved via
    043   *   {@link #getValue()} for any given {@link MapObject}.
    044   * @return the icon, which represents the given objectTypeID
    045   */
    046  public static ImageIcon getIcon(final String objectTypeID) {
    047    final ImageIcon cachedIcon = MapObjectIconCache.getInstance().get(objectTypeID);
    048    if ("not-in-set".equals(objectTypeID)) {
    049      return ICON_UNKNOWN_TYPE;
    050    } else if (cachedIcon == null) {
    051      /*try {
    052        final ImageIcon downloadedIcon = new ImageIcon(ImageIO.read(iconUrlGen.apply(objectTypeID)));
    053        MapObjectIconCache.getInstance().put(objectTypeID, downloadedIcon);
    054        return downloadedIcon;
    055      } catch (IOException e) {
    056        logger.warn(I18n.tr("Failed to download icon " + objectTypeID, e));
    057        return ICON_UNKNOWN_TYPE;
    058      }*/
    059    }
    060    return cachedIcon;
    061  }
    062
    063  public String getPackage() {
    064    return objPackage;
    065  }
    066
    067  public long getFirstSeenTime() {
    068    return firstSeenTime;
    069  }
    070
    071  public long getLastSeenTime() {
    072    return lastSeenTime;
    073  }
    074
    075  public long getUpdatedTime() {
    076    return updatedTime;
    077  }
    078
    079  public String getValue() {
    080    return value;
    081  }
    082}