Author: dcosse Date: 2014-03-14 22:17:19 +0100 (Fri, 14 Mar 2014) New Revision: 3763 Url: http://forge.chorem.org/projects/lima/repository/revisions/3763 Log: refs #993 mise en place d'un timer afin de laisser le temps ?\195?\160 l'utilisateur d'entrer plusieurs carat?\195?\168res pour la recherche Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountComboBox.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountComboBox.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountComboBox.java 2014-03-14 16:43:51 UTC (rev 3762) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountComboBox.java 2014-03-14 21:17:19 UTC (rev 3763) @@ -27,6 +27,8 @@ import java.awt.event.KeyEvent; import java.awt.event.KeyListener; +import java.util.Timer; +import java.util.TimerTask; import javax.swing.JComboBox; @@ -48,6 +50,10 @@ private static final long serialVersionUID = 1L; + protected Timer timer; + + protected boolean sheduledTask; + public AccountComboBox() { AutoCompleteDecorator.decorate(this, AccountToString.getInstance()); getEditor().getEditorComponent().addKeyListener(this); @@ -77,19 +83,58 @@ @Override public void keyReleased(KeyEvent e) { - Object object = getSelectedItem(); - if (object instanceof Account) { - fireActionEvent(); - } + if (!sheduledTask) { + Timer timer = getTimer(); + TimerTaskKeyEvent task = new TimerTaskKeyEvent(); + task.setE(e); - // delegate popup list menu - if (e.getKeyChar() == KeyEvent.VK_ENTER) { - firePopupMenuCanceled(); + timer.schedule(task, 2000); + sheduledTask = true; } } @Override public void keyTyped(KeyEvent e) { + Timer timer = getTimer(); + if (sheduledTask){ + timer.cancel(); + sheduledTask = false; + resetTimer(); + } + } + protected void resetTimer(){ + this.timer = null; + } + protected Timer getTimer() { + if (timer == null) { + timer = new Timer(); + } + return this.timer; } + + + + public class TimerTaskKeyEvent extends TimerTask { + + protected KeyEvent e; + + @Override + public void run() { + Object object = getSelectedItem(); + if (object instanceof Account) { + fireActionEvent(); + } + + // delegate popup list menu + if (e.getKeyChar() == KeyEvent.VK_ENTER) { + firePopupMenuCanceled(); + } + sheduledTask = false; + } + + public void setE(KeyEvent e) { + this.e = e; + } + } }