Author: dcosse Date: 2014-03-17 09:36:38 +0100 (Mon, 17 Mar 2014) New Revision: 3764 Url: http://forge.chorem.org/projects/lima/repository/revisions/3764 Log: fixes #993 utilisation d'un boolean safe thread 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 21:17:19 UTC (rev 3763) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountComboBox.java 2014-03-17 08:36:38 UTC (rev 3764) @@ -29,6 +29,7 @@ import java.awt.event.KeyListener; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.atomic.AtomicBoolean; import javax.swing.JComboBox; @@ -52,7 +53,7 @@ protected Timer timer; - protected boolean sheduledTask; + protected AtomicBoolean scheduledTask = new AtomicBoolean(false); public AccountComboBox() { AutoCompleteDecorator.decorate(this, AccountToString.getInstance()); @@ -83,22 +84,22 @@ @Override public void keyReleased(KeyEvent e) { - if (!sheduledTask) { + if (scheduledTask.get() == false) { Timer timer = getTimer(); TimerTaskKeyEvent task = new TimerTaskKeyEvent(); task.setE(e); timer.schedule(task, 2000); - sheduledTask = true; + scheduledTask.set(true); } } @Override public void keyTyped(KeyEvent e) { Timer timer = getTimer(); - if (sheduledTask){ + if (scheduledTask.get() == true){ timer.cancel(); - sheduledTask = false; + scheduledTask.set(false); resetTimer(); } } @@ -130,11 +131,12 @@ if (e.getKeyChar() == KeyEvent.VK_ENTER) { firePopupMenuCanceled(); } - sheduledTask = false; + scheduledTask.compareAndSet(true, false); } public void setE(KeyEvent e) { this.e = e; } } + }