mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-10 17:55:57 +01:00
[IMPL] path supports dir and files now
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import config.CustomOutputStream;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import model.FileAttribute;
|
||||
import query.QueryBuilder;
|
||||
@@ -17,7 +18,7 @@ public class GUI {
|
||||
private JButton openFileBrowser;
|
||||
private JButton startOperation;
|
||||
private JButton openProperties;
|
||||
private JTextPane outputArea;
|
||||
private JTextArea outputArea;
|
||||
|
||||
public GUI() {
|
||||
JFrame frame = new JFrame();
|
||||
@@ -28,7 +29,10 @@ public class GUI {
|
||||
|
||||
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);
|
||||
|
||||
openFileBrowser = new JButton("Browse directory");
|
||||
@@ -38,7 +42,7 @@ public class GUI {
|
||||
JFileChooser fileChooser = new JFileChooser();
|
||||
try{
|
||||
if(! readFile("lastDir", Charset.defaultCharset()).isEmpty()){
|
||||
String temp = readFile("dir.txt", Charset.defaultCharset());
|
||||
String temp = readFile("lastDir", Charset.defaultCharset());
|
||||
fileChooser.setCurrentDirectory(new File(temp));
|
||||
}
|
||||
}catch(IOException ie){
|
||||
@@ -61,7 +65,7 @@ public class GUI {
|
||||
startOperation.setEnabled(true);
|
||||
}
|
||||
}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);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +80,8 @@ public class GUI {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
QueryBuilder queryBuilder = new QueryBuilder();
|
||||
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!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
21
src/main/java/config/CustomOutputStream.java
Normal file
21
src/main/java/config/CustomOutputStream.java
Normal 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());
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class QueryBuilder {
|
||||
public QueryBuilder() {
|
||||
}
|
||||
|
||||
public boolean executeUpdateOnAllFiles(String path, JTextPane outputArea) {
|
||||
public boolean executeUpdateOnAllFiles(String path, JTextArea outputArea) {
|
||||
List<String> allFilePaths = getAllFilesFromDirectory(path);
|
||||
if(allFilePaths == null){
|
||||
log.error("Couldn't process path!");
|
||||
@@ -32,7 +32,8 @@ public class QueryBuilder {
|
||||
}
|
||||
for(String filePath : allFilePaths){
|
||||
updateAttributes(filePath, queryAttributes(filePath));
|
||||
outputArea.setText("Success: " + filePath + "\n" + outputArea.getPage());
|
||||
log.info("Success: " + filePath);
|
||||
System.out.println("Success: " + filePath);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user