Skip to content

Commit

Permalink
#150: cleanup, code simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Nov 2, 2023
1 parent 07f4a35 commit 23acf9c
Show file tree
Hide file tree
Showing 18 changed files with 98 additions and 253 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app.logorrr.model

import app.logorrr.util.CanLog
import app.logorrr.views.search.Fltr
import javafx.collections.{FXCollections, ObservableList}

import java.nio.file.Path
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/scala/app/logorrr/util/ImageCp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import javafx.scene.image.{Image, ImageView}
import java.util.Properties


abstract class CpResource(value: String)
abstract class CpResource

case class PropsCp(classPathResource : String) extends CpResource(classPathResource) {
case class PropsCp(classPathResource: String) extends CpResource {

def asProperties(clazz: Class[_]): Properties = {
val properties = new Properties()
Expand All @@ -22,7 +22,7 @@ case class PropsCp(classPathResource : String) extends CpResource(classPathResou

}

case class ImageCp(value: String, width: Int, height: Int) extends CpResource(value) {
case class ImageCp(value: String, width: Int, height: Int) extends CpResource {
def imageView(): ImageView =
new ImageView(new Image(value, width, height, true, true, true))
}
8 changes: 0 additions & 8 deletions app/src/main/scala/app/logorrr/util/LogoRRRFileChooser.scala

This file was deleted.

56 changes: 36 additions & 20 deletions app/src/main/scala/app/logorrr/views/block/BlockImage.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package app.logorrr.views.block

import app.logorrr.model.LogEntry
import app.logorrr.util.{CanLog, ColorUtil}
import app.logorrr.util.{CanLog, ColorUtil, MathUtil}
import app.logorrr.views.search.Filter
import javafx.beans.property.{ReadOnlyDoubleProperty, SimpleIntegerProperty, SimpleObjectProperty}
import javafx.beans.property.{ReadOnlyDoubleProperty, SimpleIntegerProperty}
import javafx.collections.ObservableList
import javafx.scene.image.WritableImage
import javafx.scene.paint.Color
Expand All @@ -12,42 +12,58 @@ object BlockImage {

val MaxWidth = 4096

// val MaxHeight = 4096
val MaxHeight = 4096

/** defines how many table cells should be rendered per list height */
val DefaultBlocksPerPage = 4

@deprecated val Height = 100 // remove when blockviewpane is gone
def indexOf(x: Int, y: Int, blockWidth: Int, blockViewWidth: Int): Int = y / blockWidth * (blockViewWidth / blockWidth) + x / blockWidth

/**
* Calculates overall height of virtual canvas
*
* @param blockWidth width of a block
* @param blockHeight height of a block
* @param width width of canvas
* @param nrEntries number of elements
* @return
*/
def calcVirtualHeight(blockWidth: Int
, blockHeight: Int
, width: Int
, nrEntries: Int): Int = {
if (blockHeight == 0 || nrEntries == 0) {
0
} else {
if (width > blockWidth) {
val elemsPerRow = width.toDouble / blockWidth
val nrRows = nrEntries.toDouble / elemsPerRow
val decimal1: BigDecimal = MathUtil.roundUp(nrRows)
val res = decimal1.intValue * blockHeight
res
} else {
0
}
}
}


}


class BlockImage(blockNumber: Int
, widthProperty: ReadOnlyDoubleProperty
, blockSizeProperty: SimpleIntegerProperty
, entries: java.util.List[LogEntry]
, selectedLineNumberProperty: SimpleIntegerProperty
, filtersProperty: ObservableList[Filter]
, selectedEntryProperty: SimpleObjectProperty[LogEntry]
, blockSizeProperty: SimpleIntegerProperty
, widthProperty: ReadOnlyDoubleProperty
, heightProperty: SimpleIntegerProperty
, selectedLineNumberProperty: SimpleIntegerProperty)
)
extends WritableImage(LPixelBuffer(blockNumber
, Range(entries.get(0).lineNumber, entries.get(entries.size - 1).lineNumber)
, RectangularShape(widthProperty.get().toInt, heightProperty.get())
, blockSizeProperty
, entries
, filtersProperty
, selectedEntryProperty
, Array.fill(widthProperty.get().toInt * heightProperty.get())(ColorUtil.toARGB(Color.GREEN))
, selectedLineNumberProperty)) with CanLog {

def draw(i: Int, color: Color): Unit = {
logError("implement me")
}

def shutdown(): Unit = {
logError("implement me")
}

}
, selectedLineNumberProperty)) with CanLog
169 changes: 0 additions & 169 deletions app/src/main/scala/app/logorrr/views/block/BlockView.scala

This file was deleted.

2 changes: 1 addition & 1 deletion app/src/main/scala/app/logorrr/views/block/Chunk.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Chunk {
// nr of chunks is calculated as follows:
// how many entries fit into a chunk?
// given their size and the width and height of a chunk it is easy to calculate.
val (cols, rows, height) = MathUtil.calcBoundedHeight(widthProperty, blockSizeProperty, entriesProperty, listViewHeightProperty)
val (cols, _, height) = MathUtil.calcBoundedHeight(widthProperty, blockSizeProperty, entriesProperty, listViewHeightProperty)
val nrElements = height / blockSizeProperty.get() * cols

val entriesSize = entriesProperty.size()
Expand Down
41 changes: 28 additions & 13 deletions app/src/main/scala/app/logorrr/views/block/ChunkListCell.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package app.logorrr.views.block
import app.logorrr.model.LogEntry
import app.logorrr.util.{CanLog, JfxUtils}
import app.logorrr.views.search.Filter
import javafx.beans.property.{ReadOnlyDoubleProperty, SimpleIntegerProperty, SimpleObjectProperty}
import javafx.beans.property.{ReadOnlyDoubleProperty, SimpleIntegerProperty}
import javafx.collections.ObservableList
import javafx.event.EventHandler
import javafx.scene.control.ListCell
import javafx.scene.image.ImageView
import javafx.scene.input.MouseEvent

import scala.util.Try


/**
Expand All @@ -20,15 +25,23 @@ class ChunkListCell(selectedLineNumberProperty: SimpleIntegerProperty
, widthProperty: ReadOnlyDoubleProperty
, blockSizeProperty: SimpleIntegerProperty
, filtersProperty: ObservableList[Filter]
) extends ListCell[Chunk] with CanLog {
) extends ListCell[Chunk] with CanLog {

// if user selects an entry in the ChunkListView set selectedLineNumberProperty. This property is observed
// via an listener and a yellow square will be painted.
val mouseEventHandler = new EventHandler[MouseEvent]() {
override def handle(me: MouseEvent): Unit = {
val index = BlockImage.indexOf(me.getX.toInt, me.getY.toInt, blockSizeProperty.get, widthProperty.get.toInt)
getEntryAt(getItem, index) match {
case Some(value) =>
selectedLineNumberProperty.set(value.lineNumber)
case None => System.err.println("no element found")
}
}
}

setOnMouseClicked(mouseEventHandler)

setStyle(
"""
|-fx-padding: 0;
|-fx-margin: 0;
|-fx-background-insets: 0;
|
|""".stripMargin)

override def updateItem(t: Chunk, empty: Boolean): Unit = JfxUtils.execOnUiThread {
super.updateItem(t, empty)
Expand All @@ -38,15 +51,14 @@ class ChunkListCell(selectedLineNumberProperty: SimpleIntegerProperty
} else {
if (widthProperty.get() > 0) {
if (blockSizeProperty.get() > 0) {
val bv = new BlockView(t.number
val bv = new BlockImage(t.number
, entries = t.entries
, selectedLineNumberProperty
, filtersProperty
, blockSizeProperty
, widthProperty
, selectedEntryProperty = new SimpleObjectProperty[LogEntry]()
, entries = t.entries
, heightProperty = new SimpleIntegerProperty(t.height))
setGraphic(bv)
setGraphic(new ImageView(bv))
} else {
logTrace(s"Blocksize was ${blockSizeProperty.get()}, setting graphic to null")
setGraphic(null)
Expand All @@ -57,4 +69,7 @@ class ChunkListCell(selectedLineNumberProperty: SimpleIntegerProperty
}
}
}

private def getEntryAt(chunk: Chunk, index: Int): Option[LogEntry] = Try(chunk.entries.get(index)).toOption

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ChunkListView(val entries: ObservableList[LogEntry]
val chunks1 = FXCollections.observableArrayList(chunks: _*)
setItems(chunks1)
} match {
case Success(value) => ()
case Success(_) => ()
case Failure(exception) => logException(exception.getMessage, exception)
}

Expand Down
Loading

0 comments on commit 23acf9c

Please sign in to comment.