Skip to content

Commit

Permalink
#114: adds a more compact display of searchtags
Browse files Browse the repository at this point in the history
  • Loading branch information
rladstaetter committed Oct 29, 2022
1 parent af30d85 commit 58883d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 41 deletions.
1 change: 0 additions & 1 deletion app/src/main/scala/app/logorrr/views/ops/RectButton.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ abstract class RectButton(width: Int
, tooltipMessage: String) extends Button {

setTooltip(new Tooltip(tooltipMessage))

setGraphic(ColorUtil.mkR(width, height, color))
setOnKeyPressed((event: KeyEvent) => {
if (event.getCode == KeyCode.ENTER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class FiltersToolBar(filteredList: FilteredList[LogEntry]
private def updateUnclassified(): Unit = {
val unclassified = new UnclassifiedFilter(filterButtons.keySet)
updateOccurrences(unclassified)
val searchTag = SearchTag(unclassified, occurrences, updateActiveFilter, removeFilter)
val searchTag = new SearchTag(unclassified, occurrences(unclassified), updateActiveFilter, removeFilter)
someUnclassifiedFilter.foreach(ftb => getItems.remove(ftb._2))
getItems.add(0, searchTag)
someUnclassifiedFilter = Option((unclassified, searchTag))
Expand All @@ -85,13 +85,13 @@ class FiltersToolBar(filteredList: FilteredList[LogEntry]
* @return
*/
def computeCurrentFilter(): Fltr = {
new AnyFilter(someUnclassifiedFilter.map(fst => if (fst._2.toggleButton.isSelected) Set(fst._1) else Set()).getOrElse(Set()) ++
filterButtons.filter(fst => fst._2.toggleButton.isSelected).keySet)
new AnyFilter(someUnclassifiedFilter.map(fst => if (fst._2.isSelected) Set(fst._1) else Set()).getOrElse(Set()) ++
filterButtons.filter(fst => fst._2.isSelected).keySet)
}

private def addSearchTag(filter: Filter): Unit = {
updateOccurrences(filter)
val searchTag = SearchTag(filter, occurrences, updateActiveFilter, removeFilter)
val searchTag = new SearchTag(filter, occurrences(filter), updateActiveFilter, removeFilter)
getItems.add(searchTag)
filterButtons = filterButtons + (filter -> searchTag)
}
Expand Down
63 changes: 27 additions & 36 deletions app/src/main/scala/app/logorrr/views/search/SearchTag.scala
Original file line number Diff line number Diff line change
@@ -1,47 +1,38 @@
package app.logorrr.views.search

import app.logorrr.views.ops.RectButton
import javafx.beans.{InvalidationListener, Observable}
import javafx.scene.control.{ToggleButton, ToolBar, Tooltip}
import javafx.scene.paint.Color
import javafx.scene.shape.Rectangle

import javafx.scene.control.{ContentDisplay, ToggleButton, Tooltip}

object SearchTag {

def apply(filter: Filter
, occurrences: Map[Filter, Int]
, updateActiveFilter: () => Unit
, removeFilter: Filter => Unit): SearchTag = {
val i = occurrences(filter)
val button = new ToggleButton(filter.pattern)
val tooltipMessage = if (i == 1) "one item found" else s"$i items found"
button.setTooltip(new Tooltip(tooltipMessage))
val r = new Rectangle(10, 10)
r.setFill(filter.color)
r.setStroke(Color.WHITE)
button.setGraphic(r)
button.setSelected(true)


button.selectedProperty().addListener(new InvalidationListener {
// if any of the buttons changes its selected value, reevaluate predicate
// and thus change contents of all views which display filtered List
override def invalidated(observable: Observable): Unit = updateActiveFilter()
})

/** filters can be removed, in this case update display */
val removeButton = new FiltersToolBar.RemoveButton(filter, removeFilter)

val st = new SearchTag(button)
if (!filter.isInstanceOf[UnclassifiedFilter]) {
st.getItems.add(removeButton)
}
st
class RemoveFilterbutton(filter: Filter, removeFilter: Filter => Unit) extends RectButton(10, 10, filter.color, "remove") {
setOnAction(_ => removeFilter(filter))
setStyle(
"""-fx-padding: 1 4 1 4;
|-fx-background-radius: 0;
|""".stripMargin)
}

}

/**
* Groups a toggle button to activate a filter and a button to remove it
* Displays a search term and triggers displaying the results.
*/
class SearchTag(val toggleButton: ToggleButton) extends ToolBar(toggleButton)
class SearchTag(filter: Filter
, i: Int
, updateActiveFilter: () => Unit
, removeFilter: Filter => Unit) extends ToggleButton(filter.pattern) {

setTooltip(new Tooltip(if (i == 1) "one item found" else s"$i items found"))

if (!filter.isInstanceOf[UnclassifiedFilter]) {
setContentDisplay(ContentDisplay.RIGHT)
setGraphic(new SearchTag.RemoveFilterbutton(filter, removeFilter))
}
setSelected(true)
selectedProperty().addListener(new InvalidationListener {
// if any of the buttons changes its selected value, reevaluate predicate
// and thus change contents of all views which display filtered List
override def invalidated(observable: Observable): Unit = updateActiveFilter()
})
}

0 comments on commit 58883d1

Please sign in to comment.