|
| 1 | +/* |
| 2 | + * This file is part of Arduino. |
| 3 | + * |
| 4 | + * Copyright 2014 Arduino LLC (http://www.arduino.cc/) |
| 5 | + * |
| 6 | + * Arduino is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or |
| 9 | + * (at your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | + * |
| 20 | + * As a special exception, you may use this file as part of a free software |
| 21 | + * library without restriction. Specifically, if other files instantiate |
| 22 | + * templates or use macros or inline functions from this file, or you compile |
| 23 | + * this file and link it with other files to produce an executable, this |
| 24 | + * file does not by itself cause the resulting executable to be covered by |
| 25 | + * the GNU General Public License. This exception does not however |
| 26 | + * invalidate any other reasons why the executable file might be covered by |
| 27 | + * the GNU General Public License. |
| 28 | + */ |
1 | 29 | package cc.arduino.packages.contributions.ui;
|
2 | 30 |
|
3 | 31 | import java.awt.Color;
|
4 | 32 | import java.awt.Font;
|
5 | 33 | import java.awt.event.FocusEvent;
|
6 | 34 | import java.awt.event.FocusListener;
|
7 |
| -import java.util.ArrayList; |
8 |
| -import java.util.Arrays; |
9 |
| -import java.util.List; |
10 | 35 |
|
11 | 36 | import javax.swing.JTextField;
|
12 | 37 | import javax.swing.UIManager;
|
|
16 | 41 | @SuppressWarnings("serial")
|
17 | 42 | public class FilterJTextField extends JTextField {
|
18 | 43 | private String filterHint;
|
19 |
| - boolean showingHint; |
20 |
| - List<String> filters; |
| 44 | + |
| 45 | + private boolean showingHint; |
21 | 46 |
|
22 | 47 | public FilterJTextField(String hint) {
|
23 | 48 | super(hint);
|
24 | 49 | filterHint = hint;
|
25 | 50 |
|
26 | 51 | showingHint = true;
|
27 |
| - filters = new ArrayList<String>(); |
28 | 52 | updateStyle();
|
29 | 53 |
|
30 | 54 | addFocusListener(new FocusListener() {
|
@@ -59,18 +83,17 @@ public void changedUpdate(DocumentEvent e) {
|
59 | 83 | });
|
60 | 84 | }
|
61 | 85 |
|
62 |
| - public void applyFilter() { |
63 |
| - String filter = getFilterText(); |
| 86 | + private void applyFilter() { |
| 87 | + String filter = showingHint ? "" : getText(); |
64 | 88 | filter = filter.toLowerCase();
|
65 | 89 |
|
66 | 90 | // Replace anything but 0-9, a-z, or : with a space
|
67 | 91 | filter = filter.replaceAll("[^\\x30-\\x39^\\x61-\\x7a^\\x3a]", " ");
|
68 |
| - filters = Arrays.asList(filter.split(" ")); |
69 |
| - // filterLibraries(category, filters); |
| 92 | + onFilter(filter.split(" ")); |
70 | 93 | }
|
71 | 94 |
|
72 |
| - public String getFilterText() { |
73 |
| - return showingHint ? "" : getText(); |
| 95 | + protected void onFilter(String[] strings) { |
| 96 | + // Empty |
74 | 97 | }
|
75 | 98 |
|
76 | 99 | public void updateStyle() {
|
|
0 commit comments