From: tcofoegbu Date: Tue, 26 Apr 2016 09:21:56 +0000 (+0100) Subject: JAL-2071 improvement to reduce webservice requests to Free Text Search (FTS) services... X-Git-Tag: Release_2_10_0~255 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=0f2e9e7f2244495f17a7facc5925f74c3b322324;p=jalview.git JAL-2071 improvement to reduce webservice requests to Free Text Search (FTS) services by using swing timer to deffer textfield actions until user stops typing for a certain amount of time --- 0f2e9e7f2244495f17a7facc5925f74c3b322324 diff --cc src/jalview/fts/core/GFTSPanel.java index 67983a1,d640df8..cae271d --- a/src/jalview/fts/core/GFTSPanel.java +++ b/src/jalview/fts/core/GFTSPanel.java @@@ -35,6 -32,6 +35,8 @@@ import java.awt.CardLayout import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; ++import java.awt.event.FocusEvent; ++import java.awt.event.FocusListener; import java.awt.event.KeyAdapter; import java.awt.event.KeyEvent; import java.awt.event.MouseAdapter; @@@ -57,6 -49,6 +59,7 @@@ import javax.swing.JScrollPane import javax.swing.JTabbedPane; import javax.swing.JTable; import javax.swing.JTextField; ++import javax.swing.Timer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; @@@ -354,24 -342,24 +357,29 @@@ public abstract class GFTSPanel extend } }); -- txt_search.getDocument().addDocumentListener(new DocumentListener() ++ final DeferredTextInputListener listener = new DeferredTextInputListener( ++ 500, ++ new ActionListener() ++ { ++ @Override ++ public void actionPerformed(ActionEvent e) ++ { ++ searchAction(); ++ } ++ }, false); ++ txt_search.getDocument().addDocumentListener(listener); ++ txt_search.addFocusListener(new FocusListener() { @Override -- public void insertUpdate(DocumentEvent e) ++ public void focusGained(FocusEvent e) { - searchAction(); - } - - @Override - public void removeUpdate(DocumentEvent e) - { - searchAction(); - txt_search_ActionPerformed(); ++ listener.start(); } @Override - public void changedUpdate(DocumentEvent e) - public void removeUpdate(DocumentEvent e) ++ public void focusLost(FocusEvent e) { - searchAction(); - txt_search_ActionPerformed(); - } - - @Override - public void changedUpdate(DocumentEvent e) - { - txt_search_ActionPerformed(); ++ listener.stop(); } }); @@@ -441,9 -427,9 +449,50 @@@ mainFrame.setVisible(true); mainFrame.setContentPane(this); mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); + Desktop.addInternalFrame(mainFrame, getFTSFrameTitle(), 800, 400); + } + ++ public class DeferredTextInputListener implements DocumentListener ++ { ++ private final Timer swingTimer; ++ ++ public DeferredTextInputListener(int timeOut, ActionListener listener, ++ boolean repeats) ++ { ++ swingTimer = new Timer(timeOut, listener); ++ swingTimer.setRepeats(repeats); ++ } ++ ++ public void start() ++ { ++ swingTimer.start(); ++ } ++ ++ public void stop() ++ { ++ swingTimer.stop(); ++ } ++ ++ @Override ++ public void insertUpdate(DocumentEvent e) ++ { ++ swingTimer.restart(); ++ } ++ ++ @Override ++ public void removeUpdate(DocumentEvent e) ++ { ++ swingTimer.restart(); ++ } ++ ++ @Override ++ public void changedUpdate(DocumentEvent e) ++ { ++ swingTimer.restart(); ++ } ++ + } + public boolean wantedFieldsUpdated() { if (previousWantedFields == null)