Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

j3dcore: use annotated ArrayList of AWTEvents in WakeupOnAWTEvent

Make the locking explicit where used.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
  • Loading branch information...
commit f38135af0a367cbfacf34bf2de29f2f87ecd15b0 1 parent bdf8d52
@hharrison authored
Showing with 12 additions and 16 deletions.
  1. +12 −16 src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java
View
28 src/classes/share/javax/media/j3d/WakeupOnAWTEvent.java
@@ -36,7 +36,7 @@
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 @@
int AwtId;
long EventMask;
long enableAWTEventTS = 0L;
- Vector events = new Vector();
+final ArrayList<AWTEvent> events = new ArrayList<AWTEvent>();
/**
* Constructs a new WakeupOnAWTEvent object that informs the Java 3D
@@ -84,28 +84,24 @@ public WakeupOnAWTEvent(long eventMask) {
* @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
Please sign in to comment.
Something went wrong with that request. Please try again.