1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-31 20:52:13 +01:00

[LibManager] Restore "search on type" with 1 second grace period

This commit is contained in:
Martino Facchin 2019-02-15 10:44:56 +01:00
parent f3d521d820
commit 8f5f4f594d

View File

@ -43,6 +43,7 @@ public class FilterJTextField extends JTextField {
private final String filterHint;
private boolean showingHint;
private Timer timer;
public FilterJTextField(String hint) {
super(hint);
@ -50,6 +51,13 @@ public class FilterJTextField extends JTextField {
showingHint = true;
updateStyle();
timer = new Timer(1000, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
applyFilter();
timer.stop();
}
});
addFocusListener(new FocusListener() {
public void focusLost(FocusEvent focusEvent) {
@ -68,14 +76,38 @@ public class FilterJTextField extends JTextField {
}
});
getDocument().addDocumentListener(new DocumentListener() {
public void removeUpdate(DocumentEvent e) {
spawnTimer();
}
public void insertUpdate(DocumentEvent e) {
spawnTimer();
}
public void changedUpdate(DocumentEvent e) {
}
});
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (timer.isRunning()) {
timer.stop();
}
applyFilter();
}
});
}
private void spawnTimer() {
if (timer.isRunning()) {
timer.stop();
}
timer.start();
}
public void applyFilter() {
String filter = showingHint ? "" : getText();
filter = filter.toLowerCase();