Browse Source

Refactor: Code Style Cleanup

* Whitespace fixes (tabs vs spaces for portability)
* EOF whitespace removal
master
Drew Short 7 years ago
parent
commit
031133caaa
  1. 8
      cli/src/main/java/com/sothr/imagetools/cli/AppCLI.java
  2. 2
      engine/src/main/scala/com/sothr/imagetools/engine/ConcurrentEngine.scala
  3. 16
      engine/src/main/scala/com/sothr/imagetools/engine/Engine.scala
  4. 2
      engine/src/main/scala/com/sothr/imagetools/engine/dao/HibernateUtil.scala
  5. 1
      engine/src/main/scala/com/sothr/imagetools/engine/dao/ImageDAO.scala
  6. 1
      engine/src/main/scala/com/sothr/imagetools/engine/image/Image.scala
  7. 10
      engine/src/main/scala/com/sothr/imagetools/engine/image/ImageService.scala
  8. 2
      engine/src/main/scala/com/sothr/imagetools/engine/image/SimilarImages.scala
  9. 1
      engine/src/main/scala/com/sothr/imagetools/engine/util/Timing.scala
  10. 25
      gui/src/main/resources/fxml/mainapp/MainApp.fxml
  11. 1
      gui/src/main/scala/com/sothr/imagetools/ui/component/ImageTileFactory.scala
  12. 37
      gui/src/main/scala/com/sothr/imagetools/ui/component/ImageTilePane.scala
  13. 1
      gui/src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala
  14. 4
      hash/pom.xml
  15. 32
      hash/src/main/scala/com/sothr/imagetools/hash/HashService.scala

8
cli/src/main/java/com/sothr/imagetools/cli/AppCLI.java

@ -8,7 +8,13 @@ import com.sothr.imagetools.engine.CLIEngineListener;
import com.sothr.imagetools.engine.ConcurrentEngine; import com.sothr.imagetools.engine.ConcurrentEngine;
import com.sothr.imagetools.engine.Engine; import com.sothr.imagetools.engine.Engine;
import com.sothr.imagetools.engine.image.SimilarImages; import com.sothr.imagetools.engine.image.SimilarImages;
import org.apache.commons.cli.*;
import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import scala.collection.immutable.List; import scala.collection.immutable.List;

2
engine/src/main/scala/com/sothr/imagetools/engine/ConcurrentEngine.scala

@ -7,9 +7,9 @@ import akka.actor.{Actor, ActorLogging, ActorRef, PoisonPill, Props}
import akka.pattern.ask import akka.pattern.ask
import akka.routing.{Broadcast, RoundRobinPool, SmallestMailboxPool} import akka.routing.{Broadcast, RoundRobinPool, SmallestMailboxPool}
import akka.util.Timeout import akka.util.Timeout
import com.sothr.imagetools.hash.{HashService, ImageHash}
import com.sothr.imagetools.engine.image.{Image, ImageService, SimilarImages} import com.sothr.imagetools.engine.image.{Image, ImageService, SimilarImages}
import com.sothr.imagetools.engine.util.{PropertiesService, PropertyEnum} import com.sothr.imagetools.engine.util.{PropertiesService, PropertyEnum}
import com.sothr.imagetools.hash.HashService
import scala.collection.mutable import scala.collection.mutable
import scala.concurrent.Await import scala.concurrent.Await

16
engine/src/main/scala/com/sothr/imagetools/engine/Engine.scala

@ -69,16 +69,16 @@ abstract class Engine extends Logging {
*/ */
def getSimilarImagesForDirectory(directoryPath: String, recursive: Boolean = false, recursiveDepth: Int = 500): List[SimilarImages] def getSimilarImagesForDirectory(directoryPath: String, recursive: Boolean = false, recursiveDepth: Int = 500): List[SimilarImages]
def deleteImage(image: Image): Unit = {
ImageService.deleteImage(image)
}
def deleteImages(images: List[Image]): Unit = { def deleteImages(images: List[Image]): Unit = {
for (image <- images) { for (image <- images) {
deleteImage(image) deleteImage(image)
} }
} }
def deleteImage(image: Image): Unit = {
ImageService.deleteImage(image)
}
/** /**
* Go through the list of similarities and group them so that they represent actual similarities * Go through the list of similarities and group them so that they represent actual similarities
* *
@ -109,14 +109,16 @@ abstract class Engine extends Logging {
this.searchedListener ! SubmitMessage(s"Cleaning similar images. $count/${similarList.length}") this.searchedListener ! SubmitMessage(s"Cleaning similar images. $count/${similarList.length}")
} }
var foundSimilarity = false var foundSimilarity = false
var similarity:SimilarImages = null
breakable { for (similarImage <- similarImages.similarImages) {
var similarity: SimilarImages = null
breakable {
for (similarImage <- similarImages.similarImages) {
if (similarImageMap.contains(similarImage)) { if (similarImageMap.contains(similarImage)) {
similarity = similarImageMap(similarImage) similarity = similarImageMap(similarImage)
foundSimilarity = true foundSimilarity = true
break() break()
} }
} }
}
}
//if no similarity was found, one should be created //if no similarity was found, one should be created
if (!foundSimilarity) { if (!foundSimilarity) {

2
engine/src/main/scala/com/sothr/imagetools/engine/dao/HibernateUtil.scala

@ -37,6 +37,4 @@ object HibernateUtil extends Logging {
throw new ExceptionInInitializerError(ex) throw new ExceptionInInitializerError(ex)
} }
} }
} }

1
engine/src/main/scala/com/sothr/imagetools/engine/dao/ImageDAO.scala

@ -40,5 +40,4 @@ class ImageDAO {
session.delete(image) session.delete(image)
session.getTransaction.commit() session.getTransaction.commit()
} }
} }

1
engine/src/main/scala/com/sothr/imagetools/engine/image/Image.scala

@ -107,5 +107,4 @@ class Image(val image: String, val thumbnail: String, val size: (Int, Int), val
result = 41 * result + hashes.hashCode() result = 41 * result + hashes.hashCode()
result result
} }
} }

10
engine/src/main/scala/com/sothr/imagetools/engine/image/ImageService.scala

@ -8,8 +8,8 @@ import com.sothr.imagetools.engine.AppConfig
import com.sothr.imagetools.engine.dao.ImageDAO import com.sothr.imagetools.engine.dao.ImageDAO
import com.sothr.imagetools.engine.util.{PropertiesService, PropertyEnum} import com.sothr.imagetools.engine.util.{PropertiesService, PropertyEnum}
import com.sothr.imagetools.engine.vo.ImageHashVO import com.sothr.imagetools.engine.vo.ImageHashVO
import com.sothr.imagetools.hash.{HashService, ImageHash}
import com.sothr.imagetools.hash.util.ImageUtil import com.sothr.imagetools.hash.util.ImageUtil
import com.sothr.imagetools.hash.{HashService, ImageHash}
import grizzled.slf4j.Logging import grizzled.slf4j.Logging
import net.sf.ehcache.Element import net.sf.ehcache.Element
import org.hibernate.HibernateException import org.hibernate.HibernateException
@ -51,10 +51,6 @@ object ImageService extends Logging {
null null
} }
def convertToImageHashDTO(imageHashVO: ImageHashVO): ImageHash = {
new ImageHash(imageHashVO.ahash, imageHashVO.dhash, imageHashVO.phash, imageHashVO.fileHash)
}
def convertToImageHashVO(imageHashDTO: ImageHash): ImageHashVO = { def convertToImageHashVO(imageHashDTO: ImageHash): ImageHashVO = {
new ImageHashVO(imageHashDTO.ahash, imageHashDTO.dhash, imageHashDTO.phash, imageHashDTO.fileHash) new ImageHashVO(imageHashDTO.ahash, imageHashDTO.dhash, imageHashDTO.phash, imageHashDTO.fileHash)
} }
@ -137,6 +133,10 @@ object ImageService extends Logging {
path path
} }
def convertToImageHashDTO(imageHashVO: ImageHashVO): ImageHash = {
new ImageHash(imageHashVO.ahash, imageHashVO.dhash, imageHashVO.phash, imageHashVO.fileHash)
}
def deleteImage(image: Image) = { def deleteImage(image: Image) = {
debug(s"Attempting to delete all traces of image: ${image.getImagePath}") debug(s"Attempting to delete all traces of image: ${image.getImagePath}")
try { try {

2
engine/src/main/scala/com/sothr/imagetools/engine/image/SimilarImages.scala

@ -39,5 +39,5 @@ class SimilarImages(var similarImages: Set[Image]) extends Logging {
} }
object SimilarImagesOrdering extends Ordering[SimilarImages] { object SimilarImagesOrdering extends Ordering[SimilarImages] {
def compare(a:SimilarImages, b:SimilarImages) = a.ordering() compare b.ordering()
def compare(a: SimilarImages, b: SimilarImages) = a.ordering() compare b.ordering()
} }

1
engine/src/main/scala/com/sothr/imagetools/engine/util/Timing.scala

@ -31,5 +31,4 @@ trait Timing extends Logging {
} }
ag / times.length ag / times.length
} }
} }

25
gui/src/main/resources/fxml/mainapp/MainApp.fxml

@ -2,9 +2,28 @@
<!--suppress ALL --> <!--suppress ALL -->
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.Pagination?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.ToolBar?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.TilePane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?> <?import javafx.scene.text.Font?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:id="rootPane" minHeight="600.0" minWidth="1024.0" prefHeight="600.0" <AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:id="rootPane" minHeight="600.0" minWidth="1024.0" prefHeight="600.0"
prefWidth="1024.0" xmlns="http://javafx.com/javafx/8" prefWidth="1024.0" xmlns="http://javafx.com/javafx/8"

1
gui/src/main/scala/com/sothr/imagetools/ui/component/ImageTileFactory.scala

@ -21,5 +21,4 @@ object ImageTileFactory extends Logging {
imageTile imageTile
} }
} }

37
gui/src/main/scala/com/sothr/imagetools/ui/component/ImageTilePane.scala

@ -179,6 +179,24 @@ class ImageTilePaneSelectionModel[ImageTile](parentTilePane: ImageTilePane) exte
this.selectedIndexes.add(index) this.selectedIndexes.add(index)
} }
private def setSelectionFormatting(index: Int): Unit = {
setSelectionFormatting(this.parentTilePane.getChildren.get(index).asInstanceOf[ImageTile])
}
private def setSelectionFormatting(imageTile: ImageTile) = {
val borderStroke = new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderStroke.THIN)
imageTile.asInstanceOf[VBox].setBorder(new Border(borderStroke))
}
private def clearSelectionFormatting() = {
val iterator = this.parentTilePane.getChildren.iterator()
while (iterator.hasNext) {
//remove the selection styling
val imageTile: VBox = iterator.next().asInstanceOf[VBox]
imageTile.setBorder(Border.EMPTY)
}
}
override def clearSelection(index: Int): Unit = { override def clearSelection(index: Int): Unit = {
val i = this.selectedIndexes.indexOf(index) val i = this.selectedIndexes.indexOf(index)
if (i >= 0) { if (i >= 0) {
@ -221,15 +239,6 @@ class ImageTilePaneSelectionModel[ImageTile](parentTilePane: ImageTilePane) exte
} }
} }
private def setSelectionFormatting(index: Int): Unit = {
setSelectionFormatting(this.parentTilePane.getChildren.get(index).asInstanceOf[ImageTile])
}
private def setSelectionFormatting(imageTile: ImageTile) = {
val borderStroke = new BorderStroke(Color.BLUE, BorderStrokeStyle.SOLID, CornerRadii.EMPTY, BorderStroke.THIN)
imageTile.asInstanceOf[VBox].setBorder(new Border(borderStroke))
}
override def select(obj: ImageTile): Unit = { override def select(obj: ImageTile): Unit = {
if (this.parentTilePane.getChildren.contains(obj)) { if (this.parentTilePane.getChildren.contains(obj)) {
clearSelectionFormatting clearSelectionFormatting
@ -239,15 +248,6 @@ class ImageTilePaneSelectionModel[ImageTile](parentTilePane: ImageTilePane) exte
} }
} }
private def clearSelectionFormatting() = {
val iterator = this.parentTilePane.getChildren.iterator()
while (iterator.hasNext) {
//remove the selection styling
val imageTile: VBox = iterator.next().asInstanceOf[VBox]
imageTile.setBorder(Border.EMPTY)
}
}
override def isEmpty: Boolean = { override def isEmpty: Boolean = {
this.parentTilePane.getChildren.isEmpty this.parentTilePane.getChildren.isEmpty
} }
@ -281,5 +281,4 @@ class ArrayObservableList[E] extends ModifiableObservableListBase[E] {
def doRemove(index: Int): E = { def doRemove(index: Int): E = {
delegate.remove(index) delegate.remove(index)
} }
} }

1
gui/src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala

@ -457,5 +457,4 @@ class GUIEngineListener extends EngineListener with ActorLogging {
}) })
} }
} }
//endregion //endregion

4
hash/pom.xml

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<groupId>com.sothr.imagetools</groupId> <groupId>com.sothr.imagetools</groupId>

32
hash/src/main/scala/com/sothr/imagetools/hash/HashService.scala

@ -37,10 +37,6 @@ object HashService extends Logging {
imagePath) imagePath)
} }
def getPrecisionMap(precisionSet: Set[Int], grayImage: BufferedImage): Map[Int, Array[Array[Int]]] = {
precisionSet.map(p => p -> getImageData(p, grayImage, alreadyGray = true))(collection.breakOut)
}
/** /**
* Given hash settings, a buffered image and an image path, calculate the perceptual hashes * Given hash settings, a buffered image and an image path, calculate the perceptual hashes
* *
@ -86,18 +82,8 @@ object HashService extends Logging {
hashes hashes
} }
def getSHA1(filePath: String): String = {
managed(new FileInputStream(filePath)) acquireAndGet {
input => DigestUtils.sha1Hex(input)
}
}
def getPrecisionSet(ahashSettings: HashSetting, dhashSettings: HashSetting, phashSettings: HashSetting): Set[Int] = {
Set(
if (ahashSettings.use) Option(ahashSettings.precision) else None,
if (dhashSettings.use) Option(dhashSettings.precision) else None,
if (phashSettings.use) Option(phashSettings.precision) else None
).flatten
def getPrecisionMap(precisionSet: Set[Int], grayImage: BufferedImage): Map[Int, Array[Array[Int]]] = {
precisionSet.map(p => p -> getImageData(p, grayImage, alreadyGray = true))(collection.breakOut)
} }
def getImageData(precision: Int, image: BufferedImage, alreadyGray: Boolean): Array[Array[Int]] = { def getImageData(precision: Int, image: BufferedImage, alreadyGray: Boolean): Array[Array[Int]] = {
@ -113,6 +99,20 @@ object HashService extends Logging {
ImageUtil.getImageData(resizedImage) ImageUtil.getImageData(resizedImage)
} }
def getSHA1(filePath: String): String = {
managed(new FileInputStream(filePath)) acquireAndGet {
input => DigestUtils.sha1Hex(input)
}
}
def getPrecisionSet(ahashSettings: HashSetting, dhashSettings: HashSetting, phashSettings: HashSetting): Set[Int] = {
Set(
if (ahashSettings.use) Option(ahashSettings.precision) else None,
if (dhashSettings.use) Option(dhashSettings.precision) else None,
if (phashSettings.use) Option(phashSettings.precision) else None
).flatten
}
/** /**
* Simpler function that only works with the imageData and the hashFunction * Simpler function that only works with the imageData and the hashFunction
* *

Loading…
Cancel
Save