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

Remember active filters #156

Merged
merged 6 commits into from
Oct 2, 2023
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
2 changes: 1 addition & 1 deletion app/src/main/java/app/logorrr/io/FileManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ object FileManager extends CanLog {
private def openFileWithDetectedEncoding(path: Path): BufferedReader = {
val encoding = FEncoding(path)
if (encoding == Unknown) {
logWarn(encoding.asString + " encoding - fallback to UTF-8")
logTrace(s"${encoding.asString} encoding - fallback to UTF-8")
new BufferedReader(new InputStreamReader(new FileInputStream(path.toFile), UTF8.asString))
} else {
new BufferedReader(new InputStreamReader(new FileInputStream(path.toFile), encoding.asString))
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/scala/app/logorrr/LogoRRRApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LogoRRRApp extends javafx.application.Application with CanLog {


def start(stage: Stage): Unit = {
logInfo(s"Started " + AppMeta.fullAppNameWithVersion)
logInfo(s"Started ${AppMeta.fullAppNameWithVersion}")
logInfo(s"Working directory: ${Paths.get("").toAbsolutePath.toString}")
val settings: Settings = SettingsIO.fromFile()
LogoRRRGlobals.set(settings, getHostServices)
Expand Down
28 changes: 14 additions & 14 deletions app/src/main/scala/app/logorrr/conf/LogoRRRGlobals.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,29 @@ object LogoRRRGlobals extends CanLog {
private val hostServicesProperty = new SimpleObjectProperty[HostServices]()

def persist(): Unit = {
Fs.write(FilePaths.settingsFilePath, ConfigWriter[Settings].to(LogoRRRGlobals.getSettings()).render(renderOptions))
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())
window.setX(LogoRRRGlobals.getStageX)
window.setY(LogoRRRGlobals.getStageY)
window.setWidth(LogoRRRGlobals.getStageWidth)
window.setHeight(LogoRRRGlobals.getStageHeight)

mutSettings.bindWindowProperties(window)
}

def unbindWindow(): Unit = mutSettings.unbindWindow()

def getStageWidth(): Int = mutSettings.getStageWidth()
def getStageWidth: Int = mutSettings.getStageWidth()

def getStageHeight(): Int = mutSettings.getStageHeight()
def getStageHeight: Int = mutSettings.getStageHeight()

def getStageX(): Double = mutSettings.getStageX()
def getStageX: Double = mutSettings.getStageX()

def getStageY(): Double = mutSettings.getStageY()
def getStageY: Double = mutSettings.getStageY()

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

Expand All @@ -56,11 +56,11 @@ object LogoRRRGlobals extends CanLog {
setHostServices(hostServices)
}

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

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

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

def removeLogFile(pathAsString: String): Unit = {

Expand All @@ -70,7 +70,7 @@ object LogoRRRGlobals extends CanLog {
case x => x
})

if (OsUtil.isMac && !OsUtil.inTest) {
if (OsUtil.enableSecurityBookmarks) {
OsxBridge.releasePath(pathAsString)
}

Expand All @@ -86,11 +86,11 @@ object LogoRRRGlobals extends CanLog {
def mupdate(t: MutLogFileSettings => Unit)(pathAsString: String): Unit =
Option(mutSettings.getMutLogFileSetting(pathAsString)) match {
case Some(logFileSettings) => t(logFileSettings)
case None => logWarn(s"${pathAsString} not found.")
case None => logWarn(s"$pathAsString not found.")
}


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
26 changes: 16 additions & 10 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,9 +40,15 @@ class MutLogFileSettings {
val someLogEntrySettingsProperty = new SimpleObjectProperty[Option[LogEntryInstantFormat]](None)
val blockWidthSettingsProperty = new SimpleIntegerProperty()

def getSomeLogEntrySetting: Option[LogEntryInstantFormat] = someLogEntrySettingsProperty.get()
def setFilters(filters: Seq[Filter]): Unit = {
filtersProperty.setAll(filters.asJava)
}

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

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

override def computeValue(): Boolean = {
Expand All @@ -62,19 +68,19 @@ class MutLogFileSettings {

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

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

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

def getFilters() = filtersProperty.asScala.toSeq
def getFilters: Seq[Filter] = 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 selectedLineNumber(lineNumber: Int): Unit = selectedLineNumber.set(lineNumber)

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

Expand All @@ -87,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
4 changes: 2 additions & 2 deletions app/src/main/scala/app/logorrr/model/LogFileReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import java.nio.file.Path
object LogFileReader extends CanLog {

def readFromFile(logFile: Path): Seq[String] = {
if (OsUtil.isMac && !OsUtil.inTest) {
logInfo("Registering security bookmark for " + logFile.toAbsolutePath.toString)
if (OsUtil.enableSecurityBookmarks) {
logInfo(s"Registering security bookmark for ${logFile.toAbsolutePath.toString}")
OsxBridge.registerPath(logFile.toAbsolutePath.toString)
}
val lines = FileManager.fromPath(logFile)
Expand Down
12 changes: 6 additions & 6 deletions app/src/main/scala/app/logorrr/model/LogFileSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import app.logorrr.util.{CanLog, OsUtil}
import app.logorrr.views.search.Filter
import javafx.collections.{FXCollections, ObservableList}
import javafx.scene.paint.Color
import pureconfig.{ConfigReader, ConfigWriter}
import pureconfig.generic.semiauto.{deriveReader, deriveWriter}
import pureconfig.{ConfigReader, ConfigWriter}

import java.nio.file.{Files, Path, Paths}
import java.time.Instant
Expand All @@ -23,10 +23,10 @@ object LogFileSettings {
private val DefaultLogFormat: Option[LogEntryInstantFormat] = None
private val DefaultAutoScroll = false

private val finest: Filter = new Filter("FINEST", Color.GREY)
private val info: Filter = new Filter("INFO", Color.GREEN)
private val warning: Filter = new Filter("WARNING", Color.ORANGE)
private val severe: Filter = new Filter("SEVERE", Color.RED)
private val finest: Filter = new Filter("FINEST", Color.GREY, true)
private val info: Filter = new Filter("INFO", Color.GREEN, true)
private val warning: Filter = new Filter("WARNING", Color.ORANGE, true)
private val severe: Filter = new Filter("SEVERE", Color.RED, true)

val DefaultFilter: Seq[Filter] = Seq(finest, info, warning, severe)
val DefaultFontSize = 12
Expand Down 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
4 changes: 2 additions & 2 deletions app/src/main/scala/app/logorrr/util/HLink.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package app.logorrr.util
import app.logorrr.conf.LogoRRRGlobals
import javafx.scene.control.Hyperlink

import java.net.URL
import java.net.{URI, URL}

object HLink {

def apply(url: String, description: String): HLink = {
apply(new URL(url), description)
apply(URI.create(url).toURL, description)
}

}
Expand Down
29 changes: 5 additions & 24 deletions app/src/main/scala/app/logorrr/views/LogFileTab.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class LogFileTab(val pathAsString: String
op
}

private val filtersToolBar = {
val filtersToolBar = {
val fbtb = new FiltersToolBar(filteredList, removeFilter)
fbtb.filtersProperty.bind(filtersListProperty)
fbtb
Expand Down Expand Up @@ -159,7 +159,7 @@ class LogFileTab(val pathAsString: String
}
})

if (getLogFileSettings.isAutoScroll()) {
if (getLogFileSettings.isAutoScroll) {
startTailer()
}

Expand All @@ -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 Expand Up @@ -267,12 +259,11 @@ class LogFileTab(val pathAsString: String
* - update file menu
*
*/
def closeTab(): Unit = {
shutdown()
}
def closeTab(): Unit = shutdown()


def shutdown(): Unit = {
if (getLogFileSettings.isAutoScroll()) {
if (getLogFileSettings.isAutoScroll) {
stopTailer()
}
LogoRRRGlobals.removeLogFile(pathAsString)
Expand All @@ -285,15 +276,5 @@ class LogFileTab(val pathAsString: String

def removeFilter(filter: Filter): Unit = filtersListProperty.remove(filter)

/*
def getVisualViewWidth(): Double = {
val w = splitPane.getDividers.get(0).getPosition * splitPane.getWidth
if (w != 0.0) {
w
} else {
initialWidth.doubleValue()
}
}
*/

}
13 changes: 0 additions & 13 deletions app/src/main/scala/app/logorrr/views/autoscroll/AutoScroller.scala

This file was deleted.

Loading