diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..1629551
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,8 @@
+
+Copyright 2022 Prithvi singh
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..35a8858
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+## Download Manager
+
+[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
+
+
+A simple tool to manage all your downloads. Just add a downloadable URL of a file,
+and you are good to go.
+
+### Usage Examples
+
+![Download manager](https://github.com/prithvitewatia/DownloadManager/src/main/resources/img/DownloadManager.png)
+
+### Feedback
+
+Write your suggestions to prithvisinghtewatia@gmail.com .
+Follow me on [Linkedin](https://www.linkedin.com/in/prithvi-singh-tewatia-0161b5171/).
diff --git a/pom.xml b/pom.xml
index 9769d80..61f72a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -60,7 +60,7 @@
default-cli
- dev.prithvis.downloadmanager/dev.prithvis.downloadmanager.HelloApplication
+ dev.prithvis.downloadmanager/dev.prithvis.downloadmanager.MainDownload
app
app
diff --git a/src/main/java/dev/prithvis/downloadmanager/DownloadManager.java b/src/main/java/dev/prithvis/downloadmanager/DownloadManager.java
new file mode 100644
index 0000000..3987b42
--- /dev/null
+++ b/src/main/java/dev/prithvis/downloadmanager/DownloadManager.java
@@ -0,0 +1,69 @@
+package dev.prithvis.downloadmanager;
+
+import dev.prithvis.downloadmanager.config.DownloadThread;
+import dev.prithvis.downloadmanager.models.FileInfo;
+import javafx.collections.FXCollections;
+import javafx.collections.ObservableList;
+import javafx.event.ActionEvent;
+import javafx.fxml.FXML;
+import javafx.scene.control.TableColumn;
+import javafx.scene.control.TableView;
+import javafx.scene.control.TextField;
+
+import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
+
+public class DownloadManager {
+ public final System.Logger LOGGER=System.getLogger(this.getClass().getName());
+ @FXML
+ private TableView downloadTable;
+
+ @FXML
+ private TextField download_url_text_field;
+
+ @FXML
+ private TextField file_name_field;
+
+ @FXML
+ private TextField save_location_field;
+
+ @FXML
+ void downloadButtonClicked(ActionEvent event) {
+ String urlTextField=this.download_url_text_field.getText().trim();
+ String downloadLocation=this.save_location_field.getText().trim();
+ String filename=this.file_name_field.getText().trim();
+ String status="STARTED";
+ String action="OPEN";
+ DateTimeFormatter dateTimeFormatter=DateTimeFormatter.ofPattern("MMMM-dd-yyyy");
+ LocalDate dateNow= LocalDate.now();
+ String date= dateNow.format(dateTimeFormatter);
+ FileInfo file=new FileInfo(downloadLocation,filename,urlTextField,status,action,date);
+ LOGGER.log(System.Logger.Level.INFO,"Download file with info "+file+" started");
+ DownloadThread thread=new DownloadThread(file,this);
+ this.downloadTable.getItems().add(file);
+ thread.start();
+ this.download_url_text_field.setText("");
+ this.file_name_field.setText("");
+ }
+ @FXML
+ public void initialize(){
+ TableColumn location= (TableColumn) this.downloadTable.getColumns().get(0);
+ TableColumn fileName= (TableColumn) this.downloadTable.getColumns().get(1);
+ TableColumn downloadUrl= (TableColumn) this.downloadTable.getColumns().get(2);
+ TableColumn status= (TableColumn) this.downloadTable.getColumns().get(3);
+ TableColumn action= (TableColumn) this.downloadTable.getColumns().get(4);
+ TableColumn addedOn= (TableColumn) this.downloadTable.getColumns().get(5);
+
+ location.setCellValueFactory(p -> p.getValue().locationProperty());
+ fileName.setCellValueFactory(p -> p.getValue().nameProperty());
+ downloadUrl.setCellValueFactory(p -> p.getValue().urlProperty());
+ status.setCellValueFactory(p -> p.getValue().statusProperty());
+ action.setCellValueFactory(p -> p.getValue().actionProperty());
+ addedOn.setCellValueFactory(p -> p.getValue().addedOnProperty());
+
+ LOGGER.log(System.Logger.Level.DEBUG,"Initialized table");
+ }
+ public void updateTable(){
+ this.downloadTable.refresh();
+ }
+}
diff --git a/src/main/java/dev/prithvis/downloadmanager/HelloApplication.java b/src/main/java/dev/prithvis/downloadmanager/HelloApplication.java
deleted file mode 100644
index 58183e9..0000000
--- a/src/main/java/dev/prithvis/downloadmanager/HelloApplication.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package dev.prithvis.downloadmanager;
-
-import javafx.application.Application;
-import javafx.fxml.FXMLLoader;
-import javafx.scene.Scene;
-import javafx.stage.Stage;
-
-import java.io.IOException;
-
-public class HelloApplication extends Application {
- @Override
- public void start(Stage stage) throws IOException {
- FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
- Scene scene = new Scene(fxmlLoader.load(), 320, 240);
- stage.setTitle("Hello!");
- stage.setScene(scene);
- stage.show();
- }
-
- public static void main(String[] args) {
- launch();
- }
-}
\ No newline at end of file
diff --git a/src/main/java/dev/prithvis/downloadmanager/HelloController.java b/src/main/java/dev/prithvis/downloadmanager/HelloController.java
deleted file mode 100644
index bffbb51..0000000
--- a/src/main/java/dev/prithvis/downloadmanager/HelloController.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package dev.prithvis.downloadmanager;
-
-import javafx.fxml.FXML;
-import javafx.scene.control.Label;
-
-public class HelloController {
- @FXML
- private Label welcomeText;
-
- @FXML
- protected void onHelloButtonClick() {
- welcomeText.setText("Welcome to JavaFX Application!");
- }
-}
\ No newline at end of file
diff --git a/src/main/java/dev/prithvis/downloadmanager/MainDownload.java b/src/main/java/dev/prithvis/downloadmanager/MainDownload.java
new file mode 100644
index 0000000..e9f7dac
--- /dev/null
+++ b/src/main/java/dev/prithvis/downloadmanager/MainDownload.java
@@ -0,0 +1,29 @@
+package dev.prithvis.downloadmanager;
+
+import javafx.application.Application;
+import javafx.fxml.FXMLLoader;
+import javafx.scene.Parent;
+import javafx.scene.Scene;
+import javafx.stage.Stage;
+
+import java.io.IOException;
+import java.util.ResourceBundle;
+
+public class MainDownload extends Application {
+ public final System.Logger LOGGER= System.getLogger(this.getClass().getName());
+ @Override
+ public void start(Stage stage) throws IOException {
+ ResourceBundle resourceBundle=ResourceBundle.getBundle("application");
+ FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/download-manager.fxml"),resourceBundle);
+ Parent root = loader.load();
+ LOGGER.log(System.Logger.Level.INFO,"Started application");
+ Scene scene = new Scene(root,800,600);
+ stage.setTitle("Download Manager");
+ stage.setScene(scene);
+ stage.show();
+ }
+
+ public static void main(String[] args) {
+ launch(args);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/dev/prithvis/downloadmanager/config/DownloadThread.java b/src/main/java/dev/prithvis/downloadmanager/config/DownloadThread.java
new file mode 100644
index 0000000..71b970d
--- /dev/null
+++ b/src/main/java/dev/prithvis/downloadmanager/config/DownloadThread.java
@@ -0,0 +1,44 @@
+package dev.prithvis.downloadmanager.config;
+
+import dev.prithvis.downloadmanager.DownloadManager;
+import dev.prithvis.downloadmanager.models.FileInfo;
+
+import java.io.IOException;
+import java.net.URL;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+public class DownloadThread extends Thread{
+ public FileInfo file;
+ public final System.Logger LOGGER=System.getLogger(this.getClass().getName());
+ private final DownloadManager manager;
+ public DownloadThread(FileInfo file,DownloadManager manager){
+ this.file=file;
+ this.manager=manager;
+ }
+ @Override
+ public void run(){
+ this.file.setStatus("DOWNLOADING");
+ this.manager.updateTable();
+ try {
+ Files.copy((new URL(this.file.getUrl()).openStream()), Paths.get(file.getLocation(), file.getName()));
+ this.file.setStatus("DOWNLOADED");
+ LOGGER.log(System.Logger.Level.INFO,String.format("%s downloaded at %s",
+ file.getName(),file.getLocation()));
+ }catch (FileAlreadyExistsException fileAlreadyExistsException){
+ this.file.setStatus("SKIPPED");
+ LOGGER.log(System.Logger.Level.WARNING,String.format("%s already exists at %s.Skipping download"
+ ,file.getName(),file.getLocation()));
+ }
+ catch (IOException e) {
+ this.file.setStatus("FAILED");
+ LOGGER.log(System.Logger.Level.ERROR,String.format("Download of %s failed because of %s",
+ file.getName(),e.getMessage()));
+ throw new RuntimeException(e);
+ }
+ this.manager.updateTable();
+ LOGGER.log(System.Logger.Level.INFO,String.format("Download of %s completed",
+ file.getName()));
+ }
+}
diff --git a/src/main/java/dev/prithvis/downloadmanager/models/FileInfo.java b/src/main/java/dev/prithvis/downloadmanager/models/FileInfo.java
new file mode 100644
index 0000000..c0e7989
--- /dev/null
+++ b/src/main/java/dev/prithvis/downloadmanager/models/FileInfo.java
@@ -0,0 +1,100 @@
+package dev.prithvis.downloadmanager.models;
+
+import javafx.beans.property.SimpleStringProperty;
+
+
+public class FileInfo {
+ private final SimpleStringProperty location=new SimpleStringProperty();
+ private final SimpleStringProperty name=new SimpleStringProperty();
+ private final SimpleStringProperty url=new SimpleStringProperty();
+ private final SimpleStringProperty status=new SimpleStringProperty();
+ private final SimpleStringProperty action=new SimpleStringProperty();
+ private final SimpleStringProperty addedOn=new SimpleStringProperty();
+
+ public FileInfo(String downloadLocation, String filename, String urlTextField, String status, String action, String date) {
+ this.setLocation(downloadLocation);
+ this.setName(filename);
+ this.setUrl(urlTextField);
+ this.setStatus(status);
+ this.setAction(action);
+ this.setAddedOn(date);
+ }
+
+ public String getLocation() {
+ return location.get();
+ }
+
+ public SimpleStringProperty locationProperty() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location.set(location);
+ }
+
+ public String getName() {
+ return name.get();
+ }
+
+ public SimpleStringProperty nameProperty() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name.set(name);
+ }
+
+ public String getUrl() {
+ return url.get();
+ }
+
+ public SimpleStringProperty urlProperty() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url.set(url);
+ }
+
+ public String getStatus() {
+ return status.get();
+ }
+
+ public SimpleStringProperty statusProperty() {
+ return status;
+ }
+
+ public void setStatus(String status) {
+ this.status.set(status);
+ }
+
+ public String getAddedOn() {
+ return addedOn.get();
+ }
+
+ public SimpleStringProperty addedOnProperty() {
+ return addedOn;
+ }
+
+ public void setAddedOn(String addedOn) {
+ this.addedOn.set(addedOn);
+ }
+
+ public String getAction() {
+ return action.get();
+ }
+
+ public SimpleStringProperty actionProperty() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action.set(action);
+ }
+
+ @Override
+ public String toString() {
+ return "name=" + name.get() +
+ ",location=" + location.get();
+ }
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
new file mode 100644
index 0000000..27fb8fa
--- /dev/null
+++ b/src/main/resources/application.properties
@@ -0,0 +1,2 @@
+DOWNLOAD_PATH=/Users/prithvisingh/Documents/Downloads
+
diff --git a/src/main/resources/dev/prithvis/downloadmanager/hello-view.fxml b/src/main/resources/dev/prithvis/downloadmanager/hello-view.fxml
deleted file mode 100644
index 83c06df..0000000
--- a/src/main/resources/dev/prithvis/downloadmanager/hello-view.fxml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/main/resources/fxml/download-manager.fxml b/src/main/resources/fxml/download-manager.fxml
new file mode 100644
index 0000000..d2f9c7d
--- /dev/null
+++ b/src/main/resources/fxml/download-manager.fxml
@@ -0,0 +1,106 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+