/** Applies the selected filter. */
  public synchronized void refresh() {
    boolean imported = this.imported.isSelected();
    boolean downloaded = this.downloaded.isSelected();
    boolean onlySigns = this.onlySigns.isSelected();

    for (MapillaryAbstractImage img : MapillaryLayer.getInstance().getData().getImages()) {
      img.setVisible(true);
      if (img instanceof MapillaryImportedImage) {
        if (!imported) img.setVisible(false);
        continue;
      } else if (img instanceof MapillaryImage) {
        if (!downloaded) {
          img.setVisible(false);
          continue;
        }
        if (onlySigns) {
          if (((MapillaryImage) img).getSigns().isEmpty()) {
            img.setVisible(false);
            continue;
          }
          if (!checkSigns((MapillaryImage) img)) {
            img.setVisible(false);
            continue;
          }
        }
        if (!this.user.getText().equals("")
            && !this.user.getText().equals(((MapillaryImage) img).getUser())) {
          img.setVisible(false);
          continue;
        }
      }
      // Calculates the amount of days since the image was taken
      Long currentTime = currentTime();
      if (this.time.getSelectedItem().equals(TIME_LIST[1])) {
        if (img.getCapturedAt()
            < currentTime
                - ((Integer) this.spinner.getValue()).longValue() * 365 * 24 * 60 * 60 * 1000) {
          img.setVisible(false);
          continue;
        }
      }
      if (this.time.getSelectedItem().equals(TIME_LIST[2])) {
        if (img.getCapturedAt()
            < currentTime
                - ((Integer) this.spinner.getValue()).longValue() * 30 * 24 * 60 * 60 * 1000) {
          img.setVisible(false);
          continue;
        }
      }
      if (this.time.getSelectedItem().equals(TIME_LIST[3])) {
        if (img.getCapturedAt()
            < currentTime - ((Integer) this.spinner.getValue()).longValue() * 60 * 60 * 1000) {
          img.setVisible(false);
          continue;
        }
      }
    }
    Main.map.repaint();
  }
  /**
   * Downloads the picture of the selected MapillaryImage and sets in the MapillaryImageDisplay
   * object.
   *
   * @param fullQuality If the full quality picture must be downloaded or just the thumbnail.
   */
  public synchronized void updateImage(boolean fullQuality) {
    if (!SwingUtilities.isEventDispatchThread()) {
      SwingUtilities.invokeLater(this::updateImage);
    } else {
      if (!MapillaryLayer.hasInstance()) {
        return;
      }
      if (this.image == null) {
        this.mapillaryImageDisplay.setImage(null);
        setTitle(tr(BASE_TITLE));
        disableAllButtons();
        return;
      }
      // Enables/disables next/previous buttons
      this.nextButton.setEnabled(false);
      this.previousButton.setEnabled(false);
      if (this.image.getSequence() != null) {
        MapillaryAbstractImage tempImage = this.image;
        while (tempImage.next() != null) {
          tempImage = tempImage.next();
          if (tempImage.isVisible()) {
            this.nextButton.setEnabled(true);
            break;
          }
        }
      }
      if (this.image.getSequence() != null) {
        MapillaryAbstractImage tempImage = this.image;
        while (tempImage.previous() != null) {
          tempImage = tempImage.previous();
          if (tempImage.isVisible()) {
            this.previousButton.setEnabled(true);
            break;
          }
        }
      }
      if (this.image instanceof MapillaryImage) {
        this.mapillaryImageDisplay.hyperlink.setVisible(true);
        MapillaryImage mapillaryImage = (MapillaryImage) this.image;
        this.mapillaryImageDisplay.hyperlink.setURL(mapillaryImage.getKey());
        // Downloads the thumbnail.
        this.mapillaryImageDisplay.setImage(null);
        if (this.thumbnailCache != null) this.thumbnailCache.cancelOutstandingTasks();
        this.thumbnailCache =
            new MapillaryCache(mapillaryImage.getKey(), MapillaryCache.Type.THUMBNAIL);
        try {
          this.thumbnailCache.submit(this, false);
        } catch (IOException e) {
          Main.error(e);
        }

        // Downloads the full resolution image.
        if (fullQuality
            || new MapillaryCache(mapillaryImage.getKey(), MapillaryCache.Type.FULL_IMAGE).get()
                != null) {
          if (this.imageCache != null) this.imageCache.cancelOutstandingTasks();
          this.imageCache =
              new MapillaryCache(mapillaryImage.getKey(), MapillaryCache.Type.FULL_IMAGE);
          try {
            this.imageCache.submit(this, false);
          } catch (IOException e) {
            Main.error(e);
          }
        }
      } else if (this.image instanceof MapillaryImportedImage) {
        this.mapillaryImageDisplay.hyperlink.setVisible(false);
        this.mapillaryImageDisplay.hyperlink.setURL(null);
        MapillaryImportedImage mapillaryImage = (MapillaryImportedImage) this.image;
        try {
          this.mapillaryImageDisplay.setImage(mapillaryImage.getImage());
        } catch (IOException e) {
          Main.error(e);
        }
      }
      updateTitle();
    }
  }
 @Override
 public int compareTo(MapillaryAbstractImage mapillaryAbstractImage) {
   return hashCode() - mapillaryAbstractImage.hashCode();
 }