File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
app/src/cc/arduino/contributions/ui Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -43,13 +43,21 @@ public class FilterJTextField extends JTextField {
4343 private final String filterHint ;
4444
4545 private boolean showingHint ;
46+ private Timer timer ;
4647
4748 public FilterJTextField (String hint ) {
4849 super (hint );
4950 filterHint = hint ;
5051
5152 showingHint = true ;
5253 updateStyle ();
54+ timer = new Timer (1000 , new ActionListener () {
55+ @ Override
56+ public void actionPerformed (ActionEvent e ) {
57+ applyFilter ();
58+ timer .stop ();
59+ }
60+ });
5361
5462 addFocusListener (new FocusListener () {
5563 public void focusLost (FocusEvent focusEvent ) {
@@ -68,14 +76,38 @@ public void focusGained(FocusEvent focusEvent) {
6876 }
6977 });
7078
79+ getDocument ().addDocumentListener (new DocumentListener () {
80+ public void removeUpdate (DocumentEvent e ) {
81+ spawnTimer ();
82+ }
83+
84+ public void insertUpdate (DocumentEvent e ) {
85+ spawnTimer ();
86+ }
87+
88+ public void changedUpdate (DocumentEvent e ) {
89+
90+ }
91+ });
92+
7193 addActionListener (new ActionListener () {
7294 @ Override
7395 public void actionPerformed (ActionEvent e ) {
96+ if (timer .isRunning ()) {
97+ timer .stop ();
98+ }
7499 applyFilter ();
75100 }
76101 });
77102 }
78103
104+ private void spawnTimer () {
105+ if (timer .isRunning ()) {
106+ timer .stop ();
107+ }
108+ timer .start ();
109+ }
110+
79111 public void applyFilter () {
80112 String filter = showingHint ? "" : getText ();
81113 filter = filter .toLowerCase ();
You can’t perform that action at this time.
0 commit comments