private void tableSelectionChanged() {

    if (selectedDownload != null) selectedDownload.deleteObserver(DownloadGUI.this);

    if (!clearing && table.getSelectedRow() > -1) {
      selectedDownload = tableModel.getDownload(table.getSelectedRow());
      selectedDownload.addObserver(DownloadGUI.this);
      updateButtons();
    }
  }
  private void updateButtons() {
    if (selectedDownload != null) {
      int status = selectedDownload.getStatus();
      switch (status) {
        case DownloadFile.DOWNLOADING:
          pauseButton.setEnabled(true);
          resumeButton.setEnabled(false);
          cancelButton.setEnabled(true);
          clearButton.setEnabled(false);
          break;
        case DownloadFile.PAUSED:
          pauseButton.setEnabled(false);
          resumeButton.setEnabled(true);
          cancelButton.setEnabled(true);
          clearButton.setEnabled(false);
          break;
        case DownloadFile.ERROR:
          pauseButton.setEnabled(false);
          resumeButton.setEnabled(true);
          cancelButton.setEnabled(false);
          clearButton.setEnabled(true);
          break;
        default:
          pauseButton.setEnabled(false);
          resumeButton.setEnabled(false);
          cancelButton.setEnabled(false);
          clearButton.setEnabled(true);
      }
    } else {

      pauseButton.setEnabled(false);
      resumeButton.setEnabled(false);
      cancelButton.setEnabled(false);
      clearButton.setEnabled(false);
    }
  }
  public void update(Observable o, Object arg) {

    if (selectedDownload != null && selectedDownload.equals(o)) updateButtons();
  }
 private void actionCancel() {
   selectedDownload.cancel();
   updateButtons();
 }
 private void actionResume() {
   selectedDownload.resume();
   updateButtons();
 }
 private void actionPause() {
   selectedDownload.pause();
   updateButtons();
 }