Implemented main functionality
This commit is contained in:
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
82
pom.xml
82
pom.xml
@@ -8,5 +8,87 @@
|
|||||||
<artifactId>exif-image-rotation-tool</artifactId>
|
<artifactId>exif-image-rotation-tool</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.7.0</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-dependencies</id>
|
||||||
|
<phase>prepare-package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-dependencies</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||||
|
<overWriteReleases>false</overWriteReleases>
|
||||||
|
<overWriteSnapshots>false</overWriteSnapshots>
|
||||||
|
<overWriteIfNewer>true</overWriteIfNewer>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<addClasspath>true</addClasspath>
|
||||||
|
<classpathPrefix>lib/</classpathPrefix>
|
||||||
|
<mainClass>org.lalber.tools.exifrotation.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>org.lalber.tools.exifrotation.Main</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
<descriptorRefs>
|
||||||
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
|
</descriptorRefs>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||||
|
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||||
|
<goals>
|
||||||
|
<goal>single</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>javaxt.com</id>
|
||||||
|
<url>http://www.javaxt.com/maven</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javaxt</groupId>
|
||||||
|
<artifactId>javaxt-core</artifactId>
|
||||||
|
<version>1.9.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
83
src/main/java/org/lalber/tools/exifrotation/Main.java
Normal file
83
src/main/java/org/lalber/tools/exifrotation/Main.java
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
package org.lalber.tools.exifrotation;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.EtchedBorder;
|
||||||
|
import javax.swing.border.TitledBorder;
|
||||||
|
import javaxt.io.Image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Lucas Alber
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Main entry point to application.
|
||||||
|
*
|
||||||
|
* @param args not used.
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
File folder = showFileSelectionDialog();
|
||||||
|
if (folder == null) return;
|
||||||
|
|
||||||
|
JPanel mainPanel = new JPanel();
|
||||||
|
mainPanel.setBorder(new TitledBorder(new EtchedBorder(), "Process:"));
|
||||||
|
|
||||||
|
JTextArea textArea = new JTextArea(16, 58);
|
||||||
|
textArea.setEditable(false);
|
||||||
|
JScrollPane scroll = new JScrollPane(textArea);
|
||||||
|
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
|
|
||||||
|
mainPanel.add(scroll);
|
||||||
|
|
||||||
|
JFrame frame = new JFrame();
|
||||||
|
frame.setTitle("Exif Image-Rotation Tool");
|
||||||
|
frame.add(mainPanel);
|
||||||
|
frame.pack();
|
||||||
|
frame.setLocationRelativeTo(null);
|
||||||
|
frame.setVisible(true);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Files.walk(folder.toPath())
|
||||||
|
.filter(Main::isImage)
|
||||||
|
.forEach(p -> {
|
||||||
|
textArea.append("Processing: " + p.getFileName().toString() + "\n");
|
||||||
|
Image img = new Image(p.toFile());
|
||||||
|
img.rotate();
|
||||||
|
img.saveAs(p.toFile());
|
||||||
|
});
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.err.println("Error processing images!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
textArea.append("FINISHED!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a Dialog to choose a Directory.
|
||||||
|
* @return the directory or null if the dialog was closed
|
||||||
|
*/
|
||||||
|
private static File showFileSelectionDialog() {
|
||||||
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
|
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||||||
|
if (fileChooser.showDialog(null, "OK") != JFileChooser.APPROVE_OPTION)
|
||||||
|
return null;
|
||||||
|
return fileChooser.getSelectedFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isImage(Path p) {
|
||||||
|
try {
|
||||||
|
String content = Files.probeContentType(p);
|
||||||
|
if (content == null) return false;
|
||||||
|
return content.split("/")[0].equals("image");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user