summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Bien <[email protected]>2009-09-16 23:49:33 +0200
committerMichael Bien <[email protected]>2009-09-16 23:49:33 +0200
commit9fe768e87aa5adafce88f81d333f260191da5fe9 (patch)
treed75371e4dc0c00d1be3a077f3b79bb59fb134c9c
parent38a4d23ff05e4fc59775cc5ea961497197bd2e50 (diff)
fixed EDT deadlock in redbook applet
-rw-r--r--src/redbook/preview-applet.html1
-rw-r--r--src/redbook/src/glredbook/JOGLApplet.java39
2 files changed, 30 insertions, 10 deletions
diff --git a/src/redbook/preview-applet.html b/src/redbook/preview-applet.html
index d2c6c4b..8fcc655 100644
--- a/src/redbook/preview-applet.html
+++ b/src/redbook/preview-applet.html
@@ -111,7 +111,6 @@
<option value='glredbook10.scenebamb' selected>glredbook10.scenebamb
<option value='glredbook10.sceneflat' selected>glredbook10.sceneflat
<option value='glredbook10.select' selected>glredbook10.select
- <option value='glredbook10.simple' selected>glredbook10.simple
<option value='glredbook10.smooth' selected>glredbook10.smooth
<option value='glredbook10.sphere' selected>glredbook10.sphere
<option value='glredbook10.stencil' selected>glredbook10.stencil
diff --git a/src/redbook/src/glredbook/JOGLApplet.java b/src/redbook/src/glredbook/JOGLApplet.java
index d11deac..4c0f833 100644
--- a/src/redbook/src/glredbook/JOGLApplet.java
+++ b/src/redbook/src/glredbook/JOGLApplet.java
@@ -5,9 +5,10 @@ import java.awt.Component;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JApplet;
+import javax.swing.SwingUtilities;
/**
- *
+ * Slideshow applet for iterating through the red book samples.
* @author michael-bien.com
*/
public class JOGLApplet extends JApplet {
@@ -16,6 +17,7 @@ public class JOGLApplet extends JApplet {
@Override
public void start() {
+ //start a default sample
String className = getParameter("demo");
loadDemo(className);
}
@@ -27,15 +29,21 @@ public class JOGLApplet extends JApplet {
}
}
- private Logger log() {
- return Logger.getLogger(JOGLApplet.class.getName());
- }
-
+ /*
+ * called via javascript
+ */
public void loadDemo(String className) {
if (skeleton != null) {
skeleton.runExit();
- remove((Component) skeleton.drawable);
+
+ // remove old drawable on EDT
+ SwingUtilities.invokeLater(new Runnable() {
+ final Component drawable = (Component)skeleton.drawable;
+ public void run() {
+ remove(drawable);
+ }
+ });
}
log().info("i'll try to instantiate: " + className);
@@ -47,9 +55,18 @@ public class JOGLApplet extends JApplet {
try {
skeleton = (GLSkeleton<?>) clazz.newInstance();
System.out.println(skeleton);
- add((Component) skeleton.drawable);
- System.out.println("added");
- validate();
+
+ // add new drawable on EDT
+ SwingUtilities.invokeLater(new Runnable() {
+ final GLSkeleton<?> s = skeleton;
+ public void run() {
+ if(skeleton == s) {
+ add((Component) s.drawable);
+ System.out.println("added");
+ validate();
+ }
+ }
+ });
} catch (InstantiationException ex) {
log().log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
@@ -61,4 +78,8 @@ public class JOGLApplet extends JApplet {
log().log(Level.SEVERE, "can't find main class", ex);
}
}
+
+ private Logger log() {
+ return Logger.getLogger(JOGLApplet.class.getName());
+ }
}