Exit application on window closed
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package org.lalber.tools.exifrotation;
|
package org.lalber.tools.exifrotation;
|
||||||
|
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.border.EtchedBorder;
|
import javax.swing.border.EtchedBorder;
|
||||||
import javax.swing.border.TitledBorder;
|
import javax.swing.border.TitledBorder;
|
||||||
@@ -14,6 +17,9 @@ import javaxt.io.Image;
|
|||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
private static Thread processingThread;
|
||||||
|
private static boolean aborted;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main entry point to application.
|
* Main entry point to application.
|
||||||
*
|
*
|
||||||
@@ -38,26 +44,48 @@ public class Main {
|
|||||||
frame.add(mainPanel);
|
frame.add(mainPanel);
|
||||||
frame.pack();
|
frame.pack();
|
||||||
frame.setLocationRelativeTo(null);
|
frame.setLocationRelativeTo(null);
|
||||||
|
|
||||||
|
frame.addWindowListener(new WindowAdapter(){
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
if (JOptionPane.showConfirmDialog(frame, "Abort and Close?") == 0) {
|
||||||
|
aborted = true;
|
||||||
|
if (processingThread != null) {
|
||||||
|
try {
|
||||||
|
processingThread.join();
|
||||||
|
} catch (InterruptedException e1) {
|
||||||
|
e1.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
|
|
||||||
try {
|
processingThread = new Thread(() -> {
|
||||||
Files.walk(folder.toPath())
|
try {
|
||||||
.filter(Main::isImage)
|
Files.walk(folder.toPath())
|
||||||
|
.filter(Main::isImage)
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
.parallelStream()
|
.parallelStream()
|
||||||
.forEach(p -> {
|
.forEach(p -> {
|
||||||
textArea.append("Processing: " + p.getFileName().toString() + "\n");
|
if (aborted) return;
|
||||||
Image img = new Image(p.toFile());
|
textArea.append("Processing: " + p.getFileName().toString() + "\n");
|
||||||
img.rotate();
|
Image img = new Image(p.toFile());
|
||||||
img.saveAs(p.toFile());
|
img.rotate();
|
||||||
});
|
img.saveAs(p.toFile());
|
||||||
|
});
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Error processing images!");
|
System.err.println("Error processing images!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
textArea.append("FINISHED!");
|
textArea.append("FINISHED!");
|
||||||
|
});
|
||||||
|
|
||||||
|
processingThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user