-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#114: adds a more compact display of searchtags
- Loading branch information
1 parent
af30d85
commit 58883d1
Showing
3 changed files
with
31 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 27 additions & 36 deletions
63
app/src/main/scala/app/logorrr/views/search/SearchTag.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) | ||
} |