public void performAction(ActionEvent e) {
   BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();
   for (int i = 0; i < downloaders.length; i++) {
     downloaders[i].pause();
   }
   UXStats.instance().log(UXAction.DOWNLOAD_PAUSE);
 }
 @Override
 protected void performAction(ActionEvent e) {
   // toggle the setting
   ApplicationSettings.SHOW_SEEDING_TRANSFERS.setValue(
       !ApplicationSettings.SHOW_SEEDING_TRANSFERS.getValue());
   updateName();
   BTDownloadMediator.instance().updateTableFilters();
 }
 public void performAction(ActionEvent e) {
   BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();
   String str = "";
   for (int i = 0; i < downloaders.length; i++) {
     str += downloaders[i].getHash();
     if (i < downloaders.length - 1) {
       str += "\n";
     }
   }
   GUIMediator.setClipboardContent(str);
 }
    public void performAction(ActionEvent e) {
      if (_deleteData) {

        DialogOption result =
            GUIMediator.showYesNoMessage(
                I18n.tr(
                    "Are you sure you want to remove the data files from your computer?\n\nYou won't be able to recover the files."),
                I18n.tr("Are you sure?"),
                JOptionPane.QUESTION_MESSAGE);

        if (result != DialogOption.YES) return;
      }

      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();
      for (int i = 0; i < downloaders.length; i++) {
        downloaders[i].setDeleteTorrentWhenRemove(_deleteTorrent);
        downloaders[i].setDeleteDataWhenRemove(_deleteData);
      }
      BTDownloadMediator.instance().removeSelection();
      UXStats.instance().log(UXAction.DOWNLOAD_REMOVE);
    }
    public void performAction(ActionEvent e) {
      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();
      if (downloaders.length > 0) {
        final String toExplore = downloaders[0].getDisplayName();

        if (toExplore == null) {
          return;
        }

        LibraryMediator.instance()
            .getLibrarySearch()
            .searchFor(toExplore.replace("_", " ").replace("-", " ").replace(".", " "), false);
      }
    }
    public void performAction(ActionEvent e) {
      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();
      if (downloaders.length != 1) {
        return;
      }

      BTDownload btDownload = downloaders[0];

      if (btDownload instanceof BittorrentDownload) {
        TorrentInfo t = ((BittorrentDownload) btDownload).getTorrentInfo();
        if (t != null) { // avoid NPE due to an invalid torrent handle
          new ShareTorrentDialog(t).setVisible(true);
        }
      }
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      File file = BTDownloadMediator.instance().getSelectedDownloaders()[0].getSaveLocation();

      if (file.isDirectory() && LibraryUtils.directoryContainsASinglePlayableFile(file, 4)) {
        try {
          file = file.listFiles()[0];
        } catch (Throwable t) {
          file = null;
        }
      }

      if (file != null && MediaPlayer.isPlayableFile(file)) {
        MediaPlayer.instance().loadMedia(new MediaSource(file), true, false, false);
      }
    }
    public void performAction(ActionEvent e) {
      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();
      String str = "";
      for (int i = 0; i < downloaders.length; i++) {
        BTDownload d = downloaders[i];
        if (d instanceof BittorrentDownload) {
          String magnetUri = ((BittorrentDownload) d).makeMagnetUri();
          str += magnetUri;
          if (i < downloaders.length - 1) {
            str += System.lineSeparator();
          }
        }
      }

      GUIMediator.setClipboardContent(str);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();

      List<File> playlistFiles = new ArrayList<File>(downloaders.length);

      for (BTDownload d : downloaders) {
        if (!d.isCompleted()) {
          return;
        }

        playlistFiles.add(d.getSaveLocation());
      }

      LibraryUtils.asyncAddToPlaylist(playlist, playlistFiles.toArray(new File[0]));
      GUIMediator.instance().setWindow(GUIMediator.Tabs.LIBRARY);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();

      List<File> playlistFiles = new ArrayList<File>(downloaders.length);

      for (BTDownload d : downloaders) {
        if (!d.isCompleted()) {
          return;
        }

        File downloadFolder = new File(d.getSaveLocation(), d.getDisplayName());
        if (downloadFolder.exists()) {
          playlistFiles.add(downloadFolder);
        }
      }

      LibraryUtils.createNewPlaylist(playlistFiles.toArray(new File[0]));
    }
    @Override
    public void actionPerformed(ActionEvent e) {
      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();

      if (downloaders != null && downloaders.length > 0) {
        try {
          final BTDownload downloader = downloaders[0];
          File saveLocation = downloader.getSaveLocation();

          if (downloader instanceof BittorrentDownload) {
            BittorrentDownload btDownload = (BittorrentDownload) downloader;
            saveLocation = new File(btDownload.getSaveLocation(), btDownload.getName());
          }

          System.out.println("Sending to iTunes " + saveLocation.getAbsolutePath());

          iTunesMediator.instance().scanForSongs(saveLocation);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }
    public void performAction(ActionEvent e) {
      boolean oneIsCompleted = false;

      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();

      for (int i = 0; i < downloaders.length; i++) {
        if (downloaders[i].isCompleted()) {
          oneIsCompleted = true;
          break;
        }
      }

      boolean allowedToResume = true;
      DialogOption answer = null;
      if (oneIsCompleted && !SharingSettings.SEED_FINISHED_TORRENTS.getValue()) {
        String message1 =
            (downloaders.length > 1)
                ? I18n.tr(
                    "One of the transfers is complete and resuming will cause it to start seeding")
                : I18n.tr(
                    "This transfer is already complete, resuming it will cause it to start seeding");
        String message2 = I18n.tr("Do you want to enable torrent seeding?");
        answer = GUIMediator.showYesNoMessage(message1 + "\n\n" + message2, DialogOption.YES);
        allowedToResume = answer.equals(DialogOption.YES);

        if (allowedToResume) {
          SharingSettings.SEED_FINISHED_TORRENTS.setValue(true);
        }
      }

      if (allowedToResume) {
        for (int i = 0; i < downloaders.length; i++) {
          downloaders[i].resume();
        }
      }

      UXStats.instance().log(UXAction.DOWNLOAD_RESUME);
    }
    public void performAction(ActionEvent e) {
      BTDownload[] downloaders = BTDownloadMediator.instance().getSelectedDownloaders();
      if (downloaders.length > 0) {
        // when the downloader is a single file, this is appending a folder to the actual file path
        // treating it like a bittorrent download.
        File toExplore =
            new File(downloaders[0].getSaveLocation(), downloaders[0].getDisplayName());

        if (toExplore != null) {
          // but perhaps it's a single file, make sure it is then... (Re: Issue #366)
          if (!toExplore.exists()
              && downloaders[0].getSaveLocation() != null
              && downloaders[0].getSaveLocation().isFile()) {
            // (made this if very explicit and dumb on purpose to make logic clear, reverse logic is
            // shorter)
            toExplore = downloaders[0].getSaveLocation();
          }

          if (toExplore.exists()) {
            GUIMediator.launchExplorer(toExplore);
          }
        }
      }
    }
 @Override
 protected void performAction(ActionEvent e) {
   BTDownloadMediator.instance().removeCompleted();
 }
 public final void actionPerformed(ActionEvent e) {
   performAction(e);
   BTDownloadMediator.instance().doRefresh();
 }
  /**
   * Override the default removal so we can actually stop sharing and delete the file. Deletes the
   * selected rows in the table. CAUTION: THIS WILL DELETE THE FILE FROM THE DISK.
   */
  public void removeSelection() {
    int[] rows = TABLE.getSelectedRows();
    if (rows.length == 0) return;

    if (TABLE.isEditing()) {
      TableCellEditor editor = TABLE.getCellEditor();
      editor.cancelCellEditing();
    }

    List<File> files = new ArrayList<File>(rows.length);

    // sort row indices and go backwards so list indices don't change when
    // removing the files from the model list
    Arrays.sort(rows);
    for (int i = rows.length - 1; i >= 0; i--) {
      File file = DATA_MODEL.getFile(rows[i]);
      files.add(file);
    }

    CheckBoxListPanel<File> listPanel =
        new CheckBoxListPanel<File>(files, new FileTextProvider(), true);
    listPanel.getList().setVisibleRowCount(4);

    // display list of files that should be deleted
    Object[] message =
        new Object[] {
          new MultiLineLabel(
              I18n.tr(
                  "Are you sure you want to delete the selected file(s), thus removing it from your computer?"),
              400),
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
          listPanel,
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP)
        };

    // get platform dependent options which are displayed as buttons in the dialog
    Object[] removeOptions = createRemoveOptions();

    int option =
        JOptionPane.showOptionDialog(
            MessageService.getParentComponent(),
            message,
            I18n.tr("Message"),
            JOptionPane.YES_NO_OPTION,
            JOptionPane.QUESTION_MESSAGE,
            null,
            removeOptions,
            removeOptions[0] /* default option */);

    if (option == removeOptions.length - 1 /* "cancel" option index */
        || option == JOptionPane.CLOSED_OPTION) {
      return;
    }

    // remove still selected files
    List<File> selected = listPanel.getSelectedElements();
    List<String> undeletedFileNames = new ArrayList<String>();

    boolean somethingWasRemoved = false;

    for (File file : selected) {
      // stop seeding if seeding
      BittorrentDownload dm = null;
      if ((dm = TorrentUtil.getDownloadManager(file)) != null) {
        dm.setDeleteDataWhenRemove(false);
        dm.setDeleteTorrentWhenRemove(false);
        BTDownloadMediator.instance().remove(dm);
      }

      // close media player if still playing
      if (MediaPlayer.instance().isThisBeingPlayed(file)) {
        MediaPlayer.instance().stop();
        MPlayerMediator.instance().showPlayerWindow(false);
      }

      // removeOptions > 2 => OS offers trash options
      boolean removed =
          FileUtils.delete(
              file, removeOptions.length > 2 && option == 0 /* "move to trash" option index */);
      if (removed) {
        somethingWasRemoved = true;
        DATA_MODEL.remove(DATA_MODEL.getRow(file));
      } else {
        undeletedFileNames.add(getCompleteFileName(file));
      }
    }

    clearSelection();

    if (somethingWasRemoved) {
      LibraryMediator.instance().getLibraryExplorer().refreshSelection(true);
    }

    if (undeletedFileNames.isEmpty()) {
      return;
    }

    // display list of files that could not be deleted
    message =
        new Object[] {
          new MultiLineLabel(
              I18n.tr(
                  "The following files could not be deleted. They may be in use by another application or are currently being downloaded to."),
              400),
          Box.createVerticalStrut(ButtonRow.BUTTON_SEP),
          new JScrollPane(createFileList(undeletedFileNames))
        };

    JOptionPane.showMessageDialog(
        MessageService.getParentComponent(), message, I18n.tr("Error"), JOptionPane.ERROR_MESSAGE);

    super.removeSelection();
  }