File tree 1 file changed +32
-0
lines changed
app/src/cc/arduino/contributions/ui
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 {
43
43
private final String filterHint ;
44
44
45
45
private boolean showingHint ;
46
+ private Timer timer ;
46
47
47
48
public FilterJTextField (String hint ) {
48
49
super (hint );
49
50
filterHint = hint ;
50
51
51
52
showingHint = true ;
52
53
updateStyle ();
54
+ timer = new Timer (1000 , new ActionListener () {
55
+ @ Override
56
+ public void actionPerformed (ActionEvent e ) {
57
+ applyFilter ();
58
+ timer .stop ();
59
+ }
60
+ });
53
61
54
62
addFocusListener (new FocusListener () {
55
63
public void focusLost (FocusEvent focusEvent ) {
@@ -68,14 +76,38 @@ public void focusGained(FocusEvent focusEvent) {
68
76
}
69
77
});
70
78
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
+
71
93
addActionListener (new ActionListener () {
72
94
@ Override
73
95
public void actionPerformed (ActionEvent e ) {
96
+ if (timer .isRunning ()) {
97
+ timer .stop ();
98
+ }
74
99
applyFilter ();
75
100
}
76
101
});
77
102
}
78
103
104
+ private void spawnTimer () {
105
+ if (timer .isRunning ()) {
106
+ timer .stop ();
107
+ }
108
+ timer .start ();
109
+ }
110
+
79
111
public void applyFilter () {
80
112
String filter = showingHint ? "" : getText ();
81
113
filter = filter .toLowerCase ();
You can’t perform that action at this time.
0 commit comments