diff --git a/app/src/main/scala/app/logorrr/model/LogEntryInstantFormat.scala b/app/src/main/scala/app/logorrr/model/LogEntryInstantFormat.scala index 99f143c0..cb766cce 100644 --- a/app/src/main/scala/app/logorrr/model/LogEntryInstantFormat.scala +++ b/app/src/main/scala/app/logorrr/model/LogEntryInstantFormat.scala @@ -1,7 +1,7 @@ package app.logorrr.model import app.logorrr.util.CanLog -import app.logorrr.views.settings.timer.SimpleRange +import app.logorrr.views.settings.timestamp.SimpleRange import pureconfig.{ConfigReader, ConfigWriter} import pureconfig.generic.semiauto.{deriveReader, deriveWriter} diff --git a/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala b/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala index 838c33bd..864803bf 100644 --- a/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala +++ b/app/src/main/scala/app/logorrr/views/search/OpsToolBar.scala @@ -1,11 +1,13 @@ package app.logorrr.views.search +import app.logorrr.conf.LogoRRRGlobals import app.logorrr.io.FileId import app.logorrr.model.LogEntry import app.logorrr.util.OsUtil import app.logorrr.views.autoscroll.AutoScrollCheckBox import app.logorrr.views.block.HasBlockSizeProperty import app.logorrr.views.ops.{ClearLogButton, CopyLogButton, DecreaseBlockSizeButton, IncreaseBlockSizeButton} +import app.logorrr.views.settings.timestamp.TimerSettingsLogView import app.logorrr.views.text.toolbaractions.{DecreaseTextSizeButton, IncreaseTextSizeButton} import javafx.beans.property.SimpleIntegerProperty import javafx.collections.ObservableList @@ -18,7 +20,6 @@ import javafx.scene.input.{KeyCode, KeyEvent} object OpsToolBar { - /** increment / decrement font size */ val fontSizeStep: Int = 1 @@ -63,9 +64,12 @@ class OpsToolBar(fileId: FileId private val copySelectionButton = new CopyLogButton(fileId, filteredList) - // val firstNEntries: ObservableList[LogEntry] = TimerSettingsLogView.mkEntriesToShow(logEntries) + val logEntriesToShowInTimerSettingsStage: ObservableList[LogEntry] = TimerSettingsLogView.mkEntriesToShow(logEntries) - // val timerButton = new TimerButton(fileId, firstNEntries) + /** + * To configure the logformat of the timestamp used in a logfile + */ + val timestampSettingsButton = new TimestampSettingsButton( LogoRRRGlobals.getLogFileSettings(fileId), logEntriesToShowInTimerSettingsStage) def execSearchOnHitEnter(event: KeyEvent): Unit = { if (event.getCode == KeyCode.ENTER) { @@ -87,7 +91,7 @@ class OpsToolBar(fileId: FileId } val otherItems: Seq[Node] = { - Seq(autoScrollCheckBox, clearLogButton, copySelectionButton) + Seq(autoScrollCheckBox, clearLogButton, copySelectionButton, timestampSettingsButton) } getItems.addAll(searchItems ++ sizeItems ++ otherItems: _*) diff --git a/app/src/main/scala/app/logorrr/views/search/TimerButton.scala b/app/src/main/scala/app/logorrr/views/search/TimerButton.scala deleted file mode 100644 index a29edd45..00000000 --- a/app/src/main/scala/app/logorrr/views/search/TimerButton.scala +++ /dev/null @@ -1,55 +0,0 @@ -package app.logorrr.views.search - -import app.logorrr.conf.LogoRRRGlobals -import app.logorrr.conf.mut.MutLogFileSettings -import app.logorrr.io.FileId -import app.logorrr.model.{LogEntry, LogEntryInstantFormat} -import app.logorrr.util.CanLog -import app.logorrr.views.settings.timer.TimerSettingStage -import javafx.beans.binding.BooleanBinding -import javafx.collections.ObservableList -import javafx.scene.control.{Button, Tooltip} -import javafx.scene.layout.StackPane -import org.kordamp.ikonli.fontawesome5.FontAwesomeRegular -import org.kordamp.ikonli.javafx.FontIcon - - -class TimerButton(fileId: FileId - , logEntriesToDisplay: ObservableList[LogEntry]) - extends StackPane - with CanLog { - - def getSettings: MutLogFileSettings = LogoRRRGlobals.getLogFileSettings(fileId) - - def updateLogEntrySetting(leif: LogEntryInstantFormat): Unit = { - getSettings.setLogEntryInstantFormat(leif) - LogoRRRGlobals.persist() - } - - val button = new Button() - button.setBackground(null) - // since timerbutton is a stackpane, this css commands are necessary to have the same effect as - // defined in primer-light.css - button.setStyle( - """ - |-color-button-bg: -color-bg-subtle; - |-fx-background-insets: 0; - |""".stripMargin) - - button.setGraphic(new FontIcon(FontAwesomeRegular.CLOCK)) - button.setTooltip(new Tooltip("configure time format")) - - button.setOnAction(_ => { - new TimerSettingStage(getSettings, updateLogEntrySetting, logEntriesToDisplay).showAndWait() - }) - - private val binding: BooleanBinding = LogoRRRGlobals.getLogFileSettings(fileId).hasLogEntrySettingBinding.not() - - private val icon = new FontIcon() - icon.setStyle("-fx-icon-code:fas-exclamation-circle;-fx-icon-color:rgba(255, 0, 0, 1);-fx-icon-size:8;") - icon.setTranslateX(10) - icon.setTranslateY(-10) - icon.visibleProperty().bind(binding) - - getChildren.addAll(button, icon) -} diff --git a/app/src/main/scala/app/logorrr/views/search/TimestampSettingsButton.scala b/app/src/main/scala/app/logorrr/views/search/TimestampSettingsButton.scala new file mode 100644 index 00000000..c92eebb1 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/search/TimestampSettingsButton.scala @@ -0,0 +1,53 @@ +package app.logorrr.views.search + +import app.logorrr.conf.mut.MutLogFileSettings +import app.logorrr.model.LogEntry +import app.logorrr.views.settings.timestamp.TimestampSettingStage +import javafx.collections.ObservableList +import javafx.scene.control.{Button, Tooltip} +import javafx.scene.layout.StackPane +import org.kordamp.ikonli.fontawesome5.FontAwesomeRegular +import org.kordamp.ikonli.javafx.FontIcon + +/** + * Displays a clock in the ops tool bar, with a red exclamation mark if there is no setting for the + * timestamp format for the given log file. + * + * Given a time stamp format (for example: YYYY-MM-dd HH:mm:ss.SSS), LogoRRR is able to parse the timestamp + * and thus has new possibilities to analyse the log file. + * + * @param settings settings for specific log file + * @param logEntriesToDisplay the list of log entries to display in order to configure a time format + */ +class TimestampSettingsButton(settings: MutLogFileSettings + , logEntriesToDisplay: ObservableList[LogEntry]) extends StackPane { + + // since timerbutton is a stackpane, this css commands are necessary to have the same effect as + // defined in primer-light.css + val button: Button = { + val btn = new Button() + btn.setBackground(null) + btn.setStyle( + """ + |-color-button-bg: -color-bg-subtle; + |-fx-background-insets: 0; + |""".stripMargin) + btn.setGraphic(new FontIcon(FontAwesomeRegular.CLOCK)) + btn.setTooltip(new Tooltip("configure time format")) + btn.setOnAction(_ => new TimestampSettingStage(settings, logEntriesToDisplay).showAndWait()) + btn + } + + private val fontIcon = { + val icon = new FontIcon() + icon.setStyle("-fx-icon-code:fas-exclamation-circle;-fx-icon-color:rgba(255, 0, 0, 1);-fx-icon-size:8;") + icon.setTranslateX(10) + icon.setTranslateY(-10) + /** red exclamation mark is only visible if there is no timestamp setting for a given log file */ + icon.visibleProperty().bind(settings.hasLogEntrySettingBinding.not()) + icon + } + + getChildren.addAll(button, fontIcon) + +} diff --git a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingStage.scala b/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingStage.scala deleted file mode 100644 index 32b7344c..00000000 --- a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingStage.scala +++ /dev/null @@ -1,27 +0,0 @@ -package app.logorrr.views.settings.timer - -import app.logorrr.conf.mut.MutLogFileSettings -import app.logorrr.model.{LogEntry, LogEntryInstantFormat} -import app.logorrr.util.JfxUtils -import javafx.collections.ObservableList -import javafx.scene.Scene -import javafx.stage.{Modality, Stage} - -object TimerSettingStage { - - val width = 1100 - val height = 300 - -} - -class TimerSettingStage(settings: MutLogFileSettings - , updateLogEntrySetting: LogEntryInstantFormat => Unit - , logEntriesToDisplay: ObservableList[LogEntry]) extends Stage { - - private val timerSettingsBorderPane = new TimerSettingsBorderPane(settings, logEntriesToDisplay, updateLogEntrySetting, JfxUtils.closeStage(this)) - val scene = new Scene(timerSettingsBorderPane, TimerSettingStage.width, TimerSettingStage.height) - initModality(Modality.APPLICATION_MODAL) - setTitle(s"Timer settings for ${settings.getFileId.fileName}") - setScene(scene) - setOnCloseRequest(_ => this.close()) -} diff --git a/app/src/main/scala/app/logorrr/views/settings/timer/SimpleRange.scala b/app/src/main/scala/app/logorrr/views/settings/timestamp/SimpleRange.scala similarity index 89% rename from app/src/main/scala/app/logorrr/views/settings/timer/SimpleRange.scala rename to app/src/main/scala/app/logorrr/views/settings/timestamp/SimpleRange.scala index 40e3bde1..c4789fda 100644 --- a/app/src/main/scala/app/logorrr/views/settings/timer/SimpleRange.scala +++ b/app/src/main/scala/app/logorrr/views/settings/timestamp/SimpleRange.scala @@ -1,4 +1,4 @@ -package app.logorrr.views.settings.timer +package app.logorrr.views.settings.timestamp import pureconfig.{ConfigReader, ConfigWriter} import pureconfig.generic.semiauto.{deriveReader, deriveWriter} diff --git a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsLogView.scala b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimerSettingsLogView.scala similarity index 98% rename from app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsLogView.scala rename to app/src/main/scala/app/logorrr/views/settings/timestamp/TimerSettingsLogView.scala index 6e830e97..27b98f23 100644 --- a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsLogView.scala +++ b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimerSettingsLogView.scala @@ -1,4 +1,4 @@ -package app.logorrr.views.settings.timer +package app.logorrr.views.settings.timestamp import app.logorrr.conf.mut.MutLogFileSettings import app.logorrr.model.LogEntry diff --git a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsLogViewLabel.scala b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimerSettingsLogViewLabel.scala similarity index 98% rename from app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsLogViewLabel.scala rename to app/src/main/scala/app/logorrr/views/settings/timestamp/TimerSettingsLogViewLabel.scala index 44cb1c91..85756df2 100644 --- a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsLogViewLabel.scala +++ b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimerSettingsLogViewLabel.scala @@ -1,4 +1,4 @@ -package app.logorrr.views.settings.timer +package app.logorrr.views.settings.timestamp import app.logorrr.conf.mut.MutLogFileSettings import app.logorrr.model.LogEntry diff --git a/app/src/main/scala/app/logorrr/views/settings/timestamp/TimestampSettingStage.scala b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimestampSettingStage.scala new file mode 100644 index 00000000..3ce16bc3 --- /dev/null +++ b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimestampSettingStage.scala @@ -0,0 +1,26 @@ +package app.logorrr.views.settings.timestamp + +import app.logorrr.conf.mut.MutLogFileSettings +import app.logorrr.model.LogEntry +import app.logorrr.util.JfxUtils +import javafx.collections.ObservableList +import javafx.scene.Scene +import javafx.stage.{Modality, Stage} + +object TimestampSettingStage { + + val width = 1100 + val height = 300 + +} + +class TimestampSettingStage(settings: MutLogFileSettings + , logEntriesToDisplay: ObservableList[LogEntry]) extends Stage { + + private val timerSettingsBorderPane = new TimestampSettingsBorderPane(settings, logEntriesToDisplay, JfxUtils.closeStage(this)) + val scene = new Scene(timerSettingsBorderPane, TimestampSettingStage.width, TimestampSettingStage.height) + initModality(Modality.APPLICATION_MODAL) + setTitle(s"Timestamp settings for ${settings.getFileId.fileName}") + setScene(scene) + setOnCloseRequest(_ => this.close()) +} diff --git a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsBorderPane.scala b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimestampSettingsBorderPane.scala similarity index 78% rename from app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsBorderPane.scala rename to app/src/main/scala/app/logorrr/views/settings/timestamp/TimestampSettingsBorderPane.scala index 98b12f72..3b9e45b6 100644 --- a/app/src/main/scala/app/logorrr/views/settings/timer/TimerSettingsBorderPane.scala +++ b/app/src/main/scala/app/logorrr/views/settings/timestamp/TimestampSettingsBorderPane.scala @@ -1,5 +1,6 @@ -package app.logorrr.views.settings.timer +package app.logorrr.views.settings.timestamp +import app.logorrr.conf.LogoRRRGlobals import app.logorrr.conf.mut.MutLogFileSettings import app.logorrr.model.{LogEntry, LogEntryInstantFormat} import app.logorrr.util.{CanLog, HLink} @@ -11,10 +12,9 @@ import javafx.scene.control._ import javafx.scene.layout.{BorderPane, VBox} -object TimerSettingsBorderPane { +object TimestampSettingsBorderPane { - - private val dateTimeFormatterLink: HLink = HLink(UiNodes.OpenDateFormatterSite,"https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html", "format description") + private val dateTimeFormatterLink: HLink = HLink(UiNodes.OpenDateFormatterSite,"https://docs.oracle.com/en/java/javase/22/docs/api/java.base/java/time/format/DateTimeFormatter.html", "format description") def mkTf(name: String , somePrompt: Option[String] @@ -29,10 +29,9 @@ object TimerSettingsBorderPane { } } -class TimerSettingsBorderPane(settings: MutLogFileSettings - , logEntriesToDisplay: ObservableList[LogEntry] - , updateLogEntrySetting: LogEntryInstantFormat => Unit - , closeStage: => Unit) +class TimestampSettingsBorderPane(settings: MutLogFileSettings + , logEntriesToDisplay: ObservableList[LogEntry] + , closeStage: => Unit) extends BorderPane with CanLog { /* @@ -60,7 +59,7 @@ class TimerSettingsBorderPane(settings: MutLogFileSettings } private val selectedRangeLabel = new Label("Selected: ") - private val (timeFormatLabel, timeFormatTf) = TimerSettingsBorderPane.mkTf("time format", Option(""), Option(LogEntryInstantFormat.DefaultPattern), 30) + private val (timeFormatLabel, timeFormatTf) = TimestampSettingsBorderPane.mkTf("time format", Option(""), Option(LogEntryInstantFormat.DefaultPattern), 30) private val timerSettingsLogTextView = { val tslv = new TimerSettingsLogView(settings, logEntriesToDisplay) @@ -76,7 +75,9 @@ class TimerSettingsBorderPane(settings: MutLogFileSettings private val okButton = { val b = new Button("set new format") b.setOnAction(_ => { - updateLogEntrySetting(LogEntryInstantFormat(SimpleRange(getStartCol, getEndCol), timeFormatTf.getText.trim)) + val leif = LogEntryInstantFormat(SimpleRange(getStartCol, getEndCol), timeFormatTf.getText.trim) + settings.setLogEntryInstantFormat(leif) + LogoRRRGlobals.persist() closeStage }) b @@ -90,7 +91,7 @@ class TimerSettingsBorderPane(settings: MutLogFileSettings } }*/ - private val hyperlink: Hyperlink = TimerSettingsBorderPane.dateTimeFormatterLink.mkHyperLink() + private val hyperlink: Hyperlink = TimestampSettingsBorderPane.dateTimeFormatterLink.mkHyperLink() private val selectedBar = new ToolBar(selectedRangeLabel) private val timeFormatBar = new ToolBar(timeFormatLabel, timeFormatTf, hyperlink) private val bar = new ToolBar(rangeColLabel, okButton) diff --git a/app/src/test/scala/app/logorrr/conf/mut/SimpleRangeSpec.scala b/app/src/test/scala/app/logorrr/conf/mut/SimpleRangeSpec.scala index 81274979..34585e49 100644 --- a/app/src/test/scala/app/logorrr/conf/mut/SimpleRangeSpec.scala +++ b/app/src/test/scala/app/logorrr/conf/mut/SimpleRangeSpec.scala @@ -1,6 +1,6 @@ package app.logorrr.conf.mut -import app.logorrr.views.settings.timer.SimpleRange +import app.logorrr.views.settings.timestamp.SimpleRange import org.scalacheck.Gen import scala.util.Random