summaryrefslogtreecommitdiff
path: root/src/main/java/sevenUnitsGUI/SearchBoxList.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/sevenUnitsGUI/SearchBoxList.java')
-rw-r--r--src/main/java/sevenUnitsGUI/SearchBoxList.java54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/main/java/sevenUnitsGUI/SearchBoxList.java b/src/main/java/sevenUnitsGUI/SearchBoxList.java
index 8fba459..96f71de 100644
--- a/src/main/java/sevenUnitsGUI/SearchBoxList.java
+++ b/src/main/java/sevenUnitsGUI/SearchBoxList.java
@@ -1,5 +1,5 @@
/**
- * Copyright (C) 2019 Adrien Hopkins
+ * Copyright (C) 2019, 2022, 2024, 2025 Adrien Hopkins
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
@@ -49,7 +49,7 @@ final class SearchBoxList<E> extends JPanel {
/**
* The text to place in an empty search box.
- *
+ *
* @since 2019-04-13
* @since v0.2.0
*/
@@ -57,7 +57,7 @@ final class SearchBoxList<E> extends JPanel {
/**
* The color to use for an empty foreground.
- *
+ *
* @since 2019-04-13
* @since v0.2.0
*/
@@ -82,8 +82,9 @@ final class SearchBoxList<E> extends JPanel {
/**
* Creates an empty SearchBoxList
- *
+ *
* @since 2022-02-19
+ * @since v0.4.0
*/
public SearchBoxList() {
this(List.of(), null, false);
@@ -91,9 +92,10 @@ final class SearchBoxList<E> extends JPanel {
/**
* Creates the {@code SearchBoxList}.
- *
+ *
* @param itemsToFilter items to put in the list
* @since 2019-04-14
+ * @since v0.2.0
*/
public SearchBoxList(final Collection<E> itemsToFilter) {
this(itemsToFilter, null, false);
@@ -101,12 +103,12 @@ final class SearchBoxList<E> extends JPanel {
/**
* Creates the {@code SearchBoxList}.
- *
+ *
* @param itemsToFilter items to put in the list
* @param defaultOrdering default ordering of items after filtration
* (null=Comparable)
* @param caseSensitive whether or not the filtration is case-sensitive
- *
+ *
* @since 2019-04-13
* @since v0.2.0
*/
@@ -147,7 +149,7 @@ final class SearchBoxList<E> extends JPanel {
/**
* Adds an additional filter for searching.
- *
+ *
* @param filter filter to add.
* @since 2019-04-13
* @since v0.2.0
@@ -158,7 +160,7 @@ final class SearchBoxList<E> extends JPanel {
/**
* Resets the search filter.
- *
+ *
* @since 2019-04-13
* @since v0.2.0
*/
@@ -170,6 +172,7 @@ final class SearchBoxList<E> extends JPanel {
* @return items available in search list, including items that are hidden by
* the search filter
* @since 2022-03-30
+ * @since v0.4.0
*/
public Collection<E> getItems() {
return Collections.unmodifiableCollection(this.itemsToFilter);
@@ -180,7 +183,7 @@ final class SearchBoxList<E> extends JPanel {
* @since 2019-04-14
* @since v0.2.0
*/
- public final JTextField getSearchBox() {
+ public JTextField getSearchBox() {
return this.searchBox;
}
@@ -194,9 +197,8 @@ final class SearchBoxList<E> extends JPanel {
private Predicate<E> getSearchFilter(final String searchText) {
if (this.caseSensitive)
return item -> item.toString().contains(searchText);
- else
- return item -> item.toString().toLowerCase()
- .contains(searchText.toLowerCase());
+ return item -> item.toString().toLowerCase()
+ .contains(searchText.toLowerCase());
}
/**
@@ -204,7 +206,7 @@ final class SearchBoxList<E> extends JPanel {
* @since 2019-04-14
* @since v0.2.0
*/
- public final JList<E> getSearchList() {
+ public JList<E> getSearchList() {
return this.searchItems;
}
@@ -228,16 +230,16 @@ final class SearchBoxList<E> extends JPanel {
/**
* Re-applies the filters.
- *
+ *
* @since 2019-04-13
* @since v0.2.0
*/
public void reapplyFilter() {
- final String searchText = this.searchBoxEmpty ? ""
+ final var searchText = this.searchBoxEmpty ? ""
: this.searchBox.getText();
- final FilterComparator<E> comparator = new FilterComparator<>(searchText,
+ final var comparator = new FilterComparator<>(searchText,
this.defaultOrdering, this.caseSensitive);
- final Predicate<E> searchFilter = this.getSearchFilter(searchText);
+ final var searchFilter = this.getSearchFilter(searchText);
this.listModel.clear();
this.itemsToFilter.forEach(item -> {
@@ -255,7 +257,7 @@ final class SearchBoxList<E> extends JPanel {
/**
* Runs whenever the search box gains focus.
- *
+ *
* @param e focus event
* @since 2019-04-13
* @since v0.2.0
@@ -270,7 +272,7 @@ final class SearchBoxList<E> extends JPanel {
/**
* Runs whenever the search box loses focus.
- *
+ *
* @param e focus event
* @since 2019-04-13
* @since v0.2.0
@@ -288,7 +290,7 @@ final class SearchBoxList<E> extends JPanel {
* <p>
* Reapplies the search filter, and custom filters.
* </p>
- *
+ *
* @since 2019-04-14
* @since v0.2.0
*/
@@ -296,11 +298,11 @@ final class SearchBoxList<E> extends JPanel {
if (this.searchBoxFocused) {
this.searchBoxEmpty = this.searchBox.getText().equals("");
}
- final String searchText = this.searchBoxEmpty ? ""
+ final var searchText = this.searchBoxEmpty ? ""
: this.searchBox.getText();
- final FilterComparator<E> comparator = new FilterComparator<>(searchText,
+ final var comparator = new FilterComparator<>(searchText,
this.defaultOrdering, this.caseSensitive);
- final Predicate<E> searchFilter = this.getSearchFilter(searchText);
+ final var searchFilter = this.getSearchFilter(searchText);
// initialize list with items that match the filter then sort
this.listModel.clear();
@@ -323,6 +325,7 @@ final class SearchBoxList<E> extends JPanel {
*
* @param newItems new items to put in list
* @since 2021-05-22
+ * @since v0.3.0
*/
public void setItems(Collection<? extends E> newItems) {
this.itemsToFilter.clear();
@@ -332,8 +335,9 @@ final class SearchBoxList<E> extends JPanel {
/**
* Manually updates the search box's item list.
- *
+ *
* @since 2020-08-27
+ * @since v0.3.0
*/
public void updateList() {
this.searchBoxTextChanged();