Fixes to homogenizeContrast
[trakem2.git] / ini / trakem2 / display / AbstractOffscreenThread.java
blob9b719ef38428db7056f5fe29010d580835317b0a
1 /**
3 TrakEM2 plugin for ImageJ(C).
4 Copyright (C) 2007 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;
25 import java.util.concurrent.atomic.AtomicBoolean;
26 import ini.trakem2.utils.IJError;
28 /** To be used in combination with the AbstractRepaintThread, as a thread to create graphics offscreen.*/
29 public abstract class AbstractOffscreenThread extends Thread {
31 protected RepaintProperties rp = null;
32 private AtomicBoolean mustRepaint = new AtomicBoolean(false);
34 AbstractOffscreenThread(String name) {
35 super(name);
36 setPriority(Thread.NORM_PRIORITY);
37 try { setDaemon(true); } catch (Exception e) { e.printStackTrace(); }
38 start();
41 public void setProperties(final RepaintProperties rp) {
42 synchronized (this) {
43 this.rp = rp;
44 this.mustRepaint.set(true);
45 notify();
49 public void run() {
50 while (!isInterrupted()) {
51 try {
52 if (mustRepaint.getAndSet(false)) {
53 paint();
54 } else {
55 synchronized (this) {
56 try { wait(); } catch (InterruptedException ie) {}
59 } catch (Exception e) {
60 IJError.print(e);
65 public void waitOnRepaintCycle() {
66 while (mustRepaint.get()) {
67 try { Thread.sleep(500); } catch (InterruptedException ie) {}
71 public abstract void paint();
73 protected interface RepaintProperties {}