/**
   * Add a webLinkedFile in the queue if it hasn't been already downloaded and if it respect the
   * good host or protocol
   *
   * @param uri the URI to add
   * @param depth the depth of the URI
   * @param parent the webHtmlFile parent
   */
  public void addLinkedFile(URI uri, int depth, WebFile parent) {
    // creates the webLinkedFile according to the URI
    if (!isUriAlreadyDownloaded(uri)) {
      // verification if the depth is good
      if (depth <= maxDepth) {
        discoveredURI.add(Utils.getCompletePath(uri));
        WebLinkedFile webLinkedFile = new WebLinkedFile(uri, depth, parent);
        String webFileHost = Utils.getCompleteHost(webLinkedFile.getURI());

        // filter the linked files with the Filter
        RE r = new RE(regExp);
        if (r.match(webLinkedFile.getFileName())) {
          if (webFileHost.equals(defaultHost)) {
            linkedFileToDownload.add(webLinkedFile);
            // add the webHtmlFile in the treeModel
            DiscoveryTreeNode parentNode = (DiscoveryTreeNode) treeRoot.getChild(parent);
            DiscoveryTreeNode node = parentNode.add(webLinkedFile);
            treeModel.nodesWereInserted(parentNode, new int[] {parentNode.getIndex(node)});
            // add the webHtmlFile in the detailledModel
            detailledModel.addElement(webLinkedFile);
          } else {
            // it is not the same web site or the same protocol
            System.err.println(
                webLinkedFile.getURI()
                    + " / "
                    + defaultHost
                    + ": NOT THE SAME HOST OR THE SAME PROTOCOL");
          }
        }
      }
    }
  }
 /**
  * Thread to download files Take all the webLinkedFile contained in the htmlFileToDownload list
  * and download them
  */
 public void run() {
   testIfPaused();
   DownloadAndParseFile downloadFile;
   boolean isInterrupted = false;
   while (!Thread.interrupted()
       && (htmlFileToDownload.isEmpty() == false
           || linkedFileToDownload.isEmpty() == false
           || htmlFileInDownloading.isEmpty() == false
           || linkedFileInDownloading.isEmpty() == false)) {
     if (currentDLHtml < maxDLHtml && htmlFileToDownload.isEmpty() == false) {
       WebHtmlFile webHtmlFile;
       webHtmlFile = htmlFileToDownload.get(0);
       this.htmlFileToDownload.remove(0);
       if (webHtmlFile.getProgression() != -1) { // was not cancelled
         htmlFileInDownloading.add(webHtmlFile);
         // start a new download of Html File in a new Thread
         downloadFile = new DownloadAndParseFile(this, webHtmlFile, defaultHost, destDirectory);
         downloadFile.start();
         threadList.add(downloadFile);
         currentDLHtml++;
       }
     }
     testIfPaused();
     if (currentDLLink < maxDLLink && linkedFileToDownload.isEmpty() == false) {
       WebLinkedFile webLinkedFile;
       webLinkedFile = linkedFileToDownload.get(0);
       this.linkedFileToDownload.remove(0);
       if (webLinkedFile.getProgression() != -1) { // was not cancelled
         linkedFileInDownloading.add(webLinkedFile);
         // start a new download of Linked File in a new Thread
         downloadFile = new DownloadAndParseFile(this, webLinkedFile, defaultHost, destDirectory);
         downloadFile.start();
         threadList.add(downloadFile);
         currentDLLink++;
       }
     }
     try {
       Thread.sleep(HtmlConstants.TIME_BETWEEN_EACH_DOWNLOAD);
     } catch (InterruptedException e) {
       interrupt();
       isInterrupted = true;
     }
   }
   if (!isInterrupted) {
     // End of Download (successfull)
     JOptionPane.showMessageDialog(
         JHMainFrame.getInstance(),
         Labels.DOWNLOAD_FINISHED_LABEL,
         Labels.DOWNLOAD_STATUS_LABEL,
         JOptionPane.INFORMATION_MESSAGE);
   }
   // free the DownloadManager
   freeDownloadManager();
 }