1 /**
2  * Copyright 2011 JogAmp Community. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are
5  * permitted provided that the following conditions are met:
6  *
7  *    1. Redistributions of source code must retain the above copyright notice, this list of
8  *       conditions and the following disclaimer.
9  *
10  *    2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *       of conditions and the following disclaimer in the documentation and/or other materials
12  *       provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * The views and conclusions contained in the software and documentation are those of the
25  * authors and should not be interpreted as representing official policies, either expressed
26  * or implied, of JogAmp Community.
27  */
28 
29 package jogamp.opengl;
30 
31 import java.util.ArrayList;
32 
33 /**
34  * Simple locked listener implementation stub to be used for listener handler,
35  * synchronized on it's instance.
36  *
37  * <p>Utilizing simple locking via synchronized.</p>
38  *
39  * @param <E> The listener type
40  */
41 public class ListenerSyncedImplStub<E> {
42   private ArrayList<E> listeners;
43 
ListenerSyncedImplStub()44   public ListenerSyncedImplStub() {
45     reset();
46   }
47 
reset()48   public synchronized final void reset() {
49     listeners = new ArrayList<E>();
50   }
51 
destroy()52   public synchronized final void destroy() {
53     listeners.clear();
54     listeners = null;
55   }
56 
size()57   public synchronized final int size() {
58     return listeners.size();
59   }
60 
addListener(final E listener)61   public synchronized final void addListener(final E listener) {
62     addListener(-1, listener);
63   }
64 
addListener(int index, final E listener)65   public synchronized final void addListener(int index, final E listener) {
66     if(0>index) {
67         index = listeners.size();
68     }
69     listeners.add(index, listener);
70   }
71 
removeListener(final E listener)72   public synchronized final void removeListener(final E listener) {
73     listeners.remove(listener);
74   }
75 
getListeners()76   public final ArrayList<E> getListeners() {
77       return listeners;
78   }
79 }
80