Skip to content

Commit

Permalink
serialization/deserialization of ICF state, UI fixes, more classes ar…
Browse files Browse the repository at this point in the history
…e final
  • Loading branch information
kamil-sita committed Feb 13, 2020
1 parent 07c3431 commit dad43a2
Show file tree
Hide file tree
Showing 16 changed files with 164 additions and 28 deletions.
14 changes: 7 additions & 7 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ <h3>Modules:</h3>
<h3>Image copy finder</h3>
<h4>Description:</h4>
Image copy finder attempts to find copies of images in folders selected by the user. After initial scan
should any pairs of similar-looking images be found, they are displayed to the user, who can decide
to move one of them into user-selected "delete" folder or ignore that pair.
if any pairs of similar-looking images are found, they are displayed to the user. User can then decide for each pair
to move one of the images into user-selected "delete" folder or ignore that pair.

<h4>Important tip:</h4>

If you compare a large amount of images it might not only take a long time, but also a lot of memory space.
The application won't crash, but the thread that compares images will be probably killed, resulting in no progress
The application might not crash, but the thread that compares images will be probably killed, resulting in no progress
at all.
If you fear that it might happen, select lower size of compared image (for example less than 64)

Expand Down Expand Up @@ -98,14 +98,14 @@ <h4>How it works:</h4>
they
are added as a pair to list containing similar images.
</ol>
After completing those two phases list of images is displayed to the user.
After completing those two phases list of pairs of images is displayed to the user.
</div>
<hr/>

<div>
<h3>Scanprocessing</h3>
<h3>Scan-processing</h3>
<h4>Description:</h4>
This module contains filters created to make printing scanned or photographed text or pictures clearer.
This module contains filters created to make printed images cleaner, no matter whether they come from image or from presentation, or from a book.
Filters can be used on either a single image or on .pdf file. <br/> <br/>
Currently there are two modules: high-pass-filter and quantization. <br/>
High pass filter works by dividing the original image by the blurred version of it. <br/>
Expand All @@ -129,7 +129,7 @@ <h3>Image compression</h3>
<h4>Description:</h4>
Image compression uses my custom lossy compression algorithm to compress images. It uses a combination of chroma
subsampling, dictionary compression and RLE compression. Additional improvements are planned. <br/>
<b>Do not use it for serious storage currently - it is too slow and sometimes the files are damaged</b>
<b><u>Do not use it for serious storage currently - it is too slow and sometimes the files are damaged</u></b>
<h4>File structure:</h4>
Best way to describe algorithm is to describe its file structure (somewhat outdated currently):
<ol>
Expand Down
6 changes: 5 additions & 1 deletion docs/ss.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
strong, b {
font-weight: bold;
}

body {
background-color: rgb(248, 248, 248);
max-width: 700px;
Expand All @@ -24,4 +28,4 @@ p, h1, h2, h3, h4 {
div {
font-weight: lighter;
color: rgb(32, 32, 32);
}
}
2 changes: 1 addition & 1 deletion src/main/java/XIS/WindowStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void start(Stage stage) throws Exception{
var res = getClass().getResource("main/mainView.fxml");

Parent root = FXMLLoader.load(res);
stage.setTitle("XIS 0.4.1");
stage.setTitle("XIS 0.5.0");
stage.setScene(new Scene (root, 1280, 800));
stage.setMinHeight(480);
stage.setMinWidth(800);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/XIS/sections/GlobalSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ public class GlobalSettings {

private static GlobalSettings globalSettingsInstance;

private int maxThreads = Integer.MAX_VALUE;

public GlobalSettings() {

}

private int availableProcessors = -1;

public int getNormalizedThreadCount() {
if (availableProcessors == -1) {
availableProcessors = Math.max(Math.min(Runtime.getRuntime().availableProcessors(), maxThreads), 1);
final int MAX_THREADS = Integer.MAX_VALUE;
availableProcessors = Math.max(Math.min(Runtime.getRuntime().availableProcessors(), MAX_THREADS), 1);
}
return availableProcessors;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/XIS/sections/compression/compression.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Button layoutX="7.0" layoutY="14.0" mnemonicParsing="false" onAction="#loadFilePress" text="load image" AnchorPane.leftAnchor="7.0" AnchorPane.topAnchor="14.0" />
<Button layoutX="1127.0" layoutY="14.0" mnemonicParsing="false" onAction="#saveFilePress" text="save file" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="49.0" />
<Button layoutX="1018.0" layoutY="14.0" mnemonicParsing="false" onAction="#compressButton" text="compress" AnchorPane.rightAnchor="7.0" AnchorPane.topAnchor="14.0" />
<ImageView fx:id="imagePreview" fitHeight="195.0" fitWidth="1152.0" layoutX="14.0" layoutY="96.0" pickOnBounds="true" preserveRatio="true" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="34.0" AnchorPane.topAnchor="96.0" />
<ImageView fx:id="imagePreview" fitHeight="231.0" fitWidth="1152.0" layoutX="14.0" layoutY="96.0" pickOnBounds="true" preserveRatio="true" AnchorPane.bottomAnchor="12.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="34.0" AnchorPane.topAnchor="96.0" />
<Separator layoutX="12.0" layoutY="82.0" prefWidth="200.0" AnchorPane.leftAnchor="12.0" AnchorPane.rightAnchor="12.0" AnchorPane.topAnchor="82.0" />
<TextField fx:id="yWeight" layoutX="299.0" layoutY="16.0" prefHeight="25.0" prefWidth="74.0" AnchorPane.leftAnchor="299.0" AnchorPane.topAnchor="14.0" />
<Text layoutX="245.0" layoutY="33.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Y weight" AnchorPane.leftAnchor="245.0" AnchorPane.topAnchor="20.0" />
Expand All @@ -22,6 +22,6 @@
<TextField fx:id="blockSize" layoutX="607.0" layoutY="16.0" prefHeight="25.0" prefWidth="74.0" text="32" AnchorPane.leftAnchor="607.0" AnchorPane.topAnchor="14.0" />
<Button layoutX="89.0" layoutY="15.0" mnemonicParsing="false" onAction="#loadCompressedFilePress" text="load compressed image" AnchorPane.leftAnchor="90.0" AnchorPane.topAnchor="14.0" />
<Button layoutX="1063.0" layoutY="49.0" mnemonicParsing="false" onAction="#statisticPress" text="Statistic" AnchorPane.rightAnchor="70.0" AnchorPane.topAnchor="49.0" />
<CheckBox fx:id="allowReordering" layoutX="694.0" layoutY="18.0" mnemonicParsing="false" text="Allow reordering" AnchorPane.leftAnchor="694.0" />
<CheckBox fx:id="allowReordering" layoutX="694.0" layoutY="18.0" mnemonicParsing="false" text="Allow reordering" AnchorPane.leftAnchor="694.0" AnchorPane.topAnchor="18.0" />
</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import java.util.Collections;
import java.util.List;

public class ComparableImageIO {
public final class ComparableImageIO {

public static List<ComparableImage> loadFiles(List<GroupedFolder> groupedFolders, int generatedMiniatureSize, Interruptible interruptible) {
interruptible.reportProgress("Finding files in folder");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package XIS.sections.imagecopyfinder;

import java.io.Serializable;

/**
* Pair of compared images images
*/
public final class ComparedImagePair {
public final class ComparedImagePair implements Serializable {

private ComparedImage image1;
private ComparedImage image2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.File;

public class GroupedFile {
public final class GroupedFile {
private int groupId;
private CompareGroup compareGroup;
private File file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.io.File;

public class GroupedFolder {
public final class GroupedFolder {
private int groupId;
private CompareGroup compareGroup;
private boolean openRecursively;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import static XIS.sections.imagecopyfinder.CompareGroup.*;

public class GroupedFoldersParser {
public final class GroupedFoldersParser {
public static List<GroupedFolder> parse(String[] input) {
ArrayList<GroupedFolder> groupedFolders = new ArrayList<>();
int currentGroupdId = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import XIS.sections.Vista;

import java.nio.file.FileSystems;
import java.util.List;

public final class ImageCopyFinderModuleVista extends Vista {

private static final String LOCATION_VIEW1 = "/XIS/sections/imagecopyfinder/view1settings/view1.fxml";
private static final String LOCATION_VIEW2 = "/XIS/sections/imagecopyfinder/view2comparison/view2.fxml";
private static ImageComparator imageComparator;
private static List<ComparedImagePair> imagePairList;
private static String deleteDirectory;
private static int imageSize;
private static String inputString;

public ImageCopyFinderModuleVista() {
this.defaultLocation = LOCATION_VIEW1;
Expand All @@ -26,12 +29,12 @@ public void setInterface(ImageCopyFinderViews view) {
}
}

public static ImageComparator getImageComparator() {
return imageComparator;
public static List<ComparedImagePair> getImagePairList() {
return imagePairList;
}

public static void setImageComparator(ImageComparator imageComparator) {
ImageCopyFinderModuleVista.imageComparator = imageComparator;
public static void setImagePairList(List<ComparedImagePair> imagePairList) {
ImageCopyFinderModuleVista.imagePairList = imagePairList;
}

public static String getDeleteDirectory() {
Expand All @@ -46,6 +49,22 @@ public static void setDeleteDirectory(String loc) {
deleteDirectory = loc;
}

public static int getImageSize() {
return imageSize;
}

public static void setImageSize(int imageSize) {
ImageCopyFinderModuleVista.imageSize = imageSize;
}

public static String getInputString() {
return inputString;
}

public static void setInputString(String inputString) {
ImageCopyFinderModuleVista.inputString = inputString;
}

public enum ImageCopyFinderViews {
mainView, compareCopiedImagesView
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package XIS.sections.imagecopyfinder;

public class ParsingException extends RuntimeException {
public final class ParsingException extends RuntimeException {
public ParsingException(String cause, String line, int lineId) {
super("Parsing exception caused by " + cause + ", at line (" + lineId + "): " + System.lineSeparator() + line);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package XIS.sections.imagecopyfinder;

import java.io.*;
import java.util.List;

public final class SerializableIcfState implements Serializable {

public static final long serialVersionUID = 1L;
private List<ComparedImagePair> imagePairs;
private String inputCommand;
private int inputImageSize;
private String inputCommandDeleteLocation;

public SerializableIcfState(List<ComparedImagePair> imagePairs, String inputCommand, int inputImageSize, String inputCommandDeleteLocation) {
this.imagePairs = imagePairs;
this.inputCommand = inputCommand;
this.inputImageSize = inputImageSize;
this.inputCommandDeleteLocation = inputCommandDeleteLocation;
}

public List<ComparedImagePair> getImagePairs() {
return imagePairs;
}

public String getInputCommand() {
return inputCommand;
}

public int getInputImageSize() {
return inputImageSize;
}

public String getInputCommandDeleteLocation() {
return inputCommandDeleteLocation;
}

public static boolean serialize(SerializableIcfState serializableIcfState) {
try (ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("icf.serialized"))) {
outputStream.writeObject(serializableIcfState);
outputStream.close();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}

public static SerializableIcfState deserialize() {
try (ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream("icf.serialized"))) {
return (SerializableIcfState) inputStream.readObject();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import XIS.sections.Interruptible;
import XIS.sections.SingleJobManager;
import XIS.sections.UserFeedback;
import XIS.sections.XisController;
import XIS.sections.imagecopyfinder.FolderImageComparator;
import XIS.sections.imagecopyfinder.ImageComparator;
import XIS.sections.imagecopyfinder.ImageCopyFinderModuleVista;
import XIS.sections.imagecopyfinder.SerializableIcfState;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -66,10 +68,50 @@ public Runnable onUninterruptedFinish() {

}


@FXML
void restoreOldSettingsPress(ActionEvent event) {
var state = getState();
if (state == null) {
UserFeedback.getInstance().popup("Could not load state!");
return;
}
folderLocations.setText(state.getInputCommand());
deleteFolder.setText(state.getInputCommandDeleteLocation());
int index = imageSizeComboBox.getItems().indexOf(state.getInputImageSize());
if (index < 0) index = 0;
imageSizeComboBox.getSelectionModel().select(index);

}

@FXML
void restoreOldStatePress(ActionEvent event) {
var state = getState();
if (state == null) {
UserFeedback.getInstance().popup("Could not load state!");
return;
}

ImageCopyFinderModuleVista.setImagePairList(state.getImagePairs());
ImageCopyFinderModuleVista.setDeleteDirectory(state.getInputCommandDeleteLocation());
ImageCopyFinderModuleVista.setImageSize(state.getInputImageSize());
ImageCopyFinderModuleVista.setInputString(state.getInputCommand());

getMainViewController().getImageCopyFinder().setInterface(ImageCopyFinderModuleVista.ImageCopyFinderViews.compareCopiedImagesView);
refreshVista();
}

private SerializableIcfState getState() {
return SerializableIcfState.deserialize();
}

private void onFinish(ImageComparator imageComparator) {
if (imageComparator.getStatus() == ImageComparator.ImageComparatorStatus.SUCCESSFUL) {
ImageCopyFinderModuleVista.setImageComparator(imageComparator);
ImageCopyFinderModuleVista.setImagePairList(imageComparator.getImagePairs());
ImageCopyFinderModuleVista.setDeleteDirectory(deleteFolder.getText());
ImageCopyFinderModuleVista.setImageSize(imageSizeComboBox.getValue());
ImageCopyFinderModuleVista.setInputString(folderLocations.getText());

getMainViewController().getImageCopyFinder().setInterface(ImageCopyFinderModuleVista.ImageCopyFinderViews.compareCopiedImagesView);
refreshVista();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
<TextArea fx:id="folderLocations" layoutX="14.0" layoutY="176.0" prefHeight="113.0" prefWidth="1158.0" AnchorPane.leftAnchor="21.0" AnchorPane.rightAnchor="21.0" AnchorPane.topAnchor="176.0" />
<Label layoutX="14.0" layoutY="300.0" styleClass="caption" text="Move deleted to" AnchorPane.leftAnchor="14.0" AnchorPane.topAnchor="300.0" />
<TextField fx:id="deleteFolder" layoutX="24.0" layoutY="329.0" prefHeight="25.0" prefWidth="1158.0" AnchorPane.leftAnchor="21.0" AnchorPane.rightAnchor="21.0" AnchorPane.topAnchor="329.0" />
<Button layoutX="1054.0" layoutY="80.0" mnemonicParsing="false" onAction="#restoreOldStatePress" prefHeight="25.0" prefWidth="129.0" text="Restore old state" AnchorPane.rightAnchor="17.0" AnchorPane.topAnchor="85.0" />
<Button layoutX="1054.0" layoutY="118.0" mnemonicParsing="false" onAction="#restoreOldSettingsPress" prefHeight="25.0" prefWidth="129.0" text="Restore old settings" AnchorPane.rightAnchor="17.0" AnchorPane.topAnchor="120.0" />
</children>
</AnchorPane>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import XIS.sections.imagecopyfinder.ComparedImage;
import XIS.sections.imagecopyfinder.ComparedImagePair;
import XIS.sections.imagecopyfinder.ImageCopyFinderModuleVista;
import XIS.sections.imagecopyfinder.SerializableIcfState;
import XIS.sections.imagecopyfinder.imageinfoview.ImageInfoView;
import XIS.sections.imagecopyfinder.imageinfoview.ImageInfoViewController;
import javafx.collections.FXCollections;
Expand All @@ -31,6 +32,8 @@ public final class View2Controller extends XisController {
private List<ComparedImagePair> imagePairs;
private ComparedImagePair hoveredElement;
private String deleteLocation;
private String inputCommand;
private int imageInputSize;

@FXML
private ListView<ComparedImagePair> comparableImagePairListView;
Expand All @@ -55,7 +58,13 @@ public final class View2Controller extends XisController {

@FXML
void serializePress(ActionEvent event) {
UserFeedback.getInstance().popup("No implementation!");
SerializableIcfState icfState = new SerializableIcfState(imagePairs, inputCommand, imageInputSize, deleteLocation);
boolean result = SerializableIcfState.serialize(icfState);
if (result) {
UserFeedback.getInstance().popup("Saved successfully!");
} else {
UserFeedback.getInstance().popup("Could not save!");
}
}


Expand Down Expand Up @@ -90,6 +99,8 @@ public void initialize() {
});

deleteLocation = ImageCopyFinderModuleVista.getDeleteDirectory();
imageInputSize = ImageCopyFinderModuleVista.getImageSize();
inputCommand = ImageCopyFinderModuleVista.getInputString();

sliderPercentIdentical.valueProperty().addListener((observable, oldValue, newValue) -> {
double x = sliderPercentIdentical.getValue() / 100.0;
Expand All @@ -109,7 +120,7 @@ protected void updateItem(ComparedImagePair comparedImagePair, boolean empty) {
}
}
);
imagePairs = ImageCopyFinderModuleVista.getImageComparator().getImagePairs();
imagePairs = ImageCopyFinderModuleVista.getImagePairList();
displayAllImages();
comparableImagePairListView.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue) -> elementHovered(newValue)
Expand Down

0 comments on commit dad43a2

Please sign in to comment.