From f38135af0a367cbfacf34bf2de29f2f87ecd15b0 Mon Sep 17 00:00:00 2001 From: Harvey Harrison Date: Mon, 20 Feb 2012 19:20:15 -0800 Subject: j3dcore: use annotated ArrayList of AWTEvents in WakeupOnAWTEvent Make the locking explicit where used. Signed-off-by: Harvey Harrison --- .../share/javax/media/j3d/WakeupOnAWTEvent.java | 28 ++++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) (limited to 'src/classes') diff --git a/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java b/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java index de85870..e250889 100644 --- a/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java +++ b/src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java @@ -36,7 +36,7 @@ import java.awt.event.ComponentEvent; import java.awt.event.FocusEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; -import java.util.Vector; +import java.util.ArrayList; /** * Class that specifies a Behavior wakeup when a specific AWT event occurs. @@ -53,7 +53,7 @@ public final class WakeupOnAWTEvent extends WakeupCriterion { int AwtId; long EventMask; long enableAWTEventTS = 0L; - Vector events = new Vector(); +final ArrayList events = new ArrayList(); /** * Constructs a new WakeupOnAWTEvent object that informs the Java 3D @@ -84,28 +84,24 @@ public final class WakeupOnAWTEvent extends WakeupCriterion { * @return either null (if not resposible for wakeup) or the array of * AWTEvents responsible for the wakeup. */ - public AWTEvent[] getAWTEvent(){ - AWTEvent eventArray[]; - +public AWTEvent[] getAWTEvent() { synchronized (events) { - eventArray = new AWTEvent[events.size()]; - events.copyInto(eventArray); - events.removeAllElements(); + AWTEvent[] eventArray = events.toArray(new AWTEvent[events.size()]); + events.clear(); + return eventArray; } - - return eventArray; - } - +} /** * Sets the AWT event that will cause a behavior wakeup. * @param event The event causing this wakeup */ - void addAWTEvent(AWTEvent event){ - events.addElement(event); +void addAWTEvent(AWTEvent event) { + synchronized (events) { + events.add(event); + } this.setTriggered(); - } - +} /** * This is a callback from BehaviorStructure. It is -- cgit v1.2.3