public void actionPerformed(ActionEvent e) {

		if (e.getSource() == downloadBt ) {

			downloadBt.setEnabled(false);
			String inputURL = url.getText();

			//Check a url was inserted
			if (inputURL.length() == 0) {
				JOptionPane.showMessageDialog(null, "Please enter a url to download from");
				downloadBt.setEnabled(true);
				return;
			}
			
			//Allow the user to choose the output file destination
			JFileChooser dirChooser = new JFileChooser();  
			dirChooser.setDialogTitle("Save to ...");
			dirChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
	
			int returnVal = dirChooser.showSaveDialog(null);
			
			//If no directory was selected, don't download!
			if(returnVal != JFileChooser.APPROVE_OPTION) {
				downloadBt.setEnabled(true);
				return;
			}
			//Get the name of the chosen directory 
			String chosenDir = dirChooser.getSelectedFile().getPath();

			//Get the file name from the url
			File f = new File(inputURL);
			String fileName = f.getName();

			//Check if the file exists locally
			chosenFile = new File(chosenDir+"/"+fileName);
			if ( chosenFile.exists()) {

				//Allow user to choose either resuming the download or overwriting the current file
				Object[] existOptions = {"Proceed", "Overwrite"};
				int optionChosen = JOptionPane.showOptionDialog(null, "File already exists. " +
						"Do you want to proceed downloading or overwrite the existing file?",
						"File Exists!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
						null,existOptions, existOptions[0]);

				if (optionChosen == 1) {
					chosenFile.delete(); //Delete the existing file
				} else if (optionChosen == -1) {
					downloadBt.setEnabled(true);
					return;
				}
			}

			//Check a url is open source
			Object[] OSoptions = {"Yes, it is.", "No, it is not"};
			int optionChosen = JOptionPane.showOptionDialog(null, "Please confirm that the file is open source.",
					"Confirm open source!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE,
					null,OSoptions, OSoptions[0]);
			if (optionChosen == 1 || optionChosen == -1) {
				JOptionPane.showMessageDialog(null, "Sorry, file must be an open source");
				downloadBt.setEnabled(true);
				url.setText("");
				return;
			}

			//Start downloading in background thread
			download = new DownloadTask(inputURL, chosenDir);
			download.execute();
			cancelBt.setEnabled(true);
			url.setText("");

		} else { //Cancel button is pressed
			//Cancel the download process
			if (download != null) {
				download.cancel(false);
			}
		}

	}