Added a first rudimentary file filter
This commit is contained in:
parent
83b27531e0
commit
935c7eda3e
2 changed files with 69 additions and 11 deletions
|
|
@ -6,6 +6,7 @@ import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
@ -22,6 +23,8 @@ import java.awt.event.ActionEvent;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
|
import javax.swing.BoxLayout;
|
||||||
|
import java.awt.FlowLayout;
|
||||||
|
|
||||||
public class MainForm {
|
public class MainForm {
|
||||||
|
|
||||||
|
|
@ -33,6 +36,12 @@ public class MainForm {
|
||||||
private JButton btnBrowse;
|
private JButton btnBrowse;
|
||||||
private File[] dirs;
|
private File[] dirs;
|
||||||
private JLabel lblDone;
|
private JLabel lblDone;
|
||||||
|
static ArrayList<String> extensions;
|
||||||
|
private SettingsFilter filter;
|
||||||
|
private JPanel panel;
|
||||||
|
private JPanel panel_settings;
|
||||||
|
private JLabel lblSettings;
|
||||||
|
private JTextField textField_extensions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch the application.
|
* Launch the application.
|
||||||
|
|
@ -54,6 +63,8 @@ public class MainForm {
|
||||||
* Create the application.
|
* Create the application.
|
||||||
*/
|
*/
|
||||||
public MainForm() {
|
public MainForm() {
|
||||||
|
filter = new SettingsFilter();
|
||||||
|
extensions = new ArrayList<String>();
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,9 +83,13 @@ public class MainForm {
|
||||||
frmGetYourFiles.setLocationRelativeTo(null);
|
frmGetYourFiles.setLocationRelativeTo(null);
|
||||||
frmGetYourFiles.getContentPane().setLayout(new BorderLayout(0, 0));
|
frmGetYourFiles.getContentPane().setLayout(new BorderLayout(0, 0));
|
||||||
|
|
||||||
|
panel = new JPanel();
|
||||||
|
frmGetYourFiles.getContentPane().add(panel, BorderLayout.NORTH);
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
JPanel panel_path = new JPanel();
|
JPanel panel_path = new JPanel();
|
||||||
|
panel.add(panel_path);
|
||||||
panel_path.setBackground(Color.WHITE);
|
panel_path.setBackground(Color.WHITE);
|
||||||
frmGetYourFiles.getContentPane().add(panel_path, BorderLayout.NORTH);
|
|
||||||
|
|
||||||
lblPath = new JLabel("Path: ");
|
lblPath = new JLabel("Path: ");
|
||||||
panel_path.add(lblPath);
|
panel_path.add(lblPath);
|
||||||
|
|
@ -109,16 +124,30 @@ public class MainForm {
|
||||||
});
|
});
|
||||||
panel_path.add(btnBrowse);
|
panel_path.add(btnBrowse);
|
||||||
|
|
||||||
|
panel_settings = new JPanel();
|
||||||
|
panel_settings.setBackground(Color.WHITE);
|
||||||
|
panel.add(panel_settings);
|
||||||
|
panel_settings.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||||
|
|
||||||
|
lblSettings = new JLabel("Extensions: ");
|
||||||
|
panel_settings.add(lblSettings);
|
||||||
|
|
||||||
|
textField_extensions = new JTextField();
|
||||||
|
panel_settings.add(textField_extensions);
|
||||||
|
textField_extensions.setColumns(35);
|
||||||
|
|
||||||
JButton btnStart = new JButton("Start");
|
JButton btnStart = new JButton("Start");
|
||||||
|
frmGetYourFiles.getContentPane().add(btnStart, BorderLayout.SOUTH);
|
||||||
btnStart.setSelected(true);
|
btnStart.setSelected(true);
|
||||||
btnStart.setBackground(Color.LIGHT_GRAY);
|
btnStart.setBackground(Color.LIGHT_GRAY);
|
||||||
|
|
||||||
frmGetYourFiles.getRootPane().setDefaultButton(btnStart);
|
frmGetYourFiles.getRootPane().setDefaultButton(btnStart);
|
||||||
|
|
||||||
btnStart.addActionListener(new ActionListener() {
|
btnStart.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent arg0) {
|
public void actionPerformed(ActionEvent arg0) {
|
||||||
Thread noBlock = new Thread() {
|
Thread noBlock = new Thread() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
setExtensionSettings();
|
||||||
resetElements();
|
resetElements();
|
||||||
extractFiles();
|
extractFiles();
|
||||||
}
|
}
|
||||||
|
|
@ -131,27 +160,29 @@ public class MainForm {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
frmGetYourFiles.getContentPane().add(btnStart, BorderLayout.SOUTH);
|
|
||||||
|
|
||||||
panel_progress = new JPanel();
|
panel_progress = new JPanel();
|
||||||
panel_progress.setBackground(Color.WHITE);
|
panel_progress.setBackground(Color.WHITE);
|
||||||
frmGetYourFiles.getContentPane().add(panel_progress, BorderLayout.CENTER);
|
frmGetYourFiles.getContentPane().add(panel_progress, BorderLayout.CENTER);
|
||||||
|
|
||||||
lblDone = new JLabel("");
|
lblDone = new JLabel("");
|
||||||
panel_progress.add(lblDone);
|
panel_progress.add(lblDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void extractFiles() {
|
private void extractFiles() {
|
||||||
|
|
||||||
for(File dir:dirs) {
|
for(File dir:dirs) {
|
||||||
try {
|
try {
|
||||||
String parentDir = dir.getCanonicalFile().getParent();
|
String parentDir = dir.getCanonicalFile().getParent();
|
||||||
|
|
||||||
File[] files;
|
File[] files;
|
||||||
files = dir.listFiles();
|
if(MainForm.extensions.size() == 1 && MainForm.extensions.get(0).equals(""))
|
||||||
|
files = dir.listFiles();
|
||||||
|
else
|
||||||
|
files = dir.listFiles(filter);
|
||||||
|
|
||||||
for(File file:files) {
|
for(File file:files) {
|
||||||
Path target = FileSystems.getDefault().getPath(parentDir + "\\" + file.getName());
|
Path target = FileSystems.getDefault().getPath(parentDir + "\\" + file.getName());
|
||||||
|
|
||||||
Files.move(file.toPath(), target, StandardCopyOption.REPLACE_EXISTING);
|
Files.move(file.toPath(), target, StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -171,5 +202,14 @@ public class MainForm {
|
||||||
//progressBar_Extraction.setValue(0);
|
//progressBar_Extraction.setValue(0);
|
||||||
//progressBar_Zip.setValue(0);
|
//progressBar_Zip.setValue(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setExtensionSettings() {
|
||||||
|
String[] extensions = textField_extensions.getText().split(",");
|
||||||
|
if (extensions.length == 0)
|
||||||
|
return;
|
||||||
|
for(String extension:extensions) {
|
||||||
|
MainForm.extensions.add(extension.trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
18
src/eu/seelenoede/getyourfilesoutthere/SettingsFilter.java
Normal file
18
src/eu/seelenoede/getyourfilesoutthere/SettingsFilter.java
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package eu.seelenoede.getyourfilesoutthere;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
|
||||||
|
public class SettingsFilter implements FileFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
String filePath = pathname.getAbsolutePath();
|
||||||
|
String fileExtension = filePath.substring(filePath.lastIndexOf('.') + 1);
|
||||||
|
|
||||||
|
if(MainForm.extensions.contains(fileExtension))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue