Skip to content

Commit

Permalink
#147: calculate LogEntry color on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Oct 2, 2023
1 parent ab3f905 commit bf86d1d
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 90 deletions.
2 changes: 1 addition & 1 deletion app/src/main/scala/app/logorrr/conf/LogoRRRGlobals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object LogoRRRGlobals extends CanLog {
}


def setSelectedIndex(pathAsString: String, index: Int): Unit = getLogFileSettings(pathAsString).setSelectedIndex(index)
def setSelectedIndex(pathAsString: String, index: Int): Unit = getLogFileSettings(pathAsString).selectedLineNumber(index)

def setBlockSettings(pathAsString: String, bs: BlockSettings): Unit =
mupdate({ lfs: MutLogFileSettings => lfs.setBlockSettings(bs) })(pathAsString)
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/scala/app/logorrr/conf/mut/MutLogFileSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ object MutLogFileSettings {

def apply(logFileSettings: LogFileSettings): MutLogFileSettings = {
val s = new MutLogFileSettings
s.setSelectedIndex(logFileSettings.selectedIndex)
s.selectedLineNumber(logFileSettings.selectedLineNumber)
s.setFontSize(logFileSettings.fontSize)
s.setBlockSettings(logFileSettings.blockSettings)
s.setPathAsString(logFileSettings.pathAsString)
s.firstOpenedProperty.set(logFileSettings.firstOpened)
s.setDividerPosition(logFileSettings.dividerPosition)
s.filtersProperty.setAll(logFileSettings.filters.asJava)
s.setFilters(logFileSettings.filters)
s.someLogEntrySettingsProperty.set(logFileSettings.someLogEntryInstantFormat)
s.setAutoScroll(logFileSettings.autoScroll)
s
Expand All @@ -31,7 +31,7 @@ class MutLogFileSettings {

private val pathAsStringProperty = new SimpleStringProperty()
private val firstOpenedProperty = new SimpleLongProperty()
val selectedIndexProperty = new SimpleIntegerProperty()
val selectedLineNumber = new SimpleIntegerProperty()
private val dividerPositionProperty = new SimpleDoubleProperty()
private val fontSizeProperty = new SimpleIntegerProperty()

Expand All @@ -40,6 +40,14 @@ class MutLogFileSettings {
val someLogEntrySettingsProperty = new SimpleObjectProperty[Option[LogEntryInstantFormat]](None)
val blockWidthSettingsProperty = new SimpleIntegerProperty()

def setFilters(filters: Seq[Filter]): Unit = {
filtersProperty.setAll(filters.asJava)
}

def setFilter(index: Int, filter: Filter): Unit = {
filtersProperty.set(index, filter)
}

val hasLogEntrySettingBinding: BooleanBinding = new BooleanBinding {
bind(someLogEntrySettingsProperty)

Expand Down Expand Up @@ -72,7 +80,7 @@ class MutLogFileSettings {

def getPathAsString(): String = pathAsStringProperty.get()

def setSelectedIndex(index: Int): Unit = selectedIndexProperty.set(index)
def selectedLineNumber(lineNumber: Int): Unit = selectedLineNumber.set(lineNumber)

def setFontSize(fontSize: Int): Unit = fontSizeProperty.set(fontSize)

Expand All @@ -85,7 +93,7 @@ class MutLogFileSettings {
def petrify(): LogFileSettings = {
val lfs =
LogFileSettings(pathAsStringProperty.get()
, selectedIndexProperty.get()
, selectedLineNumber.get()
, firstOpenedProperty.get()
, dividerPositionProperty.get()
, fontSizeProperty.get()
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/scala/app/logorrr/model/LogEntry.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package app.logorrr.model

import app.logorrr.views.block.BlockView
import javafx.scene.paint.Color

import java.time.Instant

Expand All @@ -13,7 +11,5 @@ import java.time.Instant
* @param someInstant a timestamp if there is any
* */
case class LogEntry(lineNumber: Int
, color: Color // remove, should be calculated because of given filters
, value: String
, someInstant: Option[Instant])
extends BlockView.E
12 changes: 5 additions & 7 deletions app/src/main/scala/app/logorrr/model/LogEntryFileReader.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package app.logorrr.model

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

import java.nio.file.Path
import java.time.Instant
Expand All @@ -12,23 +11,22 @@ import java.util
/** Abstraction for a log file */
object LogEntryFileReader extends CanLog {

private def mkLogEntryList(parseColor: String => Color
, parseEntryForTimeInstant: String => Option[Instant])
private def mkLogEntryList(parseEntryForTimeInstant: String => Option[Instant])
(logFilePath: Path): ObservableList[LogEntry] = timeR({
var lineNumber: Int = 0
val arraylist = new util.ArrayList[LogEntry]()
LogFileReader.readFromFile(logFilePath).map(l => {
lineNumber = lineNumber + 1
arraylist.add(LogEntry(lineNumber, parseColor(l), l, parseEntryForTimeInstant(l)))
arraylist.add(LogEntry(lineNumber, l, parseEntryForTimeInstant(l)))
})
FXCollections.observableList(arraylist)
}, s"Imported ${logFilePath.toAbsolutePath.toString} ... ")

def from(logFilePath: Path, filters: Seq[Fltr], logEntryTimeFormat: LogEntryInstantFormat): ObservableList[LogEntry] = {
mkLogEntryList(l => Filter.calcColor(l, filters), l => LogEntryInstantFormat.parseInstant(l, logEntryTimeFormat))(logFilePath)
mkLogEntryList(l => LogEntryInstantFormat.parseInstant(l, logEntryTimeFormat))(logFilePath)
}

def from(logFile: Path, filters: Seq[Fltr]): ObservableList[LogEntry] = mkLogEntryList(l => Filter.calcColor(l, filters), _ => None)(logFile)
def from(logFile: Path, filters: Seq[Fltr]): ObservableList[LogEntry] = mkLogEntryList(_ => None)(logFile)


}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/scala/app/logorrr/model/LogFileSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object LogFileSettings {
*
*/
case class LogFileSettings(pathAsString: String
, selectedIndex: Int
, selectedLineNumber: Int
, firstOpened: Long
, dividerPosition: Double
, fontSize: Int
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/scala/app/logorrr/views/LogFileTab.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,19 +171,11 @@ class LogFileTab(val pathAsString: String
filtersListProperty.addListener(JfxUtils.mkListChangeListener(handleFilterChange))
}

/** update all log entries with current filter settings */
def updateLogEntryColors(): Unit = {
val filters = filtersListProperty.get().asScala.toSeq
val lE: mutable.Seq[LogEntry] = for (old <- logEntries.asScala) yield old.copy(color = Filter.calcColor(old.value, filters))
logEntries.setAll(lE.asJava)
}

private def handleFilterChange(change: ListChangeListener.Change[_ <: Fltr]): Unit = {
while (change.next()) {
Future {
LogoRRRGlobals.persist()
}
updateLogEntryColors()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app.logorrr.views.autoscroll
import app.logorrr.conf.LogoRRRGlobals
import app.logorrr.model.LogEntry
import app.logorrr.util.{CanLog, JfxUtils}
import app.logorrr.views.search.Filter
import javafx.collections.ObservableList
import org.apache.commons.io.input.{Tailer, TailerListener}

Expand All @@ -24,8 +23,7 @@ class LogEntryListener(pathAsString: String

override def handle(l: String): Unit = {
currentCnt = currentCnt + 1
val filters = LogoRRRGlobals.getLogFileSettings(pathAsString).getFilters
val e = LogEntry(currentCnt, Filter.calcColor(l, filters), l, None)
val e = LogEntry(currentCnt, l, None)
JfxUtils.execOnUiThread(ol.add(e))
}

Expand Down
12 changes: 9 additions & 3 deletions app/src/main/scala/app/logorrr/views/block/BlockImage.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package app.logorrr.views.block

import app.logorrr.conf.LogoRRRGlobals
import app.logorrr.model.LogEntry
import app.logorrr.util.{CanLog, ColorUtil, JfxUtils}
import app.logorrr.views.search.Filter
import javafx.beans.property.{SimpleIntegerProperty, SimpleListProperty, SimpleObjectProperty}
import javafx.beans.{InvalidationListener, Observable}
import javafx.collections.FXCollections
Expand All @@ -9,6 +12,7 @@ import javafx.scene.image.{PixelBuffer, PixelFormat, WritableImage}
import javafx.scene.paint.Color

import java.nio.IntBuffer
import scala.jdk.CollectionConverters.ListHasAsScala

object BlockImage {

Expand All @@ -20,7 +24,9 @@ object BlockImage {

}

class BlockImage[Elem <: BlockView.E] extends CanLog {
class BlockImage extends CanLog {

val filtersProperty = new SimpleListProperty[Filter]()

var pixelBuffer: PixelBuffer[IntBuffer] = _
var intBuffer: IntBuffer = _
Expand All @@ -31,7 +37,7 @@ class BlockImage[Elem <: BlockView.E] extends CanLog {

private val redrawListener: InvalidationListener = (_: Observable) => repaint()

val entries = new SimpleListProperty[Elem](FXCollections.observableArrayList())
val entries = new SimpleListProperty[LogEntry](FXCollections.observableArrayList())

/* if blockwidth is changed redraw */
val blockWidthProperty = {
Expand Down Expand Up @@ -112,7 +118,7 @@ class BlockImage[Elem <: BlockView.E] extends CanLog {
cleanBackground()
var i = 0
entries.forEach(e => {
drawRect(i, e.color)
drawRect(i, Filter.calcColor(e.value, filtersProperty.asScala.toSeq))
i = i + 1
})
roi
Expand Down
29 changes: 15 additions & 14 deletions app/src/main/scala/app/logorrr/views/block/BlockView.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,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, SimpleListProperty, SimpleObjectProperty}
import javafx.beans.value.ChangeListener
import javafx.collections.FXCollections
import javafx.event.EventHandler
import javafx.scene.image.ImageView
import javafx.scene.input.MouseEvent
import javafx.scene.paint.Color

import scala.math.BigDecimal.RoundingMode
import scala.util.Try
Expand All @@ -18,10 +19,6 @@ object BlockView {

val MinWidth = 200

trait E {
def color: Color
}


def indexOf(x: Int, y: Int, blockWidth: Int, blockViewWidth: Int): Int = y / blockWidth * (blockViewWidth / blockWidth) + x / blockWidth

Expand Down Expand Up @@ -57,16 +54,17 @@ object BlockView {
/**
* Displays a region with max 4096 x 4096 pixels and as many entries as can fit in this region.
*/
class BlockView[Elem <: BlockView.E] extends ImageView with CanLog {
class BlockView extends ImageView with CanLog {

private val blockSizeProperty = new SimpleIntegerProperty()
private val widthProperty = new SimpleIntegerProperty()
private val filtersProperty = new SimpleListProperty[Filter]()

val entriesProperty = new SimpleListProperty[Elem](FXCollections.observableArrayList())
val entriesProperty = new SimpleListProperty[LogEntry](FXCollections.observableArrayList())

val selectedEntryProperty: SimpleObjectProperty[Elem] = new SimpleObjectProperty[Elem]()
val selectedEntryProperty: SimpleObjectProperty[LogEntry] = new SimpleObjectProperty[LogEntry]()

var selectedListener: ChangeListener[Elem] = _
var selectedListener: ChangeListener[LogEntry] = _

private val mouseEventHandler: EventHandler[MouseEvent] = new EventHandler[MouseEvent]() {
override def handle(me: MouseEvent): Unit = {
Expand All @@ -85,11 +83,12 @@ class BlockView[Elem <: BlockView.E] extends ImageView with CanLog {


private val blockImage = {
val bi = new BlockImage[Elem]
val bi = new BlockImage
bi.widthProperty.bind(widthProperty)
bi.blockWidthProperty.bind(blockSizeProperty)
bi.blockHeightProperty.bind(blockSizeProperty)
bi.entries.bind(entriesProperty)
bi.filtersProperty.bind(filtersProperty)
bi
}

Expand All @@ -114,9 +113,11 @@ class BlockView[Elem <: BlockView.E] extends ImageView with CanLog {

def setWidth(width: Int): Unit = widthProperty.set(width)

def bind(blockSizeProperty: SimpleIntegerProperty
def bind(filtersProperty: SimpleListProperty[Filter]
, blockSizeProperty: SimpleIntegerProperty
, blockViewWidthProperty: ReadOnlyDoubleProperty
, setEntry: Elem => Unit): Unit = {
, setEntry: LogEntry => Unit): Unit = {
this.filtersProperty.bind(filtersProperty)
this.blockSizeProperty.bind(blockSizeProperty)
this.blockViewWidthPropertyHolder = blockViewWidthProperty
this.blockViewWidthPropertyHolder.addListener(widthListener)
Expand All @@ -129,9 +130,9 @@ class BlockView[Elem <: BlockView.E] extends ImageView with CanLog {
this.selectedListener = null
}

def setEntries(entries: java.util.List[Elem]): Unit = entriesProperty.setAll(entries)
def setEntries(entries: java.util.List[LogEntry]): Unit = entriesProperty.setAll(entries)

def getEntryAt(index: Int): Option[Elem] = Try(entriesProperty.get(index)).toOption
def getEntryAt(index: Int): Option[LogEntry] = Try(entriesProperty.get(index)).toOption

def repaint(): Unit = blockImage.repaint()

Expand Down
Loading

0 comments on commit bf86d1d

Please sign in to comment.