diff --git a/app/src/main/scala/app/logorrr/views/ops/RectButton.scala b/app/src/main/scala/app/logorrr/views/ops/RectButton.scala index 799bbb57..eaf8ada8 100644 --- a/app/src/main/scala/app/logorrr/views/ops/RectButton.scala +++ b/app/src/main/scala/app/logorrr/views/ops/RectButton.scala @@ -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) { diff --git a/app/src/main/scala/app/logorrr/views/search/FiltersToolBar.scala b/app/src/main/scala/app/logorrr/views/search/FiltersToolBar.scala index f9791033..8543f8cf 100644 --- a/app/src/main/scala/app/logorrr/views/search/FiltersToolBar.scala +++ b/app/src/main/scala/app/logorrr/views/search/FiltersToolBar.scala @@ -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)) @@ -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) } diff --git a/app/src/main/scala/app/logorrr/views/search/SearchTag.scala b/app/src/main/scala/app/logorrr/views/search/SearchTag.scala index f5d6c7d2..a14a56f0 100644 --- a/app/src/main/scala/app/logorrr/views/search/SearchTag.scala +++ b/app/src/main/scala/app/logorrr/views/search/SearchTag.scala @@ -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() + }) +}