From d564baa691d5852c4d5abe47d3a8150688e1af2e Mon Sep 17 00:00:00 2001 From: benfry Date: Sat, 5 Feb 2005 22:01:55 +0000 Subject: [PATCH] swing working now working with no swing --- processing/core/PApplet.java | 153 +++++++++++++---------------------- 1 file changed, 58 insertions(+), 95 deletions(-) diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index 519a664fa..ca5998110 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -4286,115 +4286,78 @@ public class PApplet extends Applet value = x; } - /** - * Compute the value to be returned by the get method. - */ - //public abstract Object construct(); - public Object construct() { - //while ((Thread.currentThread() == this) && !finished) { - try { - // is this what's causing all the trouble? - int anything = System.in.read(); - if (anything == EXTERNAL_STOP) { - //System.out.println("********** STOPPING"); + public Object construct() { + try { + int anything = System.in.read(); + if (anything == EXTERNAL_STOP) { - // adding this for 0073.. need to stop libraries - // when the stop button is hit. - PApplet.this.stop(); + // adding this for 0073.. need to stop libraries + // when the stop button is hit. + PApplet.this.stop(); + finished = true; + } + } catch (IOException e) { + finished = true; + } + try { + Thread.sleep(250); + //Thread.sleep(100); // kick up latency for 0075? + } catch (InterruptedException e) { } + return null; + } - //System.out.println("********** REALLY"); - finished = true; - } - } catch (IOException e) { - // not tested (needed?) but seems correct - //stop(); - finished = true; - //thread = null; - } - try { - Thread.sleep(250); - //Thread.sleep(100); // kick up latency for 0075? - } catch (InterruptedException e) { } + // removing this from SwingWorker + //public void finished() { } + + public void interrupt() { + Thread t = workerVar.get(); + if (t != null) { + t.interrupt(); + } + workerVar.clear(); + } + + public Object get() { + while (true) { + Thread t = workerVar.get(); + if (t == null) { + return getValue(); + } + try { + t.join(); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); // propagate return null; } - - /** - * Called on the event dispatching thread (not on the worker thread) - * after the construct method has returned. - */ - public void finished() { + } } - /** - * A new method that interrupts the worker thread. Call this method - * to force the worker to stop what it's doing. - */ - public void interrupt() { - Thread t = workerVar.get(); - if (t != null) { - t.interrupt(); - } - workerVar.clear(); - } - - /** - * Return the value created by the construct method. - * Returns null if either the constructing thread or the current - * thread was interrupted before a value was produced. - * - * @return the value created by the construct method - */ - public Object get() { - while (true) { - Thread t = workerVar.get(); - if (t == null) { - return getValue(); - } - try { - t.join(); - } - catch (InterruptedException e) { - Thread.currentThread().interrupt(); // propagate - return null; - } - } - } - - - /** - * Start a thread that will call the construct method - * and then exit. - */ public Worker() { - final Runnable doFinished = new Runnable() { - public void run() { finished(); } - }; + // removing this from SwingWorker + //final Runnable doFinished = new Runnable() { + // public void run() { finished(); } + // }; - Runnable doConstruct = new Runnable() { - public void run() { - try { - setValue(construct()); - } - finally { - workerVar.clear(); - } + Runnable doConstruct = new Runnable() { + public void run() { + try { + setValue(construct()); - javax.swing.SwingUtilities.invokeLater(doFinished); + } finally { + workerVar.clear(); } + // removing this from SwingWorker to avoid swing + //javax.swing.SwingUtilities.invokeLater(doFinished); + } }; - Thread t = new Thread(doConstruct); - workerVar = new WorkerVar(t); + Thread t = new Thread(doConstruct); + workerVar = new WorkerVar(t); } - /** - * Start the worker thread. - */ public void start() { - Thread t = workerVar.get(); - if (t != null) { - t.start(); - } + Thread t = workerVar.get(); + if (t != null) t.start(); } } @@ -4414,7 +4377,7 @@ public class PApplet extends Applet // adding this for 0073.. need to stop libraries // when the stop button is hit. - PApplet.this.stop(); +v PApplet.this.stop(); //System.out.println("********** REALLY"); finished = true;