Hello,
I'm wondering if anyone can shed some light on the following behavior for
me. I've created a test program (below) that creates 3 behaviors. One
posts a notification, and the other two (what I call ReceivePostBehaviors)
listen for it. The two ReceivePostBehaviors differ in that one's wakeup
condition is a WakeupOr composed of a WakeupOnBehaviorPost and a
WakeupOnAWTEvent (mouse clicked) (call this behavior #1), and the other's
wakeup condition is simply a WakeupOnBehaviorPost (call this behavior #2).
In the program, I disable the two ReceivePostBehaviors and then have the
PostBehavior post its message. Then I sleep for 3 seconds and afterwards
enable the two ReceivePostBehaviors. I would expect the
WakeupOnBehaviorPost sent by the PostBehavior to be lost to both
ReceivePostBehaviors, since both are disabled at the time the PostBehavior
posts.
What instead happens is that when I click on the screen after the 3 seconds
have elapsed, #1 receives the mouse click notification AND the
WakeupOnBehaviorPost from the PostBehavior. #2 does not receive the
WakeupOnBehaviorPost. I don't get it. Why is the WakeupOnBehaviorPost
being queued and delivered later to #1?
Below is the test program. Also notice that you can click on the screen
before the 3 second wait period has expired, and no WakeupOnAWTEvents are
delivered to #1. Those messages are lost, why aren't the
WakeupOnPostBehaviors lost as well?
Thanks for any insight,
Peter
// TEST PROGRAM
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.media.j3d.*;
import javax.swing.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
public class Test
extends JFrame
{
private Behavior receive1;
private Behavior receive2;
private PostBehavior post1;
public static void main(String[] args)
{
Test test = new Test();
test.setVisible(true);
}
public Test()
{
super();
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas = new Canvas3D(config);
SimpleUniverse simpleU = new SimpleUniverse(canvas);
simpleU.getViewingPlatform().setNominalViewingTransform();
BranchGroup contentBranch = createContentBranch();
simpleU.addBranchGraph(contentBranch);
this.getContentPane().setLayout(new BorderLayout());
this.getContentPane().add("Center", canvas);
this.setSize(300, 300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ExecThread execThread = new ExecThread();
execThread.start();
}
private BranchGroup createContentBranch()
{
BranchGroup contentBranch = new BranchGroup();
TransformGroup tg = new TransformGroup();
WakeupOnAWTEvent wakeup1 =
new WakeupOnAWTEvent(java.awt.event.MouseEvent.MOUSE_CLICKED);
WakeupOnBehaviorPost wakeup2 =
new WakeupOnBehaviorPost(post1, PostBehavior.ID);
WakeupCriterion[] criteria = { wakeup1, wakeup2 };
WakeupOr wakeupOr = new WakeupOr(criteria);
receive1 = new ReceivePostBehavior(1, wakeupOr);
WakeupOnBehaviorPost wakeup3 =
new WakeupOnBehaviorPost(post1, PostBehavior.ID);
receive2 = new ReceivePostBehavior(2, wakeup3);
post1 = new PostBehavior();
Bounds bounds = new BoundingSphere();
post1.setSchedulingBounds(bounds);
receive1.setSchedulingBounds(bounds);
receive2.setSchedulingBounds(bounds);
// will all be enabled by exec thread
receive1.setEnable(false);
receive2.setEnable(false);
post1.setEnable(false);
tg.addChild(post1);
tg.addChild(receive1);
tg.addChild(receive2);
contentBranch.addChild(tg);
return contentBranch;
}
private class ExecThread
extends Thread
{
public void run()
{
try
{
post1.setEnable(true);
int sleepTime = 3000;
Thread.sleep(sleepTime);
System.out.println("slept " + sleepTime);
receive1.setEnable(true);
receive2.setEnable(true);
}
catch (InterruptedException ie)
{
ie.printStackTrace();
}
}
}
private class PostBehavior
extends Behavior
{
private static final int ID = 1;
private WakeupCriterion firstFrame;
private PostBehavior()
{
firstFrame = new WakeupOnElapsedFrames(0);
}
public void initialize()
{
wakeupOn(firstFrame);
}
public void processStimulus(Enumeration enumeration)
{
System.out.println("posting");
postId(ID);
}
}
private class ReceivePostBehavior
extends Behavior
{
private int id;
private WakeupCondition wakeup;
private ReceivePostBehavior(int id, WakeupCondition wakeup)
{
this.id = id;
this.wakeup = wakeup;
}
public void initialize()
{
wakeupOn(wakeup);
}
public void processStimulus(Enumeration enumeration)
{
System.out.println("awoken: " + id);
while (enumeration.hasMoreElements())
{
Object element = enumeration.nextElement();
System.out.println("wakeup type: " + element);
if (element instanceof WakeupOnBehaviorPost)
{
System.out.println("disabling");
setEnable(false);
}
wakeupOn(wakeup);
}
}
}
}
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".