Updated copyright dates.
[trakem2.git] / ini / trakem2 / display / DisplayableChooser.java
blobe6f8c84e361e3a89720153424344c56c15e48ac6
1 /**
3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2005-2009 Albert Cardona and Rodney Douglas.
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation (http://www.gnu.org/licenses/gpl.txt )
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 You may contact Albert Cardona at acardona at ini.phys.ethz.ch
20 Institute of Neuroinformatics, University of Zurich / ETH, Switzerland.
21 **/
23 package ini.trakem2.display;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.util.ArrayList;
30 import java.util.Iterator;
31 import java.util.Collection;
33 /** A class to be used when a click to select Displayable objects on the Display detects that there are more than one under the mouse cursor.
37 public final class DisplayableChooser implements ActionListener {
39 protected Collection al_under;
40 protected boolean waiting = true;
41 protected Displayable chosen = null;
42 private Object lock;
44 public DisplayableChooser(Collection al_under, Object lock) {
45 this.al_under = al_under;
46 this.lock = lock;
49 public void actionPerformed(final ActionEvent ae) {
50 String command = ae.getActionCommand();
51 //find the object that has the command as title
52 final Iterator it = al_under.iterator();
53 while (it.hasNext()) {
54 final Displayable d = (Displayable)it.next();
55 if (d.toString().equals(command)) {
56 chosen = d;
57 break;
60 //no more waiting!
61 synchronized(this.lock) {
62 this.lock.notifyAll();
63 waiting = false;
67 public boolean isWaiting() {
68 return this.waiting;
71 public Displayable getChosen() {
72 return this.chosen;