Example #1
0
  private void update() {
    int state = downloader.getDownloadState();
    int percentDone = downloader.getPercentDone();

    IProgressReport pReport = pReporter.getProgressReport();
    switch (state) {
      case TorrentDownloader.STATE_CANCELLED:
        if (false == pReport.isCanceled()) {
          pReporter.cancel();
        }
        return;
      case TorrentDownloader.STATE_DOWNLOADING:
        pReporter.setPercentage(percentDone, downloader.getStatus());
        break;
      case TorrentDownloader.STATE_ERROR:
        /*
         * If the user has canceled then a call  to downloader.cancel() has already been made
         * so don't bother prompting for the user to retry
         */
        if (true == pReport.isCanceled()) {
          return;
        }

        pReporter.setErrorMessage(
            MessageText.getString("fileDownloadWindow.state_error") + downloader.getError());
        return;
      case TorrentDownloader.STATE_FINISHED:
        pReporter.setDone();

        /*
         * If the listener is present then it handle finishing up; otherwise open the torrent that
         * was just downloaded
         */
        if (listener == null) {
          TorrentOpener.openTorrent(downloader.getFile().getAbsolutePath());
        }
        return;
      default:
    }
  }