Skip to content

Commit 7651ead

Browse files
committed
SwingSearchBar: make result limit configurable
1 parent af1b603 commit 7651ead

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main/java/org/scijava/ui/swing/search/SwingSearchBar.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
public class SwingSearchBar extends JTextField {
104104

105105
private static final String DEFAULT_MESSAGE = "Click here to search";
106-
private static final int MAX_RESULTS = 8;
107106

108107
private static final Color SEARCHBAR_FONT_COLOR = new Color(0, 0, 0);
109108
private static final Color SEARCHBAR_FONT_DEFAULT_COLOR = new Color(150, 150,
@@ -128,6 +127,9 @@ public class SwingSearchBar extends JTextField {
128127

129128
private final JButton exitButton;
130129

130+
/** The maximum number of results per search category. */
131+
private int resultLimit = 8;
132+
131133
private String searchTerm;
132134

133135
public SwingSearchBar(final Context context) {
@@ -194,6 +196,19 @@ public void activate() {
194196
});
195197
}
196198

199+
/** Gets the maximum number of results per search category. */
200+
public int getResultLimit() {
201+
return resultLimit;
202+
}
203+
204+
/** Sets the maximum number of results per search category. */
205+
public void setResultLimit(final int resultLimit) {
206+
if (resultLimit <= 0) {
207+
throw new IllegalArgumentException("Limit must be positive");
208+
}
209+
this.resultLimit = resultLimit;
210+
}
211+
197212
// -- Utility methods --
198213

199214
// TODO: Move this method to PluginService.
@@ -615,9 +630,9 @@ private void rebuild() {
615630

616631
if (completeResults.isEmpty()) continue;
617632

618-
// Limit to the top MAX_RESULTS matches only.
633+
// Limit to the top matches only.
619634
final List<SearchResult> results = completeResults.stream() //
620-
.limit(MAX_RESULTS).collect(Collectors.toList());
635+
.limit(resultLimit).collect(Collectors.toList());
621636

622637
// Add results as entries.
623638
for (final SearchResult result : results) {

0 commit comments

Comments
 (0)