Uwe Trostheide wrote:
> In the first line of your source-code you write
>
> "public class MouseSelectBehaviour extends MouseClickBehaviour"
>
> Well, i can not find the class MouseClickBehaviour anywhere. Is it a
> custom class as well ? And if so, whats the purpose of it ?
Here they are. There's two classes MouseClickBehaviour extends
MouseBehaviour. Hope these are useful too :)
--
Justin Couch Author, Java Hacker
Snr Software Engineer [EMAIL PROTECTED]
ADI Ltd, Systems Group http://www.vlc.com.au/~justin/
Java3D FAQ: http://tintoy.ncsa.uiuc.edu/~srp/java3d/faq.html
-------------------------------------------------------------------
"Look through the lens, and the light breaks down into many lights.
Turn it or move it, and a new set of arrangements appears... is it
a single light or many lights, lights that one must know how to
distinguish, recognise and appreciate? Is it one light with many
frames or one frame for many lights?" -Subcomandante Marcos
-------------------------------------------------------------------
// no package
// Standard imports
import javax.media.j3d.*;
import java.awt.AWTEvent;
import java.util.Enumeration;
import javax.vecmath.Point3d;
// Application specific imports
// none
/**
* Behaviour class illustrating the use of Mouse input behaviour.
* <P>
* The basic behaviour registers for the types of events needed.
*
* @author Justin Couch
* @version Who Cares!
*/
public abstract class MouseBehaviour extends Behavior
{
/** The event mask of the events needed */
private int[] event_masks;
private WakeupCondition critters = null;
/**
* Construct the test behaviour. Initally, nothing will be registered.
*
*/
protected MouseBehaviour(int[] awtEventMasks)
{
if(awtEventMasks == null || awtEventMasks.length == 0)
throw new IllegalArgumentException("No event masks defined");
event_masks = awtEventMasks;
}
/**
* Initialise the class to deal with all the AWT events nominated in the
* constructor. These events are |'ed together for criteria.
*/
public void initialize()
{
int i;
int size = event_masks.length;
WakeupCriterion[] events = new WakeupCriterion[size];
for(i = 0; i < size; i++)
events[i] = new WakeupOnAWTEvent(event_masks[i]);
critters = new WakeupOr(events);
resetEvents();
}
/**
* Re register the mouse events as defined in the constructor
*/
protected final void resetEvents()
{
wakeupOn(critters);
}
/**
* Process the given AWT Event. Derived classes must implement this method
* to provide the correct behaviour for a particular mouse event type.
*
* @param evt The event to be processed
*/
protected abstract void processAWTEvent(AWTEvent evt);
/**
* Process the event that caused this behaviour to be executed.
*
* @param criteria The list of criteria that caused this stimulus
*/
public void processStimulus(Enumeration criteria)
{
WakeupCondition cond;
AWTEvent[] events;
while(criteria.hasMoreElements())
{
cond = (WakeupCondition)criteria.nextElement();
if(!(cond instanceof WakeupOnAWTEvent))
continue;
events = ((WakeupOnAWTEvent)cond).getAWTEvent();
for(int i = 0; i < events.length; i++)
{
try
{
processAWTEvent(events[i]);
}
catch(Exception e)
{
System.out.println("Error processing AWT event input");
e.printStackTrace();
}
}
}
}
}
// no package
// Standard imports
import javax.media.j3d.*;
import java.awt.AWTEvent;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import javax.vecmath.Point3d;
// Application specific imports
// none
/**
* Behaviour class illustrating the use of Mouse input behaviour.
* <P>
* The basic behaviour registers for the types of events needed.
*
* @author Justin Couch
* @version Who Cares!
*/
public class MouseClickBehaviour extends MouseBehaviour
{
private static final int[] AWT_EVENTS = {
MouseEvent.MOUSE_CLICKED
};
/**
* Construct the test behaviour. Initally, nothing will be registered.
*
*/
public MouseClickBehaviour()
{
super(AWT_EVENTS);
}
/**
* Process the given AWT Event. Derived classes must implement this method
* to provide the correct behaviour for a particular mouse event type.
*
* @param evt The event to be processed
*/
protected void processAWTEvent(AWTEvent evt)
{
System.out.println("got mouse event");
resetEvents();
}
}