diff options
Diffstat (limited to 'src/main/java/DownloadConfigPane.java')
| -rw-r--r-- | src/main/java/DownloadConfigPane.java | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/src/main/java/DownloadConfigPane.java b/src/main/java/DownloadConfigPane.java index 058cc07..ba2f6dd 100644 --- a/src/main/java/DownloadConfigPane.java +++ b/src/main/java/DownloadConfigPane.java @@ -4,6 +4,8 @@ import javax.swing.table.DefaultTableModel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.nio.file.Files; public class DownloadConfigPane extends JFrame{ @@ -76,7 +78,11 @@ public class DownloadConfigPane extends JFrame{ saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - saveConfigToFile(); + try { + saveConfigToFile(); + } catch (IOException ex) { + throw new RuntimeException(ex); + } } }); } @@ -112,6 +118,19 @@ public class DownloadConfigPane extends JFrame{ return null; } + private File selectDirectoryFileChooser(){ + JFileChooser chooser = new JFileChooser(); + chooser.setCurrentDirectory(new File(System.getProperty("user.home"))); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + int result = chooser.showOpenDialog(this); + if (result == JFileChooser.APPROVE_OPTION) { + File selectedFile = chooser.getSelectedFile(); + System.out.println("Selected file: " + selectedFile.getAbsolutePath()); + return selectedFile; + } + return null; + } + private void loadConfigFromFile(){ File file = selectTextFileChooser(); if (file == null){ @@ -158,12 +177,16 @@ public class DownloadConfigPane extends JFrame{ } - private void saveConfigToFile(){ + private void saveConfigToFile() throws IOException { if(loadedPath == null){ - System.out.println("No file loaded"); - return; + File selectedDirectory = selectDirectoryFileChooser(); + if (selectedDirectory == null){ + return; + } + loadedPath = selectedDirectory.getAbsolutePath() + "/download_config.txt"; } File saveFile = new File(loadedPath); + FileWriter writer = new FileWriter(saveFile); if(!saveFile.exists()){ System.out.println("File does not exist"); return; @@ -172,9 +195,22 @@ public class DownloadConfigPane extends JFrame{ String url = (String) outputTable.getValueAt(i, 0); String from = (String) outputTable.getValueAt(i, 1); String to = (String) outputTable.getValueAt(i, 2); - String line = url + "," + from + "-" + to; + String line = ""; + if (from.equals("00:00:00") && to.equals("00:00:00")){ + line = url; + } + else{ + line = url + "," + from + "-" + to; + } + try{ + writer.write(line + System.lineSeparator()); + } + catch (Exception e){ + e.printStackTrace(); + } System.out.println(line); } + writer.close(); JOptionPane.showConfirmDialog(null, "Saved to " + loadedPath, "Saved", JOptionPane.DEFAULT_OPTION); } |
