summaryrefslogtreecommitdiff
path: root/src/org/unitConverter/converterGUI/SearchBoxList.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/unitConverter/converterGUI/SearchBoxList.java')
-rw-r--r--src/org/unitConverter/converterGUI/SearchBoxList.java35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/org/unitConverter/converterGUI/SearchBoxList.java b/src/org/unitConverter/converterGUI/SearchBoxList.java
index 35cc347..1995466 100644
--- a/src/org/unitConverter/converterGUI/SearchBoxList.java
+++ b/src/org/unitConverter/converterGUI/SearchBoxList.java
@@ -33,20 +33,29 @@ import javax.swing.JTextField;
/**
* @author Adrien Hopkins
* @since 2019-04-13
+ * @since v0.2.0
*/
final class SearchBoxList extends JPanel {
/**
* @since 2019-04-13
+ * @since v0.2.0
*/
private static final long serialVersionUID = 6226930279415983433L;
/**
* The text to place in an empty search box.
+ *
+ * @since 2019-04-13
+ * @since v0.2.0
*/
private static final String EMPTY_TEXT = "Search...";
+
/**
* The color to use for an empty foreground.
+ *
+ * @since 2019-04-13
+ * @since v0.2.0
*/
private static final Color EMPTY_FOREGROUND = new Color(192, 192, 192);
@@ -66,6 +75,13 @@ final class SearchBoxList extends JPanel {
private final Comparator<String> defaultOrdering;
private final boolean caseSensitive;
+ /**
+ * Creates the {@code SearchBoxList}.
+ *
+ * @param itemsToFilter
+ * items to put in the list
+ * @since 2019-04-14
+ */
public SearchBoxList(final Collection<String> itemsToFilter) {
this(itemsToFilter, null, false);
}
@@ -73,7 +89,15 @@ final class SearchBoxList 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
*/
public SearchBoxList(final Collection<String> itemsToFilter, final Comparator<String> defaultOrdering,
final boolean caseSensitive) {
@@ -116,6 +140,7 @@ final class SearchBoxList extends JPanel {
* @param filter
* filter to add.
* @since 2019-04-13
+ * @since v0.2.0
*/
public void addSearchFilter(final Predicate<String> filter) {
this.customSearchFilter = this.customSearchFilter.and(filter);
@@ -125,6 +150,7 @@ final class SearchBoxList extends JPanel {
* Resets the search filter.
*
* @since 2019-04-13
+ * @since v0.2.0
*/
public void clearSearchFilters() {
this.customSearchFilter = o -> true;
@@ -133,6 +159,7 @@ final class SearchBoxList extends JPanel {
/**
* @return this component's search box component
* @since 2019-04-14
+ * @since v0.2.0
*/
public final JTextField getSearchBox() {
return this.searchBox;
@@ -143,6 +170,7 @@ final class SearchBoxList extends JPanel {
* text to search for
* @return a filter that filters out that text, based on this list's case sensitive setting
* @since 2019-04-14
+ * @since v0.2.0
*/
private Predicate<String> getSearchFilter(final String searchText) {
if (this.caseSensitive)
@@ -154,6 +182,7 @@ final class SearchBoxList extends JPanel {
/**
* @return this component's list component
* @since 2019-04-14
+ * @since v0.2.0
*/
public final JList<String> getSearchList() {
return this.searchItems;
@@ -162,6 +191,7 @@ final class SearchBoxList extends JPanel {
/**
* @return index selected in item list
* @since 2019-04-14
+ * @since v0.2.0
*/
public int getSelectedIndex() {
return this.searchItems.getSelectedIndex();
@@ -170,6 +200,7 @@ final class SearchBoxList extends JPanel {
/**
* @return value selected in item list
* @since 2019-04-13
+ * @since v0.2.0
*/
public String getSelectedValue() {
return this.searchItems.getSelectedValue();
@@ -179,6 +210,7 @@ final class SearchBoxList extends JPanel {
* Re-applies the filters.
*
* @since 2019-04-13
+ * @since v0.2.0
*/
public void reapplyFilter() {
final String searchText = this.searchBoxEmpty ? "" : this.searchBox.getText();
@@ -205,6 +237,7 @@ final class SearchBoxList extends JPanel {
* @param e
* focus event
* @since 2019-04-13
+ * @since v0.2.0
*/
private void searchBoxFocusGained(final FocusEvent e) {
this.searchBoxFocused = true;
@@ -220,6 +253,7 @@ final class SearchBoxList extends JPanel {
* @param e
* focus event
* @since 2019-04-13
+ * @since v0.2.0
*/
private void searchBoxFocusLost(final FocusEvent e) {
this.searchBoxFocused = false;
@@ -236,6 +270,7 @@ final class SearchBoxList extends JPanel {
* </p>
*
* @since 2019-04-14
+ * @since v0.2.0
*/
private void searchBoxTextChanged() {
if (this.searchBoxFocused) {