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
013  private final LatLon coordinate;
014  private final String objPackage;
015  private final String value;
016  private final long firstSeenTime;
017  private final long lastSeenTime;
018  private final long updatedTime;
019
020  public MapObject(
021    final LatLon coordinate, final String key, final String objPackage, final String value,
022    long firstSeenTime, long lastSeenTime, long updatedTime
023  ) {
024    super(key);
025    if (objPackage == null || value == null || coordinate == null) {
026      throw new IllegalArgumentException("The fields of a MapObject must not be null!");
027    }
028    this.coordinate = coordinate;
029    this.objPackage = objPackage;
030    this.value = value;
031    this.firstSeenTime = firstSeenTime;
032    this.lastSeenTime = lastSeenTime;
033    this.updatedTime = updatedTime;
034  }
035
036  public LatLon getCoordinate() {
037    return coordinate;
038  }
039
040  /**
041   * @param objectTypeID the {@link String} representing the type of map object. This ID can be retrieved via
042   *   {@link #getValue()} for any given {@link MapObject}.
043   * @return the icon, which represents the given objectTypeID
044   */
045  public static ImageIcon getIcon(final String objectTypeID) {
046    final ImageIcon cachedIcon = MapObjectIconCache.getInstance().get(objectTypeID);
047    if ("not-in-set".equals(objectTypeID)) {
048      return ICON_UNKNOWN_TYPE;
049    } else if (cachedIcon == null) {
050      // downloading of map icons is not currently supported by Streetside
051    }
052    return cachedIcon;
053  }
054
055  public String getPackage() {
056    return objPackage;
057  }
058
059  public long getFirstSeenTime() {
060    return firstSeenTime;
061  }
062
063  public long getLastSeenTime() {
064    return lastSeenTime;
065  }
066
067  public long getUpdatedTime() {
068    return updatedTime;
069  }
070
071  public String getValue() {
072    return value;
073  }
074}