Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

112 autoscroll the log #124

Merged
merged 3 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 24 additions & 54 deletions app/src/main/scala/app/logorrr/conf/LogoRRRGlobals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,118 +10,88 @@ import javafx.beans.property.SimpleObjectProperty
import javafx.stage.Window
import pureconfig.ConfigWriter

import scala.jdk.CollectionConverters._

/**
* Place LogoRRR's settings.
*
* The user can change certain values via interacting or explicitly setting values in the preferences dialog.
*/
object LogoRRRGlobals extends CanLog {

def persist(): Unit = write(LogoRRRGlobals.getSettings())
val mutSettings = new MutSettings

private val hostServicesProperty = new SimpleObjectProperty[HostServices]()

def allLogs(): Seq[LogFileSettings] = {
settings.logFileSettingsProperty.get().values.asScala.toSeq.sortWith((lt, gt) => lt.getFirstOpened() < gt.getFirstOpened()).map(_.petrify())
def persist(): Unit = {
Fs.write(FilePaths.settingsFilePath, ConfigWriter[Settings].to(LogoRRRGlobals.getSettings()).render(renderOptions))
}

def getOrderedLogFileSettings(): Seq[LogFileSettings] = mutSettings.getOrderedLogFileSettings()

def bindWindow(window: Window): Unit = {
window.setX(LogoRRRGlobals.getStageX())
window.setY(LogoRRRGlobals.getStageY())
window.setWidth(LogoRRRGlobals.getStageWidth())
window.setHeight(LogoRRRGlobals.getStageHeight())

settings.stageSettings.widthProperty.bind(window.getScene.widthProperty())
settings.stageSettings.heightProperty.bind(window.getScene.heightProperty())
settings.stageSettings.xProperty.bind(window.xProperty())
settings.stageSettings.yProperty.bind(window.yProperty())
}

def unbindWindow(): Unit = {
settings.stageSettings.widthProperty.unbind()
settings.stageSettings.heightProperty.unbind()
settings.stageSettings.xProperty.unbind()
settings.stageSettings.yProperty.unbind()
mutSettings.bindWindowProperties(window)
}

def getStageWidth(): Int = settings.stageSettings.widthProperty.get()
def unbindWindow(): Unit = mutSettings.unbindWindow()

def getStageHeight(): Int = settings.stageSettings.heightProperty.get()
def getStageWidth(): Int = mutSettings.getStageWidth()

def getStageX(): Double = settings.stageSettings.xProperty.get()
def getStageHeight(): Int = mutSettings.getStageHeight()

def getStageY(): Double = settings.stageSettings.yProperty.get()
def getStageX(): Double = mutSettings.getStageX()

val settings = new MutSettings
private val hostServicesProperty = new SimpleObjectProperty[HostServices]()
def getStageY(): Double = mutSettings.getStageY()

def setHostServices(hostServices: HostServices): Unit = hostServicesProperty.set(hostServices)

def getHostServices: HostServices = hostServicesProperty.get()

def set(settings: Settings, hostServices: HostServices): Unit = {
this.settings.set(settings)
mutSettings.set(settings)
setHostServices(hostServices)
}

def getSettings(): Settings = settings.petrify()

/** persists settings */
def write(settings: Settings): Unit = {
Fs.write(FilePaths.settingsFilePath, ConfigWriter[Settings].to(settings).render(renderOptions))
}
def getSettings(): Settings = mutSettings.petrify()

private def update(fn: Settings => Settings): Unit = write(fn(LogoRRRGlobals.getSettings()))

def setSomeActive(sActive: Option[String]): Unit = settings.setSomeActive(sActive)

def getSomeActive(): Option[String] = settings.getSomeActive()
def setSomeActive(sActive: Option[String]): Unit = mutSettings.setSomeActive(sActive)

def getSomeActive(): Option[String] = mutSettings.getSomeActive()

def removeLogFile(pathAsString: String): Unit = {
settings.removeLogFileSetting(pathAsString)
settings.setSomeActive(settings.getSomeActive() match {
mutSettings.removeLogFileSetting(pathAsString)
mutSettings.setSomeActive(mutSettings.getSomeActive() match {
case Some(value) if value == pathAsString => None
case x => x
})
logInfo(s"Removed file ${pathAsString} ...")
}

def resetLogs(): Unit = {
settings.logFileSettingsProperty.clear()
settings.setSomeActive(None)
}
def clearLogFileSettings(): Unit = mutSettings.clearLogFileSettings()

def getLogFileSettings(pathAsString: String): MutLogFileSettings = {
settings.getLogFileSetting(pathAsString)
mutSettings.getMutLogFileSetting(pathAsString)
}

def mupdate(t: MutLogFileSettings => Unit)(pathAsString: String): Unit =
Option(settings.getLogFileSetting(pathAsString)) match {
Option(mutSettings.getMutLogFileSetting(pathAsString)) match {
case Some(logFileSettings) => t(logFileSettings)
case None => logWarn(s"${pathAsString} not found.")
}

def kupdate(t: StageSettings => Unit)(pathAsString: String): Unit =
Option(settings.getStageSettings()) match {
case Some(stageSettings: StageSettings) => t(stageSettings)
case None => logWarn(s"${pathAsString} not found.")
}

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

def setBlockSettings(pathAsString: String, bs: BlockSettings): Unit =
mupdate({ lfs: MutLogFileSettings => lfs.setBlockSettings(bs) })(pathAsString)

def setDividerPosition(pathAsString: String, dividerPosition: Double): Unit = {
settings.getLogFileSetting(pathAsString).setDividerPosition(dividerPosition)
// mupdate({ lfs: MutLogFileSettings => lfs.setDividerPosition(dividerPosition) })(pathAsString)
}
def setDividerPosition(pathAsString: String, dividerPosition: Double): Unit = mutSettings.getMutLogFileSetting(pathAsString).setDividerPosition(dividerPosition)

def updateLogFile(fs: LogFileSettings): Unit = {
settings.putLogFileSetting(fs)
}
def updateLogFile(fs: LogFileSettings): Unit = mutSettings.putMutLogFileSetting(MutLogFileSettings(fs))

def logVisualCanvasWidth(pathAsString: String): Int = (mutSettings.getStageWidth() * LogoRRRGlobals.getLogFileSettings(pathAsString).getDividerPosition()).intValue

}
15 changes: 0 additions & 15 deletions app/src/main/scala/app/logorrr/conf/mut/MutBlockSettings.scala

This file was deleted.

41 changes: 29 additions & 12 deletions app/src/main/scala/app/logorrr/conf/mut/MutLogFileSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,48 +23,65 @@ object MutLogFileSettings {
s.setDividerPosition(logFileSettings.dividerPosition)
s.filtersProperty.setAll(logFileSettings.filters.asJava)
s.someLogEntrySettings.set(logFileSettings.someLogEntrySetting)
s.setAutoScroll(logFileSettings.autoScroll)
s
}
}

class MutLogFileSettings extends Petrify[LogFileSettings] {
def getFontSize(): Int = fontSizeProperty.get()

def getFilters() = filtersProperty.asScala.toSeq
class MutLogFileSettings {

private val pathAsStringProperty = new SimpleStringProperty()
private val firstOpenedProperty = new SimpleLongProperty()
val selectedIndexProperty = new SimpleIntegerProperty()
val dividerPositionProperty = new SimpleDoubleProperty()
val fontSizeProperty = new SimpleIntegerProperty()
val autoScrollProperty = new SimpleBooleanProperty()
val filtersProperty = new SimpleListProperty[Filter](FXCollections.observableArrayList())
val someLogEntrySettings = new SimpleObjectProperty[Option[LogEntryInstantFormat]]()
val blockWidthSettingsProperty = new SimpleIntegerProperty()

val fontStyle: ObservableValue[_ <: String] = new StringBinding {
bind(fontSizeProperty)

override def computeValue(): String = LogoRRRFonts.jetBrainsMono(fontSizeProperty.get())
}

def setAutoScroll(autoScroll: Boolean): Unit = autoScrollProperty.set(autoScroll)

def isAutoScroll(): Boolean = autoScrollProperty.get()

def getFontSize(): Int = fontSizeProperty.get()

def getFilters() = filtersProperty.asScala.toSeq

def setBlockSettings(bs: BlockSettings): Unit = blockWidthSettingsProperty.set(bs.width)

def setPathAsString(path: String): Unit = pathAsStringProperty.set(path)

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

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

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

def setDividerPosition(dividerPosition: Double): Unit = dividerPositionProperty.set(dividerPosition)

def getDividerPosition(): Double = dividerPositionProperty.get()

def getFirstOpened(): Long = firstOpenedProperty.get()

override def petrify(): LogFileSettings = LogFileSettings(pathAsStringProperty.get()
, selectedIndexProperty.get()
, firstOpenedProperty.get()
, dividerPositionProperty.get()
, fontSizeProperty.get()
, filtersProperty.get().asScala.toSeq
, BlockSettings(blockWidthSettingsProperty.get())
, someLogEntrySettings.get())
def petrify(): LogFileSettings = {
val lfs =
LogFileSettings(pathAsStringProperty.get()
, selectedIndexProperty.get()
, firstOpenedProperty.get()
, dividerPositionProperty.get()
, fontSizeProperty.get()
, filtersProperty.get().asScala.toSeq
, BlockSettings(blockWidthSettingsProperty.get())
, someLogEntrySettings.get()
, autoScrollProperty.get())
lfs
}
}

71 changes: 53 additions & 18 deletions app/src/main/scala/app/logorrr/conf/mut/MutSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import app.logorrr.conf.{Settings, StageSettings}
import app.logorrr.model.LogFileSettings
import javafx.beans.property.{SimpleMapProperty, SimpleObjectProperty}
import javafx.collections.FXCollections
import javafx.stage.Window

import java.util
import scala.jdk.CollectionConverters._
Expand All @@ -27,21 +28,22 @@ object MutSettings {

class MutSettings {

val stageSettings = new MutStageSettings
val logFileSettingsProperty = new SimpleMapProperty[String, MutLogFileSettings](FXCollections.observableMap(new util.HashMap()))
val someActiveLogProperty = new SimpleObjectProperty[Option[String]](None)
/** contains mutable information for the application stage */
private val mutStageSettings = new MutStageSettings

def getLogFileSetting(key: String): MutLogFileSettings = logFileSettingsProperty.get(key)
/** contains mutable state information for all log files */
private val mutLogFileSettingsMapProperty = new SimpleMapProperty[String, MutLogFileSettings](FXCollections.observableMap(new util.HashMap()))

def putLogFileSetting(logFileSettings: LogFileSettings): Unit = logFileSettingsProperty.put(logFileSettings.pathAsString, MutLogFileSettings(logFileSettings))
/** tracks which log file is active */
private val someActiveLogProperty = new SimpleObjectProperty[Option[String]](None)

def removeLogFileSetting(pathAsString: String): Unit = {
logFileSettingsProperty.remove(pathAsString)
}
def getMutLogFileSetting(key: String): MutLogFileSettings = mutLogFileSettingsMapProperty.get(key)

def putMutLogFileSetting(mutLogFileSettings: MutLogFileSettings): Unit = mutLogFileSettingsMapProperty.put(mutLogFileSettings.getPathAsString(), mutLogFileSettings)

def getStageSettings(): StageSettings = stageSettings.petrify()
def removeLogFileSetting(pathAsString: String): Unit = mutLogFileSettingsMapProperty.remove(pathAsString)

def set(settings: Settings) = {
def set(settings: Settings): Unit = {
setStageSettings(settings.stageSettings)
setLogFileSettings(settings.logFileSettings)
setSomeActive(settings.someActive)
Expand All @@ -55,19 +57,52 @@ class MutSettings {
val m = for ((k, v) <- logFileSettings) yield {
k -> MutLogFileSettings(v)
}
logFileSettingsProperty.putAll(m.asJava)
mutLogFileSettingsMapProperty.putAll(m.asJava)
}


def petrify(): Settings = {
val m = (for ((k, v) <- logFileSettingsProperty.get.asScala) yield k -> v.petrify()).toMap
Settings(stageSettings.petrify(), m, getSomeActive())
val logFileSettings: Map[String, LogFileSettings] = (for ((k, v) <- mutLogFileSettingsMapProperty.get.asScala) yield {
k -> v.petrify()
}).toMap
Settings(mutStageSettings.petrify(), logFileSettings, getSomeActive())
}

def setStageSettings(stageSettings: StageSettings): Unit = {
this.stageSettings.setX(stageSettings.x)
this.stageSettings.setY(stageSettings.y)
this.stageSettings.setHeight(stageSettings.height)
this.stageSettings.setWidth(stageSettings.width)
mutStageSettings.setX(stageSettings.x)
mutStageSettings.setY(stageSettings.y)
mutStageSettings.setHeight(stageSettings.height)
mutStageSettings.setWidth(stageSettings.width)
}

def clearLogFileSettings(): Unit = {
mutLogFileSettingsMapProperty.clear()
setSomeActive(None)
}

def bindWindowProperties(window: Window): Unit = {
mutStageSettings.widthProperty.bind(window.getScene.widthProperty())
mutStageSettings.heightProperty.bind(window.getScene.heightProperty())
mutStageSettings.xProperty.bind(window.xProperty())
mutStageSettings.yProperty.bind(window.yProperty())
}

def unbindWindow(): Unit = {
mutStageSettings.widthProperty.unbind()
mutStageSettings.heightProperty.unbind()
mutStageSettings.xProperty.unbind()
mutStageSettings.yProperty.unbind()
}

def getStageY(): Double = mutStageSettings.yProperty.get()

def getStageX(): Double = mutStageSettings.xProperty.get()

def getStageHeight(): Int = mutStageSettings.heightProperty.get()

def getStageWidth(): Int = mutStageSettings.getWidth()

def getOrderedLogFileSettings(): Seq[LogFileSettings] =
mutLogFileSettingsMapProperty.get().values.asScala.toSeq.sortWith((lt, gt) => lt.getFirstOpened() < gt.getFirstOpened()).map(_.petrify())


}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object MutStageSettings {
}


class MutStageSettings extends Petrify[StageSettings] {
class MutStageSettings {

val xProperty = new SimpleDoubleProperty()

Expand All @@ -31,9 +31,11 @@ class MutStageSettings extends Petrify[StageSettings] {

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

def getWidth(): Int = widthProperty.get()

def setHeight(height: Int): Unit = heightProperty.set(height)

override def petrify(): StageSettings =
def petrify(): StageSettings =
StageSettings(xProperty.get()
, yProperty.get()
, widthProperty.get()
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/scala/app/logorrr/conf/mut/Petrify.scala

This file was deleted.

14 changes: 0 additions & 14 deletions app/src/main/scala/app/logorrr/io/Fs.scala

This file was deleted.

Loading