[IMPL] path supports dir and files now

This commit is contained in:
RatzzFatzz
2020-02-11 19:58:27 +01:00
parent 5c36511774
commit 5c37fc6842
3 changed files with 34 additions and 7 deletions

View File

@@ -1,3 +1,4 @@
import config.CustomOutputStream;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import model.FileAttribute; import model.FileAttribute;
import query.QueryBuilder; import query.QueryBuilder;
@@ -17,7 +18,7 @@ public class GUI {
private JButton openFileBrowser; private JButton openFileBrowser;
private JButton startOperation; private JButton startOperation;
private JButton openProperties; private JButton openProperties;
private JTextPane outputArea; private JTextArea outputArea;
public GUI() { public GUI() {
JFrame frame = new JFrame(); JFrame frame = new JFrame();
@@ -28,7 +29,10 @@ public class GUI {
JPanel top = new JPanel(new GridLayout(1, 3, 20, 20)); JPanel top = new JPanel(new GridLayout(1, 3, 20, 20));
outputArea = new JTextPane(); outputArea = new JTextArea();
PrintStream printStream = new PrintStream(new CustomOutputStream(outputArea));
System.setOut(printStream);
System.setErr(printStream);
outputArea.setEditable(false); outputArea.setEditable(false);
openFileBrowser = new JButton("Browse directory"); openFileBrowser = new JButton("Browse directory");
@@ -38,7 +42,7 @@ public class GUI {
JFileChooser fileChooser = new JFileChooser(); JFileChooser fileChooser = new JFileChooser();
try{ try{
if(! readFile("lastDir", Charset.defaultCharset()).isEmpty()){ if(! readFile("lastDir", Charset.defaultCharset()).isEmpty()){
String temp = readFile("dir.txt", Charset.defaultCharset()); String temp = readFile("lastDir", Charset.defaultCharset());
fileChooser.setCurrentDirectory(new File(temp)); fileChooser.setCurrentDirectory(new File(temp));
} }
}catch(IOException ie){ }catch(IOException ie){
@@ -61,7 +65,7 @@ public class GUI {
startOperation.setEnabled(true); startOperation.setEnabled(true);
} }
}catch(NullPointerException ne){ }catch(NullPointerException ne){
outputArea.setText("File or directory not found!\n" + (outputArea.getText() == null ? "" : outputArea.getText())); System.out.println("File or directory not found!");
log.error("File or directory not found!", ne); log.error("File or directory not found!", ne);
} }
} }
@@ -76,7 +80,8 @@ public class GUI {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
QueryBuilder queryBuilder = new QueryBuilder(); QueryBuilder queryBuilder = new QueryBuilder();
if(queryBuilder.executeUpdateOnAllFiles(path, outputArea)){ if(queryBuilder.executeUpdateOnAllFiles(path, outputArea)){
outputArea.setText("All files updated!\n" + (outputArea.getText() == null ? "" : outputArea.getText())); log.info("All files updated!");
System.out.println("All files updated!");
} }
} }
}); });

View File

@@ -0,0 +1,21 @@
package config;
import javax.swing.*;
import java.io.IOException;
import java.io.OutputStream;
public class CustomOutputStream extends OutputStream {
private JTextArea textArea;
public CustomOutputStream(JTextArea textArea) {
this.textArea = textArea;
}
@Override
public void write(int b) throws IOException {
// redirects data to the text area
textArea.append(String.valueOf((char) b));
// scrolls the text area to the end of data
textArea.setCaretPosition(textArea.getDocument().getLength());
}
}

View File

@@ -24,7 +24,7 @@ public class QueryBuilder {
public QueryBuilder() { public QueryBuilder() {
} }
public boolean executeUpdateOnAllFiles(String path, JTextPane outputArea) { public boolean executeUpdateOnAllFiles(String path, JTextArea outputArea) {
List<String> allFilePaths = getAllFilesFromDirectory(path); List<String> allFilePaths = getAllFilesFromDirectory(path);
if(allFilePaths == null){ if(allFilePaths == null){
log.error("Couldn't process path!"); log.error("Couldn't process path!");
@@ -32,7 +32,8 @@ public class QueryBuilder {
} }
for(String filePath : allFilePaths){ for(String filePath : allFilePaths){
updateAttributes(filePath, queryAttributes(filePath)); updateAttributes(filePath, queryAttributes(filePath));
outputArea.setText("Success: " + filePath + "\n" + outputArea.getPage()); log.info("Success: " + filePath);
System.out.println("Success: " + filePath);
} }
return true; return true;
} }