summaryrefslogtreecommitdiffstats
path: root/src/demos
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-08-14 18:02:54 +0000
committerKenneth Russel <[email protected]>2005-08-14 18:02:54 +0000
commit176c245639ff00c9254751bcc860b842e003ed6b (patch)
treec00617b5335950e2add6ae52cd2ad2886dafd37b /src/demos
parent49ae3a22cb0f12f93a3ebbff68407876a1aa4f99 (diff)
Restructured Animator to handle multiple GLAutoDrawables and to yield
CPU within animation loop (configurable by overriding sync()). Added FPSAnimator subclass. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/../svn-server-sync/jogl-demos/branches/JSR-231@112 3298f667-5e0e-4b4a-8ed4-a3559d26a5f4
Diffstat (limited to 'src/demos')
-rwxr-xr-xsrc/demos/jrefract/JRefract.java48
1 files changed, 6 insertions, 42 deletions
diff --git a/src/demos/jrefract/JRefract.java b/src/demos/jrefract/JRefract.java
index d0686a6..5b8e4c1 100755
--- a/src/demos/jrefract/JRefract.java
+++ b/src/demos/jrefract/JRefract.java
@@ -70,10 +70,8 @@ import demos.vertexProgWarp.VertexProgWarp;
public class JRefract {
private boolean useRegisterCombiners;
- private ArrayList canvases;
- private volatile boolean quit;
- private volatile boolean animatorStopped;
+ private Animator animator;
private JDesktopPane desktop;
public static void main(String[] args) {
@@ -251,8 +249,6 @@ public class JRefract {
public void run(String[] args) {
- canvases = new ArrayList();
-
JFrame frame = new JFrame("JOGL and Swing Interoperability");
desktop = new JDesktopPane();
desktop.setSize(1024, 768);
@@ -365,7 +361,8 @@ public class JRefract {
frame.setSize(desktop.getSize());
frame.setVisible(true);
- new Thread(new ListAnimator()).start();
+ animator = new Animator();
+ animator.start();
}
private void runExit() {
@@ -376,51 +373,18 @@ public class JRefract {
// the exit routine in another thread.
new Thread(new Runnable() {
public void run() {
- quit = true;
- while (!animatorStopped) {
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- }
- }
+ animator.stop();
System.exit(0);
}
}).start();
}
private synchronized void addJPanel(GLJPanel panel) {
- ArrayList newCanvases = (ArrayList) canvases.clone();
- newCanvases.add(panel);
- canvases = newCanvases;
+ animator.add(panel);
}
private synchronized void removeJPanel(GLJPanel panel) {
- ArrayList newCanvases = (ArrayList) canvases.clone();
- newCanvases.remove(panel);
- canvases = newCanvases;
- }
-
- class ListAnimator implements Runnable {
- public void run() {
- while (!quit) {
- if (canvases.isEmpty()) {
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- }
- } else {
- for (Iterator iter = canvases.iterator(); iter.hasNext(); ) {
- GLJPanel panel = (GLJPanel) iter.next();
- panel.display();
- }
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- }
- }
- }
- animatorStopped = true;
- }
+ animator.remove(panel);
}
private JInternalFrame curFrame;