Browse Source

Started work on a custom component for image tiles since no default exists

master
Drew Short 11 years ago
parent
commit
37497a0f7d
  1. 14
      src/main/scala/com/sothr/imagetools/image/Image.scala
  2. 37
      src/main/scala/com/sothr/imagetools/ui/component/ImageTileFactory.scala
  3. 15
      src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala

14
src/main/scala/com/sothr/imagetools/image/Image.scala

@ -7,7 +7,7 @@ import javax.persistence._
@Entity
@Table(name = "Image")
class Image(val image:String, val thumbnail:String, val size:Tuple2[Int,Int], val imageHashes:ImageHashDTO = null) extends Serializable with Logging {
class Image(val image:String, val thumbnail:String, val size:(Int, Int), val imageHashes:ImageHashDTO = null) extends Serializable with Logging {
def this() = this ("", "", (0,0), null)
@ -29,10 +29,20 @@ class Image(val image:String, val thumbnail:String, val size:Tuple2[Int,Int], va
def setHashes(newHashes:ImageHashDTO) = { hashes = newHashes}
@transient
var imageSize:Tuple2[Int,Int] = { new Tuple2(width, height) }
var imageSize:(Int, Int) = { new Tuple2(width, height) }
@transient
var imageName:String = ""
var imageType:ImageType = ImageType.SingleFrameImage
def getName():String = {
if(this.imageName.length < 1) {
this.imageName = this.getImagePath.split('/').last
}
this.imageName
}
def isSimilarTo(otherImage:Image):Boolean = {
//debug(s"Checking $imagePath for similarities with ${otherImage.imagePath}")
HashService.areImageHashesSimilar(this.hashes,otherImage.hashes)

37
src/main/scala/com/sothr/imagetools/ui/component/ImageTileFactory.scala

@ -0,0 +1,37 @@
package com.sothr.imagetools.ui.component
import javafx.geometry.Pos
import javafx.scene.control.Label
import javafx.scene.image.{ImageView, Image}
import javafx.scene.layout.{VBox}
/**
* Created by drew on 8/6/14.
*
* Creates pre-generated image tiles that can be rendered to a scene
*/
object ImageTileFactory {
def get(image:com.sothr.imagetools.image.Image):VBox = {
val imageTile = new VBox()
imageTile.setPrefSize(192.0d,192.0d)
imageTile.setAlignment(Pos.TOP_CENTER)
// Image
val genImageView = new ImageView()
val thumbnail = new Image(image.getThumbnailPath)
genImageView.setImage(thumbnail)
genImageView.setFitWidth(128.0)
genImageView.setPreserveRatio(true)
imageTile.getChildren.add(genImageView)
//Label
val imageLabel = new Label()
imageLabel.setText(image.getName())
imageLabel.setWrapText(true)
imageTile.getChildren.add(imageLabel)
imageTile
}
}

15
src/main/scala/com/sothr/imagetools/ui/controller/AppController.scala

@ -7,12 +7,13 @@ import javafx.scene.{Scene,Group}
import javafx.scene.text.{TextAlignment, Text}
import java.io.IOException
import java.util.Scanner
import com.sothr.imagetools.image.Image
import com.sothr.imagetools.ui.component.ImageTileFactory
import com.sothr.imagetools.util.ResourceLoader
import grizzled.slf4j.Logging
import javafx.scene.web.WebView
import org.markdown4j.Markdown4jProcessor
import javafx.scene.image.{Image, ImageView}
import javafx.collections.{FXCollections, ObservableList}
import javafx.collections.{FXCollections}
/**
* Created by drew on 12/31/13.
@ -28,13 +29,11 @@ class AppController extends Logging {
@FXML def initialize() = {
//test
val testImage = new Image("test.jpg")
val testImage = new Image()
testImage.setThumbnailPath("test.jpg")
testImage.setImagePath("test.jpg")
for (i <- 1 to 100) {
val genImageView = new ImageView()
genImageView.setImage(testImage)
genImageView.setFitWidth(128.0)
genImageView.setPreserveRatio(true)
imageTilePane.getChildren.add(genImageView)
imageTilePane.getChildren.add(ImageTileFactory.get(testImage))
}
val list = FXCollections.observableArrayList[String]()
for (i <- 1 to 100) {

Loading…
Cancel
Save