Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauville committed Aug 6, 2019
0 parents commit a9490e5
Show file tree
Hide file tree
Showing 11 changed files with 535 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 74 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mauville.sorth</groupId>
<artifactId>sortH</artifactId>
<version>1.9-SNAPSHOT</version>

<name>sortH</name>
<packaging>jar</packaging>

<properties>
<jdk.version>1.8</jdk.version>
</properties>

<licenses>
<license>
<name>GNU GPLV3</name>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.6.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jolira/onejar-maven-plugin -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>com.jolira</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<mainClass>sample.Main</mainClass>
<onejarVersion>0.97</onejarVersion>
<attachToBuild>true</attachToBuild>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>

</build>

</project>
188 changes: 188 additions & 0 deletions src/main/java/sample/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
package sample;

import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

public class Controller {

private static final Logger LOGGER = LogManager.getLogger(Controller.class);

@FXML
Button button = new Button();
@FXML
Label P = new Label();
@FXML
Label threedee = new Label();
@FXML
Label T = new Label();
@FXML
Label NP = new Label();
@FXML
Label FD = new Label();
@FXML
Label EC = new Label();
@FXML
Label A = new Label();
@FXML
Label O = new Label();
private final Label SKIP = new Label();
@FXML
ImageView imageholder = new ImageView();
@FXML
Text logField = new Text();
@FXML
GridPane nonum = new GridPane();
@FXML
GridPane num = new GridPane();

//Keyboard shortcuts
private final KeyCombination PCode = new KeyCodeCombination(KeyCode.DIGIT8);
private final KeyCombination threedeeCode = new KeyCodeCombination(KeyCode.DIGIT4);
private final KeyCombination TCode = new KeyCodeCombination(KeyCode.DIGIT2);
private final KeyCombination NPCode = new KeyCodeCombination(KeyCode.DIGIT6);
private final KeyCombination FDCode = new KeyCodeCombination(KeyCode.DIGIT8, KeyCombination.CONTROL_DOWN);
private final KeyCombination ECCode = new KeyCodeCombination(KeyCode.DIGIT4, KeyCombination.CONTROL_DOWN);
private final KeyCombination ACode = new KeyCodeCombination(KeyCode.DIGIT2, KeyCombination.CONTROL_DOWN);
private final KeyCombination OCode = new KeyCodeCombination(KeyCode.DIGIT6, KeyCombination.CONTROL_DOWN);
private final KeyCombination SkipCode = new KeyCodeCombination(KeyCode.DIGIT0, KeyCombination.CONTROL_DOWN);
private final KeyCombination SkipCode2 = new KeyCodeCombination(KeyCode.DIGIT0);

private List<File> imageFiles;
private File cwd;
private int currentImage = 0;
private File currentFile;
private final Runnable rnP = () -> processImage(P);
private final Runnable rnthreedee = () -> processImage(threedee);
private final Runnable rnT = () -> processImage(T);
private final Runnable rnNP = () -> processImage(NP);
private final Runnable rnFD = () -> processImage(FD);
private final Runnable rnEC = () -> processImage(EC);
private final Runnable rnA = () -> processImage(A);
private final Runnable rnO = () -> processImage(O);
private final Runnable rnSKIP = () -> processImage(SKIP);

public void setAccel() {
Scene scn = FD.getScene();
scn.getAccelerators().put(PCode, rnP);
scn.getAccelerators().put(threedeeCode, rnthreedee);
scn.getAccelerators().put(TCode, rnT);
scn.getAccelerators().put(NPCode, rnNP);
scn.getAccelerators().put(FDCode, rnFD);
scn.getAccelerators().put(ECCode, rnEC);
scn.getAccelerators().put(ACode, rnA);
scn.getAccelerators().put(OCode, rnO);
scn.getAccelerators().put(SkipCode, rnSKIP);
scn.getAccelerators().put(SkipCode2, rnSKIP);
LOGGER.info("Set accelerators");

button.setVisible(false);


}

@FXML
public void initialize() {
boot();
SKIP.setText("SKIP");
}


private void processImage(Label dir) {
LOGGER.info(dir.getText());
if (!(dir.getText().equals("SKIP"))) {
File directory2Move2 = null;
try {
directory2Move2 = new File(cwd.getCanonicalPath() + "\\" + dir.getText());
LOGGER.info("Moving to : " + directory2Move2);
} catch (IOException e) {
LOGGER.error("Failed to convert to Canonical Path");
}
try {
FileUtils.moveFileToDirectory(currentFile, directory2Move2, true);
LOGGER.info(currentFile + " " + directory2Move2);
} catch (IOException e) {
LOGGER.error("Failed to move file");
e.printStackTrace();
}
}
logField.setText(dir.getText());
currentImage++;
try {
displayNext();
} catch (FileNotFoundException e) {
LOGGER.error("No further images found");
}
}

private void displayNext() throws FileNotFoundException {
try {
currentFile = imageFiles.get(currentImage);
FileInputStream inputstream;
inputstream = new FileInputStream(currentFile);
Image image = new Image(inputstream);
imageholder.setFitHeight(500);
imageholder.setPreserveRatio(true);
imageholder.setSmooth(true);
imageholder.setImage(image);
inputstream.close();
} catch (IndexOutOfBoundsException e) {
LOGGER.warn("End of Images");
System.exit(0);
} catch (IOException e) {
e.printStackTrace();
}
}


private void boot() {
cwd = openFileChooser();
try {
imageFiles = ImageHandler.getImages(cwd);
} catch (IOException e) {
LOGGER.error("No such directory");
e.printStackTrace();
}
try {
LOGGER.info("Loading Images");
imageFiles = ImageHandler.getImages("C:\\Users\\X220\\Desktop\\images");
cwd = new File("C:\\Users\\X220\\Desktop\\images");
displayNext();
LOGGER.info("Loaded Images");
} catch (IOException e) {
LOGGER.error("No such directory");
}
}

private File openFileChooser() {
Stage filer = new Stage();
DirectoryChooser chooser = new DirectoryChooser();
chooser.setTitle("Choose Directory");
String userWindows = System.getenv("USERPROFILE");
File defaultDirectory = new File(userWindows);
chooser.setInitialDirectory(defaultDirectory);
File mark = chooser.showDialog(filer);
LOGGER.info("Current path" + mark);
return mark;
}

}
24 changes: 24 additions & 0 deletions src/main/java/sample/ImageHandler.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package sample;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.List;

class ImageHandler {

public static List<File> getImages(File dir) throws IOException {
String[] extensions = new String[] { "jpg", "png", "gif" };
System.out.println("Getting all images " + dir.getCanonicalPath()
+ " including those in subdirectories");
return (List<File>) FileUtils.listFiles(dir, extensions,false);
}
public static List<File> getImages(String dir) throws IOException {
String[] extensions = new String[] { "jpg", "png", "gif" };
System.out.println("Getting all images " + dir
+ " including those in subdirectories");
return (List<File>) FileUtils.listFiles(new File (dir), extensions,false);
}

}
31 changes: 31 additions & 0 deletions src/main/java/sample/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.awt.*;

public class Main extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("fxml/sample.fxml"));
primaryStage.setTitle("SortH");
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
Scene scene = new Scene(root, width - width * .2, height - height * .1);
//Listen for scene changes


primaryStage.setScene(scene);
primaryStage.show();
}
}
Binary file added src/main/resources/fxml/noImage.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/main/resources/fxml/sample.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.root {
-fx-font-size: 14px;
-fx-font-family: sans-serif;
-fx-background-color: #bbbbbb;
}
.grid{
-fx-font-size: 19px;
}
.imageview{
-fx-margin: 0,auto;
}
Loading

0 comments on commit a9490e5

Please sign in to comment.